Play a little nicer with jdots template & poor implementation of drop

This commit is contained in:
Nathan Gray 2013-05-22 22:44:27 +00:00
parent e8a21565ab
commit d9b9743b81
3 changed files with 90 additions and 39 deletions

View File

@ -30,11 +30,17 @@ class home_link_portlet extends home_portlet
*/ */
public function __construct(Array &$context = array()) 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']) if($context['entry'])
{ {
$this->title = $context['entry']['title'] = egw_link::title($context['entry']['app'], $context['entry']['id']); $this->title = $context['entry']['title'] = egw_link::title($context['entry']['app'], $context['entry']['id']);
} }
$this->context = $context;
} }
/** /**

View File

@ -58,19 +58,41 @@ class home_ui
*/ */
protected function get_actions() protected function get_actions()
{ {
$portlets = $this->get_portlet_list();
$actions = array( $actions = array(
'add' => array( 'add' => array(
'type' => 'popup', 'type' => 'popup',
'caption' => 'Add', 'caption' => 'Add',
'onExecute' => 'javaScript:app.home.add', 'onExecute' => 'javaScript:app.home.add',
'children' => $this->get_portlet_list() 'children' => $portlets
), ),
'drop_create' => array( 'drop_create' => array(
'caption' => 'Add',
'type' => 'drop', 'type' => 'drop',
//'acceptedTypes' => 'apps?' 'acceptedTypes' => array('file') + array_keys($GLOBALS['egw_info']['apps']),
'onExecute' => 'javaScript:app.home.add' '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; return $actions;
} }
@ -199,7 +221,6 @@ class home_ui
$add_to[$portlet] = array( $add_to[$portlet] = array(
'id' => $portlet, 'id' => $portlet,
'type' => 'popup',
'caption' => $desc['displayName'], 'caption' => $desc['displayName'],
'hint' => $desc['description'], 'hint' => $desc['description'],
'onExecute' => 'javaScript:app.home.add' 'onExecute' => 'javaScript:app.home.add'
@ -238,6 +259,8 @@ class home_ui
} }
else else
{ {
error_log(array2string($attributes));
error_log(array2string($values));
// Get portlet settings, and merge new with old // Get portlet settings, and merge new with old
$content = ''; $content = '';
$portlet = $this->get_portlet(array_merge((array)$attributes, $values), $content, $attributes); $portlet = $this->get_portlet(array_merge((array)$attributes, $values), $content, $attributes);

View File

@ -37,41 +37,41 @@ app.home = AppJS.extend(
/** /**
* Constructor * Constructor
* *
* @memberOf app.home * @memberOf app.home
*/ */
init: function() init: function()
{ {
// call parent // call parent
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
/** /**
* Destructor * Destructor
* @memberOf app.home * @memberOf app.home
*/ */
destroy: function() destroy: function()
{ {
delete this.et2; delete this.et2;
delete this.portlet_container; 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 // 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"); this.portlet_container = this.et2.getWidgetById("portlets");
// Add 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) { add: function(action) {
var content = this.et2.getArrayMgr("content").getEntry("portlets");
var attrs = {id: this._create_id(), class: action.id}; var attrs = {id: this._create_id(), class: action.id};
var portlet = et2_createWidget('portlet',attrs, this.portlet_container); var portlet = et2_createWidget('portlet',attrs, this.portlet_container);
portlet.loadingFinished(); 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 * For link_portlet - opens the configured record when the user
* double-clicks or chooses view from the context menu * double-clicks or chooses view from the context menu
@ -130,7 +153,7 @@ app.home = AppJS.extend(
egw().log("warning", "Could not find widget"); egw().log("warning", "Could not find widget");
return; 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(); .shapeshift();
*/ */
/* Gridster */ /* Gridster */
.wrap("<div />")
.gridster({ .gridster({
widget_selector: 'div.et2_portlet', widget_selector: 'div.et2_portlet',
widget_base_dimensions: [45, 45], widget_base_dimensions: [45, 45],