Created
December 22, 2011 16:35
-
-
Save SET001/1510919 to your computer and use it in GitHub Desktop.
editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Editor = Backbone.Router.extend({ | |
immo: {}, | |
lm: {}, | |
nav: [], | |
pages: [], | |
routes: { | |
'editor/basic': 'basic', | |
'editor/basic/:id': 'basic', | |
'editor/details': 'details', | |
'editor/details/:id': 'details', | |
'editor/photos': 'photos', | |
'editor/photos/:id': 'photos', | |
'editor/publish': 'publish', | |
'editor/publish/:id': 'publish',}, | |
initialize: function(){ | |
var self = this; | |
if (!_length(self.immo)){ | |
self.immo = new Immo_Object(); | |
} | |
}, | |
basic: function(id){ | |
var self = this; | |
self.init(new View_EditorBasic({model: self.immo})); | |
self.nav.push({caption: '> Next Step', link: 'details'}); | |
self.run(id); | |
}, | |
details: function(id){ | |
var self = this; | |
self.init(new View_EditorDetails({model: self.immo})); | |
self.nav.push({caption: '< Prev Step', link: 'basic'}); | |
self.nav.push({caption: '> Next Step', link: 'photos'}); | |
self.run(id); | |
}, | |
photos: function(id){ | |
var self = this; | |
self.init(new View_EditorPhotos({model: self.immo})); | |
self.nav.push({caption: '< Prev Step', link: 'details'}); | |
self.nav.push({caption: '> Next Step', link: 'publish'}); | |
self.run(id); | |
}, | |
publish: function(id){ | |
var self = this; | |
self.init(new View_EditorPublish({model: self.immo})); | |
self.nav.push({caption: '< Prev Step', link: 'photos'}); | |
self.run(id); | |
}, | |
init: function(page){ | |
var self = this; | |
self.nav = []; | |
self.pages = [ | |
{name: 'basic', caption: 'Basic Infos'}, | |
{name: 'details', caption: 'Details'}, | |
{name: 'photos', caption: 'Photos'}, | |
{name: 'publish', caption: 'Publish'}, | |
]; | |
self.lm = new Backbone.LayoutManager({ | |
template: 'editor', | |
views:{ | |
'.editor': new View_Editor({ | |
collection: self.pages, | |
views: { | |
'.editor_form': page, | |
'.editor_top_nav, .editor_bottom_nav': new View_EditorNavigation({collection : self.nav}) | |
}}) | |
} | |
}); | |
}, | |
done: function(self){ | |
if (!self) self=this; | |
self.compose_navigation(); | |
self.lm.render(function(el){ | |
$('#content').html(el); | |
$(el).find(".facts dl").columnize(); | |
}); | |
}, | |
run: function(id){ | |
var self = this; | |
if (id && !self.immo.get('id')){ | |
self.immo.set({id: id}); | |
self.immo.fetch({success: function(){ | |
return self.done(self); | |
}}); | |
}else{ | |
self.store(); | |
self.done(); | |
} | |
}, | |
compose_navigation: function(){ | |
var self = this; | |
_.each(self.nav, function(item){ | |
item.link = 'editor/' + item.link; | |
if (self.immo.get('id')) item.link += '/' + self.immo.get('id'); | |
}); | |
}, | |
store: function(){ | |
var self = this; | |
var form = $('.editor_form form').serializeObject(); | |
self.immo.set(form); | |
return true; | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
View_EditorPublish = Backbone.View.extend({ | |
template: 'details', | |
serialize: function(){ | |
return {immo: this.model, details: Immo.details(this.model)}; | |
}, | |
render: function(layout){ | |
return layout(this).render().then(function(el) { | |
$(el).find(".facts dl").columnize(); | |
console.log($('.map')); | |
}); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment