default duration from last save

This commit is contained in:
Márton Boros
2013-02-18 08:37:55 +01:00
parent 4ff1d05dca
commit 4fa3c7bb2f
2 changed files with 12 additions and 4 deletions

View File

@@ -24,6 +24,8 @@ get_mimetype = (filename) =>
# Models
default_duration = 10
# Tell Backbone to send its saves as JSON-encoded.
Backbone.emulateJSON = on
@@ -36,7 +38,7 @@ API.Asset = class Asset extends Backbone.Model
uri: ''
start_date: now()
end_date: now()
duration: 10
duration: default_duration
API.Assets = class Assets extends Backbone.Collection
url: "/api/assets"
@@ -118,6 +120,7 @@ class EditAssetView extends Backbone.View
(@$ 'input, select').prop 'disabled', on
save.done (data) =>
default_duration = @model.get 'duration'
@collection.add @model if not @model.collection
(@$el.children ":first").modal 'hide'
_.extend @model.attributes, data
@@ -164,6 +167,7 @@ class EditAssetView extends Backbone.View
updateMimetype: (filename) =>
mt = get_mimetype filename
@$fv 'mimetype', mt if mt
_.defer @change
class AssetRowView extends Backbone.View

View File

@@ -5,7 +5,7 @@
(function() {
var API, App, Asset, AssetRowView, Assets, AssetsView, EditAssetView, date_to, delay, get_mimetype, get_template, mimetypes, now, y2ts, years_from_now,
var API, App, Asset, AssetRowView, Assets, AssetsView, EditAssetView, date_to, default_duration, delay, get_mimetype, get_template, mimetypes, now, y2ts, years_from_now,
_this = this,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
@@ -68,6 +68,8 @@
}
};
default_duration = 10;
Backbone.emulateJSON = true;
API.Asset = Asset = (function(_super) {
@@ -90,7 +92,7 @@
uri: '',
start_date: now(),
end_date: now(),
duration: 10
duration: default_duration
};
};
@@ -268,6 +270,7 @@
}
(this.$('input, select')).prop('disabled', true);
save.done(function(data) {
default_duration = _this.model.get('duration');
if (!_this.model.collection) {
_this.collection.add(_this.model);
}
@@ -343,8 +346,9 @@
var mt;
mt = get_mimetype(filename);
if (mt) {
return this.$fv('mimetype', mt);
this.$fv('mimetype', mt);
}
return _.defer(this.change);
};
return EditAssetView;