1 function ACL(backend_url, preset, automention){
4 that.url = backend_url;
5 that.automention = automention;
9 if (preset==undefined) preset = [];
10 that.allow_cid = (preset[0] || []);
11 that.allow_gid = (preset[1] || []);
12 that.deny_cid = (preset[2] || []);
13 that.deny_gid = (preset[3] || []);
15 that.nw = 4; //items per row. should be calulated from #acl-list.width
17 that.list_content = $("#acl-list-content");
18 that.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
19 that.showall = $("#acl-showall");
21 if (preset.length==0) that.showall.addClass("selected");
24 that.showall.click(that.on_showall);
25 $(document).on("click", ".acl-button-show", that.on_button_show);
26 $(document).on("click", ".acl-button-hide", that.on_button_hide);
27 $("#acl-search").keypress(that.on_search);
28 $("#acl-wrapper").parents("form").submit(that.on_submit);
30 /* add/remove mentions */
31 that.element = $("#profile-jot-text");
32 that.htmlelm = that.element.get()[0];
38 ACL.prototype.remove_mention = function(id) {
39 if (!that.automention) return;
40 var nick = that.data[id].nick;
41 var searchText = "@"+nick+"+"+id+" ";
42 if (tinyMCE.activeEditor===null) {
43 start = that.element.val().indexOf(searchText);
45 end = start+searchText.length;
46 that.element.setSelection(start,end).replaceSelectedText('').collapseSelection(false);
48 start = tinyMCE.activeEditor.getContent({format : 'raw'}).search( searchText );
49 if ( start<0 ) return;
50 txt = tinyMCE.activeEditor.getContent();
51 newtxt = txt.replace(searchText, '');
52 tinyMCE.activeEditor.setContent(newtxt);
56 ACL.prototype.add_mention = function(id) {
57 if (!that.automention) return;
58 var nick = that.data[id].nick;
59 var searchText = "@"+nick+"+"+id+" ";
60 if (tinyMCE.activeEditor===null) {
61 if ( that.element.val().indexOf( searchText) >= 0 ) return;
62 that.element.val( searchText + that.element.val() );
64 if ( tinyMCE.activeEditor.getContent({format : 'raw'}).search(searchText) >= 0 ) return;
65 tinyMCE.activeEditor.dom.add(tinyMCE.activeEditor.getBody(), 'dummy', {}, searchText);
69 ACL.prototype.on_submit = function(){
70 aclfileds = $("#acl-fields").html("");
71 $(that.allow_gid).each(function(i,v){
72 aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
74 $(that.allow_cid).each(function(i,v){
75 aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
77 $(that.deny_gid).each(function(i,v){
78 aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
80 $(that.deny_cid).each(function(i,v){
81 aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
85 ACL.prototype.search = function(){
86 var srcstr = $("#acl-search").val();
87 that.list_content.html("");
88 that.get(0,100, srcstr);
91 ACL.prototype.on_search = function(event){
92 if (that.kp_timer) clearTimeout(that.kp_timer);
93 that.kp_timer = setTimeout( that.search, 1000);
96 ACL.prototype.on_showall = function(event){
97 event.preventDefault()
98 event.stopPropagation();
100 if (that.showall.hasClass("selected")){
103 that.showall.addClass("selected");
115 ACL.prototype.on_button_show = function(event){
116 event.preventDefault()
117 event.stopImmediatePropagation()
118 event.stopPropagation();
120 /*that.showall.removeClass("selected");
121 $(this).siblings(".acl-button-hide").removeClass("selected");
122 $(this).toggleClass("selected");*/
124 that.set_allow($(this).parent().attr('id'));
128 ACL.prototype.on_button_hide = function(event){
129 event.preventDefault()
130 event.stopImmediatePropagation()
131 event.stopPropagation();
133 /*that.showall.removeClass("selected");
134 $(this).siblings(".acl-button-show").removeClass("selected");
135 $(this).toggleClass("selected");*/
137 that.set_deny($(this).parent().attr('id'));
142 ACL.prototype.set_allow = function(itemid){
144 id = parseInt(itemid.substr(1));
148 if (that.allow_gid.indexOf(id)<0){
149 that.allow_gid.push(id)
151 that.allow_gid.remove(id);
153 if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id);
156 if (that.allow_cid.indexOf(id)<0){
157 that.allow_cid.push(id)
158 if (that.data[id].forum=="1") that.add_mention(id);
160 that.allow_cid.remove(id);
161 if (that.data[id].forum=="1") that.remove_mention(id);
163 if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id);
169 ACL.prototype.set_deny = function(itemid){
171 id = parseInt(itemid.substr(1));
175 if (that.deny_gid.indexOf(id)<0){
176 that.deny_gid.push(id)
178 that.deny_gid.remove(id);
180 if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id);
183 if (that.data[id].forum=="1") that.remove_mention(id);
184 if (that.deny_cid.indexOf(id)<0){
185 that.deny_cid.push(id)
187 that.deny_cid.remove(id);
189 if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id);
195 ACL.prototype.is_show_all = function() {
196 return (that.allow_gid.length==0 && that.allow_cid.length==0 &&
197 that.deny_gid.length==0 && that.deny_cid.length==0);
200 ACL.prototype.update_view = function(){
201 if (this.is_show_all()){
202 that.showall.addClass("selected");
204 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
205 $('#jot-public').show();
206 $('.profile-jot-net input').attr('disabled', false);
207 if(typeof editor != 'undefined' && editor != false) {
208 $('#profile-jot-desc').html(ispublic);
212 that.showall.removeClass("selected");
214 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
215 $('#jot-public').hide();
216 $('.profile-jot-net input').attr('disabled', 'disabled');
217 $('#profile-jot-desc').html(' ');
219 $("#acl-list-content .acl-list-item").each(function(){
220 $(this).removeClass("groupshow grouphide");
223 $("#acl-list-content .acl-list-item").each(function(){
224 itemid = $(this).attr('id');
226 id = parseInt(itemid.substr(1));
228 btshow = $(this).children(".acl-button-show").removeClass("selected");
229 bthide = $(this).children(".acl-button-hide").removeClass("selected");
234 if (that.allow_gid.indexOf(id)>=0){
235 btshow.addClass("selected");
236 bthide.removeClass("selected");
239 if (that.deny_gid.indexOf(id)>=0){
240 btshow.removeClass("selected");
241 bthide.addClass("selected");
245 $(that.group_uids[id]).each(function(i,v) {
246 if(uclass == "grouphide")
247 $("#c"+v).removeClass("groupshow");
249 var cls = $("#c"+v).attr('class');
250 if( cls == undefined)
252 var hiding = cls.indexOf('grouphide');
254 $("#c"+v).addClass(uclass);
260 if (that.allow_cid.indexOf(id)>=0){
261 btshow.addClass("selected");
262 bthide.removeClass("selected");
264 if (that.deny_cid.indexOf(id)>=0){
265 btshow.removeClass("selected");
266 bthide.addClass("selected");
275 ACL.prototype.get = function(start,count, search){
287 success:that.populate
291 ACL.prototype.populate = function(data){
292 var height = Math.ceil(data.tot / that.nw) * 42;
293 that.list_content.height(height);
295 $(data.items).each(function(){
296 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+that.item_tpl+"</div>";
297 html = html.format(this.photo, this.name, this.type, this.id, (this.forum=='1'?'forum':''), this.network, this.link);
298 if (this.uids!=undefined) that.group_uids[this.id] = this.uids;
300 that.list_content.append(html);
301 that.data[this.id] = this;
303 $(".acl-list-item img[data-src]", that.list_content).each(function(i, el){
304 // Add src attribute for images with a data-src attribute
305 $(el).attr('src', $(el).data("src"));