application/js/content.js in spontaneous-0.2.0.beta5 vs application/js/content.js in spontaneous-0.2.0.beta6

- old
+ new

@@ -1,8 +1,9 @@ // console.log('Loading Content...') Spontaneous.Content = (function($, S) { + 'use strict'; var dom = S.Dom; var Content = new JS.Class({ include: Spontaneous.Properties, @@ -23,11 +24,11 @@ target: function() { return this.content.target; }, developer_description: function() { - return this.type().type + "["+this.id()+']'; + return this.type().type + '['+this.id()+']'; }, developer_edit_url: function() { return this.type().edit_url(); }, type: function() { @@ -49,13 +50,10 @@ unload: function() { $.each(this.field_list(), function(i, f) { f.unload(); }); $.each(this.entries(), function(i, e) { e.unload(); }); }, - has_fields: function() { - return this.field_list().length > 0; - }, field_list: function() { var type = this.type(), prototypes = type.field_prototypes, names = type.field_names; var fields = this.fields(), list = []; for (var i = 0, ii = names.length; i < ii; i++) { list.push(fields[names[i]]); @@ -101,23 +99,23 @@ prototype = prototypes[f.name]; if (f && prototype) { type_class = this.constantize(prototype.type); if (!type_class) { console.warn( - "Content#fields:", - "Field has invalid type", prototype.type, - "content_id:", this.content.id, - "type:", "'"+type.title+"'", - "field_name:", f.name + 'Content#fields:', + 'Field has invalid type', prototype.type, + 'content_id:', this.content.id, + 'type:', "'"+type.title+"'", + 'field_name:', f.name ); type_class = Spontaneous.Field.String; } - var field = new type_class(this, f); + var field = new type_class(this, f); // jshint ignore:line // field.watch('value', this.field_updated.bind(this, field)); fields[f.name] = field; } - }; + } return fields; }.cache(), field: function(name) { return this.fields()[name]; @@ -145,19 +143,27 @@ } } }, has_fields: function() { - return (this.content.fields.length > 0) + return this.field_list().length > 0; }, title: function() { return this.title_field().value(); }, title_field: function() { - return this.fields()[this.type().title_field_name]; + var self = this, title_field = self.fields()[self.type().title_field_name]; + // if we're aliasing a page with a page then it's likely that the alias type + // won't have a title field (falling back to its target's value instead) + // so we need to fall back to the target's title field in that base + if (!title_field && self.type().is_alias()) { + var target = new Content(self.target()); + title_field = target.title_field(); + } + return title_field; }, hidden: function() { return this.content.hidden; }, @@ -183,19 +189,19 @@ } return _boxes; }.cache(), has_boxes: function() { - return (this.boxes().length > 0) + return (this.boxes().length > 0); }, wrap_entry: function(entry) { var entry_class = Spontaneous.Entry; if (entry.is_page) { entry_class = Spontaneous.PageEntry; } - return new entry_class(entry, this); + return new entry_class(entry, this); // jshint ignore:line }, allowed_types: function() { return this.type().allowed_types(); }, @@ -206,10 +212,10 @@ destroy: function() { Spontaneous.Ajax.del(['/content', this.content.id].join('/'), {}, this.destroyed.bind(this)); }, toggle_visibility: function() { - Spontaneous.Ajax.patch(['/content', this.content.id, "toggle"].join('/'), {}, this.visibility_toggled.bind(this)); + Spontaneous.Ajax.patch(['/content', this.content.id, 'toggle'].join('/'), {}, this.visibility_toggled.bind(this)); }, visibility_toggled: function(result) { this.set('hidden', result.hidden); // this.trigger('visibility_toggled', result); },