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 = 3; //items per row. should be calulated from #acl-list.width
16 that.list_content = $j("#acl-list-content");
17 that.item_tpl = unescape($j(".acl-list-item[rel=acl-template]").html());
18 that.showall = $j("#acl-showall");
20 if (preset.length==0) that.showall.addClass("selected");
23 that.showall.click(that.on_showall);
24 $j(".acl-button-show").live('click', that.on_button_show);
25 $j(".acl-button-hide").live('click', that.on_button_hide);
26 $j("#acl-search").keypress(that.on_search);
27 $j("#acl-wrapper").parents("form").submit(that.on_submit);
33 ACL.prototype.on_submit = function(){
34 aclfileds = $j("#acl-fields").html("");
35 $j(that.allow_gid).each(function(i,v){
36 aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
38 $j(that.allow_cid).each(function(i,v){
39 aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
41 $j(that.deny_gid).each(function(i,v){
42 aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
44 $j(that.deny_cid).each(function(i,v){
45 aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
49 ACL.prototype.search = function(){
50 var srcstr = $j("#acl-search").val();
51 that.list_content.html("");
52 that.get(0,100, srcstr);
55 ACL.prototype.on_search = function(event){
56 if (that.kp_timer) clearTimeout(that.kp_timer);
57 that.kp_timer = setTimeout( that.search, 1000);
60 ACL.prototype.on_showall = function(event){
61 event.preventDefault()
62 event.stopPropagation();
64 if (that.showall.hasClass("selected")){
67 that.showall.addClass("selected");
79 ACL.prototype.on_button_show = function(event){
80 event.preventDefault()
81 event.stopImmediatePropagation()
82 event.stopPropagation();
84 /*that.showall.removeClass("selected");
85 $j(this).siblings(".acl-button-hide").removeClass("selected");
86 $j(this).toggleClass("selected");*/
88 that.set_allow($j(this).parent().attr('id'));
92 ACL.prototype.on_button_hide = function(event){
93 event.preventDefault()
94 event.stopImmediatePropagation()
95 event.stopPropagation();
97 /*that.showall.removeClass("selected");
98 $j(this).siblings(".acl-button-show").removeClass("selected");
99 $j(this).toggleClass("selected");*/
101 that.set_deny($j(this).parent().attr('id'));
106 ACL.prototype.set_allow = function(itemid){
108 id = parseInt(itemid.substr(1));
111 if (that.allow_gid.indexOf(id)<0){
112 that.allow_gid.push(id)
114 that.allow_gid.remove(id);
116 if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id);
119 if (that.allow_cid.indexOf(id)<0){
120 that.allow_cid.push(id)
122 that.allow_cid.remove(id);
124 if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id);
130 ACL.prototype.set_deny = function(itemid){
132 id = parseInt(itemid.substr(1));
135 if (that.deny_gid.indexOf(id)<0){
136 that.deny_gid.push(id)
138 that.deny_gid.remove(id);
140 if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id);
143 if (that.deny_cid.indexOf(id)<0){
144 that.deny_cid.push(id)
146 that.deny_cid.remove(id);
148 if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id);
154 ACL.prototype.update_view = function(){
155 if (that.allow_gid.length==0 && that.allow_cid.length==0 &&
156 that.deny_gid.length==0 && that.deny_cid.length==0){
157 that.showall.addClass("selected");
159 $j('#jot-perms-icon').removeClass('lock').addClass('unlock');
160 $j('#jot-public').show();
161 $j('.profile-jot-net input').attr('disabled', false);
162 if(typeof editor != 'undefined' && editor != false) {
163 $j('#profile-jot-desc').html(ispublic);
167 that.showall.removeClass("selected");
169 $j('#jot-perms-icon').removeClass('unlock').addClass('lock');
170 $j('#jot-public').hide();
171 $j('.profile-jot-net input').attr('disabled', 'disabled');
172 $j('#profile-jot-desc').html(' ');
174 $j("#acl-list-content .acl-list-item").each(function(){
175 $j(this).removeClass("groupshow grouphide");
178 $j("#acl-list-content .acl-list-item").each(function(){
179 itemid = $j(this).attr('id');
181 id = parseInt(itemid.substr(1));
183 btshow = $j(this).children(".acl-button-show").removeClass("selected");
184 bthide = $j(this).children(".acl-button-hide").removeClass("selected");
189 if (that.allow_gid.indexOf(id)>=0){
190 btshow.addClass("selected");
191 bthide.removeClass("selected");
194 if (that.deny_gid.indexOf(id)>=0){
195 btshow.removeClass("selected");
196 bthide.addClass("selected");
200 $j(that.group_uids[id]).each(function(i,v) {
201 if(uclass == "grouphide")
202 $j("#c"+v).removeClass("groupshow");
204 var cls = $j("#c"+v).attr('class');
205 if( cls == undefined)
207 var hiding = cls.indexOf('grouphide');
209 $j("#c"+v).addClass(uclass);
215 if (that.allow_cid.indexOf(id)>=0){
216 btshow.addClass("selected");
217 bthide.removeClass("selected");
219 if (that.deny_cid.indexOf(id)>=0){
220 btshow.removeClass("selected");
221 bthide.addClass("selected");
230 ACL.prototype.get = function(start,count, search){
242 success:that.populate
246 ACL.prototype.populate = function(data){
247 var height = Math.ceil(data.tot / that.nw) * 42;
248 that.list_content.height(height);
249 $j(data.items).each(function(){
250 html = "<div class='acl-list-item {4} {5}' title='{6}' id='{2}{3}'><img src='{0}'/><p>{1}</p>"+that.item_tpl+"</div>";
251 html = html.format( this.photo, this.name, this.type, this.id, '', this.network, this.link );
252 if (this.uids!=undefined) that.group_uids[this.id] = this.uids;
254 that.list_content.append(html);