4 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
5 * @author Cornelius Weiss <c.weiss@metaways.de>
6 * @copyright Copyright (c) 2007-2013 Metaways Infosystems GmbH (http://www.metaways.de)
8 Ext.ns('Tine.widgets.dialog');
11 * Generic 'Edit Record' dialog
12 * Base class for all 'Edit Record' dialogs
14 * @namespace Tine.widgets.dialog
15 * @class Tine.widgets.dialog.EditDialog
16 * @extends Ext.FormPanel
17 * @author Cornelius Weiss <c.weiss@metaways.de>
19 * @param {Object} config The configuration options.
22 Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
24 * @cfg {Tine.Tinebase.Application} app
25 * instance of the app object (required)
30 * Set to 'local' if the EditDialog only operates on this.record (defaults to 'remote' which loads and saves using the recordProxy)
34 * @cfg {Array} tbarItems
35 * additional toolbar items (defaults to false)
39 * internal/untranslated app name (required)
41 * @cfg {String} appName
45 * the modelName (filled by application starter)
47 * @type {String} modelName
52 * record definition class (required if no modelconfig! don't declare for modelconfig!!)
54 * @cfg {Ext.data.Record} recordClass
58 * @cfg {Ext.data.DataProxy} recordProxy
62 * @cfg {Bool} showContainerSelector
63 * show container selector in bottom area
65 showContainerSelector: null,
67 * @cfg {Bool} evalGrants
68 * should grants of a grant-aware records be evaluated (defaults to true)
72 * @cfg {String} requiredSaveGrant
73 * required grant for apply/save
75 requiredSaveGrant: 'editGrant',
78 * @cfg {Ext.data.Record} record
79 * record in edit process.
84 * holds the modelConfig for the handled record (json-encoded object)
85 * will be decoded in initComponent
92 * @cfg {String} saveAndCloseButtonText
93 * text of save and close button
95 saveAndCloseButtonText: '',
97 * @cfg {String} cancelButtonText
98 * text of cancel button
100 cancelButtonText: '',
103 * @cfg {Boolean} copyRecord
109 * @cfg {Boolean} doDuplicateCheck
110 * do duplicate check when saving record (mode remote only)
112 doDuplicateCheck: true,
115 * when a record has the relations-property the relations-panel can be disabled here
116 * @cfg {Boolean} hideRelationsPanel
118 hideRelationsPanel: false,
121 * when a record has the attachments-property the attachments-panel can be disabled here
122 * @cfg {Boolean} hideAttachmentsPanel
124 hideAttachmentsPanel: false,
127 * Registry for other relationgridpanels than the generic one,
128 * handling special types of relations the generic one will not.
129 * Panels registered here must have a store with the relation records.
133 relationPanelRegistry: null,
136 * ignore relations to given php-class names in the relation grid
139 ignoreRelatedModels: null,
142 * dialog is currently saving data
148 * Disable adding cf tab even if model has support for customfields
154 * @property window {Ext.Window|Ext.ux.PopupWindow|Ext.Air.Window}
157 * @property {Number} loadRequest
158 * transaction id of loadData request
161 * @property loadMask {Ext.LoadMask}
165 * @property containerSelectCombo {Tine.widgets.container.SelectionComboBox}
167 containerSelectCombo: null,
170 * If set, these fields are readOnly (when called dependent to related record)
172 * @type {Ext.util.MixedCollection}
177 * Plain Object with additional configuration (JSON-encoded)
181 additionalConfig: null,
185 * @cfg {String} canonicalName
187 canonicalName: 'EditDialog',
190 bodyStyle:'padding:5px',
193 cls: 'tw-editdialog',
195 deferredRender: false,
202 * @type Tine.widgets.relation.GenericPickerGridPanel
204 relationsPanel: null,
206 // Array of Relation Pickers
207 relationPickers: null,
212 * @type Tine.widgets.dialog.AttachmentsGridPanel
214 attachmentsPanel: null,
218 * set this to false, if no loadMask should be shown
220 * @type {Ext.LoadMask}
225 * hook notes panel into dialog
232 initComponent: function() {
233 this.relationPanelRegistry = this.relationPanelRegistry ? this.relationPanelRegistry : [];
237 * Fired when user pressed cancel button
241 * @event saveAndClose
242 * Fired when user pressed OK button
247 * @desc Fired when the record got updated
248 * @param {Json String} data data of the entry
249 * @pram {String} this.mode
254 * Fired when user pressed apply button
259 * @param {Tine.widgets.dialog.EditDialog} this
260 * @param {Tine.data.Record} record which got loaded
261 * @param {Function} ticket function for async defer
262 * Fired when record is loaded
267 * @param {Tine.widgets.dialog.EditDialog} this
268 * @param {Tine.data.Record} record which got loaded
269 * @param {Function} ticket function for async defer
270 * Fired when remote record is saving
274 * @event updateDependent
275 * Fired when a subpanel updates the record locally
280 * Fires just before the field blurs if the field value has changed.
281 * @param {Ext.form.Field} this
282 * @param {Mixed} newValue The new value
283 * @param {Mixed} oldValue The original value
288 if (Ext.isString(this.modelConfig)) {
289 this.modelConfig = Ext.decode(this.modelConfig);
292 if (Ext.isString(this.additionalConfig)) {
293 Ext.apply(this, Ext.decode(this.additionalConfig));
296 if (Ext.isString(this.fixedFields)) {
297 var decoded = Ext.decode(this.fixedFields);
298 this.fixedFields = new Ext.util.MixedCollection();
299 this.fixedFields.addAll(decoded);
302 if (! this.recordClass && this.modelName) {
303 this.recordClass = Tine[this.appName].Model[this.modelName];
306 if (this.recordClass) {
307 this.appName = this.appName ? this.appName : this.recordClass.getMeta('appName');
308 this.modelName = this.modelName ? this.modelName : this.recordClass.getMeta('modelName');
312 this.app = Tine.Tinebase.appMgr.get(this.appName);
315 if (! this.windowNamePrefix) {
316 this.windowNamePrefix = this.modelName + 'EditWindow_';
319 Tine.log.debug('initComponent: appName: ', this.appName);
320 Tine.log.debug('initComponent: modelName: ', this.modelName);
321 Tine.log.debug('initComponent: app: ', this.app);
323 // init some translations
324 if (this.app.i18n && this.recordClass !== null) {
325 this.i18nRecordName = this.app.i18n.n_hidden(this.recordClass.getMeta('recordName'), this.recordClass.getMeta('recordsName'), 1);
326 this.i18nRecordsName = this.app.i18n._hidden(this.recordClass.getMeta('recordsName'));
329 if (! this.recordProxy && this.recordClass) {
330 Tine.log.debug('no record proxy given, creating a new one...');
331 this.recordProxy = new Tine.Tinebase.data.RecordProxy({
332 recordClass: this.recordClass
336 var grantsField = this.recordClass.getMeta('grantsPath')
337 .replace(/^data\./, '')
338 .replace(/\.+/g, '');
340 this.evalGrants = this.evalGrants && (grantsField == 'data' || this.recordClass.hasField(grantsField));
343 this.plugins = Ext.isString(this.plugins) ? Ext.decode(this.plugins) : Ext.isArray(this.plugins) ? this.plugins.concat(Ext.decode(this.initialConfig.plugins)) : [];
345 this.plugins.push(this.tokenModePlugin = new Tine.widgets.dialog.TokenModeEditDialogPlugin({}));
346 // added possibility to disable using customfield plugin
347 if (this.disableCfs !== true) {
348 this.plugins.push(new Tine.widgets.customfields.EditDialogPlugin({}));
353 // init buttons and tbar
355 // init container selector
356 this.initContainerSelector();
359 // get items for this dialog
360 this.items = this.getFormItems();
362 // init relations panel if relations are defined
363 this.initRelationsPanel();
364 // init attachments panel
365 this.initAttachmentsPanel();
367 this.initNotesPanel();
369 Tine.widgets.dialog.EditDialog.superclass.initComponent.call(this);
371 // set fields readOnly if set
374 // firefox fix: blur each item before tab changes, so no field will be focused afterwards
376 this.items.items[0].addListener('beforetabchange', function(tabpanel, newtab, oldtab) {
380 var form = this.getForm();
382 if (form && form.hasOwnProperty('items'))
383 form.items.each(function(item, index) {
389 if (Ext.isFunction(this.window.relayEvents) && Tine.Tinebase.featureEnabled('featureRememberPopupSize')) {
390 this.window.relayEvents(this, ['resize']);
395 * returns canonical path part
398 getCanonicalPathSegment: function () {
399 if (this.recordClass) {
401 this.recordClass.getMeta('appName'),
403 this.recordClass.getMeta('modelName'),
404 ].join(Tine.Tinebase.CanonicalPath.separator);
409 * generic form layout
411 getFormItems: function() {
422 ptype : 'ux.tabpanelkeyplugin'
426 title: this.i18nRecordName,
431 defaults: { autoScroll: true },
432 items: [Ext.applyIf(this.getRecordFormItems(), {
442 })].concat(this.getEastPanel())
443 }, new Tine.widgets.activities.ActivitiesTabPanel({
445 record_id: this.record.id,
446 record_model: this.modelName
452 getEastPanel: function() {
454 if (this.recordClass.hasField('description')) {
455 items.push(new Ext.Panel({
456 title: i18n._('Description'),
457 iconCls: 'descriptionIcon',
462 style: 'margin-top: -4px; border 0px;',
468 preventScrollbars: false,
470 emptyText: i18n._('Enter description'),
471 requiredGrant: 'editGrant'
476 if (this.recordClass.hasField('tags')) {
477 items.push(new Tine.widgets.tags.TagPanel({
480 bodyStyle: 'border:1px solid #B5B8C8;'
484 return items.length ? {
491 collapseMode: 'mini',
499 getRecordFormItems: function() {
500 return new Tine.widgets.form.RecordForm({
501 recordClass: this.recordClass
506 * fix fields (used for preselecting form fields when called in dependency to another record)
509 fixFields: function() {
510 if (this.fixedFields && this.fixedFields.getCount() > 0) {
511 if (! this.rendered) {
512 this.fixFields.defer(100, this);
516 this.fixedFields.each(function(value, index) {
517 var key = this.fixedFields.keys[index];
519 var field = this.getForm().findField(key);
522 if (Ext.isFunction(this.recordClass.getField(key).type)) {
523 var foreignRecordClass = this.recordClass.getField(key).type;
524 var record = new foreignRecordClass(value);
525 field.selectedRecord = record;
526 field.setValue(value);
527 field.fireEvent('select');
529 field.setValue(value);
538 * call checkState for every field
540 checkStates: function() {
541 this.onRecordUpdate();
542 this.getForm().items.each(function (item) {
543 if (Ext.isFunction(item.checkState)) {
544 item.checkState(this, this.record);
550 * Get available model for given application
552 * @param {Mixed} application
553 * @param {Boolean} customFieldModel
555 getApplicationModels: function (application, customFieldModel) {
558 appName = Ext.isString(application) ? application : application.get('name'),
559 app = Tine.Tinebase.appMgr.get(appName),
560 trans = app && app.i18n ? app.i18n : i18n,
561 appModels = Tine[appName].Model;
564 for (var model in appModels) {
565 if (appModels.hasOwnProperty(model) && typeof appModels[model].getMeta === 'function') {
566 if (customFieldModel && appModels[model].getField('customfields')) {
567 useModel = appModels[model].getMeta('appName') + '_Model_' + appModels[model].getMeta('modelName');
569 Tine.log.info('Found model with customfields property: ' + useModel);
570 models.push([useModel, trans.n_(appModels[model].getMeta('recordName'), appModels[model].getMeta('recordsName'), 1)]);
571 } else if (! customFieldModel) {
572 useModel = 'Tine.' + appModels[model].getMeta('appName') + '.Model.' + appModels[model].getMeta('modelName');
574 Tine.log.info('Found model: ' + useModel);
575 models.push([useModel, trans.n_(appModels[model].getMeta('recordName'), appModels[model].getMeta('recordsName'), 1)]);
586 initActions: function() {
587 this.action_saveAndClose = new Ext.Action({
588 requiredGrant: this.requiredSaveGrant,
589 text: (this.saveAndCloseButtonText != '') ? this.app.i18n._(this.saveAndCloseButtonText) : i18n._('Ok'),
591 ref: '../btnSaveAndClose',
593 // TODO: remove the defer when all subpanels use the deferByTicket mechanism
594 handler: function() { this.onSaveAndClose.defer(500, this); },
595 iconCls: 'action_saveAndClose'
598 this.action_applyChanges = new Ext.Action({
599 requiredGrant: this.requiredSaveGrant,
600 text: i18n._('Apply'),
602 ref: '../btnApplyChanges',
604 handler: this.onApplyChanges,
605 iconCls: 'action_applyChanges'
608 this.action_cancel = new Ext.Action({
609 text: (this.cancelButtonText != '') ? this.app.i18n._(this.cancelButtonText) : i18n._('Cancel'),
612 handler: this.onCancel,
613 iconCls: 'action_cancel'
616 this.action_delete = new Ext.Action({
617 requiredGrant: 'deleteGrant',
618 text: i18n._('delete'),
621 handler: this.onDelete,
622 iconCls: 'action_delete',
626 this.action_export = Tine.widgets.exportAction.getExportButton(this.recordClass, {
627 getExportOptions: this.getExportOptions.createDelegate(this)
628 }, Tine.widgets.exportAction.SCOPE_SINGLE);
631 this.actionUpdater = new Tine.widgets.ActionUpdater({
632 recordClass: this.recordClass,
633 evalGrants: this.evalGrants
636 this.actionUpdater.addActions([
637 this.action_saveAndClose,
638 this.action_applyChanges,
645 * get export options/data
647 getExportOptions: function() {
648 this.onRecordUpdate();
650 recordData: this.record.data
657 * use button order from preference
659 initButtons: function () {
664 this.fbar.push(this.action_cancel, this.action_saveAndClose);
666 if (this.action_export) {
667 this.actionUpdater.addAction(this.action_export);
668 this.tbarItems = this.tbarItems || [];
669 this.tbarItems.push(this.action_export);
672 if (this.tbarItems && this.tbarItems.length) {
673 this.actionUpdater.addActions(this.tbarItems);
674 this.tbar = new Ext.Toolbar({
675 items: this.tbarItems
681 * init container selector
683 initContainerSelector: function() {
684 if (this.showContainerSelector) {
685 this.containerSelectCombo = new Tine.widgets.container.SelectionComboBox({
686 id: this.app.appName + 'EditDialogContainerSelector-' + Ext.id(),
687 fieldLabel: i18n._('Saved in'),
690 name: this.recordClass.getMeta('containerProperty'),
691 recordClass: this.recordClass,
692 containerName: this.app.i18n.n_hidden(this.recordClass.getMeta('containerName'), this.recordClass.getMeta('containersName'), 1),
693 containersName: this.app.i18n._hidden(this.recordClass.getMeta('containersName')),
694 appName: this.app.appName,
695 requiredGrant: this.evalGrants ? 'addGrant' : false,
696 disabled: this.isContainerSelectorDisabled(),
700 // enable or disable save button dependent to containers account grants
701 // on edit: check editGrant, on add: check addGrant
702 var grants = this.containerSelectCombo.selectedContainer
703 ? this.containerSelectCombo.selectedContainer.account_grants : {},
704 grantToCheck = (this.record.data.id) ? 'editGrant' : 'addGrant',
705 enabled = grants.hasOwnProperty(grantToCheck) && grants[grantToCheck]
706 || grants.hasOwnProperty('adminGrant') && grants.adminGrant ? true : false;
708 this.action_saveAndClose.setDisabled(! enabled);
712 this.on('render', function() { this.getForm().add(this.containerSelectCombo); }, this);
716 this.containerSelectCombo
723 * checks if the container selector should be disabled (dependent on account grants of the container itself)
726 isContainerSelectorDisabled: function() {
728 var cp = this.recordClass.getMeta('containerProperty'),
729 container = this.record.data[cp],
730 grants = (container && container.hasOwnProperty('account_grants')) ? container.account_grants : null,
733 // check grants if record already exists and grants should be evaluated
734 if(this.evalGrants && this.record.data.id && grants) {
735 cond = ! (grants.hasOwnProperty('editGrant') && grants.editGrant);
745 * init record to edit
747 initRecord: function() {
748 Tine.log.debug('init record with mode: ' + this.mode);
750 Tine.log.debug('creating new default data record');
751 this.record = new this.recordClass(this.recordClass.getDefaultData(), 0);
754 if (this.mode !== 'local') {
755 if (this.record && this.record.id) {
756 this.loadRemoteRecord();
758 this.onRecordLoad.defer(10, this);
761 // note: in local mode we expect a valid record
762 if (! Ext.isFunction(this.record.beginEdit)) {
763 this.record = this.recordProxy.recordReader({responseText: this.record});
765 this.onRecordLoad.defer(10, this);
770 * load record via record proxy
772 loadRemoteRecord: function() {
773 Tine.log.info('initiating record load via proxy');
774 this.loadRequest = this.recordProxy.loadRecord(this.record, {
776 success: function(record) {
777 this.record = record;
784 * copy this.record record
786 doCopyRecord: function() {
787 this.record = this.doCopyRecordToReturn(this.record);
791 * Copy record and returns "new record with same settings"
795 doCopyRecordToReturn: function(record) {
796 var omitFields = this.recordClass.getMeta('copyOmitFields') || [];
797 // always omit id + notes + attachments
798 omitFields = omitFields.concat(['id', 'notes', 'attachments', 'relations']);
800 var fieldsToCopy = this.recordClass.getFieldNames().diff(omitFields),
801 recordData = Ext.copyTo({}, record.data, fieldsToCopy);
803 var resetProperties = {
804 alarms: ['id', 'record_id', 'sent_time', 'sent_message'],
805 relations: ['id', 'own_id', 'created_by', 'creation_time', 'last_modified_by', 'last_modified_time']
808 var setProperties = {alarms: {sent_status: 'pending'}};
810 Ext.iterate(resetProperties, function(property, properties) {
811 if (recordData.hasOwnProperty(property)) {
812 var r = recordData[property];
813 for (var index = 0; index < r.length; index++) {
816 r[index][prop] = null;
823 Ext.iterate(setProperties, function(property, properties) {
824 if (recordData.hasOwnProperty(property)) {
825 var r = recordData[property];
826 for (var index = 0; index < r.length; index++) {
827 Ext.iterate(properties,
828 function(prop, value) {
829 r[index][prop] = value;
836 return new this.recordClass(recordData, 0);
841 * executed after record got updated from proxy
843 onRecordLoad: function() {
844 // interrupt process flow until dialog is rendered
845 if (! this.rendered) {
846 this.onRecordLoad.defer(250, this);
849 Tine.log.debug('Tine.widgets.dialog.EditDialog::onRecordLoad() - Loading of the following record completed:');
850 Tine.log.debug(this.record);
852 if (this.copyRecord) {
854 this.window.setTitle(String.format(i18n._('Copy {0}'), this.i18nRecordName));
856 if (! this.record.id) {
857 this.window.setTitle(String.format(i18n._('Add New {0}'), this.i18nRecordName));
859 this.window.setTitle(String.format(i18n._('Edit {0} "{1}"'), this.i18nRecordName, this.record.getTitle()));
863 var ticketFn = this.onAfterRecordLoad.deferByTickets(this),
864 wrapTicket = ticketFn();
866 this.fireEvent('load', this, this.record, ticketFn);
870 // finally load the record into the form
871 onAfterRecordLoad: function() {
872 var _ = window.lodash,
873 form = this.getForm();
876 form.loadRecord(this.record);
880 if (this.record && this.record.hasOwnProperty('data') && Ext.isObject(this.record.data[this.recordClass.getMeta('containerProperty')])) {
881 this.updateToolbars(this.record, this.recordClass.getMeta('containerProperty'));
884 // add current timestamp as id, if this is a dependent record
885 if (this.modelConfig && this.modelConfig.isDependent == true && this.record.id == 0) {
886 this.record.set('id', (new Date()).getTime());
889 // apply grants to fields with requiredGrant prop
890 if (this.evalGrants) {
891 this.getForm().items.each(function (f) {
892 if (f.isFormField && f.requiredGrant !== undefined) {
893 var hasRequiredGrant = _.get(this.record, this.recordClass.getMeta('grantsPath') + '.' + f.requiredGrant);
894 f.setDisabled(!hasRequiredGrant);
899 this.checkStates.defer(100, this);
901 if (this.loadMask && !this.saving) {
902 this.loadMask.hide();
907 * executed when record gets updated from form
909 onRecordUpdate: function(callback, scope) {
910 var form = this.getForm();
912 // merge changes from form into record
913 form.updateRecord(this.record);
915 //TODO Use Promises instead of Tickets if async is needed
916 this.fireEvent('recordUpdate', this, this.record);
922 onRender : function(ct, position){
923 Tine.widgets.dialog.EditDialog.superclass.onRender.call(this, ct, position);
925 // generalized keybord map for edit dlgs
926 new Ext.KeyMap(this.el, [
928 key: [10,13], // ctrl + return
932 if (this.getForm().hasOwnProperty('items')) {
933 // force set last selected field
934 this.getForm().items.each(function(item) {
936 item.setValue(item.getRawValue());
940 this.action_saveAndClose.execute();
945 if (this.loadMask !== false && this.i18nRecordName) {
946 this.loadMask = new Ext.LoadMask(ct, {msg: String.format(i18n._('Transferring {0}...'), this.i18nRecordName)});
947 this.loadMask.show();
951 var form = this.getForm().items.each(function(item) {
952 this.relayEvents(item, ['change', 'select']);
954 this.on('change', this.checkStates, this, {buffer: 100});
955 this.on('select', this.checkStates, this, {buffer: 100});
959 * update (action updateer) top and bottom toolbars
961 updateToolbars: function(record, containerField) {
962 if (! this.evalGrants) {
967 this.action_saveAndClose,
968 this.action_applyChanges,
972 this.actionUpdater.updateActions(record);
978 getToolbar: function() {
979 return this.getTopToolbar();
987 isValid: function() {
989 return new Promise(function (fulfill, reject) {
990 if (me.getForm().isValid()) {
993 reject(me.getValidationErrorMessage())
999 * vaidates on multiple edit
1003 isMultipleValid: function() {
1010 onCancel : function(){
1011 this.fireEvent('cancel');
1012 this.purgeListeners();
1013 this.window.close();
1019 onSaveAndClose: function() {
1020 this.fireEvent('saveAndClose');
1021 this.onApplyChanges(true);
1025 * generic apply changes handler
1026 * @param {Boolean} closeWindow
1028 onApplyChanges: function(closeWindow) {
1034 this.loadMask.show();
1036 var ticketFn = this.doApplyChanges.deferByTickets(this, [closeWindow]),
1037 wrapTicket = ticketFn();
1039 this.fireEvent('save', this, this.record, ticketFn);
1044 * is called from onApplyChanges
1045 * @param {Boolean} closeWindow
1047 doApplyChanges: function(closeWindow) {
1048 // we need to sync record before validating to let (sub) panels have
1049 // current data of other panels
1050 this.onRecordUpdate();
1053 this.copyRecord = false;
1055 var isValid = this.isValid(),
1059 if (Ext.isDefined(isValid) && ! Ext.isFunction(isValid.then)) {
1060 // convert legacy isValid into promise
1061 isValid = new Promise(function (fulfill, reject) {;
1062 return vBool ? fulfill(true) : reject(me.getValidationErrorMessage());
1066 isValid.then(function () {
1067 if (me.mode !== 'local') {
1068 me.recordProxy.saveRecord(me.record, {
1070 success: function (record) {
1071 // override record with returned data
1073 if (!Ext.isFunction(me.window.cascade)) {
1074 // update form with this new data
1075 // NOTE: We update the form also when window should be closed,
1076 // cause sometimes security restrictions might prevent
1077 // closing of native windows
1080 var ticketFn = me.onAfterApplyChanges.deferByTickets(me, [closeWindow]),
1081 wrapTicket = ticketFn();
1083 me.fireEvent('update', Ext.util.JSON.encode(me.record.data), me.mode, me, ticketFn);
1086 failure: me.onRequestFailed,
1087 timeout: 300000 // 5 minutes
1088 }, me.getAdditionalSaveParams(me));
1091 var ticketFn = me.onAfterApplyChanges.deferByTickets(me, [closeWindow]),
1092 wrapTicket = ticketFn();
1094 me.fireEvent('update', Ext.util.JSON.encode(me.record.data), me.mode, me, ticketFn);
1097 }, function (message) {
1100 Ext.MessageBox.alert(i18n._('Errors'), message);
1105 * returns additional save params
1107 * @param {EditDialog} me
1108 * @returns {{duplicateCheck: boolean}}
1110 getAdditionalSaveParams: function(me) {
1112 duplicateCheck: me.doDuplicateCheck
1116 onAfterApplyChanges: function(closeWindow) {
1117 this.window.rename(this.windowNamePrefix + this.record.id);
1118 this.saving = false;
1121 this.window.fireEvent('saveAndClose');
1122 this.purgeListeners();
1123 this.window.close();
1125 this.loadMask.hide();
1130 * get validation error message
1134 getValidationErrorMessage: function() {
1135 return i18n._('Please fix the errors noted.');
1139 * generic delete handler
1141 onDelete: function(btn, e) {
1142 Ext.MessageBox.confirm(i18n._('Confirm'), String.format(i18n._('Do you really want to delete this {0}?'), this.i18nRecordName), function(_button) {
1144 var deleteMask = new Ext.LoadMask(this.getEl(), {msg: String.format(i18n._('Deleting {0}'), this.i18nRecordName)});
1147 this.recordProxy.deleteRecords(this.record, {
1149 success: function() {
1150 this.purgeListeners();
1151 this.window.close();
1153 failure: function () {
1154 Ext.MessageBox.alert(i18n._('Failed'), String.format(i18n._('Could not delete {0}.'), this.i18nRecordName));
1155 Ext.MessageBox.hide();
1163 * duplicate(s) found exception handler
1165 * @param {Object} exception
1167 onDuplicateException: function(exception) {
1168 var resolveGridPanel = new Tine.widgets.dialog.DuplicateResolveGridPanel({
1170 store: new Tine.widgets.dialog.DuplicateResolveStore({
1172 recordClass: this.recordClass,
1173 recordProxy: this.recordProxy,
1175 clientRecord: exception.clientRecord,
1176 duplicates: exception.duplicates
1182 this.action_saveAndClose
1186 // intercept save handler
1187 resolveGridPanel.btnSaveAndClose.setHandler(function(btn, e) {
1188 var resolveStrategy = resolveGridPanel.store.resolveStrategy;
1190 // action discard -> close window
1191 if (resolveStrategy == 'discard') {
1192 return this.onCancel();
1195 this.record = resolveGridPanel.store.getResolvedRecord();
1197 // quit copy mode before populating form with resolved data
1198 this.copyRecord = false;
1199 this.onRecordLoad();
1201 mainCardPanel.layout.setActiveItem(this.id);
1202 resolveGridPanel.doLayout();
1204 this.doDuplicateCheck = false;
1205 this.onSaveAndClose();
1208 // place in viewport
1209 this.window.setTitle(String.format(i18n._('Resolve Duplicate {0} Suspicion'), this.i18nRecordName));
1210 var mainCardPanel = this.findParentBy(function(p) {return p.isWindowMainCardPanel });
1211 mainCardPanel.add(resolveGridPanel);
1212 mainCardPanel.layout.setActiveItem(resolveGridPanel.id);
1213 resolveGridPanel.doLayout();
1217 * generic request exception handler
1219 * @param {Object} exception
1221 onRequestFailed: function(exception) {
1222 this.saving = false;
1224 if (this.exceptionHandlingMap && this.exceptionHandlingMap[exception.code] && typeof this.exceptionHandlingMap[exception.code] === 'function') {
1225 this.exceptionHandlingMap[exception.code](exception);
1227 } else if (exception.code == 629) {
1228 this.onDuplicateException.apply(this, arguments);
1231 Tine.Tinebase.ExceptionHandler.handleRequestException(exception);
1234 this.loadMask.hide();
1238 * creates the relations panel, if relations are defined
1240 initRelationsPanel: function() {
1241 if (! this.hideRelationsPanel && this.recordClass && this.recordClass.hasField('relations')) {
1242 // init relations panel before onRecordLoad
1243 if (! this.relationsPanel) {
1244 this.relationsPanel = new Tine.widgets.relation.GenericPickerGridPanel({ anchor: '100% 100%', editDialog: this });
1246 // interrupt process flow until dialog is rendered
1247 if (! this.rendered) {
1248 this.initRelationsPanel.defer(250, this);
1251 // add relations panel if this is rendered
1252 if (this.items.items[0]) {
1253 this.items.items[0].add(this.relationsPanel);
1256 Tine.log.debug('Tine.widgets.dialog.EditDialog::initRelationsPanel() - Initialized relations panel and added to dialog tab items.');
1261 * create notes panel
1263 initNotesPanel: function() {
1264 // This dialog is pretty generic but for some cases it's used in a differend way
1265 if(this.displayNotes == true) {
1266 this.items.items.push(new Tine.widgets.activities.ActivitiesGridPanel({
1267 anchor: '100% 100%',
1274 * creates attachments panel
1276 initAttachmentsPanel: function() {
1277 if (! this.attachmentsPanel && ! this.hideAttachmentsPanel && this.recordClass && this.recordClass.hasField('attachments') && Tine.Tinebase.registry.get('filesystemAvailable')) {
1278 this.attachmentsPanel = new Tine.widgets.dialog.AttachmentsGridPanel({ anchor: '100% 100%', editDialog: this });
1279 this.items.items.push(this.attachmentsPanel);