| 59 |
+ result.gid +'"]').removeAttr('selected').show(); |
+ result.gid +'"]').removeAttr('selected').show(); |
| 60 |
} |
} |
| 61 |
|
|
| 62 |
var comms_tags_process_add = function(data) { |
|
| 63 |
|
// This is the callback function for the term remove links AJAX |
| 64 |
|
// function. We need to remove the term from the term list and the group i |
| 65 |
|
// from the dispatch section. |
| 66 |
|
var comms_tags_process_delete = function(data) { |
| 67 |
var result = Drupal.parseJson(data); |
var result = Drupal.parseJson(data); |
| 68 |
|
|
| 69 |
// In case an add was requested and the previous message did not time |
// In case an add was requested and the previous message did not time |
| 81 |
} |
} |
| 82 |
} |
} |
| 83 |
|
|
| 84 |
// Hide the option in the select box. |
// Unhide the term in the tags select list. |
| 85 |
$('.comms #node-'+ result.nid |
comms_tags_form_show(result.nid); |
| 86 |
+" .group_tag select option[value='"+ result.gid +"']").hide(); |
for (var tid in result.term) { |
| 87 |
|
// Remove the term from the term list. |
| 88 |
// Show the dispatch section just in case it is hidden. |
$('.comms #node-'+result.nid+' .terms li.taxonomy_term_'+tid).remove(); |
| 89 |
$('.comms #node-'+ result.nid +' .dispatch').show(); |
$('.comms #node-'+ result.nid |
| 90 |
|
+' .group_tag select option[value="' |
| 91 |
// Get the path that this js is in. This is a total hack! |
+ tid +'"]').removeAttr('selected').show(); |
|
//var path = $('head script').attr('src').grep(function(src) { |
|
|
//$('head script').each(function(script) { |
|
|
var path = ''; |
|
|
$('head script').each(function(i, script) { |
|
|
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
|
|
if (matches && matches.length == 2) { |
|
|
path = matches[1]; |
|
|
} |
|
|
}); |
|
|
|
|
|
// It's totally possible no new groups where added. |
|
|
if (result.gids.length == 0) { |
|
|
return; |
|
| 92 |
} |
} |
| 93 |
|
|
| 94 |
// Add the groups to the dispatch section. |
// We will let comms_groups_process_delete() handle message displays |
| 95 |
// for ( var i=myArray.length-1; i>=0; --i ){ |
// and all handling of groups. Since we could be working with more than |
| 96 |
// ... |
// one group we need to manipulate the json object that |
| 97 |
// } |
// comms_groups_process_delete() expects. |
| 98 |
|
data = data.replace(/"message"\s*:\s*"[^"]*"/, '"message": ""'); |
| 99 |
for (var gid in result.gids) { |
for (var gid in result.gids) { |
| 100 |
console.log('gid: '+ gid +', group: '+ result.gids[gid]); |
data = data.replace( |
| 101 |
if ($('.comms #node-'+ result.nid +' .dispatch .info a').get().length) { |
/"name"\s*:\s*"[^"]*"/, '"name": "'+ result.gids[gid] +'"'); |
| 102 |
$('.comms #node-'+ result.nid +' .dispatch .info') |
data = data.replace(/"gid"\s*:\s*"[^"]*"/, '"gid": "'+ gid +'"'); |
| 103 |
.append(', '); |
comms_groups_process_delete(data); |
|
} |
|
|
$('.comms #node-'+ result.nid +' .dispatch .info') |
|
|
.append('<a id="'+ gid +'" href="/node/'+ gid |
|
|
+'">'+ result.gids[gid] +'</a><img id="'+ gid |
|
|
+'" src="'+ path +'cancel.png" />'); |
|
|
|
|
|
// Add AJAX functionality to clicking the cancel image. This will remove |
|
|
// the group from the "dispatch to" groups. |
|
|
$('.comms #node-'+ result.nid +' div.dispatch .info img#'+ gid) |
|
|
.bind('click', function() { |
|
|
$.post('/comms/groups/'+ result.nid +'/'+ gid +'/remove', |
|
|
null, comms_groups_process_delete); |
|
|
return false; |
|
|
}); |
|
| 104 |
} |
} |
|
|
|
|
// Add the terms to the node. |
|
|
for (var tid in result.term) { |
|
|
// Place the term. |
|
|
$('.comms #node-'+ result.nid +' .terms') |
|
|
.append('<li class="taxonomy_term_'+ tid +'">'+ |
|
|
result.term[tid] +'</li>'); |
|
|
|
|
|
// Append a cancel icon to it. |
|
|
$('.comms #node-'+ result.nid +' .terms') |
|
|
.append('<img id="'+tid+'" src="'+ path +'cancel.png" />') |
|
|
// Bind a click handler to the cancel icon. |
|
|
.bind('click', function() { |
|
|
$.post('/comms/groups/'+ nid +'/'+ tid +'/remove/tags', |
|
|
null, comms_tags_process_remove); |
|
|
}); |
|
|
} |
|
|
|
|
|
// Hide the tags section if it is empty. |
|
|
var num_visible = |
|
|
$('.comms #node-'+result.nid+' .group_tag select option:visible').length; |
|
|
if (num_visible == 0) { |
|
|
$('.comms #node-'+ result.nid +' .group_tag').hide(); |
|
|
}; |
|
| 105 |
} |
} |
| 106 |
|
|
| 107 |
var comms_groups_process_add = function(data) { |
var comms_groups_process_add = function(data) { |
| 117 |
setTimeout(function() { |
setTimeout(function() { |
| 118 |
$('.comms #node-'+ result.nid +' .message').fadeOut("slow"); |
$('.comms #node-'+ result.nid +' .message').fadeOut("slow"); |
| 119 |
}, 5000); |
}, 5000); |
| 120 |
return; |
if (result.error) { |
| 121 |
|
return; |
| 122 |
|
} |
| 123 |
} |
} |
| 124 |
|
|
| 125 |
// Hide the option in the select box. |
// Hide the option in the select box. |
| 130 |
$('.comms #node-'+ result.nid +' .dispatch').show(); |
$('.comms #node-'+ result.nid +' .dispatch').show(); |
| 131 |
|
|
| 132 |
// Get the path that this js is in. This is a total hack! |
// Get the path that this js is in. This is a total hack! |
|
//var path = $('head script').attr('src').grep(function(src) { |
|
|
//$('head script').each(function(script) { |
|
| 133 |
var path = ''; |
var path = ''; |
| 134 |
$('head script').each(function(i, script) { |
$('head script').each(function(i, script) { |
| 135 |
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
| 160 |
// Hide the groups section if it is empty. |
// Hide the groups section if it is empty. |
| 161 |
var num_visible = |
var num_visible = |
| 162 |
$('.comms #node-'+result.nid+' .groups select option:visible').length; |
$('.comms #node-'+result.nid+' .groups select option:visible').length; |
|
console.log('number of visible options: %d', num_visible); |
|
| 163 |
if (num_visible == 0) { |
if (num_visible == 0) { |
| 164 |
$('.comms #node-'+ result.nid +' .comms_groups_form').hide(); |
$('.comms #node-'+ result.nid +' .comms_groups_form').hide(); |
| 165 |
}; |
}; |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
|
var comms_tags_process_add = function(data) { |
| 169 |
|
var result = Drupal.parseJson(data); |
| 170 |
|
|
| 171 |
|
// In case an add was requested and the previous message did not time |
| 172 |
|
// out, clear it. Then if we recieved a new message display it and |
| 173 |
|
// schedule the removal. |
| 174 |
|
$('.comms #node-'+ result.nid +' .message').hide(); |
| 175 |
|
if (result.message.length) { |
| 176 |
|
$('.comms #node-'+ result.nid +' .message').text(result.message); |
| 177 |
|
$('.comms #node-'+ result.nid +' .message').fadeIn("slow"); |
| 178 |
|
setTimeout(function() { |
| 179 |
|
$('.comms #node-'+ result.nid +' .message').fadeOut("slow"); |
| 180 |
|
}, 5000); |
| 181 |
|
if (result.error) { |
| 182 |
|
return; |
| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
// Hide the option in the select box. |
| 187 |
|
$('.comms #node-'+ result.nid |
| 188 |
|
+" .group_tag select option[value='"+ result.gid +"']").hide(); |
| 189 |
|
|
| 190 |
|
// Add the groups to the dispatch section. |
| 191 |
|
// Clear out the message in case there was one. |
| 192 |
|
data = data.replace(/"message"\s*:\s*"[^"]*"/, '"message": ""'); |
| 193 |
|
for (var gid in result.gids) { |
| 194 |
|
data = data.replace( |
| 195 |
|
/"name"\s*:\s*"[^"]*"/, '"name": "'+ result.gids[gid] +'"'); |
| 196 |
|
data = data.replace(/"gid"\s*:\s*"[^"]*"/, '"gid": "'+ gid +'"'); |
| 197 |
|
comms_groups_process_add(data); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
// Add the terms to the node. |
| 201 |
|
var path = getModulePath(); |
| 202 |
|
for (var tid in result.term) { |
| 203 |
|
console.log('comms_tags_process_add() tid: '+ tid +', term: '+ result.term[tid]); |
| 204 |
|
// Place the term. .comms #node-<nid> .terms does not exist if there |
| 205 |
|
// are no existing bound terms! |
| 206 |
|
$('.comms #node-'+ result.nid +' .terms ul') |
| 207 |
|
.append('<li class="first last taxonomy_term_'+ tid +'">'+ |
| 208 |
|
'<a class="taxonomy_term_'+ tid +'" title="" rel="tag" href="/taxonomy/term/'+ tid +'">'+ result.term[tid] +'</a></li>'); |
| 209 |
|
|
| 210 |
|
// Append a cancel icon to it. |
| 211 |
|
$('.comms #node-'+ result.nid +' .terms a.taxonomy_term_'+ tid) |
| 212 |
|
.after(': <img id="'+tid+'" src="'+ path +'cancel.png" />'); |
| 213 |
|
// Bind a click handler to the cancel icon. |
| 214 |
|
$('.comms #node-'+ result.nid +' .terms img#'+ tid) |
| 215 |
|
.bind('click', function() { |
| 216 |
|
$.post('/comms/groups/'+ result.nid +'/'+ tid +'/remove/tags', |
| 217 |
|
null, comms_tags_process_delete); |
| 218 |
|
}); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
// Hide the tags section if it is empty. |
| 222 |
|
var num_visible = |
| 223 |
|
$('.comms #node-'+result.nid+' .group_tag select option:visible').length; |
| 224 |
|
if (num_visible == 0) { |
| 225 |
|
$('.comms #node-'+ result.nid +' .group_tag').hide(); |
| 226 |
|
}; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
var comms_groups_form_show = function(nid) { |
var comms_groups_form_show = function(nid) { |
| 230 |
var group_form = |
var group_form = |
| 231 |
$('.comms #node-'+ nid +' .comms_groups_form'); |
$('.comms #node-'+ nid +' .comms_groups_form'); |
| 243 |
$('input.comms_group_submit', group_form).hide(); |
$('input.comms_group_submit', group_form).hide(); |
| 244 |
} |
} |
| 245 |
|
|
| 246 |
|
var comms_tags_form_show = function(nid) { |
| 247 |
|
var tag_form = |
| 248 |
|
$('.comms #node-'+ nid +' .group_tag'); |
| 249 |
|
|
| 250 |
|
// If the tag form is not visible show it, but then hide all of the |
| 251 |
|
// misc stuff we don't want displayed. |
| 252 |
|
if (! tag_form.visible) { |
| 253 |
|
tag_form.show(); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
// If all options are selected we want to hide the whole form. |
| 257 |
|
$('select option:selected', tag_form).hide(); |
| 258 |
|
|
| 259 |
|
// Hide the submit button. |
| 260 |
|
$('input.comms_group_submit', tag_form).hide(); |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
var getModulePath = function() { |
| 264 |
|
var path = ''; |
| 265 |
|
$('head script').each(function(i, script) { |
| 266 |
|
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
| 267 |
|
if (matches && matches.length == 2) { |
| 268 |
|
path = matches[1]; |
| 269 |
|
} |
| 270 |
|
}); |
| 271 |
|
return path; |
| 272 |
|
} |
| 273 |
|
|
| 274 |
// This is the main code that should be run on each page that has comms |
// This is the main code that should be run on each page that has comms |
| 275 |
// groups, dispatching stuff on it. |
// groups, dispatching stuff on it. |
| 276 |
$(document).ready(function () { |
$(document).ready(function () { |
| 277 |
// Get the path that this js is in. This is a total hack! |
// Get the path that this js is in. This is a total hack! |
|
//var path = $('head script').attr('src').grep(function(src) { |
|
|
//$('head script').each(function(script) { |
|
| 278 |
var path = ''; |
var path = ''; |
| 279 |
$('head script').each(function(i, script) { |
$('head script').each(function(i, script) { |
| 280 |
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
var matches = $(script).attr("src").match(/(.*)comms\.groups\.js/); |
| 389 |
$('.comms').each(function() { |
$('.comms').each(function() { |
| 390 |
var matches = $('.node', this).attr('id').match(/node-(\d+)/); |
var matches = $('.node', this).attr('id').match(/node-(\d+)/); |
| 391 |
var nid = matches[1]; |
var nid = matches[1]; |
| 392 |
$('.terms', this).each(function() { |
var comms = this; |
| 393 |
|
|
| 394 |
|
$('.terms a', this).each(function() { |
| 395 |
var a_matches = |
var a_matches = |
| 396 |
$('a', this).attr('href').match(/\/taxonomy\/term\/(\d+)/); |
$(this).attr('href').match(/\/taxonomy\/term\/(\d+)/); |
| 397 |
var tid = a_matches[1]; |
var tid = a_matches[1]; |
|
//$(this).replaceWith($(this).text()); |
|
|
$('a', this).replaceWith($('a', this).text()); |
|
| 398 |
$(this) |
$(this) |
| 399 |
.append('<img id="'+tid+'" src="'+ path +'cancel.png" />') |
.after('<img id="'+tid+'" src="'+ path +'cancel.png" />'); |
| 400 |
.bind('click', function() { |
$('.terms img#'+tid, comms).bind('click', function() { |
| 401 |
$.post('/comms/groups/'+ nid +'/'+ tid +'/remove/tags', |
$.post('/comms/groups/'+ nid +'/'+ tid +'/remove/tags', |
| 402 |
null, comms_tags_process_remove); |
null, comms_tags_process_delete); |
| 403 |
}); |
}); |
| 404 |
|
|
| 405 |
|
// Incomment this if you do not want the taxonomy link. |
| 406 |
|
//$(this).replaceWith($(this).text()); |
| 407 |
|
$(this).after(': '); |
| 408 |
}); |
}); |
| 409 |
|
|
| 410 |
|
// If no terms are associated with the node the .terms section does |
| 411 |
|
// not exist. We should add it hear if that is the case. |
| 412 |
|
if ($('.terms', this).length == 0) { |
| 413 |
|
$('.clear-block .meta', this) |
| 414 |
|
.append("<div class=\"terms\"><ul class=\"links inline\"></ul> </div>"); |
| 415 |
|
} |
| 416 |
}); |
}); |
| 417 |
|
|
| 418 |
}); |
}); |