diff --git a/home/inc/class.home_link_portlet.inc.php b/home/inc/class.home_link_portlet.inc.php index 97e9f7580e..ab48f42bda 100644 --- a/home/inc/class.home_link_portlet.inc.php +++ b/home/inc/class.home_link_portlet.inc.php @@ -30,11 +30,17 @@ class home_link_portlet extends home_portlet */ public function __construct(Array &$context = array()) { - $this->context = $context; + // Process dropped data into something useable + if($context['dropped_data']) + { + list($context['entry']['app'], $context['entry']['id']) = explode('::', $context['dropped_data'][0], 2); + unset($context['dropped_data']); + } if($context['entry']) { $this->title = $context['entry']['title'] = egw_link::title($context['entry']['app'], $context['entry']['id']); } + $this->context = $context; } /** diff --git a/home/inc/class.home_ui.inc.php b/home/inc/class.home_ui.inc.php index c356dac03d..f19d8f6081 100644 --- a/home/inc/class.home_ui.inc.php +++ b/home/inc/class.home_ui.inc.php @@ -58,19 +58,41 @@ class home_ui */ protected function get_actions() { + $portlets = $this->get_portlet_list(); $actions = array( 'add' => array( 'type' => 'popup', 'caption' => 'Add', 'onExecute' => 'javaScript:app.home.add', - 'children' => $this->get_portlet_list() + 'children' => $portlets ), 'drop_create' => array( + 'caption' => 'Add', 'type' => 'drop', - //'acceptedTypes' => 'apps?' - 'onExecute' => 'javaScript:app.home.add' + 'acceptedTypes' => array('file') + array_keys($GLOBALS['egw_info']['apps']), + 'onExecute' => 'javaScript:app.home.add_from_drop', ) ); + + foreach($portlets as $app => $children) + { + // Home portlets + if(!$children['children']) + { + $children['onExecute'] = $actions['drop_create']['onExecute']; + $children['acceptedTypes'] = egw_link::app_list(); + $actions[$app] = $children; + } + else + { + foreach($children as $portlet => $app_portlets) + { + $app_portlets['onExecute'] = $actions['drop_create']['onExecute']; + $app_portlet['acceptedTypes'] = $app; + $actions[$portlet] = $app_portlets; + } + } + } return $actions; } @@ -199,7 +221,6 @@ class home_ui $add_to[$portlet] = array( 'id' => $portlet, - 'type' => 'popup', 'caption' => $desc['displayName'], 'hint' => $desc['description'], 'onExecute' => 'javaScript:app.home.add' @@ -238,6 +259,8 @@ class home_ui } else { +error_log(array2string($attributes)); +error_log(array2string($values)); // Get portlet settings, and merge new with old $content = ''; $portlet = $this->get_portlet(array_merge((array)$attributes, $values), $content, $attributes); diff --git a/home/js/app.js b/home/js/app.js index 1b559c6cd6..ba088751b7 100644 --- a/home/js/app.js +++ b/home/js/app.js @@ -37,41 +37,41 @@ app.home = AppJS.extend( /** * Constructor - * - * @memberOf app.home - */ - init: function() - { - // call parent - this._super.apply(this, arguments); - }, + * + * @memberOf app.home + */ + init: function() + { + // call parent + this._super.apply(this, arguments); + }, - /** - * Destructor - * @memberOf app.home - */ - destroy: function() - { - delete this.et2; + /** + * Destructor + * @memberOf app.home + */ + destroy: function() + { + delete this.et2; delete this.portlet_container; - // call parent - this._super.apply(this, arguments); - }, - - /** - * 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 et2 etemplate2 Newly ready object - */ - et2_ready: function(et2) - { // call parent - this._super.apply(this, arguments); + this._super.apply(this, arguments); + }, - this.et2 = et2.widgetContainer; + /** + * 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 et2 etemplate2 Newly ready object + */ + et2_ready: function(et2) + { + // call parent + this._super.apply(this, arguments); + + this.et2 = et2.widgetContainer; this.portlet_container = this.et2.getWidgetById("portlets"); // Add portlets @@ -90,10 +90,9 @@ app.home = AppJS.extend( }, /** - * Add a new portlet + * Add a new portlet from the context menu */ add: function(action) { - var content = this.et2.getArrayMgr("content").getEntry("portlets"); var attrs = {id: this._create_id(), class: action.id}; var portlet = et2_createWidget('portlet',attrs, this.portlet_container); portlet.loadingFinished(); @@ -108,6 +107,30 @@ app.home = AppJS.extend( ); }, + /** + * User dropped something on home. Add a new portlet + */ + add_from_drop: function(action,source,target_action) { + var attrs = {id: this._create_id(), class: action.id}; + var portlet = et2_createWidget('portlet',attrs, this.portlet_container); + portlet.loadingFinished(); + + // Get actual attributes & settings, since they're not available client side yet + var drop_data = []; + for(var i = 0; i < source.length; i++) + { + if(source[i].id) drop_data.push(source[i].id); + } + portlet._process_edit(et2_dialog.OK_BUTTON, {dropped_data: drop_data}); + + // Set up sorting/grid of new portlet + var $portlet_container = $j(this.portlet_container.getDOMNode()); + $portlet_container.data("gridster").add_widget( + portlet.getDOMNode() + ); + console.log(this,arguments); + }, + /** * For link_portlet - opens the configured record when the user * double-clicks or chooses view from the context menu @@ -130,7 +153,7 @@ app.home = AppJS.extend( egw().log("warning", "Could not find widget"); return; } - egw().open(widget.options.settings.entry, false, 'view'); + egw().open(widget.options.settings.entry, "", 'edit'); }, /** @@ -145,7 +168,6 @@ app.home = AppJS.extend( .shapeshift(); */ /* Gridster */ - .wrap("
") .gridster({ widget_selector: 'div.et2_portlet', widget_base_dimensions: [45, 45],