Move check_owner and change_icon functions from global_category.js to app.js in admin. In addition, fix check boxes deselection issue

This commit is contained in:
Hadi Nategh 2014-01-16 16:21:17 +00:00
parent 117a2f5f6b
commit fd7aab0996
3 changed files with 68 additions and 72 deletions

View File

@ -245,4 +245,69 @@ app.classes.admin = AppJS.extend(
{ {
window.egw_refresh(_data.msg, this.appname, _data.ids, _data.type); window.egw_refresh(_data.msg, this.appname, _data.ids, _data.type);
}, },
/**
* Check to see if admin has taken away access to a category
*
* @@param {widget} button add/apply pressed button
*/
check_owner: function(button) {
var select_owner = this.et2.getWidgetById('owner');
if (typeof select_owner != 'undefined')
{
var owner = select_owner.get_value();
}
if(typeof owner != 'object')
{
owner = [owner];
}
// No owner probably means selectbox is read-only, so no need to check
if(owner == null) return true;
var all_users = owner.indexOf('0') >= 0;
// If they checked all users, uncheck the others
if(all_users) {
select_owner.set_value(['0']);
return true;
}
// Find out what changed
var cat_original_owner = this.et2.getArrayMgr('content').getEntry('owner').split(",");
var new_cat_label = jQuery.map(select_owner.options.select_options, function (val, i)
{
for (j=0; j <= cat_original_owner.length;j++)
{
if (cat_original_owner[j] == val.value)
{
return val.label;
}
}
});
// Somebody will lose permission, give warning.
if(new_cat_label)
{
var msg = this.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:');
return et2_dialog.confirm(button,msg + new_cat_label.join(','));
}
return true;
},
/**
* Show icon based on icon-selectbox, hide placeholder (broken image), if no icon selected
*
* @param {widget} widget select box widget
*/
change_icon: function(widget)
{
var img = widget.getRoot().getWidgetById('icon_url');
if (img)
{
img.set_src(widget.getValue());
}
},
}); });

View File

@ -1,69 +0,0 @@
/**
* Javascript for Admin / Global categories
*/
// Record original value
var cat_original_owner;
var permission_prompt;
/**
* Check to see if admin has taken away access to a category
*/
function check_owner(button) {
var select_owner = button.getRoot().getWidgetById('owner')
var owner = select_owner.get_value();
if(typeof owner != 'object')
{
owner = [owner];
}
// No owner probably means selectbox is read-only, so no need to check
if(owner == null) return true;
var all_users = owner.indexOf('0') >= 0;
// If they checked all users, uncheck the others
if(all_users) {
select_owner.set_value(['0']);
return true;
}
// Find out what changed
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++) {
if(owner.indexOf(cat_original_owner[i]) < 0)
{
var checkbox = $j('input[value="'+cat_original_owner[i]+'"]',select_owner.node);
diff.push(cat_original_owner[i]);
labels.push($j(checkbox.get(0).nextSibling).text());
}
}
// Somebody will lose permission, give warning.
if(diff.length > 0) {
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++) {
msg += labels[i];
}
return et2_dialog.confirm(button,msg);
}
return true;
}
/**
* Show icon based on icon-selectbox, hide placeholder (broken image), if no icon selected
*/
function change_icon(widget)
{
var img = widget.getRoot().getWidgetById('icon_url');
if (img)
{
img.set_src(widget.getValue());
}
}

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(widget);" options="None"/> <menupopup id="data[icon]" onchange="app.admin.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,8 +108,8 @@
</row> </row>
<row> <row>
<hbox> <hbox>
<button label="Save" id="button[save]" onclick="return check_owner(widget,form::name('owner'));"/> <button label="Save" id="button[save]" onclick="return app.admin.check_owner(widget);"/>
<button label="Apply" id="button[apply]" onclick="return check_owner(widget,form::name('owner'));"/> <button label="Apply" id="button[apply]" onclick="return app.admin.check_owner(widget);"/>
</hbox> </hbox>
<hbox> <hbox>
<buttononly label="Cancel" id="button[cancel]" onclick="window.close();"/> <buttononly label="Cancel" id="button[cancel]" onclick="window.close();"/>