]> git.mxchange.org Git - friendica.git/blobdiff - js/acl.js
Trust OEmbed HTML when it's available
[friendica.git] / js / acl.js
index 054f5096026f96b222bcd9134807b1e8d0d67650..257e2c158fe867694cfc21c0a6b0df50a878500f 100644 (file)
--- a/js/acl.js
+++ b/js/acl.js
@@ -7,12 +7,15 @@ function ACL(backend_url, preset, automention, is_mobile){
 
        this.kp_timer = null;
 
-       if (preset==undefined) preset = [];
+       if (preset == undefined) {
+               preset = [];
+       }
        this.allow_cid = (preset[0] || []);
        this.allow_gid = (preset[1] || []);
        this.deny_cid  = (preset[2] || []);
        this.deny_gid  = (preset[3] || []);
        this.group_uids = [];
+       this.forumCache = null;
 
        if (this.is_mobile) {
                this.nw = 1;
@@ -25,7 +28,9 @@ function ACL(backend_url, preset, automention, is_mobile){
        this.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
        this.showall = $("#acl-showall");
 
-       if (preset.length==0) this.showall.addClass("selected");
+       if (preset.length==0) {
+               this.showall.addClass("selected");
+       }
 
        /*events*/
        this.showall.click(this.on_showall.bind(this));
@@ -47,21 +52,35 @@ ACL.prototype.remove_mention = function(id) {
                return;
        }
        var nick = this.data[id].nick;
-       var searchText = "@" + nick + "+" + id + " ";
+       var addr = this.data[id].addr;
+
+       if (addr != "") {
+               var searchText = "!" + addr + " ";
+       } else {
+               var searchText = "!" + nick + "+" + id + " ";
+       }
+
        var start = this.element.val().indexOf(searchText);
        if (start < 0) {
                return;
        }
        var end = start + searchText.length;
        this.element.setSelection(start, end).replaceSelectedText('').collapseSelection(false);
-}
+};
 
 ACL.prototype.add_mention = function(id) {
        if (!this.automention) {
                return;
        }
        var nick = this.data[id].nick;
-       var searchText =  "@" + nick + "+" + id + " ";
+       var addr = this.data[id].addr;
+
+       if (addr != "") {
+               var searchText = "!" + addr + " ";
+       } else {
+               var searchText = "!" + nick + "+" + id + " ";
+       }
+
        if (this.element.val().indexOf( searchText) >= 0 ) {
                return;
        }
@@ -82,18 +101,18 @@ ACL.prototype.on_submit = function(){
        $(this.deny_cid).each(function(i,v){
                aclfields.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
        });
-}
+};
 
 ACL.prototype.search = function(){
        var srcstr = $("#acl-search").val();
        this.list_content.html("");
        this.get(0,100, srcstr);
-}
+};
 
 ACL.prototype.on_search = function(event){
        if (this.kp_timer) clearTimeout(this.kp_timer);
        this.kp_timer = setTimeout( this.search.bind(this), 1000);
-}
+};
 
 ACL.prototype.on_showall = function(event){
        event.preventDefault()
@@ -112,7 +131,7 @@ ACL.prototype.on_showall = function(event){
        this.update_view();
 
        return false;
-}
+};
 
 ACL.prototype.on_button_show = function(event){
        event.preventDefault()
@@ -122,7 +141,8 @@ ACL.prototype.on_button_show = function(event){
        this.set_allow($(event.target).parent().attr('id'));
 
        return false;
-}
+};
+
 ACL.prototype.on_button_hide = function(event){
        event.preventDefault()
        event.stopImmediatePropagation()
@@ -131,34 +151,50 @@ ACL.prototype.on_button_hide = function(event){
        this.set_deny($(event.target).parent().attr('id'));
 
        return false;
-}
+};
 
-ACL.prototype.set_allow = function(itemid){
+ACL.prototype.set_allow = function(itemid) {
        type = itemid[0];
-       id     = parseInt(itemid.substr(1));
+       id   = parseInt(itemid.substr(1));
 
-       switch(type){
+       switch (type){
                case "g":
-                       if (this.allow_gid.indexOf(id)<0){
-                               this.allow_gid.push(id)
+                       if (this.allow_gid.indexOf(id) < 0) {
+                               this.allow_gid.push(id);
                        }else {
                                this.allow_gid.remove(id);
                        }
-                       if (this.deny_gid.indexOf(id)>=0) this.deny_gid.remove(id);
+                       if (this.deny_gid.indexOf(id) >= 0) {
+                               this.deny_gid.remove(id);
+                       }
                        break;
                case "c":
-                       if (this.allow_cid.indexOf(id)<0){
-                               this.allow_cid.push(id)
-                               if (this.data[id].forum=="1") this.add_mention(id);
+                       if (this.allow_cid.indexOf(id) < 0){
+                               this.allow_cid.push(id);
+                               if (this.data[id].forum == "1") {
+                                       // If we have select already a forum,
+                                       // we need to remove the old one (because friendica does
+                                       // allow only one forum as receiver).
+                                       if (this.forumCache !== null && this.forumCache !== id) {
+                                               this.deselectCid(this.forumCache);
+                                       }
+                                       // Update the forum cache.
+                                       this.forumCache = id;
+                                       this.add_mention(id);
+                               }
                        } else {
                                this.allow_cid.remove(id);
-                               if (this.data[id].forum=="1") this.remove_mention(id);
+                               if (this.data[id].forum == "1") {
+                                       this.remove_mention(id);
+                               }
+                       }
+                       if (this.deny_cid.indexOf(id) >=0 ) {
+                               this.deny_cid.remove(id);
                        }
-                       if (this.deny_cid.indexOf(id)>=0) this.deny_cid.remove(id);
                        break;
        }
        this.update_view();
-}
+};
 
 ACL.prototype.set_deny = function(itemid){
        type = itemid[0];
@@ -184,12 +220,12 @@ ACL.prototype.set_deny = function(itemid){
                        break;
        }
        this.update_view();
-}
+};
 
 ACL.prototype.is_show_all = function() {
        return (this.allow_gid.length==0 && this.allow_cid.length==0 &&
                this.deny_gid.length==0 && this.deny_cid.length==0);
-}
+};
 
 ACL.prototype.update_view = function(){
        if (this.is_show_all()){
@@ -265,7 +301,6 @@ ACL.prototype.update_view = function(){
 
 }
 
-
 ACL.prototype.get = function(start,count, search){
        var postdata = {
                start:start,
@@ -280,17 +315,22 @@ ACL.prototype.get = function(start,count, search){
                dataType: 'json',
                success:this.populate.bind(this)
        });
-}
+};
 
 ACL.prototype.populate = function(data){
        var height = Math.ceil(data.tot / this.nw) * 42;
        this.list_content.height(height);
        this.data = {};
-       $(data.items).each(function(index, item){
-               html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
-               html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
-               if (item.uids!=undefined) this.group_uids[item.id] = item.uids;
-
+       $(data.items).each(function(index, item) {
+               if (item.separator != undefined) {
+                       html = "<hr class='clear'>";
+               } else {
+                       html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
+                       html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
+                       if (item.uids != undefined) {
+                               this.group_uids[item.id] = item.uids;
+                       }
+               }
                this.list_content.append(html);
                this.data[item.id] = item;
        }.bind(this));
@@ -300,5 +340,20 @@ ACL.prototype.populate = function(data){
        });
 
        this.update_view();
-}
-
+};
+
+/**
+ * @brief Deselect previous selected contact.
+ * 
+ * @param {int} id The contact ID.
+ * @returns {void}
+ */
+ACL.prototype.deselectCid = function(id) {
+       if (this.allow_cid.indexOf(id) >= 0) {
+               this.allow_cid.remove(id);
+       }
+       if (this.deny_cid.indexOf(id) >=0 ) {
+               this.deny_cid.remove(id);
+       }
+       this.remove_mention(id);
+};