| 1 |
/************************************************************************************************************
|
| 2 |
//ELMS: Outline Designer - Usability improvements for speedy outline creation in Drupal 6.x
|
| 3 |
//Copyright (C) 2008 The Pennsylvania State University
|
| 4 |
//
|
| 5 |
//Bryan Ollendyke
|
| 6 |
//bto108@psu.edu
|
| 7 |
//
|
| 8 |
//Keith D. Bailey
|
| 9 |
//kdb163@psu.edu
|
| 10 |
//
|
| 11 |
//12 Borland
|
| 12 |
//University Park, PA 16802
|
| 13 |
//
|
| 14 |
//This program is free software; you can redistribute it and/or modify
|
| 15 |
//it under the terms of the GNU General Public License as published by
|
| 16 |
//the Free Software Foundation; either version 2 of the License, or
|
| 17 |
//(at your option) any later version.
|
| 18 |
//
|
| 19 |
//This program is distributed in the hope that it will be useful,
|
| 20 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 21 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 22 |
//GNU General Public License for more details.
|
| 23 |
//
|
| 24 |
//You should have received a copy of the GNU General Public License along
|
| 25 |
//with this program; if not, write to the Free Software Foundation, Inc.,
|
| 26 |
//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 27 |
|
| 28 |
************************************************************************************************************/
|
| 29 |
//This script will only be applied tothe admin/content/book page
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Get rid of irritating tabledrag messages
|
| 33 |
*/
|
| 34 |
Drupal.theme.tableDragChangedWarning = function () {
|
| 35 |
return ' ';
|
| 36 |
};
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Set up the document by appending some additional elements to the page
|
| 40 |
*/
|
| 41 |
$(document).ready(function(){
|
| 42 |
//add area for status messages to float
|
| 43 |
//add the hidden modal for adding a child
|
| 44 |
//add area for type change modal
|
| 45 |
$("body").append('<div id="od_duplicate_node"><input type="checkbox" id="od_duplicate_multiple" />Duplicate all children<br /><br />How should the new title be formed?<input type="textfield" id="od_duplicate_title" value="Duplicate of %title" /><br /><br /><input type="button" name="Submit" value="Submit" onclick="od_duplicate_submit();" /><input type="button" name="Cancel" value="Cancel" onclick="tb_remove();' + "$('#od_duplicate_node').css('display','none').appendTo('body');" + '" /></div><div id="od_delete_node"><input type="checkbox" id="od_delete_multiple" />Delete all children<br /><br /><input type="button" name="Submit" value="Submit" onclick="od_delete_submit();" /><input type="button" name="Cancel" value="Cancel" onclick="tb_remove();' + "$('#od_delete_node').css('display','none').appendTo('body');" + '" /></div> <div id="od_status_msg" align="center"></div><div id="tb_ajax"></div><div id="od_change_type"><input type="button" value="Submit" id="od_change_type_submit"/> <input type="button" value="Cancel" id="od_change_type_cancel" /></div><div id="od_add_child"><div><strong>Title: </strong><input size="30" type="text" id="od_add_child_title" name="od_add_child_title"></div><div id="od_wrapper"><div id="od_content_types">'+ od_content_types() +'</div><div><input type="button" value="Submit" id="od_add_child_submit"/> <input type="button" value="Cancel" id="od_add_child_cancel" /></div></div></div>');
|
| 46 |
$("#od_content_types input").val([BOOK_DEFAULT_TYPE]);
|
| 47 |
//ADD CHILD EVENTS
|
| 48 |
$("#od_add_child_title").bind('keyup',function(e){
|
| 49 |
$("#TB_ajaxWindowTitle span").empty().append($("#od_add_child_title").val());
|
| 50 |
});
|
| 51 |
$("#od_content_types input").bind("click",function(e){
|
| 52 |
active_type = $(this).val();
|
| 53 |
$("#TB_ajaxWindowTitle img").attr('src',DRUPAL_PATH + OD_TYPES[$(this).val()][1]);
|
| 54 |
});
|
| 55 |
//if you hit enter, submit the title; if you hit esc then reset the field
|
| 56 |
$('#od_add_child_title').bind('keydown',function(e){
|
| 57 |
if(document.all)e = event;
|
| 58 |
if(e.keyCode==13){ // Enter pressed
|
| 59 |
od_add_child_submit();
|
| 60 |
return false;
|
| 61 |
}
|
| 62 |
if(e.keyCode==27){ // ESC pressed
|
| 63 |
od_add_child_tb_close();
|
| 64 |
}
|
| 65 |
});
|
| 66 |
$("#od_add_child_submit").bind("click",function(e){
|
| 67 |
od_add_child_submit();
|
| 68 |
});
|
| 69 |
$("#od_add_child_cancel").bind("click",function(e){
|
| 70 |
od_add_child_tb_close();
|
| 71 |
});
|
| 72 |
//change type events
|
| 73 |
$("#od_change_type_submit").bind("click",function(e){
|
| 74 |
od_change_type_submit();
|
| 75 |
});
|
| 76 |
$("#od_change_type_cancel").bind("click",function(e){
|
| 77 |
od_change_type_tb_close();
|
| 78 |
});
|
| 79 |
//add ability to scale interface
|
| 80 |
$("#book-admin-edit").parent().prepend('<div style="width:120px;" class="context-menu context-menu-theme-human"><div title="" class="context-menu-item"><div style="background-image: url('+ OD_PATH +'images/add.png);" class="context-menu-item-inner" onclick="active_nid='+ ROOT_NID +';od_add_child();">Add Child</div></div></div>Interface Size: <a href="#" onclick="scale_outline_designer(-1);">Smaller</a> <a href="#" onclick="scale_outline_designer(1);">Bigger</a> <a href="#" onclick="scale_outline_designer(0);">Reset</a> ');
|
| 81 |
});
|
| 82 |
/**
|
| 83 |
* behaviors specific to the outline designer for overloading functions
|
| 84 |
*/
|
| 85 |
Drupal.behaviors.outline_designer = function (context) {
|
| 86 |
$("#book-outline th:last").css('display','none');
|
| 87 |
$("tr.draggable td").each(function(i){
|
| 88 |
if((i+1) % 6 == 0 || (i+1) % 6 == 4 || (i+1) % 6 == 5) {
|
| 89 |
this.style.display = 'none';
|
| 90 |
}
|
| 91 |
});
|
| 92 |
//replace text fields with span's w/ their same content
|
| 93 |
if (context != "#TB_ajaxContent") {
|
| 94 |
$("#book-outline .form-text").each(function(){
|
| 95 |
$(this).css('display','none');
|
| 96 |
$(this).parent().append('<span id="'+ $(this).attr('id') +'-span">' + $(this).val() + '</span>');
|
| 97 |
});
|
| 98 |
//whenever you doubleclick on a title, switch it to the rename state
|
| 99 |
$("#book-outline span").bind('dblclick',function(e){
|
| 100 |
active_nid = $(this).attr('id').replace("edit-table-book-admin-","").replace("-title-span","");
|
| 101 |
od_rename();
|
| 102 |
});
|
| 103 |
//whenever you aren't active on a field, remove it
|
| 104 |
$('#book-outline input').blur(function(){
|
| 105 |
od_rename_reset();
|
| 106 |
});
|
| 107 |
//if you hit enter, submit the title; if you hit esc then reset the field
|
| 108 |
$('#book-outline input').bind('keydown',function(e){
|
| 109 |
if(document.all)e = event;
|
| 110 |
if(e.keyCode==13){ // Enter pressed
|
| 111 |
od_rename_submit();
|
| 112 |
return false;
|
| 113 |
}
|
| 114 |
if(e.keyCode==27){ // ESC pressed
|
| 115 |
od_rename_reset();
|
| 116 |
}
|
| 117 |
});
|
| 118 |
//set the active node id everytime an edit icon is clicked on
|
| 119 |
$('.outline_designer_edit_button').bind('click',function(e){
|
| 120 |
active_nid = $(this).attr('id').replace("-"," ").substring(5);
|
| 121 |
});
|
| 122 |
//bind the context menu and set it's properties
|
| 123 |
//binding isn't working in Opera / IE correctly or at all
|
| 124 |
$('.outline_designer_edit_button').contextMenu(menu1,{theme:'human',
|
| 125 |
beforeShow: function() {
|
| 126 |
$(this.menu).find('.context-menu-item-inner:first').css('backgroundImage','url(' + $("#node-" + active_nid +"-icon").attr('src') +')').empty().append("node " + active_nid);
|
| 127 |
},
|
| 128 |
showSpeed:250,
|
| 129 |
hideSpeed:250,
|
| 130 |
showTransition:'fadeIn',
|
| 131 |
hideTransition:'slideUp',
|
| 132 |
useIframe:false,
|
| 133 |
direction:'down',
|
| 134 |
offsetX:-5,
|
| 135 |
offsetY:-10,
|
| 136 |
shadowOffsetX:8,
|
| 137 |
shadowOffsetY:18,
|
| 138 |
shadowOpacity:.1,
|
| 139 |
});
|
| 140 |
/**
|
| 141 |
* Overload tabledrag onDrop event so that it ajax saves the new parent for the node
|
| 142 |
*/
|
| 143 |
Drupal.tableDrag.prototype.onDrop = function() {
|
| 144 |
//row object so we don't have to call it all the time
|
| 145 |
var row_obj = this.rowObject.element;
|
| 146 |
//get the id of what was dragged
|
| 147 |
var drag_nid = $(row_obj).find('img').attr('id').replace('node-','').replace('-icon','');
|
| 148 |
//get the parent id based on the indentations, this equation is a bit evil...
|
| 149 |
var p_nid;
|
| 150 |
var weight = $("#edit-table-book-admin-"+ drag_nid +"-weight").val();
|
| 151 |
var active_indent = Math.max($('.indentation', row_obj).size());
|
| 152 |
//if we're at level 0 then the node is at the book root
|
| 153 |
if(active_indent != 0){
|
| 154 |
var tmp_indent = -1;
|
| 155 |
var tmp_obj = row_obj;
|
| 156 |
//keep walking backwards until we find the node we need
|
| 157 |
while (tmp_indent != (active_indent-1) ) {
|
| 158 |
tmp_obj = $(tmp_obj).prev();
|
| 159 |
tmp_indent = Math.max($('.indentation', tmp_obj).size());
|
| 160 |
}
|
| 161 |
p_nid = $(tmp_obj).find('img').attr('id').replace('node-','').replace('-icon','');
|
| 162 |
} else {
|
| 163 |
p_nid = ROOT_NID;
|
| 164 |
}
|
| 165 |
$.ajax({
|
| 166 |
type: "POST",
|
| 167 |
url: AJAX_PATH + "drag_drop/" + drag_nid + "/" + p_nid + "/" + weight,
|
| 168 |
success: function(msg){
|
| 169 |
//could implement some kind of history / undo list here if we want to
|
| 170 |
od_response_msg(msg);
|
| 171 |
}
|
| 172 |
});
|
| 173 |
return null;
|
| 174 |
};
|
| 175 |
/**
|
| 176 |
* Annoying but we need to override this entire function to attach the ajax event for submitting weights behind the sceens
|
| 177 |
*/
|
| 178 |
Drupal.tableDrag.prototype.updateField = function(changedRow, group) {
|
| 179 |
var rowSettings = this.rowSettings(group, changedRow);
|
| 180 |
|
| 181 |
// Set the row as it's own target.
|
| 182 |
if (rowSettings.relationship == 'self' || rowSettings.relationship == 'group') {
|
| 183 |
var sourceRow = changedRow;
|
| 184 |
}
|
| 185 |
// Siblings are easy, check previous and next rows.
|
| 186 |
else if (rowSettings.relationship == 'sibling') {
|
| 187 |
var previousRow = $(changedRow).prev('tr').get(0);
|
| 188 |
var nextRow = $(changedRow).next('tr').get(0);
|
| 189 |
var sourceRow = changedRow;
|
| 190 |
if ($(previousRow).is('.draggable') && $('.' + group, previousRow).length) {
|
| 191 |
if (this.indentEnabled) {
|
| 192 |
if ($('.indentations', previousRow).size() == $('.indentations', changedRow)) {
|
| 193 |
sourceRow = previousRow;
|
| 194 |
}
|
| 195 |
}
|
| 196 |
else {
|
| 197 |
sourceRow = previousRow;
|
| 198 |
}
|
| 199 |
}
|
| 200 |
else if ($(nextRow).is('.draggable') && $('.' + group, nextRow).length) {
|
| 201 |
if (this.indentEnabled) {
|
| 202 |
if ($('.indentations', nextRow).size() == $('.indentations', changedRow)) {
|
| 203 |
sourceRow = nextRow;
|
| 204 |
}
|
| 205 |
}
|
| 206 |
else {
|
| 207 |
sourceRow = nextRow;
|
| 208 |
}
|
| 209 |
}
|
| 210 |
}
|
| 211 |
// Parents, look up the tree until we find a field not in this group.
|
| 212 |
// Go up as many parents as indentations in the changed row.
|
| 213 |
else if (rowSettings.relationship == 'parent') {
|
| 214 |
var previousRow = $(changedRow).prev('tr');
|
| 215 |
while (previousRow.length && $('.indentation', previousRow).length >= this.rowObject.indents) {
|
| 216 |
previousRow = previousRow.prev('tr');
|
| 217 |
}
|
| 218 |
// If we found a row.
|
| 219 |
if (previousRow.length) {
|
| 220 |
sourceRow = previousRow[0];
|
| 221 |
}
|
| 222 |
// Otherwise we went all the way to the left of the table without finding
|
| 223 |
// a parent, meaning this item has been placed at the root level.
|
| 224 |
else {
|
| 225 |
// Use the first row in the table as source, because it's garanteed to
|
| 226 |
// be at the root level. Find the first item, then compare this row
|
| 227 |
// against it as a sibling.
|
| 228 |
sourceRow = $('tr.draggable:first').get(0);
|
| 229 |
if (sourceRow == this.rowObject.element) {
|
| 230 |
sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
|
| 231 |
}
|
| 232 |
var useSibling = true;
|
| 233 |
}
|
| 234 |
}
|
| 235 |
|
| 236 |
// Because we may have moved the row from one category to another,
|
| 237 |
// take a look at our sibling and borrow its sources and targets.
|
| 238 |
this.copyDragClasses(sourceRow, changedRow, group);
|
| 239 |
rowSettings = this.rowSettings(group, changedRow);
|
| 240 |
|
| 241 |
// In the case that we're looking for a parent, but the row is at the top
|
| 242 |
// of the tree, copy our sibling's values.
|
| 243 |
if (useSibling) {
|
| 244 |
rowSettings.relationship = 'sibling';
|
| 245 |
rowSettings.source = rowSettings.target;
|
| 246 |
}
|
| 247 |
|
| 248 |
var targetClass = '.' + rowSettings.target;
|
| 249 |
var targetElement = $(targetClass, changedRow).get(0);
|
| 250 |
|
| 251 |
// Check if a target element exists in this row.
|
| 252 |
if (targetElement) {
|
| 253 |
var sourceClass = '.' + rowSettings.source;
|
| 254 |
var sourceElement = $(sourceClass, sourceRow).get(0);
|
| 255 |
switch (rowSettings.action) {
|
| 256 |
case 'depth':
|
| 257 |
// Get the depth of the target row.
|
| 258 |
targetElement.value = $('.indentation', $(sourceElement).parents('tr:first')).size();
|
| 259 |
break;
|
| 260 |
case 'match':
|
| 261 |
// Update the value.
|
| 262 |
targetElement.value = sourceElement.value;
|
| 263 |
break;
|
| 264 |
case 'order':
|
| 265 |
var siblings = this.rowObject.findSiblings(rowSettings);
|
| 266 |
if ($(targetElement).is('select')) {
|
| 267 |
// Get a list of acceptable values.
|
| 268 |
var values = new Array();
|
| 269 |
$('option', targetElement).each(function() {
|
| 270 |
values.push(this.value);
|
| 271 |
});
|
| 272 |
var maxVal = values[values.length - 1];
|
| 273 |
// Populate the values in the siblings.
|
| 274 |
var tmpVal;
|
| 275 |
var reweight_nid;
|
| 276 |
$(targetClass, siblings).each(function() {
|
| 277 |
// If there are more items than possible values, assign the maximum value to the row.
|
| 278 |
tmpVal = this.value
|
| 279 |
if (values.length > 0) {
|
| 280 |
this.value = values.shift();
|
| 281 |
}
|
| 282 |
else {
|
| 283 |
this.value = maxVal;
|
| 284 |
}
|
| 285 |
if(tmpVal != this.value) {
|
| 286 |
reweight_nid = this.id.replace('edit-table-book-admin-','').replace('-weight','');
|
| 287 |
$.ajax({
|
| 288 |
type: "POST",
|
| 289 |
url: AJAX_PATH + "reweight/" + reweight_nid + "/" + this.value,
|
| 290 |
success: function(msg){
|
| 291 |
//could implement some kind of history / undo list here if we want to
|
| 292 |
//enable this to get reweighting message support but it's annoying
|
| 293 |
//od_response_msg(msg);
|
| 294 |
}
|
| 295 |
});
|
| 296 |
}
|
| 297 |
});
|
| 298 |
}
|
| 299 |
else {
|
| 300 |
// Assume a numeric input field.
|
| 301 |
var weight = parseInt($(targetClass, siblings[0]).val()) || 0;
|
| 302 |
$(targetClass, siblings).each(function() {
|
| 303 |
this.value = weight;
|
| 304 |
weight++;
|
| 305 |
});
|
| 306 |
}
|
| 307 |
break;
|
| 308 |
}
|
| 309 |
}
|
| 310 |
};
|
| 311 |
}
|
| 312 |
};
|
| 313 |
|
| 314 |
//this adds scaling functionality to the interface, just a lil usability thing
|
| 315 |
function scale_outline_designer(scale){
|
| 316 |
if(scale == 1 && factor != 2.5){
|
| 317 |
factor = factor + .25;
|
| 318 |
}else if(scale == -1 && factor != 1){
|
| 319 |
factor = factor - .25;
|
| 320 |
}else if(scale == 0){
|
| 321 |
factor = 1;
|
| 322 |
}
|
| 323 |
if(factor == 1){
|
| 324 |
$("#book-outline img").css('width','').css('height','');
|
| 325 |
$("#book-outline").css('font-size','');
|
| 326 |
$("#book-outline .form-item").css('margin-top','');
|
| 327 |
}else{
|
| 328 |
$("#book-outline img").css('width',factor + 'em').css('height',factor + 'em');
|
| 329 |
$("#book-outline").css('font-size',factor + 'em');
|
| 330 |
$("#book-outline .form-item").css('margin-top',(factor/4) + 'em');
|
| 331 |
}
|
| 332 |
}
|
| 333 |
|
| 334 |
function od_response_msg(msg) {
|
| 335 |
$("#od_status_msg").prepend('<div class="od_msg messages status">' + msg + '</div>');
|
| 336 |
setTimeout('$(".od_msg:last").remove();',4000);
|
| 337 |
}
|
| 338 |
|
| 339 |
//geneate a table of values from the OD_TYPES Array
|
| 340 |
function od_content_types() {
|
| 341 |
var output = '<table><tr>';
|
| 342 |
var i=0;
|
| 343 |
for ( var type in OD_TYPES ) {
|
| 344 |
i++;
|
| 345 |
output+= '<td><input type="radio" name="content_type[]" value="'+ type +'"/> <img src="' + DRUPAL_PATH + OD_TYPES[type][1] + '" /> ' + OD_TYPES[type][0] + '</td>'
|
| 346 |
if(i % 3 == 0) {
|
| 347 |
output+= '</tr><tr>';
|
| 348 |
}
|
| 349 |
}
|
| 350 |
return output + '</table>';
|
| 351 |
}
|
| 352 |
|
| 353 |
function od_add_child() {
|
| 354 |
$("#od_content_types").prependTo($("#od_wrapper"));
|
| 355 |
$("#od_content_types input").val([BOOK_DEFAULT_TYPE]);
|
| 356 |
active_type = BOOK_DEFAULT_TYPE;
|
| 357 |
tb_show("Add Child Node -- <img style='vertical-align:middle;' src='"+ DRUPAL_PATH + OD_TYPES[BOOK_DEFAULT_TYPE][1] +"'/> <span></span>","#TB_inline?height=300&width=500&inlineId=od_add_child", false);
|
| 358 |
$(".node-form").append("<input type='button' name='Cancel' onclick=''/>");
|
| 359 |
$("#od_add_child_title").focus();
|
| 360 |
}
|
| 361 |
|
| 362 |
function od_add_child_submit() {
|
| 363 |
var ser = $("#od_add_child_title").serialize();
|
| 364 |
var pattern = new RegExp("od_add_child_title=");
|
| 365 |
pattern.test(ser);
|
| 366 |
var title = RegExp.rightContext;
|
| 367 |
title = title.replace(/%2F/g,"@2@F@");
|
| 368 |
if (title == "") {
|
| 369 |
alert("You must enter a title in order to submit a new node!");
|
| 370 |
return false;
|
| 371 |
}
|
| 372 |
else {
|
| 373 |
$.ajax({
|
| 374 |
type: "POST",
|
| 375 |
url: AJAX_PATH + "add_child/" + title + "/" + active_type + "/" + active_nid,
|
| 376 |
success: function(msg){
|
| 377 |
var msg_split = new RegExp(";msg:");
|
| 378 |
msg_split.test(msg);
|
| 379 |
msg = RegExp.rightContext;
|
| 380 |
$("#reload_table").trigger('change');
|
| 381 |
od_response_msg(msg);
|
| 382 |
od_add_child_tb_close();
|
| 383 |
}
|
| 384 |
});
|
| 385 |
}
|
| 386 |
}
|
| 387 |
|
| 388 |
function od_add_child_tb_close(){
|
| 389 |
tb_remove();
|
| 390 |
$("#od_add_child_title").val('');
|
| 391 |
}
|
| 392 |
|
| 393 |
function od_edit() {
|
| 394 |
$.ajax({
|
| 395 |
type: "POST",
|
| 396 |
url: AJAX_PATH + "edit/" + active_nid,
|
| 397 |
success: function(msg){
|
| 398 |
//show an error message if edit node returned 0 cause failed permissions
|
| 399 |
if(msg == 0) {
|
| 400 |
od_response_msg("You don't have sufficient permissions to edit this node");
|
| 401 |
}
|
| 402 |
else {
|
| 403 |
tb_show("","#TB_inline?height=480&width=640&modal=true", false);
|
| 404 |
$("#TB_ajaxContent").append(msg);
|
| 405 |
Drupal.attachBehaviors("#TB_ajaxContent");
|
| 406 |
//add tiny field if it exists
|
| 407 |
if (window.tinyMCE && window.tinyMCE.triggerSave && $('#edit-body').length != 0) {
|
| 408 |
tinyMCE.execCommand('mceAddControl', false, 'edit-body');
|
| 409 |
}
|
| 410 |
//append the cancel button to the form
|
| 411 |
$(".node-form").append("<input type='button' name='Cancel' value='Cancel' onclick='od_edit_cancel();'/>");
|
| 412 |
}
|
| 413 |
}
|
| 414 |
});
|
| 415 |
}
|
| 416 |
function od_edit_cancel(){
|
| 417 |
if (window.tinyMCE && window.tinyMCE.triggerSave && $('#edit-body').length != 0) {
|
| 418 |
tinyMCE.execCommand('mceFocus', false, 'edit-body');
|
| 419 |
tinyMCE.execCommand('mceRemoveControl', false, 'edit-body');
|
| 420 |
}
|
| 421 |
tb_remove();
|
| 422 |
}
|
| 423 |
|
| 424 |
//starts the rename process
|
| 425 |
function od_rename() {
|
| 426 |
$('#edit-table-book-admin-' + active_nid + '-title-span').css('display','none');
|
| 427 |
$('#edit-table-book-admin-' + active_nid + '-title').css('display','');
|
| 428 |
$('#edit-table-book-admin-' + active_nid + '-title').focus();
|
| 429 |
}
|
| 430 |
//resets the rename field should we need to cancel it
|
| 431 |
function od_rename_reset() {
|
| 432 |
$('#edit-table-book-admin-' + active_nid + '-title-span').css('display','');
|
| 433 |
$('#edit-table-book-admin-' + active_nid + '-title').val($('#edit-table-book-admin-' + active_nid + '-title-span').html());
|
| 434 |
$('#edit-table-book-admin-' + active_nid + '-title').css('display','none');
|
| 435 |
}
|
| 436 |
//sends data back to server IF there were changes
|
| 437 |
function od_rename_submit() {
|
| 438 |
//check if there was a change made. If not, then don't do anything :)
|
| 439 |
$('#edit-table-book-admin-' + active_nid + '-title-span').css('display','');
|
| 440 |
$('#edit-table-book-admin-' + active_nid + '-title').css('display','none');
|
| 441 |
if ($('#edit-table-book-admin-' + active_nid + '-title-span').html() != $('#edit-table-book-admin-' + active_nid + '-title').val()) {
|
| 442 |
var ser = $('#edit-table-book-admin-' + active_nid + '-title').serialize();
|
| 443 |
var pattern = new RegExp("%5Btitle%5D=");
|
| 444 |
pattern.test(ser);
|
| 445 |
var title = RegExp.rightContext;
|
| 446 |
title = title.replace(/%2F/g,"@2@F@");
|
| 447 |
$.ajax({
|
| 448 |
type: "POST",
|
| 449 |
url: AJAX_PATH + "rename/" + active_nid + "/" + title,
|
| 450 |
success: function(msg){
|
| 451 |
if(msg == 0) {
|
| 452 |
$('#edit-table-book-admin-' + active_nid + '-title').val($('#edit-table-book-admin-' + active_nid + '-title-span').html());
|
| 453 |
od_response_msg("You don't have sufficient permissions to rename this node");
|
| 454 |
}
|
| 455 |
else {
|
| 456 |
$('#edit-table-book-admin-' + active_nid + '-title-span').html($('#edit-table-book-admin-' + active_nid + '-title').val());
|
| 457 |
od_response_msg(msg);
|
| 458 |
}
|
| 459 |
}
|
| 460 |
});
|
| 461 |
}
|
| 462 |
}
|
| 463 |
//duplicate part (or all) of a structure
|
| 464 |
function od_duplicate(){
|
| 465 |
$("#od_duplicate_multiple").remove();
|
| 466 |
$("#od_duplicate_node").prepend('<input type="checkbox" id="od_duplicate_multiple"/>');
|
| 467 |
tb_show("Duplicate Node(s) -- <img style='vertical-align:middle;' src='"+ OD_PATH + "/images/duplicate.png'/> <span></span>","#TB_inline?height=200&width=300", false);
|
| 468 |
$("#od_duplicate_node").css('display','block').appendTo("#TB_ajaxContent");
|
| 469 |
}
|
| 470 |
function od_duplicate_submit(){
|
| 471 |
var multiple = $('#od_duplicate_multiple:checked').length;
|
| 472 |
var dup_title = $("#od_duplicate_title").val();
|
| 473 |
dup_title = dup_title.replace(/%2F/g,"@2@F@");
|
| 474 |
$.ajax({
|
| 475 |
type: "POST",
|
| 476 |
url: AJAX_PATH + "duplicate/" + active_nid + "/" + multiple + "/" + dup_title,
|
| 477 |
success: function(msg){
|
| 478 |
$("#reload_table").trigger('change');
|
| 479 |
od_response_msg(msg);
|
| 480 |
$("#od_duplicate_node").css('display','none').appendTo("body");
|
| 481 |
$("#od_duplicate_title").val('Duplicate of %title');
|
| 482 |
tb_remove();
|
| 483 |
}
|
| 484 |
});
|
| 485 |
}
|
| 486 |
|
| 487 |
function od_delete(){
|
| 488 |
$("#od_delete_multiple").remove();
|
| 489 |
$("#od_delete_node").prepend('<input type="checkbox" id="od_delete_multiple"/>');
|
| 490 |
tb_show("Delete Node(s) -- <img style='vertical-align:middle;' src='"+ OD_PATH + "/images/delete.png'/> <span></span>","#TB_inline?height=200&width=300", false);
|
| 491 |
$("#od_delete_node").css('display','block').appendTo("#TB_ajaxContent");
|
| 492 |
}
|
| 493 |
function od_delete_submit(){
|
| 494 |
var multiple = $('#od_delete_multiple:checked').length;
|
| 495 |
$.ajax({
|
| 496 |
type: "POST",
|
| 497 |
url: AJAX_PATH + "delete/" + active_nid + "/" + multiple,
|
| 498 |
success: function(msg){
|
| 499 |
$("#reload_table").trigger('change');
|
| 500 |
if(msg == 0) {
|
| 501 |
od_response_msg("You don't have sufficient permissions to delete this node");
|
| 502 |
}
|
| 503 |
else {
|
| 504 |
od_response_msg(msg);
|
| 505 |
}
|
| 506 |
$("#od_delete_node").css('display','none').appendTo("body");
|
| 507 |
tb_remove();
|
| 508 |
}
|
| 509 |
});
|
| 510 |
}
|
| 511 |
function od_change_type() {
|
| 512 |
var type_src = $("#node-" + active_nid +"-icon").attr('src').replace(DRUPAL_PATH,'');
|
| 513 |
var i=0;
|
| 514 |
for ( var type in OD_TYPES ) {
|
| 515 |
i++;
|
| 516 |
if ( OD_TYPES[type][1] == type_src) {
|
| 517 |
$("#od_content_types input").val([type]);
|
| 518 |
active_type = type;
|
| 519 |
}
|
| 520 |
}
|
| 521 |
$("#od_content_types").prependTo($("#od_change_type"));
|
| 522 |
$("#od_change_type_cancel").appendTo("#TB_ajaxContent");
|
| 523 |
tb_show("Change Node Type -- <img style='vertical-align:middle;' src='"+ $("#node-" + active_nid +"-icon").attr('src') +"'/> <span>"+ $('#edit-table-book-admin-' + active_nid + '-title').val() +"</span>","#TB_inline?height=200&width=500&inlineId=od_change_type", false);
|
| 524 |
}
|
| 525 |
|
| 526 |
function od_change_type_submit() {
|
| 527 |
$.ajax({
|
| 528 |
type: "POST",
|
| 529 |
url: AJAX_PATH + "change_type/" + active_nid + '/' + active_type,
|
| 530 |
success: function(msg){
|
| 531 |
if (msg == 0) {
|
| 532 |
od_response_msg("You don't have sufficient permissions to edit this node");
|
| 533 |
}
|
| 534 |
else {
|
| 535 |
$("#node-" + active_nid +"-icon").attr('src',DRUPAL_PATH + OD_TYPES[active_type][1]);
|
| 536 |
od_response_msg(msg);
|
| 537 |
}
|
| 538 |
od_change_type_tb_close();
|
| 539 |
}
|
| 540 |
});
|
| 541 |
}
|
| 542 |
function od_change_type_tb_close() {
|
| 543 |
tb_remove();
|
| 544 |
}
|
| 545 |
|
| 546 |
//permissions setting if the node privacy by role module exists
|
| 547 |
function od_permissions() {
|
| 548 |
alert('Future Functionality...');
|
| 549 |
//snag the possible permissions / currently selected ones for this node
|
| 550 |
//give the ability to cascade these permissions down this branch
|
| 551 |
}
|
| 552 |
/**
|
| 553 |
* Overload ajax functionality of the ajax module. onsuccess != redirect page
|
| 554 |
*/
|
| 555 |
Drupal.Ajax.response = function(submitter, formObj, data){
|
| 556 |
var newSubmitter;
|
| 557 |
/**
|
| 558 |
* Failure
|
| 559 |
*/
|
| 560 |
if (data.status === false) {
|
| 561 |
Drupal.Ajax.message(data.messages_error, 'error', formObj, submitter);
|
| 562 |
}
|
| 563 |
/**
|
| 564 |
* Success
|
| 565 |
*/
|
| 566 |
else {
|
| 567 |
// Display preview
|
| 568 |
if (data.preview !== null) {
|
| 569 |
Drupal.Ajax.message(decodeURIComponent(data.preview), 'preview',
|
| 570 |
formObj, submitter);
|
| 571 |
// Sometimes the submit button needs to show up afterwards
|
| 572 |
//if ($('#edit-submit').length === 0) {
|
| 573 |
// newSubmitter = submitter.clone(true);
|
| 574 |
// newSubmitter.attr('id', 'edit-submit').val('Submit');
|
| 575 |
// submitter.before(newSubmitter);
|
| 576 |
//}
|
| 577 |
}
|
| 578 |
// If no redirect, then simply show messages
|
| 579 |
else if (data.redirect === null) {
|
| 580 |
if (data.messages_status.length > 0) {
|
| 581 |
Drupal.Ajax.message(data.messages_status, 'status', formObj, submitter);
|
| 582 |
}
|
| 583 |
if (data.messages_warning.length > 0) {
|
| 584 |
Drupal.Ajax.message(data.messages_warning, 'warning', formObj, submitter);
|
| 585 |
}
|
| 586 |
if (data.messages_status.length === 0 &&
|
| 587 |
data.messages_warning.length === 0) {
|
| 588 |
Drupal.Ajax.message([{
|
| 589 |
id : 0,
|
| 590 |
value : 'Submission Complete.'
|
| 591 |
}], 'status', formObj, submitter);
|
| 592 |
}
|
| 593 |
}
|
| 594 |
// Redirect
|
| 595 |
else {
|
| 596 |
//console.log(data.redirect);
|
| 597 |
//window.location.href = data.redirect; //This is what we need to overload
|
| 598 |
//If there were changes to the title push them back to the outline designer
|
| 599 |
var saved_title = $("#edit-title").val();
|
| 600 |
$('#edit-table-book-admin-' + active_nid + '-title').val(saved_title);
|
| 601 |
$('#edit-table-book-admin-' + active_nid + '-title-span').html(saved_title);
|
| 602 |
//get rid of tinymce instance if it exists
|
| 603 |
if (window.tinyMCE && window.tinyMCE.triggerSave && $('#edit-body').length != 0) {
|
| 604 |
tinyMCE.execCommand('mceFocus', false, 'edit-body');
|
| 605 |
tinyMCE.execCommand('mceRemoveControl', false, 'edit-body');
|
| 606 |
}
|
| 607 |
//saving is complete, remove the thick box window
|
| 608 |
tb_remove();
|
| 609 |
//display updated message
|
| 610 |
od_response_msg("Node "+ active_nid +" updated");
|
| 611 |
}
|
| 612 |
}
|
| 613 |
}
|
| 614 |
|
| 615 |
//this was glitching out the outline designer so I had to overload it if was activated
|
| 616 |
Drupal.Ajax.plugins.thickbox = function(hook, args) {
|
| 617 |
var tb_init_original;
|
| 618 |
if (hook === 'scrollFind') {
|
| 619 |
if (args.container.id === 'TB_window') {
|
| 620 |
return false;
|
| 621 |
}
|
| 622 |
else {
|
| 623 |
return true;
|
| 624 |
}
|
| 625 |
}
|
| 626 |
else if (hook === 'init') {
|
| 627 |
tb_init_original = window.tb_init;
|
| 628 |
window.tb_init = function(domChunk){
|
| 629 |
tb_init_original(domChunk);
|
| 630 |
//Drupal.attachBehaviors($('#TB_window'));
|
| 631 |
}
|
| 632 |
}
|
| 633 |
return true;
|
| 634 |
}
|
| 635 |
|