1 function ACL(backend_url, preset){
4 that.url = backend_url;
8 if (preset==undefined) preset = [];
9 that.allow_cid = (preset[0] || []);
10 that.allow_gid = (preset[1] || []);
11 that.deny_cid = (preset[2] || []);
12 that.deny_gid = (preset[3] || []);
14 that.nw = 4; //items per row. should be calulated from #acl-list.width
16 that.list_content = $("#acl-list-content");
17 that.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
18 that.showall = $("#acl-showall");
20 if (preset.length==0) that.showall.addClass("selected");
23 that.showall.click(that.on_showall);
24 $(".acl-button-show").live('click', that.on_button_show);
25 $(".acl-button-hide").live('click', that.on_button_hide);
26 $("#acl-search").keypress(that.on_search);
27 $("#acl-wrapper").parents("form").submit(that.on_submit);
29 /* add/remove mentions */
30 that.element = $("#profile-jot-text");
31 that.htmlelm = that.element.get()[0];
37 ACL.prototype.remove_mention = function(nick) {
38 searchText = '@'+nick+ " ";
39 // 'editor' is defined in jot-header.tpl : false=plaintext, true:tinyMCE
41 start = that.element.val().search(searchText);
43 end = start+searchText.length;
44 that.element.setSelection(start,end).replaceSelectedText('').collapseSelection(false);
46 start = tinyMCE.activeEditor.getContent({format : 'raw'}).search( searchText );
47 if ( start<0 ) return;
48 txt = tinyMCE.activeEditor.getContent();
49 newtxt = txt.replace(searchText, '');
50 tinyMCE.activeEditor.setContent(newtxt);
54 ACL.prototype.add_mention = function(nick) {
55 // 'editor' is defined in jot-header.tpl : false=plaintext, true:tinyMCE
57 if ( that.element.val().search( '@'+nick) >= 0 ) return;
58 that.element.val( "@"+nick+" " + that.element.val() );
60 if ( tinyMCE.activeEditor.getContent({format : 'raw'}).search( '@'+nick) >= 0 ) return;
61 tinyMCE.activeEditor.dom.add(tinyMCE.activeEditor.getBody(), 'span', {}, '@'+nick+" ");
65 ACL.prototype.on_submit = function(){
66 aclfileds = $("#acl-fields").html("");
67 $(that.allow_gid).each(function(i,v){
68 aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
70 $(that.allow_cid).each(function(i,v){
71 aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
73 $(that.deny_gid).each(function(i,v){
74 aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
76 $(that.deny_cid).each(function(i,v){
77 aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
81 ACL.prototype.search = function(){
82 var srcstr = $("#acl-search").val();
83 that.list_content.html("");
84 that.get(0,100, srcstr);
87 ACL.prototype.on_search = function(event){
88 if (that.kp_timer) clearTimeout(that.kp_timer);
89 that.kp_timer = setTimeout( that.search, 1000);
92 ACL.prototype.on_showall = function(event){
93 event.preventDefault()
94 event.stopPropagation();
96 if (that.showall.hasClass("selected")){
99 that.showall.addClass("selected");
111 ACL.prototype.on_button_show = function(event){
112 event.preventDefault()
113 event.stopImmediatePropagation()
114 event.stopPropagation();
116 /*that.showall.removeClass("selected");
117 $(this).siblings(".acl-button-hide").removeClass("selected");
118 $(this).toggleClass("selected");*/
120 that.set_allow($(this).parent().attr('id'));
124 ACL.prototype.on_button_hide = function(event){
125 event.preventDefault()
126 event.stopImmediatePropagation()
127 event.stopPropagation();
129 /*that.showall.removeClass("selected");
130 $(this).siblings(".acl-button-show").removeClass("selected");
131 $(this).toggleClass("selected");*/
133 that.set_deny($(this).parent().attr('id'));
138 ACL.prototype.set_allow = function(itemid){
140 id = parseInt(itemid.substr(1));
144 if (that.allow_gid.indexOf(id)<0){
145 that.allow_gid.push(id)
147 that.allow_gid.remove(id);
149 if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id);
152 if (that.allow_cid.indexOf(id)<0){
153 that.allow_cid.push(id)
154 if (that.data[id].forum=="1") that.add_mention(that.data[id].nick);
156 that.allow_cid.remove(id);
157 if (that.data[id].forum=="1") that.remove_mention(that.data[id].nick);
159 if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id);
165 ACL.prototype.set_deny = function(itemid){
167 id = parseInt(itemid.substr(1));
171 if (that.deny_gid.indexOf(id)<0){
172 that.deny_gid.push(id)
174 that.deny_gid.remove(id);
176 if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id);
179 if (that.data[id].forum=="1") that.remove_mention(that.data[id].nick);
180 if (that.deny_cid.indexOf(id)<0){
181 that.deny_cid.push(id)
183 that.deny_cid.remove(id);
185 if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id);
191 ACL.prototype.update_view = function(){
192 if (that.allow_gid.length==0 && that.allow_cid.length==0 &&
193 that.deny_gid.length==0 && that.deny_cid.length==0){
194 that.showall.addClass("selected");
196 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
197 $('#jot-public').show();
198 $('.profile-jot-net input').attr('disabled', false);
199 if(typeof editor != 'undefined' && editor != false) {
200 $('#profile-jot-desc').html(ispublic);
204 that.showall.removeClass("selected");
206 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
207 $('#jot-public').hide();
208 $('.profile-jot-net input').attr('disabled', 'disabled');
209 $('#profile-jot-desc').html(' ');
211 $("#acl-list-content .acl-list-item").each(function(){
212 $(this).removeClass("groupshow grouphide");
215 $("#acl-list-content .acl-list-item").each(function(){
216 itemid = $(this).attr('id');
218 id = parseInt(itemid.substr(1));
220 btshow = $(this).children(".acl-button-show").removeClass("selected");
221 bthide = $(this).children(".acl-button-hide").removeClass("selected");
226 if (that.allow_gid.indexOf(id)>=0){
227 btshow.addClass("selected");
228 bthide.removeClass("selected");
231 if (that.deny_gid.indexOf(id)>=0){
232 btshow.removeClass("selected");
233 bthide.addClass("selected");
237 $(that.group_uids[id]).each(function(i,v) {
238 if(uclass == "grouphide")
239 $("#c"+v).removeClass("groupshow");
241 var cls = $("#c"+v).attr('class');
242 if( cls == undefined)
244 var hiding = cls.indexOf('grouphide');
246 $("#c"+v).addClass(uclass);
252 if (that.allow_cid.indexOf(id)>=0){
253 btshow.addClass("selected");
254 bthide.removeClass("selected");
256 if (that.deny_cid.indexOf(id)>=0){
257 btshow.removeClass("selected");
258 bthide.addClass("selected");
267 ACL.prototype.get = function(start,count, search){
279 success:that.populate
283 ACL.prototype.populate = function(data){
284 var height = Math.ceil(data.tot / that.nw) * 42;
285 that.list_content.height(height);
287 $(data.items).each(function(){
288 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+that.item_tpl+"</div>";
289 html = html.format(this.photo, this.name, this.type, this.id, (this.forum=='1'?'forum':''), this.network, this.link);
290 if (this.uids!=undefined) that.group_uids[this.id] = this.uids;
292 that.list_content.append(html);
293 that.data[this.id] = this;
295 $(".acl-list-item img[data-src]", that.list_content).each(function(i, el){
296 // Add src attribute for images with a data-src attribute
297 $(el).attr('src', $(el).data("src"));