More changes to get category list working using etemplate2

This commit is contained in:
Nathan Gray 2013-12-10 00:03:36 +00:00
parent 3f531a29c0
commit 7c33488596
4 changed files with 46 additions and 62 deletions

View File

@ -143,6 +143,7 @@ class admin_categories
{ {
case 'save': case 'save':
case 'apply': case 'apply':
if(is_array($content['owner'])) $content['owner'] = implode(',',$content['owner']);
if($content['owner'] == '') $content['owner'] = 0; if($content['owner'] == '') $content['owner'] = 0;
if ($content['id'] && self::$acl_edit) if ($content['id'] && self::$acl_edit)
{ {
@ -160,6 +161,10 @@ class admin_categories
!$content['parent'] && self::$acl_add)) !$content['parent'] && self::$acl_add))
{ {
$content['id'] = $cats->add($content); $content['id'] = $cats->add($content);
if ($button == 'save')
{
egw_framework::window_close();
}
$msg = lang('Category saved.'); $msg = lang('Category saved.');
} }
else else
@ -174,6 +179,9 @@ class admin_categories
{ {
$cats->delete($content['id'],$delete_subs,!$delete_subs); $cats->delete($content['id'],$delete_subs,!$delete_subs);
$msg = lang('Category deleted.'); $msg = lang('Category deleted.');
egw_framework::refresh_opener($msg, $appname, $content['id']);
egw_framework::window_close();
return;
} }
else else
{ {
@ -182,18 +190,7 @@ class admin_categories
} }
break; break;
} }
$link = egw::link('/index.php',array( egw_framework::refresh_opener($msg, $appname, $content['id']);
'menuaction' => $this->list_link,
'appname' => $appname,
'msg' => $msg,
));
$js = "window.opener.location='$link';";
if ($button == 'save' || $button == 'delete')
{
echo "<html><head><script>\n$js;\nwindow.close();\n</script></head></html>\n";
common::egw_exit();
}
if (!empty($js)) $GLOBALS['egw']->js->set_onload($js);
} }
$content['msg'] = $msg; $content['msg'] = $msg;
if(!$content['appname']) $content['appname'] = $appname; if(!$content['appname']) $content['appname'] = $appname;
@ -255,12 +252,7 @@ class admin_categories
} }
egw_framework::validate_file('.','global_categories','admin'); egw_framework::validate_file('.','global_categories','admin');
egw_framework::set_onload('$j(document).ready(function() {
cat_original_owner = [' . ($content['owner'] ? $content['owner'] : ($content['id'] ? '0' : '')) .'];
permission_prompt = \'' . lang('Removing access for groups may cause problems for data in this category. Are you sure? Users in these groups may no longer have access:').'\';
change_icon();
});');
$readonlys['button[delete]'] = !$content['id'] || !self::$acl_delete || // cant delete not yet saved category $readonlys['button[delete]'] = !$content['id'] || !self::$acl_delete || // cant delete not yet saved category
$appname != $content['appname'] || // Can't edit a category from a different app $appname != $content['appname'] || // Can't edit a category from a different app
($this->appname != 'admin' && $content['owner'] != $GLOBALS['egw_info']['user']['account_id']); ($this->appname != 'admin' && $content['owner'] != $GLOBALS['egw_info']['user']['account_id']);

View File

@ -9,45 +9,45 @@ var permission_prompt;
/** /**
* Check to see if admin has taken away access to a category * Check to see if admin has taken away access to a category
*/ */
function check_owner(element_id) { function check_owner(button) {
var checkboxes = $j(':checkbox', document.getElementById(element_id)); var select_owner = button.getRoot().getWidgetById('owner')
var all_users = $j(document.getElementById(element_id + '[0]')); var owner = select_owner.get_value();
if(typeof owner != 'object')
{
owner = [owner];
}
var all_users = owner.indexOf('0') >= 0;
// If they checked all users, uncheck the others // If they checked all users, uncheck the others
if(all_users.length > 0 && all_users.prop("checked")) { if(all_users) {
checkboxes.prop("checked",false); select_owner.set_value(['0']);
all_users.prop("checked", true);
checkboxes = $j(':checkbox', document.getElementById(element_id)).filter(':checked');
return true; return true;
} }
// Find out what changed // Find out what changed
var seen = [], diff = [], labels = []; var seen = [], diff = [], labels = [];
var cat_original_owner = select_owner.getArrayMgr('content').getEntry('owner');
if(typeof cat_original_owner != "object")
{
cat_original_owner = [cat_original_owner];
}
for ( var i = 0; i < cat_original_owner.length; i++) { for ( var i = 0; i < cat_original_owner.length; i++) {
var checkbox = checkboxes.filter('[value="'+cat_original_owner[i]+'"]'); if(owner.indexOf(cat_original_owner[i]) < 0)
if(checkbox.filter(':checked').length == 0 && checkbox.get(0) != undefined) { {
var checkbox = $j('input[value="'+cat_original_owner[i]+'"]',select_owner.node);
diff.push(cat_original_owner[i]); diff.push(cat_original_owner[i]);
labels.push($j(checkbox.get(0).nextSibling).text()); labels.push($j(checkbox.get(0).nextSibling).text());
} }
} }
// Single selection?
if(checkboxes.length == 0) {
var new_group = $j('input#'+element_id);
if(new_group.length > 0 && new_group.attr('value') != 0 && cat_original_owner.length > 0) {
diff.push(cat_original_owner[0]);
var selector = 'option[value="'+cat_original_owner[0]+'"]';
labels.push("\n"+$j(selector, new_group).text());
}
}
// Somebody will lose permission, give warning. // Somebody will lose permission, give warning.
if(diff.length > 0) { if(diff.length > 0) {
var msg = permission_prompt; var msg = egw.lang('Removing access for groups may cause problems for data in this category. Are you sure? Users in these groups may no longer have access:');
for( var i = 0; i < labels.length; i++) { for( var i = 0; i < labels.length; i++) {
msg += labels[i]; msg += labels[i];
} }
return confirm(msg); return et2_dialog.confirm(button,msg);
} }
return true; return true;
} }
@ -55,21 +55,12 @@ function check_owner(element_id) {
/** /**
* Show icon based on icon-selectbox, hide placeholder (broken image), if no icon selected * Show icon based on icon-selectbox, hide placeholder (broken image), if no icon selected
*/ */
function change_icon(_icon) function change_icon(widget)
{ {
var img = document.getElementById('exec[icon_url]') || document.getElementById('icon_url'); var img = widget.getRoot().getWidgetById('icon_url');
if (typeof _icon == 'undefined') if (img)
{ {
_icon = document.getElementById('exec[data][icon]') || document.getElementById('data[icon]'); img.set_src(widget.getValue());
}
if (_icon && _icon.value)
{
img.src = img.src.replace(/\/[^\/]*$/,'\/'+_icon.value);
img.style.display = 'block';
}
else if (img)
{
img.style.display = 'none';
} }
} }

View File

@ -87,7 +87,7 @@
<description value="Icon" for="data[icon]"/> <description value="Icon" for="data[icon]"/>
<hbox options="0,0"> <hbox options="0,0">
<menulist> <menulist>
<menupopup id="data[icon]" onchange="change_icon(this);" options="None"/> <menupopup id="data[icon]" onchange="change_icon(widget);" options="None"/>
</menulist> </menulist>
<image src="icon_url" id="icon_url" class="leftPad5"/> <image src="icon_url" id="icon_url" class="leftPad5"/>
</hbox> </hbox>
@ -108,12 +108,12 @@
</row> </row>
<row> <row>
<hbox> <hbox>
<button label="Save" id="button[save]" onclick="return check_owner(form::name('owner'));"/> <button label="Save" id="button[save]" onclick="return check_owner(widget,form::name('owner'));"/>
<button label="Apply" id="button[apply]" onclick="return check_owner(form::name('owner'));"/> <button label="Apply" id="button[apply]" onclick="return check_owner(widget,form::name('owner'));"/>
</hbox> </hbox>
<hbox> <hbox>
<buttononly label="Cancel" id="button[cancel]" onclick="window.close();"/> <buttononly label="Cancel" id="button[cancel]" onclick="window.close();"/>
<buttononly align="right" statustext="Delete this category" label="Delete" id="button[delete]" onclick="set_style_by_class('tr','confirmSubs','visibility','$cont[children]'?'visible':'collapse'); set_style_by_class('fieldset','confirmDelete','display','block');"/> <buttononly align="right" statustext="Delete this category" label="Delete" id="button[delete]" onclick="et2_dialog.confirm(widget,'Are you sure you want to delete this category ?'); return false;"/>
</hbox> </hbox>
</row> </row>
</rows> </rows>

View File

@ -1,6 +1,11 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- $Id$ --> <!-- $Id$ -->
<overlay> <overlay>
<template id="admin.categories.index.right" template="" lang="" group="0" version="1.9.001">
<hbox>
<buttononly align="right" label="Add" id="add" onclick="window.open(egw::link('/index.php','menuaction=$cont[add_link]&amp;cat_id=&amp;appname=$cont[nm][appname]'),'_blank','dependent=yes,width=600,height=380,scrollbars=yes,status=yes'); return false;"/>
</hbox>
</template>
<template id="admin.categories.index.rows" template="" lang="" group="0" version="1.9.002"> <template id="admin.categories.index.rows" template="" lang="" group="0" version="1.9.002">
<grid width="100%"> <grid width="100%">
<columns> <columns>
@ -66,14 +71,10 @@
<description/> <description/>
</row> </row>
<row> <row>
<nextmatch id="nm" options="admin.categories.index.rows" span="all"/> <description/>
</row> </row>
<row> <row>
<buttononly label="Add" id="add" onclick="window.open(egw::link('/index.php','menuaction=$cont[add_link]&amp;cat_id=&amp;appname=$cont[nm][appname]'),'_blank','dependent=yes,width=600,height=380,scrollbars=yes,status=yes'); return false;"/> <nextmatch id="nm" options="admin.categories.index.rows" span="all" header_right="admin.categories.index.right"/>
<hbox align="right" span="all">
<buttononly statustext="Select action" label="Select action" id="legacy_actions" onclick="if (!egw_globalObjectManager.getObjectById('admin.categories.index.rows').executeActionImplementation(this, 'popup')) alert(egw::lang('You need to select some entries first!')); return false;;"/>
<button statustext="Check all" label="Check all" id="check_all" needed="1" onclick="egw_globalObjectManager.getObjectById('admin.categories.index.rows').toggleAllSelected(); return false;" image="arrow_ltr" class="checkAllArrow"/>
</hbox>
</row> </row>
</rows> </rows>
</grid> </grid>