1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jappix_ynh.git synced 2024-09-03 19:26:19 +02:00
jappix_ynh/source/app/javascripts/adhoc.js

158 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-03-12 14:52:47 +01:00
/*
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
2014-11-25 23:42:38 +01:00
var html =
'<div class="top">' + Common._e("Commands") + '</div>' +
'<div class="content">' +
'<div class="adhoc-head"></div>' +
'<div class="results adhoc-results"></div>' +
'</div>' +
'<div class="bottom">' +
'<div class="wait wait-medium"></div>' +
'<a href="#" class="finish">' + Common._e("Close") + '</a>' +
2014-03-12 14:52:47 +01:00
'</div>';
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Create the popup
Popup.create('adhoc', html);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// 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();
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Add a XID marker
$('#adhoc .adhoc-head').html('<b>' + Name.getBuddy(xid).htmlEnc() + '</b> (' + xid.htmlEnc() + ')');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Get the highest entity resource
var highest = Presence.highestPriority(xid);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
if(highest)
xid = highest;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// 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();
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Add a XID marker
$('#adhoc .adhoc-head').html('<b>' + server.htmlEnc() + '</b>');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// 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
2014-11-25 20:12:58 +01:00
$('#adhoc .bottom .finish').click(self.close);
2014-03-12 14:52:47 +01:00
} catch(e) {
Console.error('AdHoc.launch', e);
}
};
/**
* Return class scope
*/
return self;
})();