diff --git a/admin/inc/class.admin_customfields.inc.php b/admin/inc/class.admin_customfields.inc.php index f43600b1f0..6fccc29f80 100644 --- a/admin/inc/class.admin_customfields.inc.php +++ b/admin/inc/class.admin_customfields.inc.php @@ -284,6 +284,21 @@ class admin_customfields $this->tmpl->exec($exec,$content,$sel_options,$readonlys,$preserve); } + /** + * Delete a type over ajax. Used when Policy is involved, otherwise + * things go normally + * + * @param Array $content + */ + public function ajax_delete_type($content) + { + // Read fields + $this->appname = $content['appname']; + $this->fields = Api\Storage\Customfields::get($content['appname'],true); + $this->content_types = Api\Config::get_content_types($content['appname']); + $this->delete_content_type($content); + } + /** * Check selectbox values to match regular expression in et2_widget_selectbox.js: _is_multiple_regexp * @@ -552,8 +567,12 @@ class admin_customfields function delete_content_type(&$content) { + $old = array('types' => $this->content_types); unset($this->content_types[$content['content_types']['types']]); unset($this->status[$content['content_types']['types']]); + $cmd = new admin_cmd_config($this->appname,array('types' => $this->content_types), $old, $content['admin_cmd']); + $cmd->run(); + // save changes to repository $this->save_repository(); } diff --git a/admin/js/app.js b/admin/js/app.js index 50a3b8646d..3e9a977f3b 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -961,6 +961,69 @@ app.classes.admin = AppJS.extend( jQuery(root.getWidgetById('cf_values').getParentDOMNode()).toggle(attributes.cf_values && true); }, + /** + * Change handler for when you delete a custom app type + * If Policy app is available, it asks for documentation + */ + cf_type_delete: function(e, widget) { + var callback = function(button, value) { + if(button === et2_dialog.YES_BUTTON) + { + var values = jQuery.extend( + {}, + this.getInstanceManager().getValues(this.getRoot()), + value, + {appname: this.getRoot().getArrayMgr('content').getEntry('content_types[appname]')} + ); + egw.json('admin.admin_customfields.ajax_delete_type', [values]).sendRequest(); + + // Immediately remove the type + var types = this.getRoot().getWidgetById('types'); + var options = types.options.select_options; + var key; + for(key in options) + { + if(options.hasOwnProperty(key) && key === types.getValue()) + { + delete options[key]; + break; + } + } + types.set_select_options(options); + this.egw().message(''); + + // Trigger load of status for existing type + types.set_value(Object.keys(options)[0]); + } + }.bind(widget); + + if(egw.app('policy')) + { + egw.includeJS(egw.link('/policy/js/app.js'), function() { + if(typeof app.policy === 'undefined' || typeof app.policy.confirm === 'undefined') + { + app.policy = new app.classes.policy(); + } + + var parent = et2_dialog._create_parent(widget.egw()); + var dialog = et2_createWidget("dialog", { + callback: callback, + template: egw.link('/policy/templates/default/admin_cmd_narrow.xet'), + title: egw.lang('Delete'), + buttons: et2_dialog.BUTTONS_YES_NO, + value: {content:{}}, + width: 'auto' + }, parent); + dialog.egw().message("Entries with a deleted type can cause problems.\nCheck for entries with this type before deleting.", 'warning'); + }); + } + else + { + callback(et2_dialog.OK_BUTTON); + } + return false; + }, + /** * Activate none standard SMTP mail accounts for selected users * diff --git a/admin/templates/default/customfields.xet b/admin/templates/default/customfields.xet index 2204ac29ed..819e362802 100644 --- a/admin/templates/default/customfields.xet +++ b/admin/templates/default/customfields.xet @@ -22,7 +22,7 @@ -