From 22a7735ae2ca64505701717e131ea5c1e6ed941a Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 11 Jun 2013 15:36:19 -0400 Subject: [PATCH] Added parse functions to handle backend representation of textbooks --- cms/templates/textbooks.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cms/templates/textbooks.html b/cms/templates/textbooks.html index 9d6c94ad6f..9b7a228450 100644 --- a/cms/templates/textbooks.html +++ b/cms/templates/textbooks.html @@ -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({