From a362235acf763f9ac7f808e6339ade6d17c24092 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 26 Sep 2016 13:54:25 +0300 Subject: [PATCH] Rename file from editors. --- apps/common/Gateway.js | 8 ++ apps/common/main/lib/template/Header.template | 2 +- apps/common/main/lib/view/Header.js | 35 ++++- apps/common/main/lib/view/RenameDialog.js | 134 ++++++++++++++++++ .../main/app/controller/Main.js | 20 ++- apps/documenteditor/main/locale/en.json | 5 + .../main/app/controller/Main.js | 19 ++- apps/presentationeditor/main/locale/en.json | 7 +- .../main/app/controller/Main.js | 16 ++- apps/spreadsheeteditor/main/locale/en.json | 5 + 10 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 apps/common/main/lib/view/RenameDialog.js diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index f47d839cf..7cb8cab20 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -232,6 +232,14 @@ Common.Gateway = new(function() { collaborativeChanges: function() { _postMessage({event: 'onCollaborativeChanges'}); }, + + requestRename: function(title) { + _postMessage({event: 'onRequestRename', data: title}); + }, + + metaChange: function(meta) { + _postMessage({event: 'onMetaChange', data: meta}); + }, on: function(event, handler){ var localHandler = function(event, data){ diff --git a/apps/common/main/lib/template/Header.template b/apps/common/main/lib/template/Header.template index 9bb4bd030..eb375f8e0 100644 --- a/apps/common/main/lib/template/Header.template +++ b/apps/common/main/lib/template/Header.template @@ -2,6 +2,6 @@
<%= headerCaption %>
-
<%= documentCaption %>
+
<%= documentCaption %>
<%= textBack %>
\ No newline at end of file diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index 126fe7c3f..2974c8971 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -46,7 +46,8 @@ Common.Views = Common.Views || {}; define([ 'backbone', 'text!common/main/lib/template/Header.template', - 'core' + 'core', + 'common/main/lib/view/RenameDialog' ], function (Backbone, headerTemplate) { 'use strict'; Common.Views.Header = Backbone.View.extend(_.extend({ @@ -165,7 +166,7 @@ define([ if (!value) value = ''; - var dc = $('#header-documentcaption'); + var dc = $('#header-documentcaption span'); if (dc) dc.html(Common.Utils.String.htmlEncode(value)); @@ -226,8 +227,36 @@ define([ $('#header-developer').toggleClass('hidden', !mode); }, + setCanRename: function(rename) { + var dc = $('#header-documentcaption span'); + if (rename) { + var me = this; + dc.tooltip({title: me.txtRename, placement: 'cursor'}); + dc.on('click', function(e) { + (new Common.Views.RenameDialog({ + filename: me.documentCaption, + handler: function(result, value) { + if (result == 'ok' && !_.isEmpty(value.trim()) && me.documentCaption !== value.trim()) { + Common.Gateway.requestRename(value); + } + Common.NotificationCenter.trigger('edit:complete', me); + } + })).show(dc.position().left-1, 20); + }); + } else { + var tip = dc.data('bs.tooltip'); + if (tip) { + tip.options.title = ''; + tip.setContent(); + } + dc.off('click'); + } + dc.css('cursor', rename ? 'pointer' : 'default'); + }, + textBack: 'Go to Documents', openNewTabText: 'Open in New Tab', - txtHeaderDeveloper: 'DEVELOPER MODE' + txtHeaderDeveloper: 'DEVELOPER MODE', + txtRename: 'Rename' }, Common.Views.Header || {})) }); diff --git a/apps/common/main/lib/view/RenameDialog.js b/apps/common/main/lib/view/RenameDialog.js new file mode 100644 index 000000000..59509069a --- /dev/null +++ b/apps/common/main/lib/view/RenameDialog.js @@ -0,0 +1,134 @@ +/* + * + * (c) Copyright Ascensio System Limited 2010-2016 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, + * EU, LV-1021. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * +*/ +/** + * RenameDialog.js + * + * Created by Julia Radzhabova on 9/23/16 + * Copyright (c) 2014 Ascensio System SIA. All rights reserved. + * + */ + +define([ + 'common/main/lib/component/Window' +], function () { 'use strict'; + + Common.Views.RenameDialog = Common.UI.Window.extend(_.extend({ + options: { + width: 330, + header: false, + cls: 'modal-dlg', + filename: '' + }, + + initialize : function(options) { + _.extend(this.options, options || {}); + + this.template = [ + '
', + '
', + '', + '
', + '
', + '
', + '' + ].join(''); + + this.options.tpl = _.template(this.template, this.options); + + Common.UI.Window.prototype.initialize.call(this, this.options); + }, + + render: function() { + Common.UI.Window.prototype.render.call(this); + + var me = this; + me.inputName = new Common.UI.InputField({ + el : $('#id-dlg-newname'), + style : 'width: 100%;', + validateOnBlur: false, + validation : function(value) { + return (/[\t*\+:\"<>?|\\\\/]/gim.test(value)) ? me.txtInvalidName + "*+:\"<>?|\/" : true; + } + }); + + var $window = this.getChild(); + $window.find('.btn').on('click', _.bind(this.onBtnClick, this)); + + me.inputNameEl = $window.find('input'); + me.inputNameEl.on('keypress', _.bind(this.onKeyPress, this)); + }, + + show: function() { + Common.UI.Window.prototype.show.apply(this, arguments); + + var me = this; + _.delay(function(){ + me.inputName.setValue(me.options.filename); + me.inputNameEl.focus().select(); + },100); + }, + + onKeyPress: function(event) { + if (event.keyCode == Common.UI.Keys.RETURN) { + this._handleInput('ok'); + } + }, + + onBtnClick: function(event) { + this._handleInput(event.currentTarget.attributes['result'].value); + }, + + _handleInput: function(state) { + if (this.options.handler) { + if (state == 'ok') { + if (this.inputName.checkValidate() !== true) { + this.inputNameEl.focus(); + return; + } + } + + this.options.handler.call(this, state, this.inputName.getValue()); + } + + this.close(); + }, + + textName : 'File name', + cancelButtonText: 'Cancel', + okButtonText : 'Ok', + txtInvalidName : 'The file name cannot contain any of the following characters: ' + }, Common.Views.RenameDialog || {})); +}); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index c83dece4a..5002066cb 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -130,6 +130,7 @@ define([ this.api.asc_registerCallback('asc_onAdvancedOptions', _.bind(this.onAdvancedOptions, this)); this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this)); this.api.asc_registerCallback('asc_onPrintUrl', _.bind(this.onPrintUrl, this)); + this.api.asc_registerCallback('asc_onMeta', _.bind(this.onMeta, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); @@ -363,6 +364,7 @@ define([ }); } else { this.api.asc_coAuthoringDisconnect(); + this.getApplication().getController('Viewport').getView('Common.Views.Header').setCanRename(false); this.getApplication().getController('LeftMenu').getView('LeftMenu').showHistory(); this.disableEditing(true); var versions = opts.data.history, @@ -976,11 +978,13 @@ define([ this._state.licenseWarning = (licType===Asc.c_oLicenseResult.Connections) && this.appOptions.canEdit && this.editorConfig.mode !== 'view'; + var headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.appOptions.canBranding = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object'); if (this.appOptions.canBranding) - this.getApplication().getController('Viewport').getView('Common.Views.Header').setBranding(this.editorConfig.customization); + headerView.setBranding(this.editorConfig.customization); - params.asc_getTrial() && this.getApplication().getController('Viewport').getView('Common.Views.Header').setDeveloperMode(true); + params.asc_getTrial() && headerView.setDeveloperMode(true); + this.permissions.rename && headerView.setCanRename(true); this.applyModeCommonElements(); this.applyModeEditorElements(); @@ -1276,6 +1280,7 @@ define([ onCoAuthoringDisconnect: function() { this.getApplication().getController('Viewport').getView('Viewport').setMode({isDisconnected:true}); + this.getApplication().getController('Viewport').getView('Common.Views.Header').setCanRename(false); this._state.isDisconnected = true; }, @@ -1706,6 +1711,17 @@ define([ this.updateWindowTitle(true); }, + onMeta: function(meta) { + var app = this.getApplication(), + filemenu = app.getController('LeftMenu').getView('LeftMenu').getMenu('file'); + app.getController('Viewport').getView('Common.Views.Header').setDocumentCaption(meta.title); + this.updateWindowTitle(true); + this.document.title = meta.title; + filemenu.loadDocument({doc:this.document}); + filemenu.panels['info'].updateInfo(this.document); + Common.Gateway.metaChange(meta); + }, + onPrint: function() { if (!this.appOptions.canPrint) return; diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 4ceed9b62..095ee0813 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -142,6 +142,7 @@ "Common.Views.Header.openNewTabText": "Open in New Tab", "Common.Views.Header.textBack": "Go to Documents", "Common.Views.Header.txtHeaderDeveloper": "DEVELOPER MODE", + "Common.Views.Header.txtRename": "Rename", "Common.Views.History.textHistoryHeader": "Back to Document", "Common.Views.History.textRestore": "Restore", "Common.Views.ImageFromUrlDialog.cancelButtonText": "Cancel", @@ -167,6 +168,10 @@ "Common.Views.Plugins.strPlugins": "Plugins", "Common.Views.Plugins.textLoading": "Loading", "Common.Views.Plugins.textStart": "Start", + "Common.Views.RenameDialog.cancelButtonText": "Cancel", + "Common.Views.RenameDialog.okButtonText": "Ok", + "Common.Views.RenameDialog.textName": "File name", + "Common.Views.RenameDialog.txtInvalidName": "The file name cannot contain any of the following characters: ", "Common.Views.ReviewChanges.txtAccept": "Accept", "Common.Views.ReviewChanges.txtAcceptAll": "Accept All Changes", "Common.Views.ReviewChanges.txtAcceptCurrent": "Accept Current Change", diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 7c3cbc395..adf033e4a 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -121,6 +121,7 @@ define([ this.api.asc_registerCallback('asc_onDocumentUpdateVersion', _.bind(this.onUpdateVersion, this)); this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this)); this.api.asc_registerCallback('asc_onPrintUrl', _.bind(this.onPrintUrl, this)); + this.api.asc_registerCallback('asc_onMeta', _.bind(this.onMeta, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); @@ -741,11 +742,13 @@ define([ this._state.licenseWarning = (licType===Asc.c_oLicenseResult.Connections) && this.appOptions.canEdit && this.editorConfig.mode !== 'view'; + var headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.appOptions.canBranding = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object'); if (this.appOptions.canBranding) - this.getApplication().getController('Viewport').getView('Common.Views.Header').setBranding(this.editorConfig.customization); + headerView.setBranding(this.editorConfig.customization); - params.asc_getTrial() && this.getApplication().getController('Viewport').getView('Common.Views.Header').setDeveloperMode(true); + params.asc_getTrial() && headerView.setDeveloperMode(true); + this.permissions.rename && headerView.setCanRename(true); this.applyModeCommonElements(); this.applyModeEditorElements(); @@ -1030,6 +1033,7 @@ define([ onCoAuthoringDisconnect: function() { // TODO: Disable all except 'Download As' and 'Print' this.getApplication().getController('Viewport').getView('Viewport').setMode({isDisconnected:true}); + this.getApplication().getController('Viewport').getView('Common.Views.Header').setCanRename(false); this._state.isDisconnected = true; // this.getFileMenu().setMode({isDisconnected:true}); }, @@ -1464,6 +1468,17 @@ define([ this.updateWindowTitle(true); }, + onMeta: function(meta) { + var app = this.getApplication(), + filemenu = app.getController('LeftMenu').getView('LeftMenu').getMenu('file'); + app.getController('Viewport').getView('Common.Views.Header').setDocumentCaption(meta.title); + this.updateWindowTitle(true); + this.document.title = meta.title; + filemenu.loadDocument({doc:this.document}); + filemenu.panels['info'].updateInfo(this.document); + Common.Gateway.metaChange(meta); + }, + onPrint: function() { if (!this.appOptions.canPrint) return; diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index 03a5b0e0b..8a1d4470f 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -81,6 +81,7 @@ "Common.Views.Header.openNewTabText": "Open in New Tab", "Common.Views.Header.textBack": "Go to Documents", "Common.Views.Header.txtHeaderDeveloper": "DEVELOPER MODE", + "Common.Views.Header.txtRename": "Rename", "Common.Views.ImageFromUrlDialog.cancelButtonText": "Cancel", "Common.Views.ImageFromUrlDialog.okButtonText": "OK", "Common.Views.ImageFromUrlDialog.textUrl": "Paste an image URL:", @@ -98,14 +99,16 @@ "Common.Views.Plugins.strPlugins": "Plugins", "Common.Views.Plugins.textLoading": "Loading", "Common.Views.Plugins.textStart": "Start", + "Common.Views.RenameDialog.cancelButtonText": "Cancel", + "Common.Views.RenameDialog.okButtonText": "Ok", + "Common.Views.RenameDialog.textName": "File name", + "Common.Views.RenameDialog.txtInvalidName": "The file name cannot contain any of the following characters: ", "PE.Controllers.LeftMenu.newDocumentTitle": "Unnamed presentation", "PE.Controllers.LeftMenu.requestEditRightsText": "Requesting editing rights...", "PE.Controllers.LeftMenu.textNoTextFound": "The data you have been searching for could not be found. Please adjust your search options.", "PE.Controllers.Main.applyChangesTextText": "Loading data...", "PE.Controllers.Main.applyChangesTitleText": "Loading Data", "del_PE.Controllers.Main.convertationErrorText": "Conversion failed.", - "PE.Controllers.Main.openErrorText": "An error has occurred while opening the file", - "PE.Controllers.Main.saveErrorText": "An error has occurred while saving the file", "PE.Controllers.Main.convertationTimeoutText": "Conversion timeout exceeded.", "PE.Controllers.Main.criticalErrorExtText": "Press \"OK\" to return to document list.", "PE.Controllers.Main.criticalErrorTitle": "Error", diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 4e7b35645..61be069d9 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -121,6 +121,7 @@ define([ this.api.asc_registerCallback('asc_onDocumentUpdateVersion', _.bind(this.onUpdateVersion, this)); this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this)); this.api.asc_registerCallback('asc_onPrintUrl', _.bind(this.onPrintUrl, this)); + this.api.asc_registerCallback('asc_onMeta', _.bind(this.onMeta, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); Common.NotificationCenter.on('namedrange:locked', _.bind(this.onNamedRangeLocked, this)); @@ -764,6 +765,7 @@ define([ this.headerView.setBranding(this.editorConfig.customization); params.asc_getTrial() && this.headerView.setDeveloperMode(true); + this.permissions.rename && this.headerView.setCanRename(true); } this.appOptions.canRequestEditRights = this.editorConfig.canRequestEditRights; @@ -1183,7 +1185,8 @@ define([ onCoAuthoringDisconnect: function() { this.getApplication().getController('Viewport').getView('Viewport').setMode({isDisconnected:true}); - this._state.isDisconnected = true; + this.getApplication().getController('Viewport').getView('Common.Views.Header').setCanRename(false); + this._state.isDisconnected = true; }, showTips: function(strings) { @@ -1699,6 +1702,17 @@ define([ this.updateWindowTitle(this.api.asc_isDocumentModified(), true); }, + onMeta: function(meta) { + var app = this.getApplication(), + filemenu = app.getController('LeftMenu').getView('LeftMenu').getMenu('file'); + app.getController('Viewport').getView('Common.Views.Header').setDocumentCaption(meta.title); + this.updateWindowTitle(true); + this.appOptions.spreadsheet.title = meta.title; + filemenu.loadDocument({doc:this.appOptions.spreadsheet}); + filemenu.panels['info'].updateInfo(this.appOptions.spreadsheet); + Common.Gateway.metaChange(meta); + }, + onPrint: function() { if (!this.appOptions.canPrint) return; Common.NotificationCenter.trigger('print', this); diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index b6f48be76..c3d89c0b1 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -75,6 +75,7 @@ "Common.Views.Header.openNewTabText": "Open in New Tab", "Common.Views.Header.textBack": "Go to Documents", "Common.Views.Header.txtHeaderDeveloper": "DEVELOPER MODE", + "Common.Views.Header.txtRename": "Rename", "Common.Views.ImageFromUrlDialog.cancelButtonText": "Cancel", "Common.Views.ImageFromUrlDialog.okButtonText": "OK", "Common.Views.ImageFromUrlDialog.textUrl": "Paste an image URL:", @@ -93,6 +94,10 @@ "Common.Views.Plugins.strPlugins": "Plugins", "Common.Views.Plugins.textLoading": "Loading", "Common.Views.Plugins.textStart": "Start", + "Common.Views.RenameDialog.cancelButtonText": "Cancel", + "Common.Views.RenameDialog.okButtonText": "Ok", + "Common.Views.RenameDialog.textName": "File name", + "Common.Views.RenameDialog.txtInvalidName": "The file name cannot contain any of the following characters: ", "SSE.Controllers.DocumentHolder.errorInvalidLink": "The link reference does not exist. Please correct the link or delete it.", "SSE.Controllers.DocumentHolder.guestText": "Guest", "SSE.Controllers.DocumentHolder.notcriticalErrorTitle": "Warning",