Added parse functions to handle backend representation of textbooks

This commit is contained in:
David Baumgold
2013-06-11 15:36:19 -04:00
parent 9e5df7e28a
commit 22a7735ae2

View File

@@ -45,6 +45,17 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
}],
isEmpty: function() {
return !this.get('name') && this.get('chapters').isEmpty();
},
parse: function(response) {
if("tab_title" in response && !("name" in response)) {
response.name = response.tab_title;
delete response.tab_title;
}
if("url" in response && !("chapters" in response)) {
response.chapters = {"url": response.url};
delete response.url;
}
return response;
}
})
CMS.Views.TextbookShow = Backbone.View.extend({
@@ -207,6 +218,17 @@ CMS.Models.Chapter = Backbone.AssociatedModel.extend({
},
isEmpty: function() {
return !this.get('name') && !this.get('asset_path');
},
parse: function(response) {
if("title" in response && !("name" in response)) {
response.name = response.title;
delete response.title;
}
if("url" in response && !("asset_path" in response)) {
response.asset_path = response.url;
delete response.url;
}
return response;
}
})
CMS.Collections.ChapterSet = Backbone.Collection.extend({