39:dd75bec0598f
Anton Shestakov <engored@ya.ru>, 2013-05-01
Fix an ImminentDeprecationWarning from webassets. The original ImminentDeprecationWarning: The "filter" option of the {% assets %} template tag has been renamed to "filters" for consistency reasons

next change 61:ecb8269aa17f
previous change 0:a02e94c5b96b

static/js/framework/views/inline.js

Permissions: -rw-r--r--

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