From 8513705b1e6f2583c838cc1db423635885bf801d Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Tue, 1 Aug 2017 15:14:19 +0300 Subject: [PATCH] [Common] added 'document rename' --- apps/common/main/lib/view/Header.js | 94 +++++++++++++++------ apps/common/main/resources/less/header.less | 15 +++- 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index 57b74b00c..789ca9506 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -70,7 +70,7 @@ define([ ''); var templateRightBox = '
' + - '' + + '
' + '<%= textSaveEnd %>' + '
' + '
' + @@ -278,6 +278,42 @@ define([ } } + function onDocNameKeyDown(e) { + var me = this; + + var name = me.labelDocName.val(); + if ( e.keyCode == Common.UI.Keys.RETURN ) { + name = name.trim(); + if ( !_.isEmpty(name) && me.documentCaption !== name ) { + if ( /[\t*\+:\"<>?|\\\\/]/gim.test(name) ) { + _.defer(function() { + Common.UI.error({ + msg: (new Common.Views.RenameDialog).txtInvalidName + "*+:\"<>?|\/" + , callback: function() { + _.delay(function() { + me.labelDocName.focus(); + }, 50); + } + }); + + me.labelDocName.blur(); + }) + } else { + Common.Gateway.requestRename(name); + Common.NotificationCenter.trigger('edit:complete', me); + } + } + } else + if ( e.keyCode == Common.UI.Keys.ESC ) { + me.labelDocName.val(me.documentCaption); + Common.NotificationCenter.trigger('edit:complete', this); + } else { + me.labelDocName.attr('size', name.length > 10 ? name.length : 10); + } + + console.log('input keydown'); + } + return { options: { branding: {}, @@ -344,7 +380,12 @@ define([ textSaveEnd: this.textSaveEnd })); + if ( this.labelDocName ) this.labelDocName.off(); this.labelDocName = $html.find('#rib-doc-name'); + this.labelDocName.on({ + 'keydown': onDocNameKeyDown.bind(this) + }); + $saveStatus = $html.find('#rib-save-status'); $saveStatus.hide(); @@ -440,8 +481,13 @@ define([ this.documentCaption = value; this.isModified && (value += '*'); - if ( this.labelDocName ) - this.labelDocName.html(Common.Utils.String.htmlEncode(value)); + if ( this.labelDocName ) { + var encoded = Common.Utils.String.htmlEncode(value); + this.labelDocName.val( encoded ); + this.labelDocName.attr('size', encoded.length); + + this.setCanRename(true); + } return value; }, @@ -470,31 +516,23 @@ define([ }, setCanRename: function (rename) { - // var dc = $('#header-documentcaption div'); - // 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'); - // dc.toggleClass('renamed', rename); + rename = false; + + var me = this, + label = me.labelDocName; + if ( rename ) { + label.removeAttr('disabled').tooltip({ + title: me.txtRename, + placement: 'cursor'} + ); + } else { + label.attr('disabled', true); + var tip = label.data('bs.tooltip'); + if ( tip ) { + tip.options.title = ''; + tip.setContent(); + } + } }, setSaveStatus: function (status) { diff --git a/apps/common/main/resources/less/header.less b/apps/common/main/resources/less/header.less index 37c6e2949..4fb0027eb 100644 --- a/apps/common/main/resources/less/header.less +++ b/apps/common/main/resources/less/header.less @@ -83,13 +83,26 @@ } } - #rib-doc-name { + #box-doc-name { flex-grow: 1; + text-align: center; + } + + #rib-doc-name { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; min-width: 50px; text-align: center; + + color: #fff; + background-color: transparent; + border: 0 none; + cursor: default; + + &:focus { + cursor: text; + } } #rib-save-status {