// userid and type of the object to send the message to // parameters must contain at least: // - obj: the link that is clicked // - friendid: the id of the third party object (user, network...) // // Optional parameters are: // - header_text: the header text of the dialog when using a dialog // - button: the button text // - button2: an additional button // - use_callback will refresh the module containing obj // - nodialog will cause the action to occur without showing the dialog // - delay_callback will cause the callback to occur only on closing the dialog // // Methods with a dialog: // _______________________________________________________ // | method | dialog | // |_______________________|_____________________________| // | edit_membership | relations_add | // | ban | relations_ban | // |_______________________|_____________________________| // // Methods without a dialog: // _________________________ // | method | // |_______________________| // | unban | // | leave | // | follow | // | reject | // | approve | // | remove_leader | // | add_leader | // |_______________________| dex.relation = function(userid, type, parameters) { this.process_answer = function(o) { var content = o; content = content.replace(new RegExp("[\n|\r|\f]", 'gi'),""); content = content.replace(new RegExp(']+type=["|\']submit[\'|"][^>]*/>', 'gi'), ''); return content; }; this.process_content = function(content) { var method = ''; var hidden_fields = YAHOO.util.Selector.query('input', content); len = hidden_fields.length; for(var i = 0; i < len; i++) { if (hidden_fields[i].name == 'method') { method = hidden_fields[i].value; break; } }; var form = YAHOO.util.Selector.query('form', content, true); form.action = '/' + this.type + '/' + this.userid + '/json/' + method + '/'; }; this.callback = function() { dex.page.find_module(this.obj).refresh(); }; this.edit_membership = function(parameters) { this.set_parameters(parameters); dex.load.onclick("dex.dialog",function() { this.dialog = new dex.dialog(this, this.config); this.dialog.load_form('/'+this.type+'/'+this.userid+'/module/relations_add/'); },{scope:this}) }; this.clear_ban = function(callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/ban/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid); } this.ban = function (parameters) { this.set_parameters(parameters); dex.load.onclick("dex.dialog",function() { this.dialog = new dex.dialog(this, this.config); this.dialog.load_form('/'+this.type+'/'+this.userid+'/module/relations_ban/?rel=ban&friendid='+this.friendid); },{scope:this}); }; this.unban = function (callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/unban/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid); }; this.leave = function () { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/leave/', { success:function(o) { this.callback(); }, scope: this}, 'friendid='+this.friendid); }; this.follow = function (callbackfn) { params = 'friendid='+this.friendid; if (typeof(this.mail) != 'undefined') { params = params+'&mail='+this.mail } if (typeof(this.activity) != 'undefined') { params = params+'&activity='+this.activity } YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/follow/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this}, params); }; this.reject = function(callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/reject/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid) }; this.approve = function(callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/approve/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid) }; this.remove_leader = function(callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/remove_leader/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid) }; this.add_leader = function(callbackfn) { YAHOO.util.Connect.initHeader('X-Signature', dex.hash); YAHOO.util.Connect.asyncRequest('POST', '/'+this.type+'/'+this.userid+'/json/add_leader/', { success:function(o) { if(callbackfn == undefined) { this.callback(); } else if (typeof callbackfn == 'function') { callbackfn(); } }, scope: this} ,'friendid='+this.friendid) //this.dialog.load_form('/network/' + this.network + '/module/99/?method=add_leader&user=' + this.user); }; this.set_parameters = function(parameters) { for (i in parameters) { this[i] = parameters[i]; this.config[i] = parameters[i]; } }; this.userid = userid; this.type = type; this.config = { process_answer:true, process_content:true, dialog_id:'relation_dialog', width:'500px'}; for (i in parameters) { this[i] = parameters[i]; this.config[i] = parameters[i]; }; }