2016-06-02 16:51:15 +02:00
|
|
|
/* global jQuery, et2_dialog, Promise, et2_nextmatch, Class, etemplate2, et2_favorites, mailvelope */
|
2015-08-31 18:40:33 +02:00
|
|
|
|
2013-04-09 10:45:59 +02:00
|
|
|
/**
|
|
|
|
* EGroupware clientside Application javascript base object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
2015-10-28 10:55:29 +01:00
|
|
|
egw_inheritance;
|
2016-04-07 12:38:05 +02:00
|
|
|
/api/js/es6-promise.min.js;
|
2013-04-09 10:45:59 +02:00
|
|
|
*/
|
|
|
|
|
2013-11-04 21:54:23 +01:00
|
|
|
/**
|
|
|
|
* Object to collect instanciated appliction objects
|
|
|
|
*
|
|
|
|
* Attributes classes collects loaded application classes,
|
|
|
|
* which can get instanciated:
|
|
|
|
*
|
|
|
|
* app[appname] = new app.classes[appname]();
|
|
|
|
*
|
|
|
|
* On destruction only app[appname] gets deleted, app.classes[appname] need to be used again!
|
|
|
|
*
|
|
|
|
* @type object
|
|
|
|
*/
|
2016-03-03 15:10:08 +01:00
|
|
|
app = {classes: {}};
|
2013-04-09 10:45:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Common base class for application javascript
|
|
|
|
* Each app should extend as needed.
|
|
|
|
*
|
|
|
|
* All application javascript should be inside. Intitialization goes in init(),
|
2013-11-04 21:54:23 +01:00
|
|
|
* clean-up code goes in destroy(). Initialization is done once all js is loaded.
|
2013-04-09 10:45:59 +02:00
|
|
|
*
|
|
|
|
* var app.appname = AppJS.extend({
|
|
|
|
* // Actually set this one, the rest is example
|
|
|
|
* appname: appname,
|
|
|
|
*
|
|
|
|
* internal_var: 1000,
|
|
|
|
*
|
|
|
|
* init: function()
|
|
|
|
* {
|
|
|
|
* // Call the super
|
|
|
|
* this._super.apply(this, arguments);
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-09 10:45:59 +02:00
|
|
|
* // Init the stuff
|
2013-11-04 21:54:23 +01:00
|
|
|
* if ( egw.preference('dateformat', 'common') )
|
2013-04-09 10:45:59 +02:00
|
|
|
* {
|
|
|
|
* // etc
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* _private: function()
|
|
|
|
* {
|
|
|
|
* // Underscore private by convention
|
|
|
|
* }
|
|
|
|
* });
|
2014-03-20 10:40:37 +01:00
|
|
|
*
|
|
|
|
* @class AppJS
|
|
|
|
* @augments Class
|
2013-04-09 10:45:59 +02:00
|
|
|
*/
|
2016-02-29 16:50:24 +01:00
|
|
|
var AppJS = (function(){ "use strict"; return Class.extend(
|
2013-11-04 21:54:23 +01:00
|
|
|
{
|
2013-04-09 10:45:59 +02:00
|
|
|
/**
|
|
|
|
* Internal application name - override this
|
|
|
|
*/
|
|
|
|
appname: '',
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-20 21:20:10 +02:00
|
|
|
/**
|
2015-12-02 19:42:55 +01:00
|
|
|
* Internal reference to the most recently loaded etemplate2 widget tree
|
|
|
|
*
|
|
|
|
* NOTE: This variable can change which etemplate it points to as the user
|
|
|
|
* works. For example, loading the home or admin apps can cause
|
|
|
|
* et2_ready() to be called again with a different template. this.et2 will
|
|
|
|
* then point to a different template. If the user then closes that tab,
|
|
|
|
* this.et2 will point to a destroyed object, and trying to use it will fail.
|
|
|
|
*
|
|
|
|
* If you need a reference to a certain template you can either store a local
|
|
|
|
* reference or access it through etemplate2.
|
2016-02-29 16:50:24 +01:00
|
|
|
*
|
2015-12-02 19:42:55 +01:00
|
|
|
* @example <caption>Store a local reference</caption>
|
|
|
|
* // in et2_ready()
|
|
|
|
* if(name == 'index') this.index_et2 = et2.widgetContainer;
|
|
|
|
*
|
|
|
|
* // Remember to clean up in destroy()
|
|
|
|
* delete this.index_et2;
|
|
|
|
*
|
|
|
|
* // Instead of this.et2, using a local reference
|
|
|
|
* this.index_et2 ...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @example <caption>Access via etemplate2 object</caption>
|
|
|
|
* // Instead of this.et2, using it's unique ID
|
|
|
|
* var et2 = etemplate2.getById('myapp-index)
|
|
|
|
* if(et2)
|
|
|
|
* {
|
|
|
|
* et2.widgetContainer. ...
|
|
|
|
* }
|
2014-03-20 10:40:37 +01:00
|
|
|
*
|
|
|
|
* @var {et2_container}
|
2013-08-20 21:20:10 +02:00
|
|
|
*/
|
|
|
|
et2: null,
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-10-07 18:53:13 +02:00
|
|
|
/**
|
|
|
|
* Internal reference to egw client-side api object for current app and window
|
2014-03-20 10:40:37 +01:00
|
|
|
*
|
|
|
|
* @var {egw}
|
2013-10-07 18:53:13 +02:00
|
|
|
*/
|
|
|
|
egw: null,
|
2013-04-09 10:45:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization and setup goes here, but the etemplate2 object
|
|
|
|
* is not yet ready.
|
|
|
|
*/
|
|
|
|
init: function() {
|
2013-10-07 18:53:13 +02:00
|
|
|
this.egw = egw(this.appname, window);
|
2013-12-06 22:26:55 +01:00
|
|
|
|
2014-05-13 08:44:50 +02:00
|
|
|
// Initialize sidebox for non-popups.
|
2014-05-12 22:36:18 +02:00
|
|
|
// ID set server side
|
2014-05-13 08:44:50 +02:00
|
|
|
if(!this.egw.is_popup())
|
2013-12-07 00:12:05 +01:00
|
|
|
{
|
2014-05-12 22:36:18 +02:00
|
|
|
var sidebox = jQuery('#favorite_sidebox_'+this.appname);
|
|
|
|
if(sidebox.length == 0 && egw_getFramework() != null)
|
|
|
|
{
|
|
|
|
var egw_fw = egw_getFramework();
|
2016-06-02 16:51:15 +02:00
|
|
|
sidebox= jQuery('#favorite_sidebox_'+this.appname,egw_fw.sidemenuDiv);
|
2014-05-12 22:36:18 +02:00
|
|
|
}
|
|
|
|
// Make sure we're running in the top window when we init sidebox
|
2016-03-17 19:12:36 +01:00
|
|
|
if(window.app[this.appname] === this && window.top.app[this.appname] !== this && window.top.app[this.appname])
|
2014-05-12 22:36:18 +02:00
|
|
|
{
|
|
|
|
window.top.app[this.appname]._init_sidebox(sidebox);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._init_sidebox(sidebox);
|
|
|
|
}
|
2014-04-29 18:51:57 +02:00
|
|
|
}
|
2013-04-09 10:45:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up any created objects & references
|
2016-03-17 19:12:36 +01:00
|
|
|
* @param {object} _app local app object
|
2013-04-09 10:45:59 +02:00
|
|
|
*/
|
2016-03-03 15:10:08 +01:00
|
|
|
destroy: function(_app) {
|
2013-08-20 21:20:10 +02:00
|
|
|
delete this.et2;
|
2014-02-19 16:10:39 +01:00
|
|
|
if (this.sidebox)
|
|
|
|
this.sidebox.off();
|
2013-12-12 00:54:42 +01:00
|
|
|
delete this.sidebox;
|
2016-03-17 19:12:36 +01:00
|
|
|
if (!_app) delete app[this.appname];
|
2013-04-09 10:45:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called when the etemplate2 object is loaded
|
|
|
|
* and ready. If you must store a reference to the et2 object,
|
2013-08-21 01:20:56 +02:00
|
|
|
* make sure to clean it up in destroy(). Note that this can be called
|
|
|
|
* several times, with different et2 objects, as templates are loaded.
|
2013-04-09 10:45:59 +02:00
|
|
|
*
|
2014-02-17 15:58:20 +01:00
|
|
|
* @param {etemplate2} et2
|
|
|
|
* @param {string} name template name
|
2013-04-09 10:45:59 +02:00
|
|
|
*/
|
2014-02-17 15:58:20 +01:00
|
|
|
et2_ready: function(et2,name) {
|
2013-08-21 01:20:56 +02:00
|
|
|
if(this.et2 !== null)
|
2013-08-20 21:20:10 +02:00
|
|
|
{
|
2013-08-21 01:20:56 +02:00
|
|
|
egw.debug('log', "Changed et2 object");
|
2013-08-20 21:20:10 +02:00
|
|
|
}
|
2013-08-21 01:20:56 +02:00
|
|
|
this.et2 = et2.widgetContainer;
|
2014-10-23 15:44:40 +02:00
|
|
|
this._fix_iFrameScrolling();
|
2015-06-09 18:14:53 +02:00
|
|
|
if (this.egw && this.egw.is_popup()) this._set_Window_title();
|
2015-06-29 21:16:56 +02:00
|
|
|
|
|
|
|
// Highlights the favorite based on initial list state
|
|
|
|
this.highlight_favorite();
|
2015-10-28 10:55:29 +01:00
|
|
|
|
2015-10-29 16:55:43 +01:00
|
|
|
|
2013-08-20 21:20:10 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-05-22 17:29:14 +02:00
|
|
|
/**
|
|
|
|
* Observer method receives update notifications from all applications
|
|
|
|
*
|
|
|
|
* App is responsible for only reacting to "messages" it is interested in!
|
|
|
|
*
|
|
|
|
* @param {string} _msg message (already translated) to show, eg. 'Entry deleted'
|
|
|
|
* @param {string} _app application name
|
|
|
|
* @param {(string|number)} _id id of entry to refresh or null
|
|
|
|
* @param {string} _type either 'update', 'edit', 'delete', 'add' or null
|
|
|
|
* - update: request just modified data from given rows. Sorting is not considered,
|
|
|
|
* so if the sort field is changed, the row will not be moved.
|
|
|
|
* - edit: rows changed, but sorting may be affected. Requires full reload.
|
|
|
|
* - delete: just delete the given rows clientside (no server interaction neccessary)
|
|
|
|
* - add: requires full reload for proper sorting
|
|
|
|
* @param {string} _msg_type 'error', 'warning' or 'success' (default)
|
2014-05-26 15:29:35 +02:00
|
|
|
* @param {object|null} _links app => array of ids of linked entries
|
|
|
|
* or null, if not triggered on server-side, which adds that info
|
2014-05-23 11:20:42 +02:00
|
|
|
* @return {false|*} false to stop regular refresh, thought all observers are run
|
2014-05-22 17:29:14 +02:00
|
|
|
*/
|
2014-05-26 15:29:35 +02:00
|
|
|
observer: function(_msg, _app, _id, _type, _msg_type, _links)
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-20 21:20:10 +02:00
|
|
|
/**
|
2013-11-04 21:54:23 +01:00
|
|
|
* Open an entry.
|
|
|
|
*
|
2013-08-20 21:20:10 +02:00
|
|
|
* Designed to be used with the action system as a callback
|
|
|
|
* eg: onExecute => app.<appname>.open
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-08-20 21:20:10 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
|
|
|
*/
|
|
|
|
open: function(_action, _senders) {
|
2014-02-12 12:23:04 +01:00
|
|
|
var id_app = _senders[0].id.split('::');
|
2013-08-20 21:20:10 +02:00
|
|
|
egw.open(id_app[1], this.appname);
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-20 21:20:10 +02:00
|
|
|
/**
|
|
|
|
* A generic method to action to server asynchronously
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-08-20 21:20:10 +02:00
|
|
|
* Designed to be used with the action system as a callback.
|
|
|
|
* In the PHP side, set the action
|
2013-11-04 21:54:23 +01:00
|
|
|
* 'onExecute' => 'javaScript:app.<appname>.action', and
|
2013-08-20 21:20:10 +02:00
|
|
|
* implement _do_action(action_id, selected)
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
2013-08-20 21:20:10 +02:00
|
|
|
* @param {egwActionObject[]} _elems
|
|
|
|
*/
|
|
|
|
action: function(_action, _elems)
|
|
|
|
{
|
|
|
|
// let user confirm select-all
|
|
|
|
var select_all = _action.getManager().getActionById("select_all");
|
2013-11-04 21:54:23 +01:00
|
|
|
var confirm_msg = (_elems.length > 1 || select_all && select_all.checked) &&
|
2013-08-20 21:20:10 +02:00
|
|
|
typeof _action.data.confirm_multiple != 'undefined' ?
|
|
|
|
_action.data.confirm_multiple : _action.data.confirm;
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-20 21:20:10 +02:00
|
|
|
if (typeof confirm_msg != 'undefined')
|
|
|
|
{
|
|
|
|
var that = this;
|
|
|
|
var action_id = _action.id;
|
|
|
|
et2_dialog.show_dialog(function(button_id,value)
|
|
|
|
{
|
|
|
|
if (button_id != et2_dialog.NO_BUTTON)
|
|
|
|
{
|
2013-11-04 21:54:23 +01:00
|
|
|
that._do_action(action_id, _elems);
|
2013-08-20 21:20:10 +02:00
|
|
|
}
|
|
|
|
}, confirm_msg, egw.lang('Confirmation required'), et2_dialog.BUTTONS_YES_NO, et2_dialog.QUESTION_MESSAGE);
|
|
|
|
}
|
|
|
|
else if (typeof this._do_action == 'function')
|
|
|
|
{
|
2013-11-04 21:54:23 +01:00
|
|
|
this._do_action(_action.id, _elems);
|
2013-08-20 21:20:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If this is a nextmatch action, do an ajax submit setting the action
|
|
|
|
var nm = null;
|
|
|
|
var action = _action;
|
|
|
|
while(nm == null && action.parent != null)
|
|
|
|
{
|
|
|
|
if(action.data.nextmatch) nm = action.data.nextmatch;
|
|
|
|
action = action.parent;
|
|
|
|
}
|
|
|
|
if(nm != null)
|
|
|
|
{
|
|
|
|
var value = {};
|
|
|
|
value[nm.options.settings.action_var] = _action.id;
|
|
|
|
nm.set_value(value);
|
|
|
|
nm.getInstanceManager().submit();
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 01:00:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the application's state to the given state.
|
|
|
|
*
|
|
|
|
* While not pretending to implement the history API, it is patterned similarly
|
|
|
|
* @link http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html
|
|
|
|
*
|
|
|
|
* The default implementation works with the favorites to apply filters to a nextmatch.
|
|
|
|
*
|
|
|
|
*
|
2013-12-06 19:24:29 +01:00
|
|
|
* @param {{name: string, state: object}|string} state Object (or JSON string) for a state.
|
2013-12-07 00:12:05 +01:00
|
|
|
* Only state is required, and its contents are application specific.
|
2015-01-30 17:59:31 +01:00
|
|
|
* @param {string} template template name to check, instead of trying all templates of current app
|
2013-12-07 00:12:05 +01:00
|
|
|
* @return {boolean} false - Returns false to stop event propagation
|
2013-12-05 01:00:43 +01:00
|
|
|
*/
|
2015-01-30 17:59:31 +01:00
|
|
|
setState: function(state, template)
|
2013-12-05 01:00:43 +01:00
|
|
|
{
|
2013-12-06 19:24:29 +01:00
|
|
|
// State should be an object, not a string, but we'll parse
|
2013-12-05 01:00:43 +01:00
|
|
|
if(typeof state == "string")
|
|
|
|
{
|
|
|
|
if(state.indexOf('{') != -1 || state =='null')
|
|
|
|
{
|
|
|
|
state = JSON.parse(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(typeof state != "object")
|
|
|
|
{
|
|
|
|
egw.debug('error', 'Unable to set state to %o, needs to be an object',state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(state == null)
|
|
|
|
{
|
|
|
|
state = {};
|
|
|
|
}
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-12-07 00:12:05 +01:00
|
|
|
// Check for egw.open() parameters
|
|
|
|
if(state.state && state.state.id && state.state.app)
|
|
|
|
{
|
|
|
|
return egw.open(state.state,undefined,undefined,{},'_self');
|
|
|
|
}
|
|
|
|
|
2013-12-05 01:00:43 +01:00
|
|
|
// Try and find a nextmatch widget, and set its filters
|
|
|
|
var nextmatched = false;
|
2015-01-30 17:59:31 +01:00
|
|
|
var et2 = template ? etemplate2.getByTemplate(template) : etemplate2.getByApplication(this.appname);
|
2013-12-05 01:00:43 +01:00
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget) {
|
2014-02-06 18:53:29 +01:00
|
|
|
// Firefox has trouble with spaces in search
|
2014-02-12 12:23:04 +01:00
|
|
|
if(state.state && state.state.search) state.state.search = unescape(state.state.search);
|
|
|
|
|
2013-12-05 01:00:43 +01:00
|
|
|
// Apply
|
2014-10-02 11:06:15 +02:00
|
|
|
if(state.state && state.state.sort && state.state.sort.id)
|
2014-09-26 21:15:50 +02:00
|
|
|
{
|
|
|
|
_widget.sortBy(state.state.sort.id, state.state.sort.asc,false);
|
|
|
|
}
|
2015-05-11 19:29:31 +02:00
|
|
|
if(state.state && state.state.selectcols)
|
|
|
|
{
|
|
|
|
// Make sure it's a real array, not an object, then set cols
|
|
|
|
_widget.set_columns(jQuery.extend([],state.state.selectcols));
|
|
|
|
}
|
2014-07-14 11:59:02 +02:00
|
|
|
_widget.applyFilters(state.state || state.filter || {});
|
2013-12-05 01:00:43 +01:00
|
|
|
nextmatched = true;
|
|
|
|
}, this, et2_nextmatch);
|
2013-12-07 00:12:05 +01:00
|
|
|
if(nextmatched) return false;
|
2013-12-05 01:00:43 +01:00
|
|
|
}
|
|
|
|
|
2013-12-07 00:12:05 +01:00
|
|
|
// 'blank' is the special name for no filters, send that instead of the nice translated name
|
|
|
|
var safe_name = jQuery.isEmptyObject(state) || jQuery.isEmptyObject(state.state||state.filter) ? 'blank' : state.name.replace(/[^A-Za-z0-9-_]/g, '_');
|
2015-01-30 17:59:31 +01:00
|
|
|
var url = '/'+this.appname+'/index.php';
|
2013-12-12 03:42:08 +01:00
|
|
|
|
2015-01-30 17:59:31 +01:00
|
|
|
// Try a redirect to list, if app defines a "list" value in registry
|
|
|
|
if (egw.link_get_registry(this.appname, 'list'))
|
|
|
|
{
|
|
|
|
url = egw.link('/index.php', jQuery.extend({'favorite': safe_name}, egw.link_get_registry(this.appname, 'list')));
|
|
|
|
}
|
|
|
|
// if no list try index value from application
|
|
|
|
else if (egw.app(this.appname).index)
|
|
|
|
{
|
|
|
|
url = egw.link('/index.php', 'menuaction='+egw.app(this.appname).index+'&favorite='+safe_name);
|
|
|
|
}
|
|
|
|
egw.open_link(url, undefined, undefined, this.appname);
|
2014-02-12 12:23:04 +01:00
|
|
|
return false;
|
2013-12-05 01:00:43 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the current state of the application for future restoration
|
|
|
|
*
|
|
|
|
* The state can be anything, as long as it's an object. The contents are
|
|
|
|
* application specific. The default implementation finds a nextmatch and
|
|
|
|
* returns its value.
|
2013-12-06 22:26:55 +01:00
|
|
|
* The return value of this function cannot be passed directly to setState(),
|
|
|
|
* since setState is expecting an additional wrapper, eg:
|
|
|
|
* {name: 'something', state: getState()}
|
2013-12-05 01:00:43 +01:00
|
|
|
*
|
2013-12-06 22:26:55 +01:00
|
|
|
* @return {object} Application specific map representing the current state
|
2013-12-05 01:00:43 +01:00
|
|
|
*/
|
|
|
|
getState: function()
|
|
|
|
{
|
|
|
|
var state = {};
|
|
|
|
|
|
|
|
// Try and find a nextmatch widget, and set its filters
|
|
|
|
var et2 = etemplate2.getByApplication(this.appname);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
2013-12-06 00:22:54 +01:00
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget) {
|
2013-12-05 01:00:43 +01:00
|
|
|
state = _widget.getValue();
|
|
|
|
}, this, et2_nextmatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
2013-12-06 00:22:54 +01:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2016-02-01 19:09:15 +01:00
|
|
|
/**
|
|
|
|
* Function to load selected row from nm into a template view
|
2016-02-29 16:50:24 +01:00
|
|
|
*
|
2016-02-01 19:09:15 +01:00
|
|
|
* @param {object} _action
|
2016-02-29 16:50:24 +01:00
|
|
|
* @param {object} _senders
|
2016-03-03 15:10:08 +01:00
|
|
|
* @param {boolean} _noEdit defines whether to set edit button or not default is false
|
2016-03-17 19:12:36 +01:00
|
|
|
* @param {function} et2_callback function to run after et2 is loaded
|
2016-02-01 19:09:15 +01:00
|
|
|
*/
|
2016-03-03 15:10:08 +01:00
|
|
|
viewEntry: function(_action, _senders, _noEdit, et2_callback)
|
2016-02-01 19:09:15 +01:00
|
|
|
{
|
2016-03-03 15:10:08 +01:00
|
|
|
//full id in nm
|
2016-02-01 19:09:15 +01:00
|
|
|
var id = _senders[0].id;
|
2016-03-03 15:10:08 +01:00
|
|
|
// flag for edit button
|
|
|
|
var noEdit = _noEdit || false;
|
|
|
|
// nm row id
|
|
|
|
var rowID = '';
|
|
|
|
// content to feed to etemplate2
|
2016-02-01 19:09:15 +01:00
|
|
|
var content = {};
|
2016-03-14 09:38:30 +01:00
|
|
|
|
2016-02-01 19:09:15 +01:00
|
|
|
var self = this;
|
2016-03-14 09:38:30 +01:00
|
|
|
|
2016-02-01 19:09:15 +01:00
|
|
|
if (id){
|
2016-03-03 15:10:08 +01:00
|
|
|
var parts = id.split('::');
|
|
|
|
rowID = parts[1];
|
2016-02-01 19:09:15 +01:00
|
|
|
content = egw.dataGetUIDdata(id);
|
|
|
|
if (content.data) content = content.data;
|
|
|
|
}
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2016-03-03 15:10:08 +01:00
|
|
|
// create a new app object with just constructors for our new etemplate2 object
|
|
|
|
var app = { classes: window.app.classes };
|
|
|
|
|
2016-02-02 11:26:13 +01:00
|
|
|
/* destroy generated etemplate for view mode in DOM*/
|
|
|
|
var destroy = function(){
|
|
|
|
self.viewContainer.remove();
|
|
|
|
delete self.viewTemplate;
|
|
|
|
delete self.viewContainer;
|
2016-03-03 15:10:08 +01:00
|
|
|
delete self.et2_view;
|
|
|
|
// we need to reference back into parent context this
|
|
|
|
for (var v in self)
|
|
|
|
{
|
|
|
|
this[v] = self[v];
|
|
|
|
}
|
|
|
|
app = null;
|
2016-02-02 11:26:13 +01:00
|
|
|
};
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2016-02-01 19:09:15 +01:00
|
|
|
// view container
|
|
|
|
this.viewContainer = jQuery(document.createElement('div'))
|
|
|
|
.addClass('et2_mobile_view')
|
2016-03-31 12:05:39 +02:00
|
|
|
.css({
|
|
|
|
"z-index":102,
|
2016-02-01 19:09:15 +01:00
|
|
|
width:"100%",
|
|
|
|
height:"100%",
|
|
|
|
background:"white",
|
|
|
|
display:'block',
|
2016-03-14 16:57:17 +01:00
|
|
|
position: 'absolute',
|
2016-02-01 19:09:15 +01:00
|
|
|
left:0,
|
2016-02-04 17:31:34 +01:00
|
|
|
bottom:0,
|
|
|
|
right:0,
|
2016-03-31 12:05:39 +02:00
|
|
|
overflow:'auto'
|
|
|
|
})
|
2016-02-02 11:26:13 +01:00
|
|
|
.attr('id','popupMainDiv')
|
|
|
|
.appendTo('body');
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2016-02-02 11:26:13 +01:00
|
|
|
// close button
|
|
|
|
var close = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egw_fw_mobile_popup_close loaded')
|
2016-05-25 17:40:31 +02:00
|
|
|
.click(function(){
|
|
|
|
destroy.call(app[self.appname]);
|
|
|
|
//disable selected actions after close
|
|
|
|
egw_globalObjectManager.setAllSelected(false);
|
|
|
|
})
|
2016-02-02 11:26:13 +01:00
|
|
|
.appendTo(this.viewContainer);
|
2016-03-03 15:10:08 +01:00
|
|
|
if (!noEdit)
|
|
|
|
{
|
|
|
|
// edit button
|
|
|
|
var edit = jQuery(document.createElement('span'))
|
|
|
|
.addClass('mobile-view-editBtn')
|
|
|
|
.click(function(){
|
|
|
|
egw.open(rowID, self.appname);
|
|
|
|
})
|
|
|
|
.appendTo(this.viewContainer);
|
|
|
|
}
|
2016-02-02 11:26:13 +01:00
|
|
|
// view template main container (content)
|
|
|
|
this.viewTemplate = jQuery(document.createElement('div'))
|
|
|
|
.attr('id', this.appname+'-view')
|
2016-03-31 12:05:39 +02:00
|
|
|
.addClass('et2_mobile-view-container popupMainDiv')
|
2016-02-01 19:09:15 +01:00
|
|
|
.appendTo(this.viewContainer);
|
2016-03-14 09:38:30 +01:00
|
|
|
|
2016-05-25 16:44:23 +02:00
|
|
|
var mobileViewTemplate = (_action.data.mobileViewTemplate ||'edit').split('?');
|
|
|
|
var templateName = mobileViewTemplate[0];
|
|
|
|
var templateTimestamp = mobileViewTemplate[1];
|
|
|
|
var templateURL = egw.webserverUrl+ '/' + this.appname + '/templates/mobile/'+templateName+'.xet'+'?'+templateTimestamp;
|
2016-03-03 15:10:08 +01:00
|
|
|
var data = {content:content, readonlys:{'__ALL__':true,'link_to':false}, currentapp:this.appname};
|
2016-03-14 09:38:30 +01:00
|
|
|
|
2016-03-03 15:10:08 +01:00
|
|
|
// etemplate2 object for view
|
|
|
|
this.et2_view = new etemplate2 (this.viewTemplate[0], false);
|
2016-04-28 15:53:44 +02:00
|
|
|
framework.pushState('view');
|
2016-03-03 15:10:08 +01:00
|
|
|
if(templateName)
|
2016-02-01 19:09:15 +01:00
|
|
|
{
|
2016-03-03 15:10:08 +01:00
|
|
|
this.et2_view.load(this.appname+'.'+templateName,templateURL, data, typeof et2_callback == 'function'?et2_callback:function(){}, app);
|
2016-02-29 16:50:24 +01:00
|
|
|
}
|
2016-03-14 09:38:30 +01:00
|
|
|
|
2016-03-03 15:10:08 +01:00
|
|
|
// define a global close function for view template
|
|
|
|
// in order to be able to destroy view on action
|
2016-03-29 17:49:33 +02:00
|
|
|
this.et2_view.close = destroy;
|
2016-02-01 19:09:15 +01:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2013-12-06 22:26:55 +01:00
|
|
|
/**
|
|
|
|
* Initializes actions and handlers on sidebox (delete)
|
2014-02-12 12:23:04 +01:00
|
|
|
*
|
|
|
|
* @param {jQuery} sidebox jQuery of DOM node
|
2013-12-06 22:26:55 +01:00
|
|
|
*/
|
|
|
|
_init_sidebox: function(sidebox)
|
|
|
|
{
|
2015-10-30 10:17:09 +01:00
|
|
|
// Initialize egw tutorial sidebox, but only for non-popups, as calendar edit app.js has this.et2 set to tutorial et2 object
|
|
|
|
if (!this.egw.is_popup())
|
2015-10-29 16:55:43 +01:00
|
|
|
{
|
2015-10-30 10:17:09 +01:00
|
|
|
var egw_fw = egw_getFramework();
|
2016-06-02 16:51:15 +02:00
|
|
|
var tutorial = jQuery('#egw_tutorial_'+this.appname+'_sidebox', egw_fw ? egw_fw.sidemenuDiv : document);
|
2015-10-30 10:17:09 +01:00
|
|
|
// _init_sidebox gets currently called multiple times, which needs to be fixed
|
|
|
|
if (tutorial.length && !this.tutorial_initialised)
|
|
|
|
{
|
|
|
|
this.egwTutorial_init(tutorial[0]);
|
|
|
|
this.tutorial_initialised = true;
|
|
|
|
}
|
2015-10-29 16:55:43 +01:00
|
|
|
}
|
2013-12-06 22:26:55 +01:00
|
|
|
if(sidebox.length)
|
|
|
|
{
|
|
|
|
var self = this;
|
2014-04-29 18:51:57 +02:00
|
|
|
if(this.sidebox) this.sidebox.off();
|
2013-12-06 22:26:55 +01:00
|
|
|
this.sidebox = sidebox;
|
|
|
|
sidebox
|
|
|
|
.off()
|
2014-02-26 16:44:00 +01:00
|
|
|
// removed .on("mouse(enter|leave)" (wrapping trash icon), as it stalls delete in IE11
|
2015-05-20 18:12:29 +02:00
|
|
|
.on("click.sidebox","div.ui-icon-trash", this, this.delete_favorite)
|
2014-02-13 16:37:49 +01:00
|
|
|
// need to install a favorite handler, as we switch original one off with .off()
|
2015-05-20 18:12:29 +02:00
|
|
|
.on('click.sidebox','li[data-id]', this, function(event) {
|
2016-06-02 16:51:15 +02:00
|
|
|
var li = jQuery(this);
|
2015-05-20 18:12:29 +02:00
|
|
|
li.siblings().removeClass('ui-state-highlight');
|
|
|
|
|
2015-08-18 23:21:33 +02:00
|
|
|
var state = {};
|
|
|
|
var pref = egw.preference('favorite_' + this.dataset.id, self.appname);
|
|
|
|
if(pref)
|
|
|
|
{
|
2015-09-29 18:21:05 +02:00
|
|
|
// Extend, to prevent changing the preference by reference
|
|
|
|
jQuery.extend(true, state, pref);
|
2015-08-18 23:21:33 +02:00
|
|
|
}
|
|
|
|
if(this.dataset.id != 'add')
|
2014-02-13 16:37:49 +01:00
|
|
|
{
|
2014-03-11 09:16:52 +01:00
|
|
|
event.stopImmediatePropagation();
|
2015-08-18 23:21:33 +02:00
|
|
|
self.setState.call(self, state);
|
2014-03-11 09:16:52 +01:00
|
|
|
return false;
|
2014-02-13 16:37:49 +01:00
|
|
|
}
|
|
|
|
})
|
2013-12-06 22:26:55 +01:00
|
|
|
.addClass("ui-helper-clearfix");
|
2014-04-29 18:51:57 +02:00
|
|
|
|
2014-11-12 00:11:16 +01:00
|
|
|
//Add Sortable handler to sideBox fav. menu
|
|
|
|
jQuery('ul','#favorite_sidebox_'+this.appname).sortable({
|
2014-04-25 09:37:11 +02:00
|
|
|
items:'li:not([data-id$="add"])',
|
|
|
|
placeholder:'ui-fav-sortable-placeholder',
|
2015-01-14 18:00:47 +01:00
|
|
|
delay:250, //(millisecond) delay before the sorting should start
|
2014-11-12 00:11:16 +01:00
|
|
|
helper: function(event, item) {
|
|
|
|
// We'll need to know which app this is for
|
|
|
|
item.attr('data-appname',self.appname);
|
|
|
|
// Create custom helper so it can be dragged to Home
|
|
|
|
var h_parent = item.parent().parent().clone();
|
|
|
|
h_parent.find('li').not('[data-id="'+item.attr('data-id')+'"]').remove();
|
|
|
|
h_parent.appendTo('body');
|
|
|
|
return h_parent;
|
|
|
|
},
|
|
|
|
refreshPositions: true,
|
2014-04-25 09:37:11 +02:00
|
|
|
update: function (event, ui)
|
|
|
|
{
|
|
|
|
var favSortedList = jQuery(this).sortable('toArray', {attribute:'data-id'});
|
|
|
|
|
|
|
|
self.egw.set_preference(self.appname,'fav_sort_pref',favSortedList);
|
2014-04-29 18:51:57 +02:00
|
|
|
|
2014-04-25 09:37:11 +02:00
|
|
|
self._refresh_fav_nm();
|
|
|
|
}
|
2014-04-29 18:51:57 +02:00
|
|
|
});
|
2015-05-20 23:20:10 +02:00
|
|
|
|
2015-05-20 18:12:29 +02:00
|
|
|
// Bind favorite de-select
|
|
|
|
var egw_fw = egw_getFramework();
|
|
|
|
if(egw_fw && egw_fw.applications[this.appname] && egw_fw.applications[this.appname].browser
|
|
|
|
&& egw_fw.applications[this.appname].browser.baseDiv)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(egw_fw.applications[this.appname].browser.baseDiv)
|
2015-05-20 18:12:29 +02:00
|
|
|
.off('.sidebox')
|
|
|
|
.on('change.sidebox', function() {
|
2015-06-29 21:16:56 +02:00
|
|
|
self.highlight_favorite();
|
2015-05-20 18:12:29 +02:00
|
|
|
});
|
|
|
|
}
|
2013-12-06 22:26:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2013-12-12 01:38:06 +01:00
|
|
|
/**
|
|
|
|
* Add a new favorite
|
|
|
|
*
|
|
|
|
* Fetches the current state from the application, then opens a dialog to get the
|
|
|
|
* name and other settings. If user proceeds, the favorite is saved, and if possible
|
|
|
|
* the sidebox is directly updated to include the new favorite
|
|
|
|
*
|
|
|
|
* @param {object} [state] State settings to be merged into the application state
|
|
|
|
*/
|
|
|
|
add_favorite: function(state)
|
2013-12-06 00:22:54 +01:00
|
|
|
{
|
|
|
|
if(typeof this.favorite_popup == "undefined")
|
|
|
|
{
|
|
|
|
this._create_favorite_popup();
|
|
|
|
}
|
|
|
|
// Get current state
|
2013-12-12 01:38:06 +01:00
|
|
|
this.favorite_popup.state = jQuery.extend({}, this.getState(), state||{});
|
2013-12-06 00:22:54 +01:00
|
|
|
/*
|
|
|
|
// Add in extras
|
|
|
|
for(var extra in this.options.filters)
|
|
|
|
{
|
|
|
|
// Don't overwrite what nm has, chances are nm has more up-to-date value
|
|
|
|
if(typeof this.popup.current_filters == 'undefined')
|
|
|
|
{
|
|
|
|
this.popup.current_filters[extra] = this.nextmatch.options.settings[extra];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in application's settings
|
|
|
|
if(this.filters != true)
|
|
|
|
{
|
|
|
|
for(var i = 0; i < this.filters.length; i++)
|
|
|
|
{
|
|
|
|
this.popup.current_filters[this.options.filters[i]] = this.nextmatch.options.settings[this.options.filters[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Make sure it's an object - deep copy to prevent references in sub-objects (col_filters)
|
|
|
|
this.favorite_popup.state = jQuery.extend(true,{},this.favorite_popup.state);
|
|
|
|
|
|
|
|
// Update popup with current set filters (more for debug than user)
|
|
|
|
var filter_list = [];
|
|
|
|
var add_to_popup = function(arr) {
|
|
|
|
filter_list.push("<ul>");
|
|
|
|
jQuery.each(arr, function(index, filter) {
|
|
|
|
filter_list.push("<li id='index'><span class='filter_id'>"+index+"</span>" +
|
|
|
|
(typeof filter != "object" ? "<span class='filter_value'>"+filter+"</span>": "")
|
|
|
|
);
|
|
|
|
if(typeof filter == "object" && filter != null) add_to_popup(filter);
|
|
|
|
filter_list.push("</li>");
|
|
|
|
});
|
|
|
|
filter_list.push("</ul>");
|
2014-02-12 12:23:04 +01:00
|
|
|
};
|
2013-12-06 00:22:54 +01:00
|
|
|
add_to_popup(this.favorite_popup.state);
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery("#"+this.appname+"_favorites_popup_state",this.favorite_popup)
|
2013-12-06 00:22:54 +01:00
|
|
|
.replaceWith(
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(filter_list.join("")).attr("id",this.appname+"_favorites_popup_state")
|
2013-12-06 00:22:54 +01:00
|
|
|
);
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery("#"+this.appname+"_favorites_popup_state",this.favorite_popup)
|
2013-12-06 00:22:54 +01:00
|
|
|
.hide()
|
|
|
|
.siblings(".ui-icon-circle-plus")
|
|
|
|
.removeClass("ui-icon-circle-minus");
|
|
|
|
|
|
|
|
// Popup
|
|
|
|
this.favorite_popup.dialog("open");
|
|
|
|
console.log(this);
|
2013-12-12 03:42:08 +01:00
|
|
|
|
|
|
|
// Stop the normal bubbling if this is called on click
|
|
|
|
return false;
|
2013-12-06 00:22:54 +01:00
|
|
|
},
|
2014-05-13 08:44:50 +02:00
|
|
|
|
2014-04-25 09:37:11 +02:00
|
|
|
/**
|
2014-05-13 08:44:50 +02:00
|
|
|
* Update favorite items in nm fav. menu
|
|
|
|
*
|
2014-04-25 09:37:11 +02:00
|
|
|
*/
|
|
|
|
_refresh_fav_nm: function ()
|
|
|
|
{
|
|
|
|
var self = this;
|
2014-05-13 08:44:50 +02:00
|
|
|
|
2014-04-25 09:37:11 +02:00
|
|
|
if(etemplate2 && etemplate2.getByApplication)
|
|
|
|
{
|
|
|
|
var et2 = etemplate2.getByApplication(self.appname);
|
|
|
|
for(var i = 0; i < et2.length; i++)
|
|
|
|
{
|
|
|
|
et2[i].widgetContainer.iterateOver(function(_widget) {
|
|
|
|
_widget.stored_filters = _widget.load_favorites(self.appname);
|
|
|
|
_widget.init_filters(_widget);
|
|
|
|
}, self, et2_favorites);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Error ("_refresh_fav_nm():Either et2 is not ready/ not there yet. Make sure that etemplate2 is ready before call this method.");
|
|
|
|
}
|
|
|
|
},
|
2014-05-13 08:44:50 +02:00
|
|
|
|
2013-12-06 00:22:54 +01:00
|
|
|
/**
|
|
|
|
* Create the "Add new" popup dialog
|
|
|
|
*/
|
|
|
|
_create_favorite_popup: function()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var favorite_prefix = 'favorite_';
|
|
|
|
|
|
|
|
// Clear old, if existing
|
|
|
|
if(this.favorite_popup && this.favorite_popup.group)
|
|
|
|
{
|
|
|
|
this.favorite_popup.group.free();
|
|
|
|
delete this.favorite_popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create popup
|
2016-06-02 16:51:15 +02:00
|
|
|
this.favorite_popup = jQuery('<div id="'+this.dom_id + '_nm_favorites_popup" title="' + egw().lang("New favorite") + '">\
|
2013-12-06 00:22:54 +01:00
|
|
|
<form>\
|
|
|
|
<label for="name">'+
|
|
|
|
this.egw.lang("name") +
|
|
|
|
'</label>' +
|
|
|
|
|
|
|
|
'<input type="text" name="name" id="name"/>\
|
|
|
|
<div id="'+this.appname+'_favorites_popup_admin"/>\
|
|
|
|
<span>'+ this.egw.lang("Details") + '</span><span style="float:left;" class="ui-icon ui-icon-circle-plus ui-button" />\
|
|
|
|
<ul id="'+this.appname+'_favorites_popup_state"/>\
|
|
|
|
</form>\
|
|
|
|
</div>'
|
2016-06-09 17:40:16 +02:00
|
|
|
).appendTo(this.et2 ? this.et2.getDOMNode() : jQuery('body'));
|
2013-12-06 00:22:54 +01:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(".ui-icon-circle-plus",this.favorite_popup).prev().andSelf().click(function() {
|
|
|
|
var details = jQuery("#"+self.appname+"_favorites_popup_state",self.favorite_popup)
|
2013-12-06 00:22:54 +01:00
|
|
|
.slideToggle()
|
|
|
|
.siblings(".ui-icon-circle-plus")
|
|
|
|
.toggleClass("ui-icon-circle-minus");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add some controls if user is an admin
|
|
|
|
var apps = egw().user('apps');
|
|
|
|
var is_admin = (typeof apps['admin'] != "undefined");
|
|
|
|
if(is_admin)
|
|
|
|
{
|
|
|
|
this.favorite_popup.group = et2_createWidget("select-account",{
|
|
|
|
id: "favorite[group]",
|
|
|
|
account_type: "groups",
|
|
|
|
empty_label: "Groups",
|
|
|
|
no_lang: true,
|
|
|
|
parent_node: this.appname+'_favorites_popup_admin'
|
2016-06-09 17:40:16 +02:00
|
|
|
},(this.et2 || null));
|
2013-12-06 22:26:55 +01:00
|
|
|
this.favorite_popup.group.loadingFinished();
|
2013-12-06 00:22:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var buttons = {};
|
2014-03-03 19:51:58 +01:00
|
|
|
buttons['save'] = {
|
|
|
|
text: this.egw.lang('save'),
|
|
|
|
default: true,
|
|
|
|
click: function() {
|
|
|
|
// Add a new favorite
|
2016-06-02 16:51:15 +02:00
|
|
|
var name = jQuery("#name",this);
|
2014-03-03 19:51:58 +01:00
|
|
|
|
|
|
|
if(name.val())
|
2013-12-06 00:22:54 +01:00
|
|
|
{
|
2014-03-03 19:51:58 +01:00
|
|
|
// Add to the list
|
|
|
|
name.val(name.val().replace(/(<([^>]+)>)/ig,""));
|
|
|
|
var safe_name = name.val().replace(/[^A-Za-z0-9-_]/g,"_");
|
|
|
|
var favorite = {
|
|
|
|
name: name.val(),
|
|
|
|
group: (typeof self.favorite_popup.group != "undefined" &&
|
|
|
|
self.favorite_popup.group.get_value() ? self.favorite_popup.group.get_value() : false),
|
|
|
|
state: self.favorite_popup.state
|
|
|
|
};
|
|
|
|
|
|
|
|
var favorite_pref = favorite_prefix+safe_name;
|
|
|
|
|
|
|
|
// Save to preferences
|
|
|
|
if(typeof self.favorite_popup.group != "undefined" && self.favorite_popup.group.getValue() != '')
|
|
|
|
{
|
|
|
|
// Admin stuff - save preference server side
|
2016-05-01 11:57:48 +02:00
|
|
|
self.egw.jsonq('EGroupware\\Api\\Framework::ajax_set_favorite',
|
2014-03-03 19:51:58 +01:00
|
|
|
[
|
|
|
|
self.appname,
|
2015-08-27 13:40:18 +02:00
|
|
|
name.val(),
|
2014-03-03 19:51:58 +01:00
|
|
|
"add",
|
|
|
|
self.favorite_popup.group.get_value(),
|
|
|
|
self.favorite_popup.state
|
|
|
|
]
|
|
|
|
);
|
|
|
|
self.favorite_popup.group.set_value('');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal user - just save to preferences client side
|
|
|
|
self.egw.set_preference(self.appname,favorite_pref,favorite);
|
|
|
|
}
|
2013-12-06 22:26:55 +01:00
|
|
|
|
2014-03-03 19:51:58 +01:00
|
|
|
// Add to list immediately
|
|
|
|
if(self.sidebox)
|
|
|
|
{
|
|
|
|
// Remove any existing with that name
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('[data-id="'+safe_name+'"]',self.sidebox).remove();
|
2014-03-03 19:51:58 +01:00
|
|
|
|
|
|
|
// Create new item
|
|
|
|
var html = "<li data-id='"+safe_name+"' data-group='" + favorite.group + "' class='ui-menu-item' role='menuitem'>\n";
|
|
|
|
var href = 'javascript:app.'+self.appname+'.setState('+JSON.stringify(favorite)+');';
|
|
|
|
html += "<a href='"+href+"' class='ui-corner-all' tabindex='-1'>";
|
|
|
|
html += "<div class='" + 'sideboxstar' + "'></div>"+
|
|
|
|
favorite.name;
|
|
|
|
html += "<div class='ui-icon ui-icon-trash' title='" + egw.lang('Delete') + "'/>";
|
|
|
|
html += "</a></li>\n";
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(html).insertBefore(jQuery('li',self.sidebox).last());
|
2014-03-03 19:51:58 +01:00
|
|
|
self._init_sidebox(self.sidebox);
|
|
|
|
}
|
2013-12-13 00:45:09 +01:00
|
|
|
|
2014-03-03 19:51:58 +01:00
|
|
|
// Try to update nextmatch favorites too
|
2014-04-25 09:37:11 +02:00
|
|
|
self._refresh_fav_nm();
|
2013-12-13 00:45:09 +01:00
|
|
|
}
|
2014-03-03 19:51:58 +01:00
|
|
|
// Reset form
|
|
|
|
delete self.favorite_popup.state;
|
|
|
|
name.val("");
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery("#filters",self.favorite_popup).empty();
|
2013-12-06 00:22:54 +01:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).dialog("close");
|
2014-03-11 09:16:52 +01:00
|
|
|
}
|
2013-12-06 00:22:54 +01:00
|
|
|
};
|
|
|
|
buttons[this.egw.lang("cancel")] = function() {
|
2014-02-05 21:53:08 +01:00
|
|
|
if(typeof self.favorite_popup.group !== 'undefined' && self.favorite_popup.group.set_value)
|
|
|
|
{
|
|
|
|
self.favorite_popup.group.set_value(null);
|
|
|
|
}
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).dialog("close");
|
2013-12-06 00:22:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.favorite_popup.dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
modal: true,
|
|
|
|
buttons: buttons,
|
|
|
|
close: function() {
|
|
|
|
}
|
|
|
|
});
|
2013-12-13 00:45:09 +01:00
|
|
|
|
2014-03-03 19:51:58 +01:00
|
|
|
// Bind handler for enter keypress
|
|
|
|
this.favorite_popup.off('keydown').on('keydown', jQuery.proxy(function(e) {
|
|
|
|
var tagName = e.target.tagName.toLowerCase();
|
|
|
|
tagName = (tagName === 'input' && e.target.type === 'button') ? 'button' : tagName;
|
|
|
|
|
|
|
|
if(e.keyCode == jQuery.ui.keyCode.ENTER && tagName !== 'textarea' && tagName !== 'select' && tagName !=='button')
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('button[default]',this.favorite_popup.parent()).trigger('click');
|
2014-03-03 19:51:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},this));
|
|
|
|
|
2013-12-13 00:45:09 +01:00
|
|
|
return false;
|
2013-12-06 00:22:54 +01:00
|
|
|
},
|
2013-12-06 22:26:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a favorite from the list and update preferences
|
|
|
|
* Registered as a handler on the delete icons
|
2014-02-12 12:23:04 +01:00
|
|
|
*
|
|
|
|
* @param {jQuery.event} event event object
|
2013-12-06 22:26:55 +01:00
|
|
|
*/
|
|
|
|
delete_favorite: function(event)
|
|
|
|
{
|
|
|
|
// Don't do the menu
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
|
|
|
var app = event.data;
|
2016-06-02 16:51:15 +02:00
|
|
|
var id = jQuery(this).parentsUntil('li').parent().attr("data-id");
|
|
|
|
var group = jQuery(this).parentsUntil('li').parent().attr("data-group") || '';
|
|
|
|
var line = jQuery('li[data-id="'+id+'"]',app.sidebox);
|
2013-12-12 01:38:06 +01:00
|
|
|
var name = line.first().text();
|
2013-12-06 22:26:55 +01:00
|
|
|
var trash = this;
|
2013-12-13 00:45:09 +01:00
|
|
|
line.addClass('loading');
|
2013-12-06 22:26:55 +01:00
|
|
|
|
|
|
|
// Make sure first
|
|
|
|
var do_delete = function(button_id)
|
|
|
|
{
|
2013-12-12 01:00:54 +01:00
|
|
|
if(button_id != et2_dialog.YES_BUTTON)
|
|
|
|
{
|
2013-12-13 00:45:09 +01:00
|
|
|
line.removeClass('loading');
|
2013-12-12 01:00:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-12-06 22:26:55 +01:00
|
|
|
|
|
|
|
// Hide the trash
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(trash).hide();
|
2013-12-06 22:26:55 +01:00
|
|
|
|
|
|
|
// Delete preference server side
|
2016-05-01 11:57:48 +02:00
|
|
|
var request = egw.json("EGroupware\\Api\\Framework::ajax_set_favorite",
|
2014-02-12 18:33:22 +01:00
|
|
|
[app.appname, id, "delete", group, ''],
|
2013-12-06 22:26:55 +01:00
|
|
|
function(result) {
|
2014-02-12 18:33:22 +01:00
|
|
|
// Got the full response from callback, which we don't want
|
|
|
|
if(result.type) return;
|
2014-02-12 22:51:25 +01:00
|
|
|
|
2014-02-12 18:33:22 +01:00
|
|
|
if(result && typeof result == 'boolean')
|
2013-12-06 22:26:55 +01:00
|
|
|
{
|
|
|
|
// Remove line from list
|
|
|
|
line.slideUp("slow", function() { });
|
2014-02-12 12:23:04 +01:00
|
|
|
|
2014-05-13 23:39:23 +02:00
|
|
|
app._refresh_fav_nm();
|
2013-12-06 22:26:55 +01:00
|
|
|
}
|
2013-12-07 00:26:48 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Something went wrong server side
|
|
|
|
line.removeClass('loading').addClass('ui-state-error');
|
|
|
|
}
|
2013-12-06 22:26:55 +01:00
|
|
|
},
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(trash).parentsUntil("li").parent(),
|
2013-12-06 22:26:55 +01:00
|
|
|
true,
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(trash).parentsUntil("li").parent()
|
2013-12-06 22:26:55 +01:00
|
|
|
);
|
|
|
|
request.sendRequest(true);
|
2014-02-12 12:23:04 +01:00
|
|
|
};
|
2013-12-06 22:26:55 +01:00
|
|
|
et2_dialog.show_dialog(do_delete, (egw.lang("Delete") + " " +name +"?"),
|
|
|
|
"Delete", et2_dialog.YES_NO, et2_dialog.QUESTION_MESSAGE);
|
2013-12-13 00:45:09 +01:00
|
|
|
|
|
|
|
return false;
|
2014-10-23 15:44:40 +02:00
|
|
|
},
|
2015-01-30 17:59:31 +01:00
|
|
|
|
2015-06-29 21:16:56 +02:00
|
|
|
/**
|
|
|
|
* Mark the favorite closest matching the current state
|
|
|
|
*
|
|
|
|
* Closest matching takes into account not set values, so we pick the favorite
|
|
|
|
* with the most matching values without a value that differs.
|
|
|
|
*/
|
|
|
|
highlight_favorite: function() {
|
|
|
|
if(!this.sidebox) return;
|
|
|
|
|
|
|
|
var state = this.getState();
|
|
|
|
var best_match = false;
|
|
|
|
var best_count = 0;
|
2015-08-18 23:21:33 +02:00
|
|
|
var self = this;
|
2015-06-29 21:16:56 +02:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('li[data-id]',this.sidebox).removeClass('ui-state-highlight');
|
2015-06-29 21:16:56 +02:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('li[data-id]',this.sidebox).each(function(i,href) {
|
2015-08-31 18:40:33 +02:00
|
|
|
var favorite = {};
|
2015-08-18 23:21:33 +02:00
|
|
|
if(this.dataset.id && egw.preference('favorite_'+this.dataset.id,self.appname))
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
2015-08-18 23:21:33 +02:00
|
|
|
favorite = egw.preference('favorite_'+this.dataset.id,self.appname);
|
2015-06-29 21:16:56 +02:00
|
|
|
}
|
|
|
|
if(!favorite || jQuery.isEmptyObject(favorite)) return;
|
2016-06-20 15:13:37 +02:00
|
|
|
|
2016-06-09 20:37:30 +02:00
|
|
|
// Handle old style by making it like new style
|
|
|
|
if(favorite.filter && !favorite.state)
|
|
|
|
{
|
|
|
|
favorite.state = favorite.filter;
|
|
|
|
}
|
2015-08-27 13:31:31 +02:00
|
|
|
|
2015-06-29 21:16:56 +02:00
|
|
|
var match_count = 0;
|
2016-06-09 20:37:30 +02:00
|
|
|
var extra_keys = Object.keys(favorite.state);
|
2015-06-29 21:16:56 +02:00
|
|
|
for(var state_key in state)
|
|
|
|
{
|
2016-05-25 21:28:27 +02:00
|
|
|
extra_keys.splice(extra_keys.indexOf(state_key),1);
|
2015-07-23 13:07:46 +02:00
|
|
|
if(typeof favorite.state != 'undefined' && typeof state[state_key] != 'undefined'&&typeof favorite.state[state_key] != 'undefined' && ( state[state_key] == favorite.state[state_key] || !state[state_key] && !favorite.state[state_key]))
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
2016-05-25 00:27:27 +02:00
|
|
|
else if (state_key == 'selectcols')
|
|
|
|
{
|
|
|
|
// Skip, might be set, might not
|
|
|
|
}
|
2015-08-27 13:31:31 +02:00
|
|
|
else if (typeof state[state_key] != 'undefined' && state[state_key] && typeof state[state_key] === 'object'
|
2015-07-23 13:07:46 +02:00
|
|
|
&& typeof favorite.state != 'undefined' && typeof favorite.state[state_key] != 'undefined' && favorite.state[state_key] && typeof favorite.state[state_key] === 'object')
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
if((typeof state[state_key].length !== 'undefined' || typeof state[state_key].length !== 'undefined')
|
|
|
|
&& (state[state_key].length || Object.keys(state[state_key]).length) != (favorite.state[state_key].length || Object.keys(favorite.state[state_key]).length ))
|
|
|
|
{
|
|
|
|
// State or favorite has a length, but the other does not
|
|
|
|
if((state[state_key].length === 0 || Object.keys(state[state_key]).length === 0) &&
|
|
|
|
(favorite.state[state_key].length == 0 || Object.keys(favorite.state[state_key]).length === 0))
|
|
|
|
{
|
|
|
|
// Just missing, or one is an array and the other is an object
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// One has a value and the other doesn't, no match
|
|
|
|
return;
|
|
|
|
}
|
2016-05-25 00:27:27 +02:00
|
|
|
else if (state[state_key].length !== 'undefined' && typeof favorite.state[state_key].length !== 'undefined' &&
|
|
|
|
state[state_key].length === 0 && favorite.state[state_key].length === 0)
|
|
|
|
{
|
|
|
|
// Both set, but both empty
|
|
|
|
match_count++;
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-29 21:16:56 +02:00
|
|
|
// Consider sub-objects (column filters) individually
|
|
|
|
for(var sub_key in state[state_key])
|
|
|
|
{
|
|
|
|
if(state[state_key][sub_key] == favorite.state[state_key][sub_key] || !state[state_key][sub_key] && !favorite.state[state_key][sub_key])
|
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
2015-07-09 20:01:22 +02:00
|
|
|
else if (state[state_key][sub_key] && favorite.state[state_key][sub_key] &&
|
|
|
|
typeof state[state_key][sub_key] === 'object' && typeof favorite.state[state_key][sub_key] === 'object')
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
// Too deep to keep going, just string compare for perfect match
|
2015-07-10 19:44:21 +02:00
|
|
|
if(JSON.stringify(state[state_key][sub_key]) === JSON.stringify(favorite.state[state_key][sub_key]))
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
match_count++;
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 00:27:27 +02:00
|
|
|
else if(typeof state[state_key][sub_key] !== 'undefined' && state[state_key][sub_key] != favorite.state[state_key][sub_key])
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
// Different values, do not match
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-27 13:31:31 +02:00
|
|
|
else if (typeof state[state_key] !== 'undefined'
|
2015-07-23 13:07:46 +02:00
|
|
|
&& typeof favorite.state != 'undefined'&&typeof favorite.state[state_key] !== 'undefined'
|
|
|
|
&& state[state_key] != favorite.state[state_key])
|
2015-06-29 21:16:56 +02:00
|
|
|
{
|
|
|
|
// Different values, do not match
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 21:28:27 +02:00
|
|
|
// Check for anything set that the current one does not have
|
|
|
|
for(var i = 0; i < extra_keys.length; i++)
|
|
|
|
{
|
|
|
|
if(favorite.state[extra_keys[i]]) return;
|
|
|
|
}
|
2015-06-29 21:16:56 +02:00
|
|
|
if(match_count > best_count)
|
|
|
|
{
|
2015-08-18 23:21:33 +02:00
|
|
|
best_match = this.dataset.id;
|
2015-06-29 21:16:56 +02:00
|
|
|
best_count = match_count;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(best_match)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('li[data-id="'+best_match+'"]',this.sidebox).addClass('ui-state-highlight');
|
2015-06-29 21:16:56 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-10-23 15:44:40 +02:00
|
|
|
/**
|
2015-01-30 17:59:31 +01:00
|
|
|
* Fix scrolling iframe browsed by iPhone/iPod/iPad touch devices
|
2014-10-23 15:44:40 +02:00
|
|
|
*/
|
|
|
|
_fix_iFrameScrolling: function()
|
|
|
|
{
|
|
|
|
if (/iPhone|iPod|iPad/.test(navigator.userAgent))
|
|
|
|
{
|
|
|
|
jQuery("iframe").on({
|
|
|
|
load: function()
|
|
|
|
{
|
|
|
|
var body = this.contentWindow.document.body;
|
|
|
|
|
|
|
|
var div = jQuery(document.createElement("div"))
|
|
|
|
.css ({
|
|
|
|
'height' : jQuery(this.parentNode).height(),
|
|
|
|
'width' : jQuery(this.parentNode).width(),
|
|
|
|
'overflow' : 'scroll'});
|
|
|
|
while (body.firstChild)
|
|
|
|
{
|
|
|
|
div.append(body.firstChild);
|
|
|
|
}
|
|
|
|
jQuery(body).append(div);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-05 15:28:35 +01:00
|
|
|
},
|
2015-01-30 17:59:31 +01:00
|
|
|
|
2015-01-05 15:28:35 +01:00
|
|
|
/**
|
|
|
|
* Set document title, uses getWindowTitle to get the correct title,
|
|
|
|
* otherwise set it with uniqueID as default title
|
|
|
|
*/
|
|
|
|
_set_Window_title: function ()
|
|
|
|
{
|
|
|
|
var title = this.getWindowTitle();
|
|
|
|
if (title)
|
|
|
|
{
|
|
|
|
document.title = this.et2._inst.uniqueId + ": " + title;
|
|
|
|
}
|
|
|
|
},
|
2015-01-30 17:59:31 +01:00
|
|
|
|
2015-01-05 15:28:35 +01:00
|
|
|
/**
|
|
|
|
* Window title getter function in order to set the window title
|
|
|
|
* this can be overridden on each application app.js file to customize the title value
|
2015-01-30 17:59:31 +01:00
|
|
|
*
|
2015-01-05 15:28:35 +01:00
|
|
|
* @returns {string} window title
|
|
|
|
*/
|
|
|
|
getWindowTitle: function ()
|
|
|
|
{
|
|
|
|
var titleWidget = this.et2.getWidgetById('title');
|
|
|
|
if (titleWidget)
|
|
|
|
{
|
2015-01-05 16:12:10 +01:00
|
|
|
return titleWidget.options.value;
|
2015-01-05 15:28:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.et2._inst.uniqueId;
|
|
|
|
}
|
2015-02-24 20:07:48 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for drag and drop when dragging nextmatch rows from mail app
|
|
|
|
* and dropped on a row in the current application. We copy the mail into
|
|
|
|
* the filemanager to link it since we can't link directly.
|
|
|
|
*
|
|
|
|
* This doesn't happen automatically. Each application must indicate that
|
|
|
|
* it will accept dropped mail by it's nextmatch actions:
|
|
|
|
*
|
|
|
|
* $actions['info_drop_mail'] = array(
|
|
|
|
* 'type' => 'drop',
|
|
|
|
* 'acceptedTypes' => 'mail',
|
|
|
|
* 'onExecute' => 'javaScript:app.infolog.handle_dropped_mail',
|
|
|
|
* 'hideOnDisabled' => true
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* This action, when defined, will not affect the automatic linking between
|
|
|
|
* normal applications.
|
|
|
|
*
|
|
|
|
* @param {egwAction} _action
|
|
|
|
* @param {egwActionObject[]} _selected Dragged mail rows
|
|
|
|
* @param {egwActionObject} _target Current application's nextmatch row the mail was dropped on
|
|
|
|
*/
|
|
|
|
handle_dropped_mail: function(_action, _selected, _target)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Mail doesn't support link system, so we copy it to VFS
|
|
|
|
*/
|
|
|
|
var ids = _target.id.split("::");
|
|
|
|
if(ids.length != 2 || ids[0] == 'mail') return;
|
|
|
|
|
|
|
|
var vfs_path = "/apps/"+ids[0]+"/"+ids[1];
|
|
|
|
var mail_ids = [];
|
|
|
|
|
|
|
|
for(var i = 0; i < _selected.length; i++)
|
|
|
|
{
|
|
|
|
mail_ids.push(_selected[i].id);
|
|
|
|
}
|
|
|
|
if(mail_ids.length)
|
|
|
|
{
|
|
|
|
egw.message(egw.lang("Please wait..."));
|
|
|
|
this.egw.json('filemanager.filemanager_ui.ajax_action',['mail',mail_ids, vfs_path],function(data){
|
|
|
|
// Trigger an update (minimal, no sorting changes) to display the new link
|
|
|
|
egw.refresh(data.msg||'',ids[0],ids[1],'update');
|
|
|
|
}).sendRequest(true);
|
|
|
|
}
|
2015-05-19 20:56:12 +02:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-09-25 17:18:35 +02:00
|
|
|
/**
|
|
|
|
* Get json data for videos from the given url
|
2015-10-28 10:55:29 +01:00
|
|
|
*
|
2015-09-25 17:18:35 +02:00
|
|
|
* @return {Promise, object} return Promise, json object as resolved result and error message in case of failure
|
|
|
|
*/
|
2015-10-05 18:01:39 +02:00
|
|
|
egwTutorialGetData: function(){
|
|
|
|
var self = this;
|
2015-09-25 17:18:35 +02:00
|
|
|
return new Promise (function(_resolve, _reject)
|
|
|
|
{
|
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
2016-06-09 17:40:16 +02:00
|
|
|
// delay the execution and let the rendering catches up. Seems only FF problem
|
|
|
|
window.setTimeout(function(){
|
|
|
|
self.egw.json('EGroupware\\Api\\Framework\\Tutorial::ajax_data', [self.egw.app_name()], function(_data){
|
|
|
|
resolve(_data);
|
|
|
|
}).sendRequest();
|
|
|
|
},0);
|
|
|
|
|
2015-09-25 17:18:35 +02:00
|
|
|
});
|
|
|
|
},
|
2015-10-28 10:55:29 +01:00
|
|
|
|
2015-09-25 17:18:35 +02:00
|
|
|
/**
|
|
|
|
* Create and Render etemplate2 for egroupware tutorial
|
2016-05-01 11:57:48 +02:00
|
|
|
* sidebox option. The .xet file is stored in api/templates/default/egw_tutorials
|
2015-10-28 10:55:29 +01:00
|
|
|
*
|
2015-09-25 17:18:35 +02:00
|
|
|
* @description tutorials json object should have the following structure:
|
|
|
|
* object:
|
|
|
|
* {
|
|
|
|
* [app name]:{
|
|
|
|
* [language tag]:[
|
2015-10-28 10:55:29 +01:00
|
|
|
* {src:"",thumbnail:"",title:"",desc:""}
|
2015-09-25 17:18:35 +02:00
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
* }
|
2015-10-28 10:55:29 +01:00
|
|
|
*
|
2015-10-19 17:00:42 +02:00
|
|
|
* *Note: "desc" and "title" are optional attributes, which "desc" would appears as tooltip for the video.
|
2015-10-28 10:55:29 +01:00
|
|
|
*
|
2015-09-25 17:18:35 +02:00
|
|
|
* example:
|
|
|
|
* {
|
|
|
|
* "mail":{
|
|
|
|
* "en":[
|
2015-10-19 17:00:42 +02:00
|
|
|
* {src:"https://www.youtube.com/embed/mCDJndpjO40", thumbnail:"http://img.youtube.com/vi/mCDJndpjO40/0.jpg", "title":"PGP Encryption", "desc":""},
|
|
|
|
* {src:"https://www.youtube.com/embed/mCDJndpjO", thumbnail:"http://img.youtube.com/vi/mCDJndpjO/0.jpg", "title":"Subscription", "desc":""},
|
2015-09-25 17:18:35 +02:00
|
|
|
* ],
|
|
|
|
* "de":[
|
2015-10-19 17:00:42 +02:00
|
|
|
* {src:"https://www.youtube.com/embed/m40", thumbnail:"http://img.youtube.com/vi/m40/0.jpg", "title":"PGP Verschlüsselung", "desc":""},
|
|
|
|
* {src:"https://www.youtube.com/embed/mpjO", thumbnail:"http://img.youtube.com/vi/mpjO/0.jpg", "title":"Ordner Abonnieren", "desc":""},
|
2015-09-25 17:18:35 +02:00
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
* }
|
2016-03-17 19:12:36 +01:00
|
|
|
*
|
|
|
|
* @param {DOMNode} div
|
2015-09-25 17:18:35 +02:00
|
|
|
*/
|
2015-10-29 16:55:43 +01:00
|
|
|
egwTutorial_init: function(div)
|
2015-09-25 17:18:35 +02:00
|
|
|
{
|
|
|
|
// et2 object
|
|
|
|
var etemplate = new etemplate2 (div, false);
|
2016-05-01 11:57:48 +02:00
|
|
|
var template = egw.webserverUrl+'/api/templates/default/egw_tutorial.xet?1';
|
2015-10-28 10:55:29 +01:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
this.egwTutorialGetData().then(function(_data){
|
2015-09-25 17:18:35 +02:00
|
|
|
var lang = egw.preference('lang');
|
|
|
|
var content = {content:{list:[]}};
|
|
|
|
if (_data && _data[egw.app_name()])
|
|
|
|
{
|
2015-09-28 11:34:09 +02:00
|
|
|
if (!_data[egw.app_name()][lang]) lang = 'en';
|
2015-10-28 10:55:29 +01:00
|
|
|
if (typeof _data[egw.app_name()][lang] !='undefined'
|
2015-09-25 17:18:35 +02:00
|
|
|
&& _data[egw.app_name()][lang].length > 0)
|
|
|
|
{
|
2015-10-05 18:01:39 +02:00
|
|
|
for (var i=0;i < _data[egw.app_name()][lang].length;i++)
|
2015-09-25 17:18:35 +02:00
|
|
|
{
|
2015-10-05 18:01:39 +02:00
|
|
|
var tuid = egw.app_name() + '-' +lang + '-' + i;
|
|
|
|
_data[egw.app_name()][lang][i]['onclick'] = 'app.'+egw.app_name()+'.egwTutorialPopup("'+tuid+'")';
|
2015-09-25 17:18:35 +02:00
|
|
|
}
|
|
|
|
content.content.list = _data[egw.app_name()][lang];
|
2015-10-28 10:55:29 +01:00
|
|
|
|
2015-09-25 17:18:35 +02:00
|
|
|
if (template.indexOf('.xet') >0)
|
|
|
|
{
|
|
|
|
etemplate.load ('',template , content, function(){});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
etemplate.load (template, '', content);
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 10:55:29 +01:00
|
|
|
}
|
2015-09-25 17:18:35 +02:00
|
|
|
},
|
|
|
|
function(_err){
|
2015-10-05 18:01:39 +02:00
|
|
|
console.log(_err);
|
2015-09-25 17:18:35 +02:00
|
|
|
});
|
|
|
|
},
|
2015-10-28 10:55:29 +01:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
/**
|
|
|
|
* Open popup to show given tutorial id
|
|
|
|
* @param {string} _tuid tutorial object id
|
|
|
|
* - tuid: appname-lang-index
|
|
|
|
*/
|
|
|
|
egwTutorialPopup: function (_tuid)
|
2015-09-25 17:18:35 +02:00
|
|
|
{
|
2016-05-01 11:57:48 +02:00
|
|
|
var url = egw.link('/index.php', 'menuaction=api.EGroupware\\Api\\Framework\\Tutorial.popup&tuid='+_tuid);
|
2015-10-19 17:00:42 +02:00
|
|
|
egw.open_link(url,'_blank','960x580');
|
2015-09-25 17:18:35 +02:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
/**
|
|
|
|
* Function to set video iframe base on selected tutorial from tutorials box
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
*/
|
|
|
|
tutorial_videoOnClick: function (_url)
|
|
|
|
{
|
|
|
|
var frame = etemplate2.getByApplication('api')[0].widgetContainer.getWidgetById('src');
|
|
|
|
if (frame)
|
|
|
|
{
|
|
|
|
frame.set_value(_url);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function calls on discard checkbox and will set
|
|
|
|
* the egw_tutorial_noautoload preference
|
|
|
|
*
|
|
|
|
* @param {type} egw
|
|
|
|
* @param {type} widget
|
|
|
|
*/
|
|
|
|
tutorial_autoloadDiscard: function (egw, widget)
|
|
|
|
{
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
this.egw.set_preference('common', 'egw_tutorial_noautoload', widget.get_value());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-19 20:56:12 +02:00
|
|
|
/**
|
|
|
|
* Check if Mailvelope is available, open (or create) "egroupware" keyring and call callback with it
|
|
|
|
*
|
|
|
|
* @param {function} _callback called if and only if mailvelope is available (context is this!)
|
|
|
|
*/
|
|
|
|
mailvelopeAvailable: function(_callback)
|
|
|
|
{
|
|
|
|
var self = this;
|
2015-05-20 17:24:08 +02:00
|
|
|
var callback = jQuery.proxy(_callback, this);
|
|
|
|
|
2015-05-19 20:56:12 +02:00
|
|
|
if (typeof mailvelope !== 'undefined')
|
|
|
|
{
|
2015-05-20 17:24:08 +02:00
|
|
|
this.mailvelopeOpenKeyring().then(callback);
|
2015-05-19 20:56:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jQuery(window).on('mailvelope', function()
|
|
|
|
{
|
2015-05-26 17:25:54 +02:00
|
|
|
self.mailvelopeOpenKeyring().then(callback);
|
2015-05-19 20:56:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-08-27 19:38:18 +02:00
|
|
|
/**
|
|
|
|
* mailvelope object contains SyncHandlers
|
2016-06-20 15:13:37 +02:00
|
|
|
*
|
2015-08-27 19:38:18 +02:00
|
|
|
* @property {function} descriptionuploadSync function called by Mailvelope to upload encrypted private key backup
|
|
|
|
* @property {function} downloadSync function called by Mailvelope to download encrypted private key backup
|
|
|
|
* @property {function} backup function called by Mailvelope to upload a public keyring backup
|
|
|
|
* @property {function} restore function called by Mailvelope to restore a public keyring backup
|
|
|
|
*/
|
2015-08-31 18:40:33 +02:00
|
|
|
mailvelopeSyncHandlerObj: {
|
2015-08-27 19:38:18 +02:00
|
|
|
/**
|
2015-09-15 10:42:21 +02:00
|
|
|
* function called by Mailvelope to upload a public keyring
|
2015-08-27 19:38:18 +02:00
|
|
|
* @param {UploadSyncHandler} _uploadObj
|
|
|
|
* @property {string} etag entity tag for the uploaded encrypted keyring, or null if initial upload
|
|
|
|
* @property {AsciiArmored} keyringMsg encrypted keyring as PGP armored message
|
|
|
|
* @returns {Promise.<UploadSyncReply, Error>}
|
|
|
|
*/
|
|
|
|
uploadSync: function(_uploadObj)
|
|
|
|
{
|
|
|
|
return new Promise(function(_resolve,_reject){});
|
2016-06-20 15:13:37 +02:00
|
|
|
},
|
2015-08-27 19:38:18 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-15 10:42:21 +02:00
|
|
|
* function called by Mailvelope to download a public keyring
|
2015-08-27 19:38:18 +02:00
|
|
|
*
|
|
|
|
* @param {object} _downloadObj
|
|
|
|
* @property {string} etag entity tag for the current local keyring, or null if no local eTag
|
|
|
|
* @returns {Promise.<DownloadSyncReply, Error>}
|
|
|
|
*/
|
|
|
|
downloadSync: function(_downloadObj)
|
|
|
|
{
|
|
|
|
return new Promise(function(_resolve,_reject){});
|
2016-05-01 11:57:48 +02:00
|
|
|
},
|
2015-08-27 19:38:18 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-15 10:42:21 +02:00
|
|
|
* function called by Mailvelope to upload an encrypted private key backup
|
2015-08-27 19:38:18 +02:00
|
|
|
*
|
|
|
|
* @param {BackupSyncPacket} _backup
|
2015-09-15 10:42:21 +02:00
|
|
|
* @property {AsciiArmored} backup an encrypted private key as PGP armored message
|
2015-08-27 19:38:18 +02:00
|
|
|
* @returns {Promise.<undefined, Error>}
|
|
|
|
*/
|
|
|
|
backup: function(_backup)
|
|
|
|
{
|
|
|
|
return new Promise(function(_resolve,_reject){
|
2016-06-21 12:54:36 +02:00
|
|
|
// Store backup sync packet into .PGP-Key-Backup file in user directory
|
2015-08-27 19:38:18 +02:00
|
|
|
jQuery.ajax({
|
|
|
|
method:'PUT',
|
2016-06-21 12:54:36 +02:00
|
|
|
url: egw.webserverUrl+'/webdav.php/home/'+egw.user('account_lid')+'/.PGP-Key-Backup',
|
2015-08-27 19:38:18 +02:00
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(_backup),
|
|
|
|
success:function(){
|
|
|
|
_resolve(_backup);
|
|
|
|
},
|
|
|
|
error: function(_err){
|
|
|
|
_reject(_err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-09-15 10:42:21 +02:00
|
|
|
* function called by Mailvelope to restore an encrypted private key backup
|
2016-06-20 15:13:37 +02:00
|
|
|
*
|
2015-08-27 19:38:18 +02:00
|
|
|
* @returns {Promise.<BackupSyncPacket, Error>}
|
|
|
|
* @todo
|
|
|
|
*/
|
|
|
|
restore: function()
|
|
|
|
{
|
|
|
|
return new Promise(function(_resolve,_reject){
|
2015-08-31 18:40:33 +02:00
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
jQuery.ajax({
|
2016-06-21 12:54:36 +02:00
|
|
|
url:egw.webserverUrl+'/webdav.php/home/'+egw.user('account_lid')+'/.PGP-Key-Backup',
|
2015-08-31 18:40:33 +02:00
|
|
|
method: 'GET',
|
|
|
|
success: function(_backup){
|
|
|
|
resolve(JSON.parse(_backup));
|
2015-09-15 10:42:21 +02:00
|
|
|
egw.message('Your key has been restored successfully.');
|
2015-08-31 18:40:33 +02:00
|
|
|
},
|
|
|
|
error: function(_err){
|
2016-06-21 12:54:36 +02:00
|
|
|
//Try with old back file name
|
|
|
|
if (_err.status == 404)
|
|
|
|
{
|
|
|
|
jQuery.ajax({
|
|
|
|
method:'GET',
|
|
|
|
url: egw.webserverUrl+'/webdav.php/home/'+egw.user('account_lid')+'/.PK_PGP',
|
|
|
|
success: function(_backup){
|
|
|
|
resolve(JSON.parse(_backup));
|
|
|
|
egw.message('Your key has been restored successfully.');
|
|
|
|
},
|
|
|
|
error: function(_err){
|
|
|
|
_reject(_err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_reject(_err);
|
|
|
|
}
|
2015-08-31 18:40:33 +02:00
|
|
|
}
|
|
|
|
});
|
2015-08-27 19:38:18 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-08-31 18:40:33 +02:00
|
|
|
/**
|
|
|
|
* Function for backup file operations
|
|
|
|
*
|
|
|
|
* @param {type} _url Url of the backup file
|
|
|
|
* @param {type} _cmd command to operate
|
|
|
|
* - PUT: to store backup file
|
|
|
|
* - GET: to read backup file
|
2016-06-20 15:13:37 +02:00
|
|
|
* - DELETE: to delete backup file
|
2015-08-31 18:40:33 +02:00
|
|
|
*
|
|
|
|
* @param {type} _successCallback function called when the operation is successful
|
|
|
|
* @param {type} _errorCallback function called when the operation fails
|
|
|
|
* @param {type} _data data which needs to be stored in file via PUT command
|
|
|
|
*/
|
|
|
|
_mailvelopeBackupFileOperator: function(_url, _cmd, _successCallback, _errorCallback, _data)
|
|
|
|
{
|
|
|
|
var ajaxObj = {
|
2016-06-20 15:13:37 +02:00
|
|
|
url: _url || egw.webserverUrl+'/webdav.php/home/'+egw.user('account_lid')+'/.PGP-Key-Backup',
|
2015-08-31 18:40:33 +02:00
|
|
|
method: _cmd,
|
|
|
|
success: _successCallback,
|
|
|
|
error: _errorCallback
|
|
|
|
};
|
|
|
|
switch (_cmd)
|
|
|
|
{
|
|
|
|
case 'PUT':
|
|
|
|
jQuery.extend({},ajaxObj, {
|
|
|
|
data: JSON.stringify(_data),
|
2015-09-08 09:36:17 +02:00
|
|
|
contentType: 'application/json'
|
2015-08-31 18:40:33 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'GET':
|
|
|
|
jQuery.extend({},ajaxObj, {
|
2015-09-08 09:36:17 +02:00
|
|
|
dataType: 'json'
|
2015-08-31 18:40:33 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'DELETE':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jQuery.ajax(ajaxObj);
|
|
|
|
},
|
|
|
|
|
2015-08-27 19:38:18 +02:00
|
|
|
/**
|
|
|
|
* Create backup dialog
|
2015-08-31 18:40:33 +02:00
|
|
|
* @param {string} _selector DOM selector to attach backupDialog
|
2015-09-01 19:07:42 +02:00
|
|
|
* @param {boolean} _initSetup determine wheter it's an initialization backup or restore backup
|
2015-08-31 18:40:33 +02:00
|
|
|
*
|
2015-08-27 19:38:18 +02:00
|
|
|
* @returns {Promise.<backupPopupId, Error>}
|
|
|
|
*/
|
2015-09-01 19:07:42 +02:00
|
|
|
mailvelopeCreateBackupDialog: function(_selector, _initSetup)
|
2015-08-27 19:38:18 +02:00
|
|
|
{
|
|
|
|
var self = this;
|
2015-08-31 18:40:33 +02:00
|
|
|
var selector = _selector || 'body';
|
2015-09-01 19:07:42 +02:00
|
|
|
var initSetup = _initSetup;
|
2015-09-15 10:42:21 +02:00
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').remove();
|
2015-08-27 19:38:18 +02:00
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
2015-08-31 18:40:33 +02:00
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
2015-08-27 19:38:18 +02:00
|
|
|
{
|
2015-08-31 18:40:33 +02:00
|
|
|
_keyring.addSyncHandler(self.mailvelopeSyncHandlerObj);
|
2015-08-27 19:38:18 +02:00
|
|
|
|
|
|
|
var options = {
|
2015-09-01 19:07:42 +02:00
|
|
|
initialSetup:initSetup
|
2015-08-31 18:40:33 +02:00
|
|
|
};
|
|
|
|
_keyring.createKeyBackupContainer(selector, options).then(function(_popupId){
|
|
|
|
var $backup_selector = jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]');
|
|
|
|
$backup_selector.css({position:'absolute', "z-index":1});
|
2016-06-21 12:54:36 +02:00
|
|
|
_popupId.isReady().then(function(result){
|
|
|
|
egw.message('Your key has been backedup into .PGP-Key-Backup successfully.');
|
|
|
|
jQuery(selector).empty();
|
|
|
|
});
|
2015-08-31 18:40:33 +02:00
|
|
|
resolve(_popupId);
|
|
|
|
},
|
|
|
|
function(_err){
|
|
|
|
reject(_err);
|
|
|
|
});
|
2015-08-27 19:38:18 +02:00
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-08-31 18:40:33 +02:00
|
|
|
/**
|
2015-09-15 10:42:21 +02:00
|
|
|
* Delete backup key from filesystem
|
2015-08-31 18:40:33 +02:00
|
|
|
*/
|
|
|
|
mailvelopeDeleteBackup: function()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
et2_dialog.show_dialog(function (_button_id)
|
|
|
|
{
|
|
|
|
if (_button_id == et2_dialog.YES_BUTTON )
|
|
|
|
{
|
|
|
|
self._mailvelopeBackupFileOperator(undefined, 'DELETE', function(){
|
2015-09-16 17:32:33 +02:00
|
|
|
self.egw.message(self.egw.lang('The backup key has been deleted.'));
|
2015-08-31 18:40:33 +02:00
|
|
|
}, function(_err){
|
2015-09-16 17:32:33 +02:00
|
|
|
self.egw.message(self.egw.lang('Was not able to delete the backup key because %1',_err));
|
2015-08-31 18:40:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2015-09-15 10:42:21 +02:00
|
|
|
self.egw.lang('Are you sure, you would like to delete the backup key?'),
|
|
|
|
self.egw.lang('Delete backup key'),
|
2015-08-31 18:40:33 +02:00
|
|
|
{}, et2_dialog.BUTTONS_YES_CANCEL, et2_dialog.QUESTION_MESSAGE, undefined, self.egw);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create mailvelope restore dialog
|
|
|
|
* @param {string} _selector DOM selector to attach restorDialog
|
|
|
|
* @param {boolean} _restorePassword if true, will restore key password too
|
|
|
|
*
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
mailvelopeCreateRestoreDialog: function(_selector, _restorePassword)
|
2015-08-27 19:38:18 +02:00
|
|
|
{
|
2015-08-31 18:40:33 +02:00
|
|
|
var self = this;
|
|
|
|
var restorePassword = _restorePassword;
|
|
|
|
var selector = _selector || 'body';
|
2016-02-29 16:50:24 +01:00
|
|
|
//Clear the
|
2015-09-15 10:42:21 +02:00
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').remove();
|
2015-08-27 19:38:18 +02:00
|
|
|
return new Promise(function(_resolve, _reject){
|
2015-08-31 18:40:33 +02:00
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
|
|
|
{
|
|
|
|
_keyring.addSyncHandler(self.mailvelopeSyncHandlerObj);
|
2015-08-27 19:38:18 +02:00
|
|
|
|
2015-08-31 18:40:33 +02:00
|
|
|
var options = {
|
|
|
|
restorePassword:restorePassword
|
|
|
|
};
|
|
|
|
_keyring.restoreBackupContainer(selector, options).then(function(_restoreId){
|
|
|
|
var $restore_selector = jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]');
|
|
|
|
$restore_selector.css({position:'absolute', "z-index":1});
|
|
|
|
resolve(_restoreId);
|
|
|
|
},
|
|
|
|
function(_err){
|
|
|
|
reject(_err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
2015-08-27 19:38:18 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-08-31 18:40:33 +02:00
|
|
|
/**
|
|
|
|
* Create a dialog to show all backup/restore options
|
|
|
|
*
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
mailvelopeCreateBackupRestoreDialog: function()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var appname = egw.app_name();
|
|
|
|
var menu = [
|
|
|
|
// Header row should be empty item 0
|
|
|
|
{},
|
|
|
|
// Restore Keyring item 1
|
2015-09-15 10:42:21 +02:00
|
|
|
{label:"Restore key" ,image:"lock", onclick:"app."+appname+".mailvelopeCreateRestoreDialog('#_mvelo')"},
|
2015-08-31 18:40:33 +02:00
|
|
|
// Restore pass phrase item 2
|
2015-09-15 10:42:21 +02:00
|
|
|
{label:"Restore password",image:"password", onclick:"app."+appname+".mailvelopeCreateRestoreDialog('#_mvelo', true)"},
|
|
|
|
// Delete backup Key item 3
|
|
|
|
{label:"Delete backup", image:"delete", onclick:"app."+appname+".mailvelopeDeleteBackup"},
|
|
|
|
// Backup Key item 4
|
|
|
|
{label:"Backup Key", image:"save", onclick:"app."+appname+".mailvelopeCreateBackupDialog('#_mvelo', false)"}
|
2015-08-31 18:40:33 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
var dialog = function(_content, _callback)
|
|
|
|
{
|
|
|
|
return et2_createWidget("dialog", {
|
|
|
|
callback: function(_button_id, _value) {
|
|
|
|
if (typeof _callback == "function")
|
|
|
|
{
|
|
|
|
_callback.call(this, _button_id, _value.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: egw.lang('Backup/Restore'),
|
2015-09-15 18:32:56 +02:00
|
|
|
buttons:[{"button_id": 'close',"text": 'Close', id: 'dialog[close]', image: 'cancelled', "default":true}],
|
2015-08-31 18:40:33 +02:00
|
|
|
value: {
|
|
|
|
content: {
|
|
|
|
menu:_content
|
|
|
|
}
|
|
|
|
},
|
2016-05-01 11:57:48 +02:00
|
|
|
template: egw.webserverUrl+'/api/templates/default/pgp_backup_restore.xet',
|
2015-08-31 18:40:33 +02:00
|
|
|
class: "pgp_backup_restore",
|
|
|
|
modal:true
|
|
|
|
});
|
|
|
|
};
|
2015-09-15 10:42:21 +02:00
|
|
|
if (typeof mailvelope != 'undefined')
|
2015-08-31 18:40:33 +02:00
|
|
|
{
|
2015-09-15 10:42:21 +02:00
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
|
|
|
{
|
|
|
|
self._mailvelopeBackupFileOperator(undefined, 'GET', function(_data){
|
|
|
|
dialog(menu);
|
|
|
|
},
|
|
|
|
function(){
|
|
|
|
// Remove delete item
|
|
|
|
menu.splice(3,1);
|
|
|
|
menu[3]['onclick'] = "app."+appname+".mailvelopeCreateBackupDialog('#_mvelo', true)";
|
|
|
|
dialog(menu);
|
|
|
|
});
|
2015-08-31 18:40:33 +02:00
|
|
|
},
|
|
|
|
function(){
|
2015-09-15 10:42:21 +02:00
|
|
|
mailvelope.createKeyring('egroupware').then(function(){dialog(menu);});
|
2015-08-31 18:40:33 +02:00
|
|
|
});
|
2015-09-15 10:42:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.mailvelopeInstallationOffer();
|
|
|
|
}
|
2015-08-31 18:40:33 +02:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-09-15 18:32:56 +02:00
|
|
|
/**
|
|
|
|
* Create a dialog and offers installation option for installing mailvelope plugin
|
|
|
|
* plus it offers a video tutorials to get the user morte familiar with mailvelope
|
|
|
|
*/
|
2015-09-14 19:38:33 +02:00
|
|
|
mailvelopeInstallationOffer: function ()
|
|
|
|
{
|
2015-09-15 18:32:56 +02:00
|
|
|
var buttons = [
|
|
|
|
{"text": 'Install', id: 'install', image: 'check', "default":true},
|
|
|
|
{"text": 'Close', id:'close', image: 'cancelled'}
|
|
|
|
];
|
2015-09-14 19:38:33 +02:00
|
|
|
var dialog = function(_content, _callback)
|
|
|
|
{
|
|
|
|
return et2_createWidget("dialog", {
|
2016-03-17 19:12:36 +01:00
|
|
|
callback: function(_button_id, _value) {
|
|
|
|
if (typeof _callback == "function")
|
|
|
|
{
|
|
|
|
_callback.call(this, _button_id, _value.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title: egw.lang('PGP Encryption Installation'),
|
|
|
|
buttons: buttons,
|
|
|
|
dialog_type: 'info',
|
|
|
|
value: {
|
|
|
|
content: _content
|
|
|
|
},
|
2016-05-01 11:57:48 +02:00
|
|
|
template: egw.webserverUrl+'/api/templates/default/pgp_installation.xet',
|
2016-03-17 19:12:36 +01:00
|
|
|
class: "pgp_installation",
|
|
|
|
modal: true
|
|
|
|
//resizable:false,
|
2015-09-14 19:38:33 +02:00
|
|
|
});
|
|
|
|
};
|
2015-09-15 18:32:56 +02:00
|
|
|
var content = [
|
|
|
|
// Header row should be empty item 0
|
|
|
|
{},
|
|
|
|
{domain:this.egw.lang('Add your domain as "%1" in options to list of email providers and enable API.',
|
|
|
|
'*.'+this._mailvelopeDomain()), video:"test", control:"true"}
|
|
|
|
];
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-09-14 19:38:33 +02:00
|
|
|
dialog(content, function(_button){
|
2015-09-15 18:32:56 +02:00
|
|
|
if (_button == 'install')
|
2015-09-14 19:38:33 +02:00
|
|
|
{
|
2015-09-15 18:32:56 +02:00
|
|
|
if (typeof chrome != 'undefined')
|
2015-09-14 19:38:33 +02:00
|
|
|
{
|
2015-09-15 18:32:56 +02:00
|
|
|
// ATM we are not able to trigger mailvelope installation directly
|
|
|
|
// since the installation should be triggered from the extension
|
|
|
|
// owner validate website (mailvelope.com), therefore, we just redirect
|
2016-02-29 16:50:24 +01:00
|
|
|
// user to chrome webstore to install mailvelope from there.
|
2015-09-15 18:32:56 +02:00
|
|
|
window.open('https://chrome.google.com/webstore/detail/mailvelope/kajibbejlbohfaggdiogboambcijhkke');
|
2015-09-14 19:38:33 +02:00
|
|
|
}
|
|
|
|
else if (typeof InstallTrigger != 'undefined' && InstallTrigger.enabled())
|
|
|
|
{
|
|
|
|
InstallTrigger.install({mailvelope:"https://download.mailvelope.com/releases/latest/mailvelope.firefox.xpi"},
|
|
|
|
function(_url, _status){
|
|
|
|
if (_status == 0)
|
|
|
|
{
|
|
|
|
et2_dialog.alert(lang('Mailvelope addon installation succeded. Now you may configure the options.'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 15:13:37 +02:00
|
|
|
et2_dialog.alert(lang('Mailvelope addon installation failed! Please try again.'));
|
2015-09-14 19:38:33 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-05-28 16:40:33 +02:00
|
|
|
/**
|
|
|
|
* PGP begin and end tags
|
|
|
|
*/
|
|
|
|
begin_pgp_message: '-----BEGIN PGP MESSAGE-----',
|
|
|
|
end_pgp_message: '-----END PGP MESSAGE-----',
|
|
|
|
|
2015-05-20 17:24:08 +02:00
|
|
|
/**
|
|
|
|
* Mailvelope "egroupware" Keyring
|
|
|
|
*/
|
|
|
|
mailvelope_keyring: undefined,
|
|
|
|
|
2015-05-29 13:04:09 +02:00
|
|
|
/**
|
|
|
|
* jQuery selector for Mailvelope iframes in all browsers
|
|
|
|
*/
|
|
|
|
mailvelope_iframe_selector: 'iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]',
|
|
|
|
|
2015-05-19 20:56:12 +02:00
|
|
|
/**
|
|
|
|
* Open (or create) "egroupware" keyring and call callback with it
|
|
|
|
*
|
2015-05-20 17:24:08 +02:00
|
|
|
* @returns {Promise.<Keyring, Error>} Keyring or Error with message
|
2015-05-19 20:56:12 +02:00
|
|
|
*/
|
2015-05-20 17:24:08 +02:00
|
|
|
mailvelopeOpenKeyring: function()
|
2015-05-19 20:56:12 +02:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
2015-05-20 17:24:08 +02:00
|
|
|
return new Promise(function(_resolve, _reject)
|
2015-05-19 20:56:12 +02:00
|
|
|
{
|
2015-05-20 17:24:08 +02:00
|
|
|
if (self.mailvelope_keyring) _resolve(self.mailvelope_keyring);
|
|
|
|
|
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
|
|
|
|
mailvelope.getKeyring('egroupware').then(function(_keyring)
|
2015-05-19 22:23:38 +02:00
|
|
|
{
|
2015-05-20 17:24:08 +02:00
|
|
|
self.mailvelope_keyring = _keyring;
|
2015-05-19 22:23:38 +02:00
|
|
|
|
2015-05-20 17:24:08 +02:00
|
|
|
resolve(_keyring);
|
2015-08-27 19:38:18 +02:00
|
|
|
},
|
2015-05-19 22:23:38 +02:00
|
|
|
function(_err)
|
|
|
|
{
|
2015-05-20 17:24:08 +02:00
|
|
|
mailvelope.createKeyring('egroupware').then(function(_keyring)
|
|
|
|
{
|
|
|
|
self.mailvelope_keyring = _keyring;
|
2015-05-29 13:04:09 +02:00
|
|
|
var mvelo_settings_selector = self.mailvelope_iframe_selector
|
|
|
|
.split(',').map(function(_val){return 'body>'+_val;}).join(',');
|
2015-05-20 17:24:08 +02:00
|
|
|
|
2015-05-23 16:04:28 +02:00
|
|
|
mailvelope.createSettingsContainer('body', _keyring, {
|
|
|
|
email: self.egw.user('account_email'),
|
|
|
|
fullName: self.egw.user('account_fullname')
|
|
|
|
}).then(function()
|
|
|
|
{
|
|
|
|
// make only Mailvelope settings dialog visible
|
2015-05-29 13:04:09 +02:00
|
|
|
jQuery(mvelo_settings_selector).css({position: 'absolute', top: 0});
|
2015-05-23 16:04:28 +02:00
|
|
|
// add a close button, so we know when to offer storing public key to AB
|
|
|
|
jQuery('<button class="et2_button et2_button_text" id="mailvelope_close_settings">'+self.egw.lang('Close')+'</button>')
|
2015-08-27 19:38:18 +02:00
|
|
|
.css({position: 'absolute', top: 8, right: 8, "z-index":2})
|
2015-05-23 16:04:28 +02:00
|
|
|
.click(function()
|
|
|
|
{
|
|
|
|
// try fetching public key, to check user created onw
|
|
|
|
self.mailvelope_keyring.exportOwnPublicKey(self.egw.user('account_email')).then(function(_pubKey)
|
|
|
|
{
|
2015-08-31 18:40:33 +02:00
|
|
|
// CreateBackupDialog
|
|
|
|
self.mailvelopeCreateBackupDialog().then(function(_popupId){
|
|
|
|
jQuery('iframe[src^="chrome-extension"],iframe[src^="about:blank?mvelo"]').css({position:'absolute', "z-index":1});
|
|
|
|
},
|
|
|
|
function(_err){
|
|
|
|
egw.message(_err);
|
|
|
|
});
|
|
|
|
|
|
|
|
// if yes, hide settings dialog
|
|
|
|
jQuery(mvelo_settings_selector).each(function(index,item){
|
|
|
|
if (!item.src.match(/keyBackupDialog.html/,'ig')) item.remove();
|
|
|
|
});
|
|
|
|
jQuery('button#mailvelope_close_settings').remove();
|
2015-08-27 19:38:18 +02:00
|
|
|
|
2015-05-23 16:04:28 +02:00
|
|
|
// offer user to store his public key to AB for other users to find
|
|
|
|
var buttons = [
|
|
|
|
{button_id: 2, text: 'Yes', id: 'dialog[yes]', image: 'check', default: true},
|
|
|
|
{button_id: 3, text : 'No', id: 'dialog[no]', image: 'cancelled'}
|
|
|
|
];
|
|
|
|
if (egw.user('apps').admin)
|
|
|
|
{
|
|
|
|
buttons.unshift({
|
|
|
|
button_id: 5, text: 'Yes and allow non-admin users to do that too (recommended)',
|
|
|
|
id: 'dialog[yes_allow]', image: 'check', default: true
|
|
|
|
});
|
|
|
|
delete buttons[1].default;
|
|
|
|
}
|
|
|
|
et2_dialog.show_dialog(function (_button_id)
|
|
|
|
{
|
|
|
|
if (_button_id != et2_dialog.NO_BUTTON )
|
|
|
|
{
|
|
|
|
var keys = {};
|
|
|
|
keys[self.egw.user('account_id')] = _pubKey;
|
|
|
|
self.egw.json('addressbook.addressbook_bo.ajax_set_pgp_keys',
|
|
|
|
[keys, _button_id != et2_dialog.YES_BUTTON ? true : undefined]).sendRequest()
|
|
|
|
.then(function(_data)
|
|
|
|
{
|
|
|
|
self.egw.message(_data.response['0'].data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self.egw.lang('It is recommended to store your public key in addressbook, so other users can write you encrypted mails.'),
|
|
|
|
self.egw.lang('Store your public key in Addressbook?'),
|
|
|
|
{}, buttons, et2_dialog.QUESTION_MESSAGE, undefined, self.egw);
|
|
|
|
},
|
|
|
|
function(_err){
|
|
|
|
self.egw.message(_err.message+"\n\n"+
|
|
|
|
self.egw.lang("You will NOT be able to send or receive encrypted mails before completing that step!"), 'error');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.appendTo('body');
|
|
|
|
});
|
2015-05-20 17:24:08 +02:00
|
|
|
resolve(_keyring);
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
2015-05-19 22:23:38 +02:00
|
|
|
});
|
2015-05-19 20:56:12 +02:00
|
|
|
});
|
2015-05-19 22:23:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mailvelope uses Domain without first part: eg. "stylite.de" for "egw.stylite.de"
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_mailvelopeDomain: function()
|
|
|
|
{
|
|
|
|
var parts = document.location.hostname.split('.');
|
|
|
|
if (parts.length > 1) parts.shift();
|
|
|
|
return parts.join('.');
|
2015-05-20 17:24:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we have a key for all recipients
|
|
|
|
*
|
|
|
|
* @param {Array} _recipients
|
|
|
|
* @returns {Promise.<Array, Error>} Array of recipients or Error with recipients without key
|
|
|
|
*/
|
|
|
|
mailvelopeGetCheckRecipients: function(_recipients)
|
|
|
|
{
|
2015-05-20 23:20:10 +02:00
|
|
|
// replace rfc822 addresses with raw email, as Mailvelop does not like them and lowercase all email
|
2015-05-20 17:24:08 +02:00
|
|
|
var rfc822_preg = /<([^'" <>]+)>$/;
|
|
|
|
var recipients = _recipients.map(function(_recipient)
|
|
|
|
{
|
|
|
|
var matches = _recipient.match(rfc822_preg);
|
2015-05-20 23:20:10 +02:00
|
|
|
return matches ? matches[1].toLowerCase() : _recipient.toLowerCase();
|
2015-05-20 17:24:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// check if we have keys for all recipients
|
|
|
|
var self = this;
|
|
|
|
return new Promise(function(_resolve, _reject)
|
|
|
|
{
|
|
|
|
var resolve = _resolve;
|
|
|
|
var reject = _reject;
|
|
|
|
self.mailvelopeOpenKeyring().then(function(_keyring)
|
|
|
|
{
|
2015-05-20 23:20:10 +02:00
|
|
|
var keyring = _keyring;
|
2015-05-20 17:24:08 +02:00
|
|
|
_keyring.validKeyForAddress(recipients).then(function(_status)
|
|
|
|
{
|
|
|
|
var no_key = [];
|
|
|
|
for(var email in _status)
|
|
|
|
{
|
|
|
|
if (!_status[email]) no_key.push(email);
|
|
|
|
}
|
|
|
|
if (no_key.length)
|
|
|
|
{
|
2015-05-20 23:20:10 +02:00
|
|
|
// server addressbook on server for missing public keys
|
|
|
|
self.egw.json('addressbook.addressbook_bo.ajax_get_pgp_keys', [no_key]).sendRequest().then(function(_data)
|
|
|
|
{
|
|
|
|
var data = _data.response['0'].data;
|
|
|
|
var promises = [];
|
|
|
|
for(var email in data)
|
|
|
|
{
|
|
|
|
promises.push(keyring.importPublicKey(data[email]).then(function(_result)
|
|
|
|
{
|
|
|
|
if (_result == 'IMPORTED')
|
|
|
|
{
|
|
|
|
no_key.splice(no_key.indexOf(email),1);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
Promise.all(promises).then(function()
|
|
|
|
{
|
|
|
|
if (no_key.length)
|
|
|
|
{
|
2015-05-25 12:08:47 +02:00
|
|
|
reject(new Error(self.egw.lang('No key for recipient:')+' '+no_key.join(', ')));
|
2015-05-20 23:20:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resolve(recipients);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-05-20 17:24:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resolve(recipients);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(_err)
|
|
|
|
{
|
|
|
|
reject(_err);
|
|
|
|
});
|
|
|
|
});
|
2013-12-13 00:45:09 +01:00
|
|
|
}
|
2016-02-29 16:50:24 +01:00
|
|
|
});}).call(this);
|