1 function ACL(backend_url, preset, automention, is_mobile){
3 this.url = backend_url;
4 this.automention = automention;
5 this.is_mobile = is_mobile;
10 if (preset==undefined) preset = [];
11 this.allow_cid = (preset[0] || []);
12 this.allow_gid = (preset[1] || []);
13 this.deny_cid = (preset[2] || []);
14 this.deny_gid = (preset[3] || []);
24 this.list_content = $("#acl-list-content");
25 this.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
26 this.showall = $("#acl-showall");
28 if (preset.length==0) this.showall.addClass("selected");
31 this.showall.click(this.on_showall);
32 $(document).on("click", ".acl-button-show", this.on_button_show.bind(this));
33 $(document).on("click", ".acl-button-hide", this.on_button_hide.bind(this));
34 $("#acl-search").keypress(this.on_search.bind(this));
35 $("#acl-wrapper").parents("form").submit(this.on_submit.bind(this));
37 /* add/remove mentions */
38 this.element = $("#profile-jot-text");
39 this.htmlelm = this.element.get()[0];
45 ACL.prototype.remove_mention = function(id) {
46 if (!this.automention) return;
47 var nick = this.data[id].nick;
48 var searchText = "@"+nick+"+"+id+" ";
49 if (tinyMCE.activeEditor===null) {
50 start = this.element.val().indexOf(searchText);
52 end = start+searchText.length;
53 this.element.setSelection(start,end).replaceSelectedText('').collapseSelection(false);
55 start = tinyMCE.activeEditor.getContent({format : 'raw'}).search( searchText );
56 if ( start<0 ) return;
57 txt = tinyMCE.activeEditor.getContent();
58 newtxt = txt.replace(searchText, '');
59 tinyMCE.activeEditor.setContent(newtxt);
63 ACL.prototype.add_mention = function(id) {
64 if (!this.automention) return;
65 var nick = this.data[id].nick;
66 var searchText = "@"+nick+"+"+id+" ";
67 if (tinyMCE.activeEditor===null) {
68 if ( this.element.val().indexOf( searchText) >= 0 ) return;
69 this.element.val( searchText + this.element.val() );
71 if ( tinyMCE.activeEditor.getContent({format : 'raw'}).search(searchText) >= 0 ) return;
72 tinyMCE.activeEditor.dom.add(tinyMCE.activeEditor.getBody(), 'dummy', {}, searchText);
76 ACL.prototype.on_submit = function(){
77 aclfileds = $("#acl-fields").html("");
78 $(this.allow_gid).each(function(i,v){
79 aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
81 $(this.allow_cid).each(function(i,v){
82 aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
84 $(this.deny_gid).each(function(i,v){
85 aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
87 $(this.deny_cid).each(function(i,v){
88 aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
92 ACL.prototype.search = function(){
93 var srcstr = $("#acl-search").val();
94 this.list_content.html("");
95 this.get(0,100, srcstr);
98 ACL.prototype.on_search = function(event){
99 if (this.kp_timer) clearTimeout(this.kp_timer);
100 this.kp_timer = setTimeout( this.search.bind(this), 1000);
103 ACL.prototype.on_showall = function(event){
104 event.preventDefault()
105 event.stopPropagation();
107 if (this.showall.hasClass("selected")){
110 this.showall.addClass("selected");
122 ACL.prototype.on_button_show = function(event){
123 event.preventDefault()
124 event.stopImmediatePropagation()
125 event.stopPropagation();
127 /*this.showall.removeClass("selected");
128 $(this).siblings(".acl-button-hide").removeClass("selected");
129 $(this).toggleClass("selected");*/
131 this.set_allow($(this).parent().attr('id'));
135 ACL.prototype.on_button_hide = function(event){
136 event.preventDefault()
137 event.stopImmediatePropagation()
138 event.stopPropagation();
140 /*this.showall.removeClass("selected");
141 $(this).siblings(".acl-button-show").removeClass("selected");
142 $(this).toggleClass("selected");*/
144 this.set_deny($(this).parent().attr('id'));
149 ACL.prototype.set_allow = function(itemid){
151 id = parseInt(itemid.substr(1));
155 if (this.allow_gid.indexOf(id)<0){
156 this.allow_gid.push(id)
158 this.allow_gid.remove(id);
160 if (this.deny_gid.indexOf(id)>=0) this.deny_gid.remove(id);
163 if (this.allow_cid.indexOf(id)<0){
164 this.allow_cid.push(id)
165 if (this.data[id].forum=="1") this.add_mention(id);
167 this.allow_cid.remove(id);
168 if (this.data[id].forum=="1") this.remove_mention(id);
170 if (this.deny_cid.indexOf(id)>=0) this.deny_cid.remove(id);
176 ACL.prototype.set_deny = function(itemid){
178 id = parseInt(itemid.substr(1));
182 if (this.deny_gid.indexOf(id)<0){
183 this.deny_gid.push(id)
185 this.deny_gid.remove(id);
187 if (this.allow_gid.indexOf(id)>=0) this.allow_gid.remove(id);
190 if (this.data[id].forum=="1") this.remove_mention(id);
191 if (this.deny_cid.indexOf(id)<0){
192 this.deny_cid.push(id)
194 this.deny_cid.remove(id);
196 if (this.allow_cid.indexOf(id)>=0) this.allow_cid.remove(id);
202 ACL.prototype.is_show_all = function() {
203 return (this.allow_gid.length==0 && this.allow_cid.length==0 &&
204 this.deny_gid.length==0 && this.deny_cid.length==0);
207 ACL.prototype.update_view = function(){
208 if (this.is_show_all()){
209 this.showall.addClass("selected");
211 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
212 $('#jot-public').show();
213 $('.profile-jot-net input').attr('disabled', false);
214 if(typeof editor != 'undefined' && editor != false) {
215 $('#profile-jot-desc').html(ispublic);
219 this.showall.removeClass("selected");
221 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
222 $('#jot-public').hide();
223 $('.profile-jot-net input').attr('disabled', 'disabled');
224 $('#profile-jot-desc').html(' ');
226 $("#acl-list-content .acl-list-item").each(function(){
227 $(this).removeClass("groupshow grouphide");
230 $("#acl-list-content .acl-list-item").each(function(index, element){
231 itemid = $(element).attr('id');
233 id = parseInt(itemid.substr(1));
235 btshow = $(element).children(".acl-button-show").removeClass("selected");
236 bthide = $(element).children(".acl-button-hide").removeClass("selected");
241 if (this.allow_gid.indexOf(id)>=0){
242 btshow.addClass("selected");
243 bthide.removeClass("selected");
246 if (this.deny_gid.indexOf(id)>=0){
247 btshow.removeClass("selected");
248 bthide.addClass("selected");
252 $(this.group_uids[id]).each(function(i,v) {
253 if(uclass == "grouphide")
254 $("#c"+v).removeClass("groupshow");
256 var cls = $("#c"+v).attr('class');
257 if( cls == undefined)
259 var hiding = cls.indexOf('grouphide');
261 $("#c"+v).addClass(uclass);
267 if (this.allow_cid.indexOf(id)>=0){
268 btshow.addClass("selected");
269 bthide.removeClass("selected");
271 if (this.deny_cid.indexOf(id)>=0){
272 btshow.removeClass("selected");
273 bthide.addClass("selected");
282 ACL.prototype.get = function(start,count, search){
294 success:this.populate.bind(this)
298 ACL.prototype.populate = function(data){
299 var height = Math.ceil(data.tot / this.nw) * 42;
300 this.list_content.height(height);
302 $(data.items).each(function(index, item){
303 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
304 html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
305 if (item.uids!=undefined) this.group_uids[item.id] = item.uids;
307 this.list_content.append(html);
308 this.data[item.id] = item;
310 $(".acl-list-item img[data-src]", this.list_content).each(function(i, el){
311 // Add src attribute for images with a data-src attribute
312 $(el).attr('src', $(el).data("src"));