0
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var InlineEditorView = Backbone.View.extend({ |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
initialize: function(options) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.render(options); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}, |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
renderInput: function(options) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var view = this; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input = $('<input>').attr('type', 'text').addClass('input-xlarge').val(options.target.text()); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input.keyup(function(e) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
switch (e.keyCode) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 13: |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.$saveButton.click(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
break; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 27: |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.$cancelButton.click(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
break; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$el.append(this.$input, this.$saveButton, this.$cancelButton); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
options.target.after(this.$el); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input.focus(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
return this; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}, |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
renderTextarea: function(options) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var view = this; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input = $('<textarea>').addClass('input-xlarge').attr('rows', 3).text(options.target.text()); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input.keyup(function(e) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
switch (e.keyCode) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 13: |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
if (e.ctrlKey) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.$saveButton.click(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
break; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 27: |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.$cancelButton.click(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
break; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$el.append(this.$input, this.$saveButton, this.$cancelButton); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
options.target.after(this.$el); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$input.focus(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
return this; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}, |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
render: function(options) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var view = this; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$saveButton = $('<button>').addClass('btn btn-small btn-success').html('<i class="icon-white icon-ok"></i>'); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$cancelButton = $('<button>').addClass('btn btn-small').html('<i class="icon-remove"></i>'); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$el = $('<div>').addClass('inline-editor input-append'); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$cancelButton.click(function() { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.$el.remove(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
options.target.show(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
this.$saveButton.click(function() { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
view.trigger('save', view.$input.val()); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
switch (options.type) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 'input': |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
return this.renderInput(options); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
case 'textarea': |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
return this.renderTextarea(options); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var CollectionViewWithInlineEditor = CollectionView.extend({ |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
bindInlineEditable: function(model, selector) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
model.$item.delegate(selector, 'click', function(e) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
e.preventDefault(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var $this = $(this); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var attribute = $this.attr('data-model-attribute'); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var inlineEditor = new InlineEditorView({ |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
target: $this, |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
type: $this.attr('data-input-type') || 'input' |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
$this.hide(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
inlineEditor.on('save', function(value) { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
var data = {}; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
data[attribute] = value; |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
|
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
model.adhoc(data).then(function() { |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
inlineEditor.remove(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
$this.show(); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
} |
Anton Shestakov <engored@ya.ru>
previous changes:
line |
diff
|
}); |