2021-07-02 11:42:24 +02:00
|
|
|
/**
|
|
|
|
* EGroupware - Home - Javascript UI
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package home
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright (c) 2013 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {et2_createWidget} from "../../api/js/etemplate/et2_core_widget";
|
2023-03-02 21:27:35 +01:00
|
|
|
import {EgwApp} from "../../api/js/jsapi/egw_app";
|
|
|
|
import {etemplate2} from "../../api/js/etemplate/etemplate2";
|
|
|
|
import {Et2Portlet} from "../../api/js/etemplate/Et2Portlet/Et2Portlet";
|
|
|
|
import {Et2PortletFavorite} from "./Et2PortletFavorite";
|
2023-03-03 23:41:56 +01:00
|
|
|
import {loadWebComponent} from "../../api/js/etemplate/Et2Widget/Et2Widget";
|
|
|
|
import "./Et2PortletList";
|
2023-03-06 21:19:07 +01:00
|
|
|
import "./Et2PortletNote";
|
2023-03-10 22:44:01 +01:00
|
|
|
import './Et2PortletWeather';
|
2023-03-06 22:47:48 +01:00
|
|
|
import "../../calendar/js/Et2PortletCalendar"
|
2023-03-03 23:41:56 +01:00
|
|
|
import Sortable from "sortablejs/modular/sortable.complete.esm.js";
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JS for home application
|
|
|
|
*
|
|
|
|
* Home is a collection of little bits of content (portlets) from the other applications.
|
|
|
|
*
|
|
|
|
* Uses Gridster for the grid layout
|
|
|
|
* @see http://gridster.net
|
|
|
|
* @augments AppJS
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
export class HomeApp extends EgwApp
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grid resolution. Must match et2_portlet GRID
|
|
|
|
*/
|
2023-03-03 23:41:56 +01:00
|
|
|
public static GRID = 150;
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// List of portlets
|
2023-03-02 21:27:35 +01:00
|
|
|
private portlets = {};
|
|
|
|
portlet_container : any;
|
2023-03-03 23:41:56 +01:00
|
|
|
private sortable : Sortable;
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
constructor()
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
// call parent
|
2023-03-02 21:27:35 +01:00
|
|
|
super("home");
|
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
destroy()
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
delete this.et2;
|
|
|
|
delete this.portlet_container;
|
|
|
|
|
|
|
|
this.portlets = {};
|
|
|
|
|
|
|
|
// call parent
|
2023-03-02 21:27:35 +01:00
|
|
|
super.destroy(this.appname);
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Make sure all other sub-etemplates in portlets are done
|
2023-03-03 23:41:56 +01:00
|
|
|
if(this == window.app.home)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
let others = etemplate2.getByApplication(this.appname);
|
|
|
|
for(let i = 0; i < others.length; i++)
|
|
|
|
{
|
|
|
|
others[i].clear();
|
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called when the etemplate2 object is loaded
|
|
|
|
* and ready. If you must store a reference to the et2 object,
|
|
|
|
* make sure to clean it up in destroy().
|
|
|
|
*
|
|
|
|
* @param {etemplate2} et2 Newly ready object
|
|
|
|
* @param {string} Template name
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
et2_ready(et2, name)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
// Top level
|
|
|
|
if(name == 'home.index')
|
|
|
|
{
|
|
|
|
// call parent
|
2023-03-02 21:27:35 +01:00
|
|
|
super.et2_ready(et2, name);
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
this.et2.set_id('home.index');
|
|
|
|
this.et2.set_actions(this.et2.getArrayMgr('modifications').getEntry('home.index')['actions']);
|
|
|
|
|
|
|
|
this.portlet_container = this.et2.getWidgetById("portlets");
|
|
|
|
|
|
|
|
// Accept drops of favorites, which aren't part of action system
|
2023-03-03 23:41:56 +01:00
|
|
|
this.sortable = new Sortable(this.et2.getDOMNode().parentNode, {
|
|
|
|
chosenClass: 'drop-hover',
|
2023-03-02 21:27:35 +01:00
|
|
|
accept: function(draggable)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
// Check for direct support for that application
|
|
|
|
if(draggable[0].dataset && draggable[0].dataset.appname)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
return egw_getActionManager('home', false, 1).getActionById('drop_' + draggable[0].dataset.appname + '_favorite_portlet') != null;
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2023-03-03 23:41:56 +01:00
|
|
|
onAdd: function(event, ui)
|
2023-03-02 21:27:35 +01:00
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
debugger;
|
2021-07-02 11:42:24 +02:00
|
|
|
// Favorite dropped on home - fake an action and divert to normal handler
|
2023-03-02 21:27:35 +01:00
|
|
|
let action = {
|
2021-07-02 11:42:24 +02:00
|
|
|
data: {
|
|
|
|
class: 'add_home_favorite_portlet'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for direct support for that application
|
|
|
|
if(ui.helper.context.dataset && ui.helper.context.dataset.appname)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
action = egw_getActionManager('home', false, 1).getActionById('drop_' + ui.helper.context.dataset.appname + '_favorite_portlet') || {}
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
action.ui = ui;
|
|
|
|
app.home.add_from_drop(action, [{data: ui.helper.context.dataset}])
|
|
|
|
}
|
2023-03-03 23:41:56 +01:00
|
|
|
});
|
2023-03-06 21:19:07 +01:00
|
|
|
|
|
|
|
this._do_ordering()
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
else if(et2.uniqueId)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
let portlet_container = this.portlet_container || window.app.home?.portlet_container;
|
|
|
|
// Handle bad timing - a sub-template was finished first
|
|
|
|
if(!portlet_container)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
window.setTimeout(() => {this.et2_ready(et2, name);}, 200);
|
2021-07-02 11:42:24 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-03-03 23:41:56 +01:00
|
|
|
let portlet = portlet_container.getWidgetById(et2.uniqueId) || et2.DOMContainer;
|
2021-07-02 11:42:24 +02:00
|
|
|
// Check for existing etemplate, this one loaded over it
|
|
|
|
// NOTE: Moving them around like this can cause problems with event handlers
|
2023-03-02 21:27:35 +01:00
|
|
|
let existing = etemplate2.getById(et2.uniqueId);
|
2021-07-02 11:42:24 +02:00
|
|
|
if(portlet && existing)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
for(let i = 0; i < portlet._children.length; i++)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
if(typeof portlet._children[i]._init == 'undefined')
|
|
|
|
{
|
|
|
|
portlet.removeChild(portlet._children[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 16:54:48 +01:00
|
|
|
// Set size & position, if somehow not set yet (Et2Portlet does it)
|
|
|
|
if(portlet.style.gridArea == "")
|
|
|
|
{
|
|
|
|
let et2_data = et2.widgetContainer.getArrayMgr("content").data;
|
|
|
|
let settings = et2_data && et2_data.id == portlet.id && et2_data || portlet_container.getArrayMgr("content").data.find(e => et2.uniqueId.endsWith(e.id)) || {settings: {}};
|
|
|
|
portlet.settings = settings.settings || {};
|
|
|
|
portlet.style.gridArea = settings.row + "/" + settings.col + "/ span " + (settings.height || 1) + "/ span " + (settings.width || 1);
|
|
|
|
}
|
2023-03-03 23:41:56 +01:00
|
|
|
|
|
|
|
|
2021-07-02 11:42:24 +02:00
|
|
|
// It's in the right place for original load, but move it into portlet
|
2023-03-03 23:41:56 +01:00
|
|
|
|
2023-03-02 21:27:35 +01:00
|
|
|
let misplaced = jQuery(etemplate2.getById('home-index').DOMContainer).siblings('#' + et2.DOMContainer.id);
|
2023-03-03 23:41:56 +01:00
|
|
|
|
|
|
|
if(portlet && et2.DOMContainer !== portlet)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
portlet.append(et2.DOMContainer);
|
2021-07-02 11:42:24 +02:00
|
|
|
et2.resize();
|
|
|
|
}
|
|
|
|
if(portlet && misplaced.length)
|
|
|
|
{
|
|
|
|
et2.DOMContainer.id = et2.uniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instanciate custom code for this portlet
|
|
|
|
this._get_portlet_code(portlet);
|
2023-03-03 23:41:56 +01:00
|
|
|
|
|
|
|
// Ordering of portlets
|
|
|
|
// Only needs to be done once, but its hard to tell when everything is loaded
|
|
|
|
this._do_ordering();
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Observer method receives update notifications from all applications
|
|
|
|
*
|
|
|
|
* Home passes the notification off to specific code for each portlet, which
|
|
|
|
* decide if they should be updated or not.
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
* @param {string} _targetapp which app's window should be refreshed, default current
|
|
|
|
* @return {false|*} false to stop regular refresh, thought all observers are run
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
observer(_msg, _app, _id, _type, _msg_type, _targetapp)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
for(let id in this.portlets)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
// App is home, refresh all portlets
|
|
|
|
if(_app == 'home')
|
|
|
|
{
|
|
|
|
this.refresh(id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask the portlets if they're interested
|
|
|
|
try
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
let code = this.portlets[id];
|
2021-07-02 11:42:24 +02:00
|
|
|
if(code)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
code.observer(_msg, _app, _id, _type, _msg_type, _targetapp);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
this.egw.debug("error", "Error trying to update portlet " + id, e);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new portlet from the context menu
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
add(action, source)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
// Basic portlet attributes
|
2023-03-02 21:27:35 +01:00
|
|
|
let attrs = {
|
|
|
|
id: this._create_id(),
|
|
|
|
class: action.data.class
|
2021-07-02 11:42:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Try to put it about where the menu was opened
|
|
|
|
if(action.menu_context)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
let $portlet_container = jQuery(this.portlet_container.getDOMNode());
|
|
|
|
attrs.row = Math.max(1, Math.round((action.menu_context.posy - $portlet_container.offset().top) / HomeApp.GRID) + 1);
|
2023-03-03 23:41:56 +01:00
|
|
|
// Use "auto" col to avoid any overlap or overflow
|
|
|
|
attrs.col = "auto";
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
|
2023-03-08 00:02:29 +01:00
|
|
|
let portlet = <Et2Portlet>loadWebComponent(this.get_portlet_tag(action), attrs, this.portlet_container);
|
2021-07-02 11:42:24 +02:00
|
|
|
portlet.loadingFinished();
|
|
|
|
|
|
|
|
// Get actual attributes & settings, since they're not available client side yet
|
2023-03-02 21:27:35 +01:00
|
|
|
portlet.update_settings(attrs);
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Instanciate custom code for this portlet
|
|
|
|
this._get_portlet_code(portlet);
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User dropped something on home. Add a new portlet
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
add_from_drop(action, source)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Actions got confused drop vs popup
|
|
|
|
if(source[0].id == 'portlets')
|
|
|
|
{
|
|
|
|
return this.add(action);
|
|
|
|
}
|
|
|
|
|
2023-03-02 21:27:35 +01:00
|
|
|
let $portlet_container = jQuery(this.portlet_container.getDOMNode());
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Basic portlet attributes
|
2023-03-02 21:27:35 +01:00
|
|
|
let attrs = {
|
2021-07-02 11:42:24 +02:00
|
|
|
id: this._create_id(),
|
|
|
|
class: action.data.class || action.id.substr(5),
|
2023-03-03 23:41:56 +01:00
|
|
|
dropped_data: []
|
2021-07-02 11:42:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Try to find where the drop was
|
|
|
|
if(action != null && action.ui && action.ui.position)
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
attrs.row = Math.max(1, Math.round((action.ui.position.top - $portlet_container.offset().top) / HomeApp.GRID));
|
|
|
|
// Use "auto" col to avoid any overlap or overflow
|
|
|
|
attrs.col = "auto";
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get actual attributes & settings, since they're not available client side yet
|
2023-03-02 21:27:35 +01:00
|
|
|
for(let i = 0; i < source.length; i++)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
if(source[i].id)
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
attrs.dropped_data.push(source[i].id);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
attrs.dropped_data.push(source[i].data);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-03 23:41:56 +01:00
|
|
|
|
2023-03-08 00:02:29 +01:00
|
|
|
let portlet = <Et2Portlet>loadWebComponent(this.get_portlet_tag(action), attrs, this.portlet_container);
|
2023-03-03 23:41:56 +01:00
|
|
|
portlet.loadingFinished();
|
|
|
|
|
|
|
|
// Get actual attributes & settings, since they're not available client side yet
|
|
|
|
portlet.update_settings(attrs);
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Instanciate custom code for this portlet
|
|
|
|
this._get_portlet_code(portlet);
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current selection as default for other users
|
|
|
|
*
|
|
|
|
* Only works (and available) for admins, this shows a dialog to select
|
|
|
|
* the group, and then sets the default for that group.
|
|
|
|
*
|
|
|
|
* @param {egwAction} action
|
|
|
|
* @param {egwActionObject[]} selected
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
set_default(action, selected)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
// Gather just IDs, server will handle the details
|
2023-03-02 21:27:35 +01:00
|
|
|
let portlet_ids = [];
|
|
|
|
let group = action.data.portlet_group || false;
|
2021-07-02 11:42:24 +02:00
|
|
|
if(selected[0].id == 'home.index')
|
|
|
|
{
|
|
|
|
// Set all
|
2023-03-02 21:27:35 +01:00
|
|
|
this.portlet_container.iterateOver(function(portlet)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
portlet_ids.push(portlet.id);
|
2023-03-02 21:27:35 +01:00
|
|
|
}, this, et2_portlet);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
for(let i = 0; i < selected.length; i++)
|
2021-07-02 11:42:24 +02:00
|
|
|
{
|
|
|
|
portlet_ids.push(selected[i].id);
|
|
|
|
|
|
|
|
// Read the associated group so we can properly remove it
|
2023-03-02 21:27:35 +01:00
|
|
|
let portlet = egw.preference(selected[i].id, 'home');
|
2021-07-02 11:42:24 +02:00
|
|
|
if(!group && portlet && portlet.group)
|
|
|
|
{
|
|
|
|
group = portlet.group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(action.id.indexOf("remove_default") == 0)
|
|
|
|
{
|
|
|
|
// Disable action for feedback
|
|
|
|
action.set_enabled(false);
|
|
|
|
|
|
|
|
// Pass them to server
|
|
|
|
egw.json('home_ui::ajax_set_default', ['delete', portlet_ids, group]).sendRequest(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
let dialog = et2_createWidget("dialog", {
|
2021-07-02 11:42:24 +02:00
|
|
|
// If you use a template, the second parameter will be the value of the template, as if it were submitted.
|
2023-03-02 21:27:35 +01:00
|
|
|
callback: function(button_id, value)
|
|
|
|
{
|
|
|
|
if(button_id != et2_dialog.OK_BUTTON)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Pass them to server
|
2023-03-02 21:27:35 +01:00
|
|
|
egw.json('home_ui::ajax_set_default', ['add', portlet_ids, value.group || false]).sendRequest(true);
|
2021-07-02 11:42:24 +02:00
|
|
|
},
|
|
|
|
buttons: et2_dialog.BUTTONS_OK_CANCEL,
|
|
|
|
title: action.caption,
|
2023-03-02 21:27:35 +01:00
|
|
|
template: "home.set_default",
|
|
|
|
value: {content: {}, sel_options: {group: {default: egw.lang('All'), forced: egw.lang('Forced')}}}
|
2021-07-02 11:42:24 +02:00
|
|
|
});
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow a refresh from anywhere by triggering an update with no changes
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
refresh(id)
|
|
|
|
{
|
|
|
|
let p = this.portlet_container.getWidgetById(id);
|
2021-07-02 11:42:24 +02:00
|
|
|
if(p)
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
p.update_settings('~reload~');
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
2023-03-08 00:02:29 +01:00
|
|
|
/**
|
|
|
|
* Determine the correct portlet type to use for the given action
|
|
|
|
*
|
|
|
|
* @param {egwAction} action
|
|
|
|
*/
|
|
|
|
get_portlet_tag(action : egwAction) : string
|
|
|
|
{
|
|
|
|
// Try to turn action ID into tag (eg: home_list_portlet -> et2-portlet-list)
|
|
|
|
let tag = "et2-" + action.id.replace("add_", "").split("_").reverse().slice(0, -1).map(i => i.toLowerCase()).join("-");
|
|
|
|
if(typeof customElements.get(tag) != "undefined")
|
|
|
|
{
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
return "et2-portlet";
|
|
|
|
}
|
|
|
|
|
2021-07-02 11:42:24 +02:00
|
|
|
/**
|
|
|
|
* Determine the best fitting code to use for the given portlet, instanciate
|
|
|
|
* it and add it to the list.
|
|
|
|
*
|
|
|
|
* @param {et2_portlet} portlet
|
|
|
|
* @returns {home_portlet}
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
_get_portlet_code(portlet)
|
|
|
|
{
|
|
|
|
let classname = portlet.class;
|
2021-07-02 11:42:24 +02:00
|
|
|
// Freshly added portlets can have 'add_' prefix
|
|
|
|
if(classname.indexOf('add_') == 0)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
classname = classname.replace('add_', '');
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
|
|
|
// Prefer a specific match
|
2023-03-02 21:27:35 +01:00
|
|
|
let _class = app.classes.home[classname] ||
|
|
|
|
(typeof customElements.get(classname) != "undefined" ? customElements.get(classname).class : false) ||
|
2021-07-02 11:42:24 +02:00
|
|
|
// If it has a nextmatch, use favorite base class
|
2023-03-02 21:27:35 +01:00
|
|
|
(portlet.getWidgetById('nm') ? Et2PortletFavorite : false) ||
|
2021-07-02 11:42:24 +02:00
|
|
|
// Fall back to base class
|
2023-03-02 21:27:35 +01:00
|
|
|
Et2Portlet;
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
this.portlets[portlet.id] = new _class(portlet);
|
|
|
|
|
|
|
|
return this.portlets[portlet.id];
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For link_portlet - opens the configured record when the user
|
|
|
|
* double-clicks or chooses view from the context menu
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
open_link(action)
|
|
|
|
{
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
// Get widget
|
2023-03-02 21:27:35 +01:00
|
|
|
let widget = null;
|
2021-07-02 11:42:24 +02:00
|
|
|
while(action.parent != null)
|
|
|
|
{
|
|
|
|
if(action.data && action.data.widget)
|
|
|
|
{
|
|
|
|
widget = action.data.widget;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
action = action.parent;
|
|
|
|
}
|
|
|
|
if(widget == null)
|
|
|
|
{
|
2023-03-02 21:27:35 +01:00
|
|
|
this.egw.log("warning", "Could not find widget");
|
2021-07-02 11:42:24 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
this.egw.open(widget.options.settings.entry, "", 'view', null, widget.options.settings.entry.app);
|
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
2023-03-07 16:54:48 +01:00
|
|
|
* Set up the positioning of portlets
|
|
|
|
*
|
|
|
|
* This handles portlets that may be offscreen because of wrong settings or changed screen size
|
|
|
|
*
|
2021-07-02 11:42:24 +02:00
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
_do_ordering()
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
if(!this.portlet_container)
|
2023-03-02 21:27:35 +01:00
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:54:48 +01:00
|
|
|
|
|
|
|
// Check for column overflow
|
|
|
|
const gridStyle = getComputedStyle(this.portlet_container.getDOMNode());
|
|
|
|
let col_list = gridStyle.getPropertyValue("grid-template-columns").split(" ") || [];
|
|
|
|
const gridWidth = parseInt(gridStyle.width);
|
|
|
|
const maxColumn = Math.floor(gridWidth / (parseInt(col_list[0]) || 1));
|
|
|
|
|
|
|
|
// Check for column overlap
|
2023-03-03 23:41:56 +01:00
|
|
|
let col_map = {};
|
2023-03-07 16:54:48 +01:00
|
|
|
let last_row = 0;
|
2023-03-03 23:41:56 +01:00
|
|
|
this.portlet_container.getDOMNode().querySelectorAll("[style*='grid-area']").forEach((n) =>
|
2023-03-02 21:27:35 +01:00
|
|
|
{
|
2023-03-07 16:54:48 +01:00
|
|
|
let [row] = (getComputedStyle(n).gridRow || "").split(" / ");
|
2023-03-08 00:02:29 +01:00
|
|
|
const colData = (getComputedStyle(n).gridColumn || "").split(" / span ");
|
|
|
|
let col = parseInt(colData[0]);
|
|
|
|
let span = parseInt(colData[1] || "1");
|
|
|
|
if(parseInt(row) != last_row && typeof col_map[row] == "undefined")
|
2023-03-07 16:54:48 +01:00
|
|
|
{
|
|
|
|
last_row = parseInt(row);
|
2023-03-08 00:02:29 +01:00
|
|
|
col_map[row] = {};
|
2023-03-07 16:54:48 +01:00
|
|
|
}
|
|
|
|
// If column is already occupied, or start off screen, or width pushes right side off screen
|
2023-03-08 00:02:29 +01:00
|
|
|
if(typeof col_map[row][col] !== "undefined" || col > maxColumn || (col + span) > maxColumn)
|
2023-03-02 21:27:35 +01:00
|
|
|
{
|
2023-03-08 00:02:29 +01:00
|
|
|
if(col + span > maxColumn)
|
|
|
|
{
|
2023-03-08 22:06:04 +01:00
|
|
|
span = Math.max(
|
|
|
|
1,
|
|
|
|
Math.min(span, (maxColumn - (parseInt(Object.keys(col_map[row]).at(-1)) || col)))
|
|
|
|
);
|
2023-03-08 00:02:29 +01:00
|
|
|
}
|
2023-03-03 23:41:56 +01:00
|
|
|
// Set column to auto to avoid overlap
|
2023-03-08 00:02:29 +01:00
|
|
|
n.style.gridColumn = "auto / span " + span;
|
2023-03-03 23:41:56 +01:00
|
|
|
}
|
2023-03-08 00:02:29 +01:00
|
|
|
for(let i = col; i <= span; i++)
|
2023-03-03 23:41:56 +01:00
|
|
|
{
|
2023-03-08 00:02:29 +01:00
|
|
|
col_map[row][i] = true;
|
2023-03-03 23:41:56 +01:00
|
|
|
}
|
|
|
|
});
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an ID that should be unique, at least amoung a single user's portlets
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
_create_id()
|
|
|
|
{
|
|
|
|
let id = '';
|
2021-07-02 11:42:24 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
id = Math.floor((1 + Math.random()) * 0x10000)
|
2023-03-02 21:27:35 +01:00
|
|
|
.toString(16)
|
|
|
|
.substring(1);
|
2021-07-02 11:42:24 +02:00
|
|
|
}
|
2023-03-02 21:27:35 +01:00
|
|
|
while(this.portlet_container.getWidgetById('portlet_' + id));
|
|
|
|
return 'portlet_' + id;
|
|
|
|
}
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for the list portlet
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Remove a link from the list
|
|
|
|
*/
|
2023-03-02 21:27:35 +01:00
|
|
|
link_change(list, link_id, row)
|
|
|
|
{
|
2023-03-03 23:41:56 +01:00
|
|
|
list.link_change(link_id, row);
|
2023-03-02 21:27:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
app.classes.home = HomeApp;
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
|
2023-03-02 21:27:35 +01:00
|
|
|
/*
|
2021-07-02 11:42:24 +02:00
|
|
|
|
|
|
|
app.classes.home.home_weather_portlet = app.classes.home.home_portlet.extend({
|
|
|
|
init: function(portlet) {
|
|
|
|
// call parent
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Use location API
|
|
|
|
if(!this.portlet.options.settings && 'geolocation' in navigator)
|
|
|
|
{
|
|
|
|
navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
|
if(portlet && portlet.options && portlet.options.settings &&
|
|
|
|
portlet.options.settings.position && portlet.options.settings.position == position.coords.latitude + ',' + position.coords.longitude)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
portlet._process_edit(et2_dialog.OK_BUTTON, {position: position.coords.latitude + ',' + position.coords.longitude});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|