Stop using iframe, better list duplicate detection, better support different ways of getting list content (ajax)

This commit is contained in:
Nathan Gray 2013-09-17 22:27:29 +00:00
parent 07b311d495
commit dadf3046c2
3 changed files with 56 additions and 43 deletions

View File

@ -59,25 +59,6 @@ class home_list_portlet extends home_portlet
{
$this->title = $context['title'];
}
// Add a new entry to the list
if($context['add'])
{
$ok_to_add = true;
foreach($context['list'] as $key => $entry)
{
if($entry == $context['add'])
{
$ok_to_add = false;
break;
}
}
if($ok_to_add)
{
$context['list'][] = $context['add'];
}
unset($context['add']);
}
$this->context = $context;
}
@ -120,7 +101,27 @@ class home_list_portlet extends home_portlet
}
// Find the portlet widget, and add a link-list to it
return "<script>app.home.List.set_content('$id', ".json_encode($list).")</script>";
$script = 'app.home.List.set_content("'.$id.'", '.json_encode($list).');';
if(egw_json_response::isJSONResponse())
{
$response = egw_json_response::get();
// This has to go last, after the template is loaded
$response->addBeforeSendDataCallback(
function($response, $script) {
// Bind to load event to make sure template is loaded first
$response->script('$j("#home-index").on("load", function() {'.$script.'});');
// Or just call it, in the event of a normal ajax change - no load event
$response->script("try { $script } catch (e) {egw.debug('error', e.message);}");
}
,$response, $script
);
} else {
// Not a JSON Response? Probably an idots first load
$response = egw_json_response::get();
// Bind to load event to make sure template is loaded first
$response->script('$j("#home-index").on("load", function() {'.$script.'});');
}
return '';
}
/**

View File

@ -303,30 +303,30 @@ app.home = AppJS.extend(
set_content: function(id, list_values)
{
var portlet = app.home.portlet_container.getWidgetById(id);
if(portlet != null)
{
var list = portlet.getWidgetById(id+'-list');
if(list)
{
if(portlet != null)
{
var list = portlet.getWidgetById(id+'-list');
if(list)
{
// List was just rudely pulled from DOM by the call to HTML, put it back
portlet.content.append(list.getDOMNode());
}
else
{
portlet.content.append(list.getDOMNode());
}
else
{
// Create widget
list = et2_createWidget('link-list', {id: id+'-list'}, portlet);
list = et2_createWidget('link-list', {id: id+'-list'}, portlet);
list.doLoadingFinished();
// Abuse link list by overwriting delete handler
list._delete_link = app.home.List.delete_link;
}
list.set_value(list_values);
// Abuse link list by overwriting delete handler
list._delete_link = app.home.List.delete_link;
}
list.set_value(list_values);
// Disable link list context menu
$j('tr',list.list).unbind('contextmenu');
// Disable link list context menu
$j('tr',list.list).unbind('contextmenu');
// Allow scroll bars
portlet.content.css('overflow', 'auto');
}
// Allow scroll bars
portlet.content.css('overflow', 'auto');
}
},
@ -356,10 +356,21 @@ app.home = AppJS.extend(
var link = et2_createWidget('link-entry', {label: egw.lang('Add')}, this.portlet_container);
var dialog = et2_dialog.show_dialog(
function(button_id) {
if(button_id == et2_dialog.CANCEL_BUTTON) return;
var new_list = widget.options.settings.list || [];
new_list.push(link.getValue());
widget._process_edit(button_id,{list: new_list || [],add: link.getValue()});
var add = link.getValue();
link.destroy();
for(var i = 0; i < new_list.length; i++)
{
if(new_list[i].app == add.app && new_list[i].id == add.id)
{
// Duplicate
return;
}
}
new_list.push(add);
widget._process_edit(button_id,{list: new_list});
},
'Add',
egw.lang('Add'), {},

View File

@ -11,9 +11,10 @@
/* Basic information about this app */
$setup_info['home']['name'] = 'home';
$setup_info['home']['title'] = 'Home';
$setup_info['home']['version'] = '1.8';
$setup_info['home']['version'] = '1.9';
$setup_info['home']['app_order'] = 1;
$setup_info['home']['enable'] = 1;
$setup_info['home']['index'] = 'home.home_ui.index&ajax=true';
$setup_info['home']['author'] = 'eGroupWare Core Team';
$setup_info['home']['license'] = 'GPL';
@ -30,5 +31,5 @@ $setup_info['home']['hooks']['showUpdates'] = 'home.updates.showUpdates';
/* Dependencies for this app to work */
$setup_info['home']['depends'][] = array(
'appname' => 'phpgwapi',
'versions' => Array('1.7','1.8','1.9')
'versions' => Array('1.9')
);