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) {
49 var nick = this.data[id].nick;
50 var searchText = "@" + nick + "+" + id + " ";
51 var start = this.element.val().indexOf(searchText);
55 var end = start + searchText.length;
56 this.element.setSelection(start, end).replaceSelectedText('').collapseSelection(false);
59 ACL.prototype.add_mention = function(id) {
60 if (!this.automention) {
63 var nick = this.data[id].nick;
64 var searchText = "@" + nick + "+" + id + " ";
65 if (this.element.val().indexOf( searchText) >= 0 ) {
68 this.element.val(searchText + this.element.val()).trigger('change');
71 ACL.prototype.on_submit = function(){
72 var aclfields = $("#acl-fields").html("");
73 $(this.allow_gid).each(function(i,v){
74 aclfields.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
76 $(this.allow_cid).each(function(i,v){
77 aclfields.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
79 $(this.deny_gid).each(function(i,v){
80 aclfields.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
82 $(this.deny_cid).each(function(i,v){
83 aclfields.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
87 ACL.prototype.search = function(){
88 var srcstr = $("#acl-search").val();
89 this.list_content.html("");
90 this.get(0,100, srcstr);
93 ACL.prototype.on_search = function(event){
94 if (this.kp_timer) clearTimeout(this.kp_timer);
95 this.kp_timer = setTimeout( this.search.bind(this), 1000);
98 ACL.prototype.on_showall = function(event){
99 event.preventDefault()
100 event.stopPropagation();
102 if (this.showall.hasClass("selected")){
105 this.showall.addClass("selected");
117 ACL.prototype.on_button_show = function(event){
118 event.preventDefault()
119 event.stopImmediatePropagation()
120 event.stopPropagation();
122 this.set_allow($(event.target).parent().attr('id'));
126 ACL.prototype.on_button_hide = function(event){
127 event.preventDefault()
128 event.stopImmediatePropagation()
129 event.stopPropagation();
131 this.set_deny($(event.target).parent().attr('id'));
136 ACL.prototype.set_allow = function(itemid){
138 id = parseInt(itemid.substr(1));
142 if (this.allow_gid.indexOf(id)<0){
143 this.allow_gid.push(id)
145 this.allow_gid.remove(id);
147 if (this.deny_gid.indexOf(id)>=0) this.deny_gid.remove(id);
150 if (this.allow_cid.indexOf(id)<0){
151 this.allow_cid.push(id)
152 if (this.data[id].forum=="1") this.add_mention(id);
154 this.allow_cid.remove(id);
155 if (this.data[id].forum=="1") this.remove_mention(id);
157 if (this.deny_cid.indexOf(id)>=0) this.deny_cid.remove(id);
163 ACL.prototype.set_deny = function(itemid){
165 id = parseInt(itemid.substr(1));
169 if (this.deny_gid.indexOf(id)<0){
170 this.deny_gid.push(id)
172 this.deny_gid.remove(id);
174 if (this.allow_gid.indexOf(id)>=0) this.allow_gid.remove(id);
177 if (this.data[id].forum=="1") this.remove_mention(id);
178 if (this.deny_cid.indexOf(id)<0){
179 this.deny_cid.push(id)
181 this.deny_cid.remove(id);
183 if (this.allow_cid.indexOf(id)>=0) this.allow_cid.remove(id);
189 ACL.prototype.is_show_all = function() {
190 return (this.allow_gid.length==0 && this.allow_cid.length==0 &&
191 this.deny_gid.length==0 && this.deny_cid.length==0);
194 ACL.prototype.update_view = function(){
195 if (this.is_show_all()){
196 this.showall.addClass("selected");
198 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
199 $('#jot-public').show();
200 $('.profile-jot-net input').attr('disabled', false);
201 if(typeof editor != 'undefined' && editor != false) {
202 $('#profile-jot-desc').html(ispublic);
206 this.showall.removeClass("selected");
208 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
209 $('#jot-public').hide();
210 $('.profile-jot-net input').attr('disabled', 'disabled');
211 $('#profile-jot-desc').html(' ');
213 $("#acl-list-content .acl-list-item").each(function(){
214 $(this).removeClass("groupshow grouphide");
217 $("#acl-list-content .acl-list-item").each(function(index, element){
218 itemid = $(element).attr('id');
220 id = parseInt(itemid.substr(1));
222 btshow = $(element).children(".acl-button-show").removeClass("selected");
223 bthide = $(element).children(".acl-button-hide").removeClass("selected");
228 if (this.allow_gid.indexOf(id)>=0){
229 btshow.addClass("selected");
230 bthide.removeClass("selected");
233 if (this.deny_gid.indexOf(id)>=0){
234 btshow.removeClass("selected");
235 bthide.addClass("selected");
239 $(this.group_uids[id]).each(function(i,v) {
240 if(uclass == "grouphide")
241 $("#c"+v).removeClass("groupshow");
243 var cls = $("#c"+v).attr('class');
244 if( cls == undefined)
246 var hiding = cls.indexOf('grouphide');
248 $("#c"+v).addClass(uclass);
254 if (this.allow_cid.indexOf(id)>=0){
255 btshow.addClass("selected");
256 bthide.removeClass("selected");
258 if (this.deny_cid.indexOf(id)>=0){
259 btshow.removeClass("selected");
260 bthide.addClass("selected");
269 ACL.prototype.get = function(start,count, search){
281 success:this.populate.bind(this)
285 ACL.prototype.populate = function(data){
286 var height = Math.ceil(data.tot / this.nw) * 42;
287 this.list_content.height(height);
289 $(data.items).each(function(index, item){
290 html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
291 html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
292 if (item.uids!=undefined) this.group_uids[item.id] = item.uids;
294 this.list_content.append(html);
295 this.data[item.id] = item;
297 $(".acl-list-item img[data-src]", this.list_content).each(function(i, el){
298 // Add src attribute for images with a data-src attribute
299 $(el).attr('src', $(el).data("src"));