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(id) {
38 var nick = that.data[id].nick;
39 var searchText = "@"+nick+"+"+id+" ";
40 if (tinyMCE.activeEditor===null) {
41 start = that.element.val().indexOf(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(id) {
55 var nick = that.data[id].nick;
56 var searchText = "@"+nick+"+"+id+" ";
57 if (tinyMCE.activeEditor===null) {
58 if ( that.element.val().indexOf( searchText) >= 0 ) return;
59 that.element.val( searchText + that.element.val() );
61 if ( tinyMCE.activeEditor.getContent({format : 'raw'}).search(searchText) >= 0 ) return;
62 tinyMCE.activeEditor.dom.add(tinyMCE.activeEditor.getBody(), 'span', {}, searchText);
66 ACL.prototype.on_submit = function(){
67 aclfileds = $("#acl-fields").html("");
68 $(that.allow_gid).each(function(i,v){
69 aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
71 $(that.allow_cid).each(function(i,v){
72 aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
74 $(that.deny_gid).each(function(i,v){
75 aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
77 $(that.deny_cid).each(function(i,v){
78 aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
82 ACL.prototype.search = function(){
83 var srcstr = $("#acl-search").val();
84 that.list_content.html("");
85 that.get(0,100, srcstr);
88 ACL.prototype.on_search = function(event){
89 if (that.kp_timer) clearTimeout(that.kp_timer);
90 that.kp_timer = setTimeout( that.search, 1000);
93 ACL.prototype.on_showall = function(event){
94 event.preventDefault()
95 event.stopPropagation();
97 if (that.showall.hasClass("selected")){
100 that.showall.addClass("selected");
112 ACL.prototype.on_button_show = function(event){
113 event.preventDefault()
114 event.stopImmediatePropagation()
115 event.stopPropagation();
117 /*that.showall.removeClass("selected");
118 $(this).siblings(".acl-button-hide").removeClass("selected");
119 $(this).toggleClass("selected");*/
121 that.set_allow($(this).parent().attr('id'));
125 ACL.prototype.on_button_hide = function(event){
126 event.preventDefault()
127 event.stopImmediatePropagation()
128 event.stopPropagation();
130 /*that.showall.removeClass("selected");
131 $(this).siblings(".acl-button-show").removeClass("selected");
132 $(this).toggleClass("selected");*/
134 that.set_deny($(this).parent().attr('id'));
139 ACL.prototype.set_allow = function(itemid){
141 id = parseInt(itemid.substr(1));
145 if (that.allow_gid.indexOf(id)<0){
146 that.allow_gid.push(id)
148 that.allow_gid.remove(id);
150 if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id);
153 if (that.allow_cid.indexOf(id)<0){
154 that.allow_cid.push(id)
155 if (that.data[id].forum=="1") that.add_mention(id);
157 that.allow_cid.remove(id);
158 if (that.data[id].forum=="1") that.remove_mention(id);
160 if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id);
166 ACL.prototype.set_deny = function(itemid){
168 id = parseInt(itemid.substr(1));
172 if (that.deny_gid.indexOf(id)<0){
173 that.deny_gid.push(id)
175 that.deny_gid.remove(id);
177 if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id);
180 if (that.data[id].forum=="1") that.remove_mention(id);
181 if (that.deny_cid.indexOf(id)<0){
182 that.deny_cid.push(id)
184 that.deny_cid.remove(id);
186 if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id);
192 ACL.prototype.is_show_all = function() {
193 return (that.allow_gid.length==0 && that.allow_cid.length==0 &&
194 that.deny_gid.length==0 && that.deny_cid.length==0);
197 ACL.prototype.update_view = function(){
198 if (this.is_show_all()){
199 that.showall.addClass("selected");
201 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
202 $('#jot-public').show();
203 $('.profile-jot-net input').attr('disabled', false);
204 if(typeof editor != 'undefined' && editor != false) {
205 $('#profile-jot-desc').html(ispublic);
209 that.showall.removeClass("selected");
211 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
212 $('#jot-public').hide();
213 $('.profile-jot-net input').attr('disabled', 'disabled');
214 $('#profile-jot-desc').html(' ');
216 $("#acl-list-content .acl-list-item").each(function(){
217 $(this).removeClass("groupshow grouphide");
220 $("#acl-list-content .acl-list-item").each(function(){
221 itemid = $(this).attr('id');
223 id = parseInt(itemid.substr(1));
225 btshow = $(this).children(".acl-button-show").removeClass("selected");
226 bthide = $(this).children(".acl-button-hide").removeClass("selected");
231 if (that.allow_gid.indexOf(id)>=0){
232 btshow.addClass("selected");
233 bthide.removeClass("selected");
236 if (that.deny_gid.indexOf(id)>=0){
237 btshow.removeClass("selected");
238 bthide.addClass("selected");
242 $(that.group_uids[id]).each(function(i,v) {
243 if(uclass == "grouphide")
244 $("#c"+v).removeClass("groupshow");
246 var cls = $("#c"+v).attr('class');
247 if( cls == undefined)
249 var hiding = cls.indexOf('grouphide');
251 $("#c"+v).addClass(uclass);
257 if (that.allow_cid.indexOf(id)>=0){
258 btshow.addClass("selected");
259 bthide.removeClass("selected");
261 if (that.deny_cid.indexOf(id)>=0){
262 btshow.removeClass("selected");
263 bthide.addClass("selected");
272 ACL.prototype.get = function(start,count, search){
284 success:that.populate
288 ACL.prototype.populate = function(data){
289 var height = Math.ceil(data.tot / that.nw) * 42;
290 that.list_content.height(height);
292 $(data.items).each(function(){
293 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+that.item_tpl+"</div>";
294 html = html.format(this.photo, this.name, this.type, this.id, (this.forum=='1'?'forum':''), this.network, this.link);
295 if (this.uids!=undefined) that.group_uids[this.id] = this.uids;
297 that.list_content.append(html);
298 that.data[this.id] = this;
300 $(".acl-list-item img[data-src]", that.list_content).each(function(i, el){
301 // Add src attribute for images with a data-src attribute
302 $(el).attr('src', $(el).data("src"));