/*
Jappix - An open social platform
These are the Ad-Hoc JS scripts for Jappix
-------------------------------------------------
License: AGPL
Author: Valérian Saliou
*/
// Bundle
var AdHoc = (function () {
/**
* Alias of this
* @private
*/
var self = {};
/**
* Opens the adhoc popup
* @public
* @return {boolean}
*/
self.open = function() {
try {
// Popup HTML content
var html =
'
' + Common._e("Commands") + '
' +
'' +
'';
// Create the popup
Popup.create('adhoc', html);
// Associate the events
self.launch();
} catch(e) {
Console.error('AdHoc.open', e);
} finally {
return false;
}
};
/**
* Closes the adhoc popup
* @public
* @return {boolean}
*/
self.close = function() {
try {
// Destroy the popup
Popup.destroy('adhoc');
} catch(e) {
Console.error('AdHoc.close', e);
} finally {
return false;
}
};
/**
* Retrieves an entity adhoc command
* @public
* @param {string} xid
* @return {boolean}
*/
self.retrieve = function(xid) {
try {
// Open the popup
self.open();
// Add a XID marker
$('#adhoc .adhoc-head').html('' + Name.getBuddy(xid).htmlEnc() + ' (' + xid.htmlEnc() + ')');
// Get the highest entity resource
var highest = Presence.highestPriority(xid);
if(highest)
xid = highest;
// Start a new adhoc command
DataForm.go(xid, 'command', '', '', 'adhoc');
} catch(e) {
Console.error('AdHoc.retrieve', e);
} finally {
return false;
}
};
/**
* Starts an adhoc command on the user server
* @public
* @param {string} server
* @return {undefined}
*/
self.server = function(server) {
try {
// Open the popup
self.open();
// Add a XID marker
$('#adhoc .adhoc-head').html('' + server.htmlEnc() + '');
// Start a new adhoc command
DataForm.go(server, 'command', '', '', 'adhoc');
} catch(e) {
Console.error('AdHoc.server', e);
}
};
/**
* Plugin launcher
* @public
* @return {undefined}
*/
self.launch = function() {
try {
// Click event
$('#adhoc .bottom .finish').click(
self.close()
);
} catch(e) {
Console.error('AdHoc.launch', e);
}
};
/**
* Return class scope
*/
return self;
})();