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.bind(this));
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.set_allow($(event.target).parent().attr('id'));
131 ACL.prototype.on_button_hide = function(event){
132 event.preventDefault()
133 event.stopImmediatePropagation()
134 event.stopPropagation();
136 this.set_deny($(event.target).parent().attr('id'));
141 ACL.prototype.set_allow = function(itemid){
143 id = parseInt(itemid.substr(1));
147 if (this.allow_gid.indexOf(id)<0){
148 this.allow_gid.push(id)
150 this.allow_gid.remove(id);
152 if (this.deny_gid.indexOf(id)>=0) this.deny_gid.remove(id);
155 if (this.allow_cid.indexOf(id)<0){
156 this.allow_cid.push(id)
157 if (this.data[id].forum=="1") this.add_mention(id);
159 this.allow_cid.remove(id);
160 if (this.data[id].forum=="1") this.remove_mention(id);
162 if (this.deny_cid.indexOf(id)>=0) this.deny_cid.remove(id);
168 ACL.prototype.set_deny = function(itemid){
170 id = parseInt(itemid.substr(1));
174 if (this.deny_gid.indexOf(id)<0){
175 this.deny_gid.push(id)
177 this.deny_gid.remove(id);
179 if (this.allow_gid.indexOf(id)>=0) this.allow_gid.remove(id);
182 if (this.data[id].forum=="1") this.remove_mention(id);
183 if (this.deny_cid.indexOf(id)<0){
184 this.deny_cid.push(id)
186 this.deny_cid.remove(id);
188 if (this.allow_cid.indexOf(id)>=0) this.allow_cid.remove(id);
194 ACL.prototype.is_show_all = function() {
195 return (this.allow_gid.length==0 && this.allow_cid.length==0 &&
196 this.deny_gid.length==0 && this.deny_cid.length==0);
199 ACL.prototype.update_view = function(){
200 if (this.is_show_all()){
201 this.showall.addClass("selected");
203 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
204 $('#jot-public').show();
205 $('.profile-jot-net input').attr('disabled', false);
206 if(typeof editor != 'undefined' && editor != false) {
207 $('#profile-jot-desc').html(ispublic);
211 this.showall.removeClass("selected");
213 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
214 $('#jot-public').hide();
215 $('.profile-jot-net input').attr('disabled', 'disabled');
216 $('#profile-jot-desc').html(' ');
218 $("#acl-list-content .acl-list-item").each(function(){
219 $(this).removeClass("groupshow grouphide");
222 $("#acl-list-content .acl-list-item").each(function(index, element){
223 itemid = $(element).attr('id');
225 id = parseInt(itemid.substr(1));
227 btshow = $(element).children(".acl-button-show").removeClass("selected");
228 bthide = $(element).children(".acl-button-hide").removeClass("selected");
233 if (this.allow_gid.indexOf(id)>=0){
234 btshow.addClass("selected");
235 bthide.removeClass("selected");
238 if (this.deny_gid.indexOf(id)>=0){
239 btshow.removeClass("selected");
240 bthide.addClass("selected");
244 $(this.group_uids[id]).each(function(i,v) {
245 if(uclass == "grouphide")
246 $("#c"+v).removeClass("groupshow");
248 var cls = $("#c"+v).attr('class');
249 if( cls == undefined)
251 var hiding = cls.indexOf('grouphide');
253 $("#c"+v).addClass(uclass);
259 if (this.allow_cid.indexOf(id)>=0){
260 btshow.addClass("selected");
261 bthide.removeClass("selected");
263 if (this.deny_cid.indexOf(id)>=0){
264 btshow.removeClass("selected");
265 bthide.addClass("selected");
274 ACL.prototype.get = function(start,count, search){
286 success:this.populate.bind(this)
290 ACL.prototype.populate = function(data){
291 var height = Math.ceil(data.tot / this.nw) * 42;
292 this.list_content.height(height);
294 $(data.items).each(function(index, item){
295 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
296 html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
297 if (item.uids!=undefined) this.group_uids[item.id] = item.uids;
299 this.list_content.append(html);
300 this.data[item.id] = item;
302 $(".acl-list-item img[data-src]", this.list_content).each(function(i, el){
303 // Add src attribute for images with a data-src attribute
304 $(el).attr('src', $(el).data("src"));