[Common] added 'document rename'

This commit is contained in:
Maxim Kadushkin 2017-08-01 15:14:19 +03:00
parent 55889a4bf4
commit 8513705b1e
2 changed files with 80 additions and 29 deletions

View file

@ -70,7 +70,7 @@ define([
'</ul>'); '</ul>');
var templateRightBox = '<section>' + var templateRightBox = '<section>' +
'<label id="rib-doc-name" class="status-label"></label>' + '<section id="box-doc-name"><input type="text" id="rib-doc-name" spellcheck="false"></input></section>' +
'<a id="rib-save-status" class="status-label locked"><%= textSaveEnd %></a>' + '<a id="rib-save-status" class="status-label locked"><%= textSaveEnd %></a>' +
'<div class="hedset">' + '<div class="hedset">' +
'<div class="btn-slot" id="slot-hbtn-edit"></div>' + '<div class="btn-slot" id="slot-hbtn-edit"></div>' +
@ -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 { return {
options: { options: {
branding: {}, branding: {},
@ -344,7 +380,12 @@ define([
textSaveEnd: this.textSaveEnd textSaveEnd: this.textSaveEnd
})); }));
if ( this.labelDocName ) this.labelDocName.off();
this.labelDocName = $html.find('#rib-doc-name'); this.labelDocName = $html.find('#rib-doc-name');
this.labelDocName.on({
'keydown': onDocNameKeyDown.bind(this)
});
$saveStatus = $html.find('#rib-save-status'); $saveStatus = $html.find('#rib-save-status');
$saveStatus.hide(); $saveStatus.hide();
@ -440,8 +481,13 @@ define([
this.documentCaption = value; this.documentCaption = value;
this.isModified && (value += '*'); this.isModified && (value += '*');
if ( this.labelDocName ) if ( this.labelDocName ) {
this.labelDocName.html(Common.Utils.String.htmlEncode(value)); var encoded = Common.Utils.String.htmlEncode(value);
this.labelDocName.val( encoded );
this.labelDocName.attr('size', encoded.length);
this.setCanRename(true);
}
return value; return value;
}, },
@ -470,31 +516,23 @@ define([
}, },
setCanRename: function (rename) { setCanRename: function (rename) {
// var dc = $('#header-documentcaption div'); rename = false;
// if (rename) {
// var me = this; var me = this,
// dc.tooltip({title: me.txtRename, placement: 'cursor'}); label = me.labelDocName;
// dc.on('click', function (e) { if ( rename ) {
// (new Common.Views.RenameDialog({ label.removeAttr('disabled').tooltip({
// filename: me.documentCaption, title: me.txtRename,
// handler: function (result, value) { placement: 'cursor'}
// if (result == 'ok' && !_.isEmpty(value.trim()) && me.documentCaption !== value.trim()) { );
// Common.Gateway.requestRename(value); } else {
// } label.attr('disabled', true);
// Common.NotificationCenter.trigger('edit:complete', me); var tip = label.data('bs.tooltip');
// } if ( tip ) {
// })).show(dc.position().left - 1, 20); tip.options.title = '';
// }); tip.setContent();
// } 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);
}, },
setSaveStatus: function (status) { setSaveStatus: function (status) {

View file

@ -83,13 +83,26 @@
} }
} }
#rib-doc-name { #box-doc-name {
flex-grow: 1; flex-grow: 1;
text-align: center;
}
#rib-doc-name {
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
min-width: 50px; min-width: 50px;
text-align: center; text-align: center;
color: #fff;
background-color: transparent;
border: 0 none;
cursor: default;
&:focus {
cursor: text;
}
} }
#rib-save-status { #rib-save-status {