1function ACL(backend_url) { 2 that = this; 3 4 that.url = backend_url; 5 6 that.kp_timer = null; 7 8 that.self = []; 9 10 that.allow_cid = []; 11 that.allow_gid = []; 12 that.deny_cid = []; 13 that.deny_gid = []; 14 15 that.group_uids = {}; 16 that.group_ids = {}; 17 that.contact_uids = {}; 18 that.contact_ids = {}; 19 20 that.bang = ''; 21 22 that.selected_id = ''; 23 24 that.info = $("#acl-info"); 25 that.list = $("#acl-list"); 26 that.list_content = $("#acl-list-content"); 27 that.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html()); 28 that.showall = $("#acl-showall"); 29 that.onlyme = $("#acl-onlyme"); 30 that.custom = $("#acl-custom"); 31 that.acl_select = $("#acl-select"); 32 33 // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. 34 //that.on_submit(); 35 36 /*events*/ 37 38 $(document).ready(function() { 39 40 that.acl_select.change(function(event) { 41 var option = that.acl_select.val(); 42 43 if(option != 'public' && option != 'onlyme' && option != 'custom') { // limited to one selected group 44 that.on_showgroup(event); 45 } 46 47 if(option == 'public') { // public 48 that.on_showall(event); 49 } 50 51 if(option == 'onlyme') { // limited to one self 52 that.on_onlyme(event); 53 } 54 55 if(option == 'custom') { // limited to custom selection 56 that.on_custom(event); 57 } 58 }); 59 60 $(document).on('focus', '.acl-form', that.get_form_data); 61 $(document).on('click', '.acl-form', that.get_form_data); 62 $(document).on('click', '.acl-form-trigger', that.get_form_data); 63 64 $(document).on('click','.acl-button-show',that.on_button_show); 65 $(document).on('click','.acl-button-hide',that.on_button_hide); 66 67 $("#acl-search").keypress(that.on_search); 68 69 /* startup! */ 70 that.get(0,15000); 71 //that.on_submit(); 72 }); 73} 74 75 76ACL.prototype.get_form_data = function(event) { 77 78 form_id = $(this).data('form_id'); 79 that.form_id = $('#' + form_id); 80 81 that.allow_cid = (that.form_id.data('allow_cid') || []); 82 that.allow_gid = (that.form_id.data('allow_gid') || []); 83 that.deny_cid = (that.form_id.data('deny_cid') || []); 84 that.deny_gid = (that.form_id.data('deny_gid') || []); 85 86 that.bang = (that.form_id.data('bang') || ''); 87 88 that.update_view(); 89 that.on_submit(); 90 91} 92 93// no longer called only on submit - call to update whenever a change occurs to the acl list. 94ACL.prototype.on_submit = function() { 95 96 $('.acl-field').remove(); 97 98 $(that.allow_gid).each(function(i,v) { 99 that.form_id.append("<input class='acl-field' type='hidden' name='group_allow[]' value='"+v+"'>"); 100 }); 101 $(that.allow_cid).each(function(i,v) { 102 that.form_id.append("<input class='acl-field' type='hidden' name='contact_allow[]' value='"+v+"'>"); 103 }); 104 $(that.deny_gid).each(function(i,v) { 105 that.form_id.append("<input class='acl-field' type='hidden' name='group_deny[]' value='"+v+"'>"); 106 }); 107 $(that.deny_cid).each(function(i,v) { 108 that.form_id.append("<input class='acl-field' type='hidden' name='contact_deny[]' value='"+v+"'>"); 109 }); 110}; 111 112ACL.prototype.search = function() { 113 var srcstr = $("#acl-search").val(); 114 that.list_content.html(""); 115 that.get(0, 15000, srcstr); 116}; 117 118ACL.prototype.on_search = function(event) { 119 if (that.kp_timer) { 120 clearTimeout(that.kp_timer); 121 } 122 that.kp_timer = setTimeout( that.search, 1000); 123}; 124 125ACL.prototype.on_onlyme = function(event) { 126 // preventDefault() isn't called here as we want state changes from update_view() to be applied to the radiobutton 127 event.stopPropagation(); 128 129 that.allow_cid = [that.self[0]]; 130 that.allow_gid = []; 131 that.deny_cid = []; 132 that.deny_gid = []; 133 134 135 that.update_view(); 136 that.on_submit(); 137 138 return true; // return true so that state changes from update_view() will be applied 139}; 140 141ACL.prototype.on_showall = function(event) { 142 // preventDefault() isn't called here as we want state changes from update_view() to be applied to the radiobutton 143 event.stopPropagation(); 144 145 that.allow_cid = []; 146 that.allow_gid = []; 147 that.deny_cid = []; 148 that.deny_gid = []; 149 150 that.update_view(); 151 that.on_submit(); 152 153 return true; // return true so that state changes from update_view() will be applied 154}; 155 156ACL.prototype.on_showgroup = function(event) { 157 158 var xid = that.acl_select.val(); 159 var cid = ''; 160 161 if(xid.length && xid.substr(0,1) == '^') { 162 cid = xid.slice(1); 163 xid = ''; 164 } 165 166 // preventDefault() isn't called here as we want state changes from update_view() to be applied to the radiobutton 167 event.stopPropagation(); 168 169 if (xid.length) { 170 that.allow_cid = [];
171 that.allow_gid = [xid]; 172 that.deny_cid = []; 173 that.deny_gid = []; 174 175 } 176 else { 177 that.allow_cid = [cid]; 178 that.allow_gid = []; 179 that.deny_cid = []; 180 that.deny_gid = []; 181 } 182 183 that.update_view(); 184 that.on_submit(); 185 186 return true; // return true so that state changes from update_view() will be applied 187}; 188 189 190ACL.prototype.on_custom = function(event) { 191 // preventDefault() isn't called here as we want state changes from update_view() to be applied to the radiobutton 192 event.stopPropagation(); 193 194 that.allow_cid = []; 195 that.allow_gid = []; 196 that.deny_cid = []; 197 that.deny_gid = []; 198 199 datasrc2src('#acl-list-content .list-group-item img[data-src]'); 200 201 that.update_view('custom'); 202 that.on_submit(); 203 204 return true; // return true so that state changes from update_view() will be applied 205} 206 207ACL.prototype.on_button_show = function(event) { 208 event.preventDefault(); 209 event.stopImmediatePropagation(); 210 event.stopPropagation(); 211 212 if(!$(this).parent().hasClass("grouphide")) { 213 that.set_allow($(this).parent().attr('id')); 214 that.on_submit(); 215 } 216 217 return false; 218}; 219 220ACL.prototype.on_button_hide = function(event) { 221 event.preventDefault(); 222 event.stopImmediatePropagation(); 223 event.stopPropagation(); 224 225 that.set_deny($(this).parent().attr('id')); 226 that.on_submit(); 227 228 return false; 229}; 230 231ACL.prototype.set_allow = function(itemid) { 232 type = itemid[0]; 233 id = decodeURIComponent(itemid.substr(1)); 234 switch(type) { 235 case "g": 236 if (that.allow_gid.indexOf(id)<0) { 237 that.allow_gid.push(id); 238 }else { 239 that.allow_gid.remove(id); 240 } 241 if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id); 242 break; 243 case "c": 244 if (that.allow_cid.indexOf(id)<0) { 245 that.allow_cid.push(id); 246 } else { 247 that.allow_cid.remove(id); 248 } 249 if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id); 250 break; 251 } 252 that.update_view('custom'); 253}; 254 255ACL.prototype.set_deny = function(itemid) { 256 type = itemid[0]; 257 id = decodeURIComponent(itemid.substr(1)); 258 switch(type) { 259 case "g": 260 if (that.deny_gid.indexOf(id)<0) { 261 that.deny_gid.push(id); 262 } else { 263 that.deny_gid.remove(id); 264 } 265 if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id); 266 break; 267 case "c": 268 if (that.deny_cid.indexOf(id)<0) { 269 that.deny_cid.push(id); 270 } else { 271 that.deny_cid.remove(id); 272 } 273 if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id); 274 break; 275 } 276 that.update_view('custom'); 277}; 278 279ACL.prototype.update_select = function(set) { 280 if(set != 'public' && set != 'onlyme' && set != 'custom') { 281 $('#' + set).prop('selected', true ); 282 } 283 that.showall.prop('selected', set === 'public'); 284 that.onlyme.prop('selected', set === 'onlyme'); 285 that.custom.prop('selected', set === 'custom'); 286}; 287 288ACL.prototype.update_view = function(value) { 289 290 if(that.form_id) { 291 that.form_id.data('allow_cid', that.allow_cid); 292 that.form_id.data('allow_gid', that.allow_gid); 293 that.form_id.data('deny_cid', that.deny_cid); 294 that.form_id.data('deny_gid', that.deny_gid); 295 } 296 297 if (that.allow_gid.length === 0 && that.allow_cid.length === 0 && that.deny_gid.length === 0 && that.deny_cid.length === 0 && value !== 'custom') { 298 that.list.hide(); //hide acl-list 299 that.info.show(); //show acl-info 300 that.update_select('public'); 301 302 /* jot acl */ 303 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-lock').addClass('bi-unlock'); 304 $('#jot-perms-icon').removeClass('jot-lock-warn'); 305 $('#dbtn-jotnets').show(); 306 $('.profile-jot-net input').attr('disabled', false); 307 308 } 309 310 else if (that.allow_gid.length === 1 && that.allow_cid.length === 0 && that.deny_gid.length === 0 && that.deny_cid.length === 0 && value !== 'custom') { 311 that.list.hide(); //hide acl-list 312 that.info.hide(); //show acl-info 313 that.selected_id = that.group_ids[that.allow_gid[0]]; 314 that.update_select(that.selected_id); 315 316 /* jot acl */ 317 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-unlock').addClass('bi-lock'); 318 $('#dbtn-jotnets').hide(); 319 $('.profile-jot-net input').attr('disabled', 'disabled'); 320 } 321 322 // if value != 'onlyme' we should fall through this one
323 else if (that.allow_gid.length === 0 && that.allow_cid.length === 1 && that.allow_cid[0] === that.self[0] && that.deny_gid.length === 0 && that.deny_cid.length === 0 && value !== 'custom') { 324 that.list.hide(); //hide acl-list 325 that.info.hide(); //show acl-info 326 that.update_select('onlyme'); 327 328 /* jot acl */ 329 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-unlock').addClass('bi-lock'); 330 $('#dbtn-jotnets').hide(); 331 $('.profile-jot-net input').attr('disabled', 'disabled'); 332 } 333 else if (that.allow_gid.length === 0 && that.allow_cid.length === 1 && that.deny_gid.length === 0 && that.deny_cid.length === 0 && value !== 'custom') { 334 335 if(that.bang && that.bang !== that.allow_cid[0]) { 336 that.update_view('custom'); 337 return; 338 } 339 340 that.list.hide(); //hide acl-list 341 that.info.hide(); //show acl-info 342 that.selected_id = that.contact_ids[that.allow_cid[0]]; 343 344 if(that.acl_select.find('option[id="\\^' + that.selected_id + '"]').length === 0) { 345 that.update_view('custom'); 346 } 347 else { 348 that.update_select('\\^' + that.selected_id); 349 } 350 351 /* jot acl */ 352 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-unlock').addClass('bi-lock'); 353 $('#dbtn-jotnets').hide(); 354 $('.profile-jot-net input').attr('disabled', 'disabled'); 355 } 356 357 else { 358 359 that.list.show(); //show acl-list 360 datasrc2src('#acl-list-content .list-group-item img[data-src]'); 361 that.info.hide(); //hide acl-info 362 that.update_select('custom'); 363 if(typeof value === 'undefined') { 364 value = 'custom'; 365 } 366 367 /* jot acl */ 368 if(that.allow_gid.length === 0 && that.allow_cid.length === 0 && that.deny_gid.length === 0 && that.deny_cid.length === 0 && value === 'custom') { 369 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-lock').addClass('bi-unlock'); 370 $('#dbtn-jotnets').show(); 371 $('.profile-jot-net input').attr('disabled', false); 372 } 373 else { 374 $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('bi-unlock').addClass('bi-lock'); 375 $('#dbtn-jotnets').hide(); 376 $('.profile-jot-net input').attr('disabled', 'disabled'); 377 } 378 } 379 380 if(value === 'custom') { 381 $("#acl-list-content .acl-list-item").each(function() { 382 $(this).removeClass("groupshow grouphide"); 383 }); 384 385 $("#acl-list-content .acl-list-item").each(function() { 386 itemid = $(this).attr('id'); 387 type = itemid[0]; 388 id = decodeURIComponent(itemid.substr(1)); 389 390 btshow = $(this).children(".acl-button-show").removeClass("btn-success").addClass("btn-outline-success"); 391 bthide = $(this).children(".acl-button-hide").removeClass("btn-danger").addClass("btn-outline-danger"); 392 393 switch(type) { 394 case "g": 395 var uclass = ""; 396 if (that.allow_gid.indexOf(id)>=0) { 397 btshow.removeClass("btn-outline-success").addClass("btn-success"); 398 bthide.removeClass("btn-danger").addClass("btn-outline-danger"); 399 uclass="groupshow"; 400 } 401 if (that.deny_gid.indexOf(id)>=0) { 402 btshow.removeClass("btn-success").addClass("btn-outline-success"); 403 bthide.removeClass("btn-outline-danger").addClass("btn-danger"); 404 uclass = "grouphide"; 405 } 406 $(that.group_uids[id]).each(function(i, v) { 407 if(uclass == "grouphide") 408 // we need attr selection here because the id can include an @ (diaspora/friendica xchans) 409 $('[id="c' + v + '"]').removeClass("groupshow"); 410 if(uclass !== "") { 411 var cls = $('[id="c' + v + '"]').attr('class'); 412 if( cls === undefined) 413 return true; 414 var hiding = cls.indexOf('grouphide'); 415 if(hiding == -1) 416 $('[id="c' + v + '"]').addClass(uclass); 417 } 418 }); 419 break; 420 case "c": 421 if (that.allow_cid.indexOf(id)>=0){ 422 if(!$(this).hasClass("grouphide") ) { 423 btshow.removeClass("btn-outline-success").addClass("btn-success"); 424 bthide.removeClass("btn-danger").addClass("btn-outline-danger"); 425 } 426 } 427 if (that.deny_cid.indexOf(id)>=0){ 428 btshow.removeClass("btn-success").addClass("btn-outline-success"); 429 bthide.removeClass("btn-outline-danger").addClass("btn-danger"); 430 $(this).removeClass("groupshow"); 431 } 432 $(that.contact_uids[id]).each(function(i, v) { 433 if(uclass == "grouphide") 434 // we need attr selection here because the id can include an @ (diaspora/friendica xchans) 435 $('[id="g' + v + '"]').removeClass("groupshow"); 436 if(uclass !== "") { 437 var cls = $('[id="g' + v + '"]').attr('class'); 438 if( cls === undefined) 439 return true; 440 var hiding = cls.indexOf('grouphide'); 441 if(hiding == -1) 442 $('[id="g' + v + '"]').addClass(uclass); 443 } 444 }); 445 break; 446 447 } 448 }); 449 } 450}; 451 452ACL.prototype.get = function(start, count, search) { 453 var postdata = { 454 start: start, 455 count: count, 456 search: search, 457 }; 458 459 $.ajax({ 460 type: 'POST', 461 url: that.url, 462 data: postdata, 463 dataType: 'json', 464 success: that.populate 465 }) 466 .done(function() { 467 if(search !== undefined) 468 datasrc2src('#acl-list-content .list-group-item img[data-src]'); 469 }); 470}; 471 472ACL.prototype.populate = function(data) { 473 $(data.items).each(function(){ 474 html = "<div class='list-group-item clearfix acl-list-item {4} {7} {5}' id='{2}{3}'>"+that.item_tpl+"</div>"; 475 html = html.format(this.photo, this.name, this.type, this.xid, '', this.self, this.link, this.taggable); 476 if (this.uids !== undefined) { 477 that.group_uids[this.xid] = this.uids; 478 that.group_ids[this.xid] = this.id; 479 } 480 else { 481 that.contact_ids[this.xid] = this.id; 482 } 483 if (this.self === 'abook-self') { 484 that.self[0] = this.xid; 485 } 486 487 that.list_content.append(html); 488 }); 489};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.