0013352: add pin protection to folders
[tine20] / tine20 / Filemanager / js / NodeEditDialog.js
1 /*
2  * Tine 2.0
3  * 
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Alexander Stintzing <a.stintzing@metaways.de>
6  * @copyright   Copyright (c) 2012-2017 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.Filemanager');
9
10 /**
11  * @namespace   Tine.Filemanager
12  * @class       Tine.Filemanager.NodeEditDialog
13  * @extends     Tine.widgets.dialog.EditDialog
14  * 
15  * <p>Node Compose Dialog</p>
16  * <p></p>
17  * 
18  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
19  * @author      Alexander Stintzing <a.stintzing@metaways.de>
20  * 
21  * @param       {Object} config
22  * @constructor
23  * Create a new Tine.Filemanager.NodeEditDialog
24  */
25 Tine.Filemanager.NodeEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
26     
27     /**
28      * @private
29      */
30     windowNamePrefix: 'NodeEditWindow_',
31     appName: 'Filemanager',
32     recordClass: Tine.Filemanager.Model.Node,
33     recordProxy: Tine.Filemanager.fileRecordBackend,
34     tbarItems: null,
35     evalGrants: true,
36     showContainerSelector: false,
37     displayNotes: true,
38     requiredSaveGrant: 'readGrant',
39     
40     /**
41      * @type Tine.Filemanager.DownloadLinkGridPanel
42      */
43     downloadLinkGrid: null,
44     
45     initComponent: function() {
46         this.app = Tine.Tinebase.appMgr.get('Filemanager');
47         this.downloadAction = new Ext.Action({
48             requiredGrant: 'readGrant',
49             allowMultiple: false,
50             actionType: 'download',
51             text: this.app.i18n._('Save locally'),
52             handler: this.onDownload,
53             iconCls: 'action_filemanager_save_all',
54             disabled: this.record.data.type === 'folder',
55             scope: this
56         });
57         
58         this.tbarItems = [this.downloadAction];
59         
60         Tine.Filemanager.NodeEditDialog.superclass.initComponent.call(this);
61     },
62
63     /**
64      * folder or file?
65      */
66     getFittingTypeTranslation: function (isWindowTitle) {
67         if (isWindowTitle) {
68             return this.record.data.type == 'folder' ? this.app.i18n._('Edit folder') : this.app.i18n._('edit file');
69         } else {
70             return this.record.data.type == 'folder' ? this.app.i18n._('Folder') : this.app.i18n._('File');
71         }
72     },
73     
74     /**
75      * executed when record is loaded
76      * @private
77      */
78     onRecordLoad: function() {
79         Tine.Filemanager.NodeEditDialog.superclass.onRecordLoad.apply(this, arguments);
80         
81         this.window.setTitle(this.getFittingTypeTranslation(true));
82     },
83     
84     /**
85      * download file
86      */
87     onDownload: function() {
88         Tine.Filemanager.downloadFile(this.record);
89     },
90
91     /**
92      * returns dialog
93      * @return {Object}
94      * @private
95      */
96     getFormItems: function() {
97         var me = this,
98             _ = window.lodash,
99             fsConfig = Tine.Tinebase.configManager.get('filesystem'),
100             formFieldDefaults = {
101             xtype:'textfield',
102             anchor: '100%',
103             labelSeparator: '',
104             columnWidth: .5,
105             readOnly: true,
106             disabled: true
107         };
108         
109         this.downloadLinkGrid = new Tine.Filemanager.DownloadLinkGridPanel({
110             node: this.record,
111             app: this.app,
112             title: this.app.i18n._('Public Links'),
113             editDialog: this
114         });
115
116         // require('./GrantsPanel');
117         var grantsPanel = new Tine.Filemanager.GrantsPanel({
118             app: this.app,
119             editDialog: this
120         });
121
122         var notificationPanel = new Tine.Filemanager.NotificationPanel({
123             app: this.app,
124             editDialog: this
125         });
126
127         var revisionPanel = {};
128
129         if (_.get(fsConfig, 'modLogActive', false)) {
130             revisionPanel = new Tine.Filemanager.RevisionPanel({
131                 editDialog: this
132             });
133         }
134
135         return {
136             xtype: 'tabpanel',
137             border: false,
138             plain:true,
139             plugins: [{
140                 ptype : 'ux.tabpanelkeyplugin'
141             }],
142             activeTab: 0,
143             border: false,
144             items:[{
145                 title: this.getFittingTypeTranslation(false),
146                 autoScroll: true,
147                 border: false,
148                 frame: true,
149                 layout: 'border',
150                 items: [{
151                     region: 'center',
152                     layout: 'hfit',
153                     border: false,
154                     items: [{
155                         xtype: 'fieldset',
156                         layout: 'hfit',
157                         autoHeight: true,
158                         title: this.getFittingTypeTranslation(false),
159                         items: [{
160                             xtype: 'columnform',
161                             labelAlign: 'top',
162                             formDefaults: formFieldDefaults,
163                             items: [[{
164                                     fieldLabel: this.app.i18n._('Name'),
165                                     requiredGrant: 'editGrant',
166                                     name: 'name',
167                                     allowBlank: false,
168                                     readOnly: false,
169                                     columnWidth: .75,
170                                     disabled: false
171                                 }, {
172                                     fieldLabel: this.app.i18n._('Type'),
173                                     name: 'contenttype',
174                                     columnWidth: .25
175                                 }],[{
176                                     xtype: 'displayfield',
177                                     name: 'isIndexed',
178                                     hideLabel: true,
179                                     fieldClass: 'x-ux-displayfield-text',
180                                     width: 10,
181                                     setValue: function(value) {
182                                         var string, color, html = '';
183                                         if (Tine.Tinebase.configManager.get('filesystem.index_content', 'Tinebase') && me.record.get('type') == 'file') {
184                                             string = value ? me.app.i18n._('Indexed') : me.app.i18n._('Not yet indexed');
185                                             color = value ? 'green' : 'yellow';
186                                             html = ['<span style="color:', color, ' !important;" qtip="',string, '">&bull;</span>'].join('');
187                                         }
188
189                                         this.setRawValue(html);
190                                     }
191                                 }, {
192                                     xtype: 'displayfield',
193                                     name: 'path',
194                                     hideLabel: true,
195                                     fieldClass: 'x-ux-displayfield-text',
196                                     columnWidth: 1
197                                 }],[
198                                 Tine.widgets.form.RecordPickerManager.get('Addressbook', 'Contact', {
199                                     userOnly: true,
200                                     useAccountRecord: true,
201                                     blurOnSelect: true,
202                                     fieldLabel: this.app.i18n._('Created By'),
203                                     name: 'created_by'
204                                 }), {
205                                     fieldLabel: this.app.i18n._('Creation Time'),
206                                     name: 'creation_time',
207                                     xtype: 'datefield'
208                                 }
209                                 ],[
210                                 Tine.widgets.form.RecordPickerManager.get('Addressbook', 'Contact', {
211                                     userOnly: true,
212                                     useAccountRecord: true,
213                                     blurOnSelect: true,
214                                     fieldLabel: this.app.i18n._('Modified By'),
215                                     name: 'last_modified_by'
216                                 }), {
217                                     fieldLabel: this.app.i18n._('Last Modified'),
218                                     name: 'last_modified_time',
219                                     xtype: 'datefield'
220                                 }
221                                 ]]
222                         }]
223                     }, revisionPanel]
224                 }, {
225                     // activities and tags
226                     layout: 'accordion',
227                     animate: true,
228                     region: 'east',
229                     width: 210,
230                     split: true,
231                     collapsible: true,
232                     collapseMode: 'mini',
233                     header: false,
234                     margins: '0 5 0 5',
235                     border: true,
236                     items: [
237                         new Ext.Panel({
238                             title: this.app.i18n._('Description'),
239                             iconCls: 'descriptionIcon',
240                             layout: 'form',
241                             labelAlign: 'top',
242                             border: false,
243                             items: [{
244                                 style: 'margin-top: -4px; border 0px;',
245                                 labelSeparator: '',
246                                 xtype: 'textarea',
247                                 name: 'description',
248                                 hideLabel: true,
249                                 grow: false,
250                                 preventScrollbars: false,
251                                 anchor: '100% 100%',
252                                 emptyText: this.app.i18n._('Enter description'),
253                                 requiredGrant: 'editGrant'
254                             }]
255                         }),
256                         new Tine.widgets.tags.TagPanel({
257                             app: 'Filemanager',
258                             border: false,
259                             bodyStyle: 'border:1px solid #B5B8C8;'
260                         })
261                     ]
262                 }]
263             },
264             new Tine.widgets.activities.ActivitiesTabPanel({
265                 app: this.appName,
266                 record_id: this.record.id,
267                 record_model: 'Tinebase_Model_Tree_Node'
268                 }),
269                 this.downloadLinkGrid,
270                 {xtype: 'Tine.Filemanager.UsagePanel'},
271                 grantsPanel,
272                 notificationPanel
273             ]
274         }
275     }
276 });
277
278 /**
279  * Filemanager Edit Popup
280  * 
281  * @param   {Object} config
282  * @return  {Ext.ux.Window}
283  */
284 Tine.Filemanager.NodeEditDialog.openWindow = function (config) {
285     var id = (config.record && config.record.id) ? config.record.id : 0;
286     var window = Tine.WindowFactory.getWindow({
287         width: 800,
288         height: 570,
289         name: Tine.Filemanager.NodeEditDialog.prototype.windowNamePrefix + id,
290         contentPanelConstructor: 'Tine.Filemanager.NodeEditDialog',
291         contentPanelConstructorConfig: config
292     });
293     
294     return window;
295 };