Browse Source

Change the layer input in editable span

pull/856/head
Artur Arseniev 8 years ago
parent
commit
ca8fba3dfe
  1. 2
      dist/css/grapes.min.css
  2. 25
      src/navigator/view/ItemView.js
  3. 1
      src/styles/scss/_gjs_layers.scss

2
dist/css/grapes.min.css

File diff suppressed because one or more lines are too long

25
src/navigator/view/ItemView.js

@ -1,5 +1,6 @@
import { isUndefined } from 'underscore'; import { isUndefined } from 'underscore';
const ComponentView = require('dom_components/view/ComponentView'); const ComponentView = require('dom_components/view/ComponentView');
const inputProp = 'contentEditable';
let ItemsView; let ItemsView;
module.exports = require('backbone').View.extend({ module.exports = require('backbone').View.extend({
@ -8,8 +9,8 @@ module.exports = require('backbone').View.extend({
'click [data-toggle-visible]': 'toggleVisibility', 'click [data-toggle-visible]': 'toggleVisibility',
'click [data-toggle-select]': 'handleSelect', 'click [data-toggle-select]': 'handleSelect',
'click [data-toggle-open]': 'toggleOpening', 'click [data-toggle-open]': 'toggleOpening',
'dblclick input': 'handleEdit', 'dblclick [data-name]': 'handleEdit',
'focusout input': 'handleEditEnd' 'focusout [data-name]': 'handleEditEnd'
}, },
template(model) { template(model) {
@ -24,6 +25,7 @@ module.exports = require('backbone').View.extend({
const clsInput = `${this.inputNameCls} ${ppfx}no-app`; const clsInput = `${this.inputNameCls} ${ppfx}no-app`;
const level = this.level + 1; const level = this.level + 1;
const gut = `${30 + level * 10}px`; const gut = `${30 + level * 10}px`;
const name = model.getName();
return ` return `
${ ${
hidable hidable
@ -38,7 +40,7 @@ module.exports = require('backbone').View.extend({
<div class="${pfx}layer-title-inn"> <div class="${pfx}layer-title-inn">
<i class="${clsCaret}" data-toggle-open></i> <i class="${clsCaret}" data-toggle-open></i>
${model.getIcon()} ${model.getIcon()}
<input class="${clsInput}" value="${model.getName()}" readonly> <span class="${clsInput}" data-name>${name}</span>
</div> </div>
</div> </div>
</div> </div>
@ -125,20 +127,21 @@ module.exports = require('backbone').View.extend({
* Handle the edit of the component name * Handle the edit of the component name
*/ */
handleEdit(e) { handleEdit(e) {
e.stopPropagation(); e && e.stopPropagation();
var inputName = this.getInputName(); const inputEl = this.getInputName();
inputName.readOnly = false; inputEl[inputProp] = true;
inputName.focus(); inputEl.focus();
}, },
/** /**
* Handle with the end of editing of the component name * Handle with the end of editing of the component name
*/ */
handleEditEnd(e) { handleEditEnd(e) {
e.stopPropagation(); e && e.stopPropagation();
var inputName = this.getInputName(); const inputEl = this.getInputName();
inputName.readOnly = true; const name = inputEl.textContent;
this.model.set('custom-name', inputName.value); inputEl[inputProp] = false;
this.model.set({ name });
}, },
/** /**

1
src/styles/scss/_gjs_layers.scss

@ -67,6 +67,7 @@
&-name { &-name {
padding: 5px; padding: 5px;
display: inline-block;
box-sizing: content-box; box-sizing: content-box;
@extend .#{$app-prefix}no-user-select; @extend .#{$app-prefix}no-user-select;
} }

Loading…
Cancel
Save