Commit fc67370ef4c2e7eb747706a5a4ce08396545bfcf

Fix few bugs

  - After new page was created in the editor, its view was dangling - it could
    not be reached. Fix that.
  - When page was refreshed, framework was taking it to home page irrespective
    of the URL hash. Fixed.
  • Diff rendering mode:
  • inline
  • side by side

static/css/mouchak.css

1.title {
2 text-align: center;
3 margin: 0 auto;
4 padding: 3px;
5 font-size: 1.5em;
6}

static/js/editor.js

107 this.render();107 this.render();
108 },108 },
109 nameChanged: function(page) {109 nameChanged: function(page) {
110 M.pagelistview.render();
110 //M.pagelistview.render();
111 console.log('name changed', page);111 console.log('name changed', page);
112 },112 },
113 render: function() {113 render: function() {
209 console.log('saved', model, response);209 console.log('saved', model, response);
210 model.set(response.page);210 model.set(response.page);
211 model.id = response.page.id;211 model.id = response.page.id;
212 //console.log(model);
213 //console.log(M.pages.models);
214 M.pagelistview.render();
212 },215 },
213 error: function(model, xhr) {216 error: function(model, xhr) {
214 console.log('failed', model, xhr);217 console.log('failed', model, xhr);

static/js/mouchak.js

14 },14 },
15 render: function() {15 render: function() {
16 var menu = new M.types.model.menu(M.site_content.menu);16 var menu = new M.types.model.menu(M.site_content.menu);
17 var navview = new NavigationView({model: menu});
18 navview.render();
17 var navView = new NavigationView({model: menu});
18 navView.render();
19 this.navView = navView;
19 },20 },
20 updateBreadcrumbs: function(event) {21 updateBreadcrumbs: function(event) {
21 //TODO: write code to use bootstrap's breadcrumbs to render a22 //TODO: write code to use bootstrap's breadcrumbs to render a
27var NavigationView = Backbone.View.extend({27var NavigationView = Backbone.View.extend({
28 el: '#navigation',28 el: '#navigation',
29 events: {29 events: {
30 'click .nav li a' : 'navClicked'
30 'click .nav li a' : 'navClicked',
31 'navclicked': 'navClicked'
31 },32 },
32 initialize: function() {33 initialize: function() {
33 _.bindAll(this);34 _.bindAll(this);
34 this.template = _.template($('#nav-bar-template').html());35 this.template = _.template($('#nav-bar-template').html());
36 this.bind('navclicked', this.navClicked);
35 },37 },
36 render: function() {38 render: function() {
37 // if custom menu is not defined, render a default menu39 // if custom menu is not defined, render a default menu
49 console.log('rendering custom menu..');49 console.log('rendering custom menu..');
50 this.$el.append(this.model.get('html'));50 this.$el.append(this.model.get('html'));
51 }51 }
52 var fragment = location.hash.split('/')[1];
53 var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
54 if(!fragment) {
55 pos = 0;
56 }
57 $(this.$links[pos]).addClass('active');
52 },58 },
53 populate: function() {59 populate: function() {
54 var item_template = _.template($('#nav-item-template').html());60 var item_template = _.template($('#nav-item-template').html());
66 }));66 }));
67 }, this);67 }, this);
68 this.$links = $('.nav li');68 this.$links = $('.nav li');
69 //console.log(this.$links[0]);
70 $(this.$links[0]).addClass('active');
71 },69 },
72 navClicked: function(event) {70 navClicked: function(event) {
73 console.log('navClicked');
74 this.$links.removeClass('active');71 this.$links.removeClass('active');
75 $(event.currentTarget).parent().addClass('active');
72 if(!event) {
73 var fragment = location.hash.split('/')[1];
74 var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
75 if(!fragment) {
76 pos = 0;
77 }
78 $(this.$links[pos]).addClass('active');
79 }
80 else {
81 $(event.currentTarget).parent().addClass('active');
82 }
76 }83 }
77});84});
7885
79var AppRouter = Backbone.Router.extend({86var AppRouter = Backbone.Router.extend({
80 routes : {87 routes : {
81 //'index' : 'index',
82 ':page' : 'showPage'88 ':page' : 'showPage'
83 },89 },
84 /*index: function() {
85 $('.pageview').hide();
86 var id = nameIdMap['index'];
87 $('#'+id).show();
88 },*/
89 showPage: function(page) {90 showPage: function(page) {
90 $('.pageview').hide();91 $('.pageview').hide();
91 //news pages are rendered on the fly,92 //news pages are rendered on the fly,
107 else {107 else {
108 $('#navigation').show();108 $('#navigation').show();
109 }109 }
110 M.appView.navView.trigger('navclicked');
110 },111 },
111 render404: function() {112 render404: function() {
112 $('.pageview').hide();113 $('.pageview').hide();
164 var app_router = new AppRouter();164 var app_router = new AppRouter();
165 Backbone.history.start();165 Backbone.history.start();
166166
167 var startpage = M.pages.models[0].get('name');
168 app_router.navigate(startpage, {trigger: true});
167 //var startpage = M.pages.models[0].get('name');
168 //app_router.navigate(startpage, {trigger: true});
169169
170 //M.simHeir();170 //M.simHeir();
171};171};

static/js/views.js

122 render: function() {122 render: function() {
123 $('#content-container').append(this.el);123 $('#content-container').append(this.el);
124 //this.appendNavTemplate();124 //this.appendNavTemplate();
125 $(this.el).append('<h3>'+this.model.get('title')+'</h3>');
125 $(this.el).append('<div class="title">'+this.model.get('title')+'</div>');
126 var self = this;126 var self = this;
127 _.each(this.model.get('content'), function(item) {127 _.each(this.model.get('content'), function(item) {
128 var view = M.types.view[item.get('type')];128 var view = M.types.view[item.get('type')];

templates/index.html

1414
15 <link rel="stylesheet" href="/static/css/normalize.css">15 <link rel="stylesheet" href="/static/css/normalize.css">
16 <link rel="stylesheet" href="/static/css/bootstrap.css">16 <link rel="stylesheet" href="/static/css/bootstrap.css">
17 <link rel="stylesheet" href="/static/css/mouchak.css">
17 <link rel="stylesheet" href="/static/css/main.css">18 <link rel="stylesheet" href="/static/css/main.css">
18 <script src="/static/js/lib/modernizr-2.6.1.min.js"></script>19 <script src="/static/js/lib/modernizr-2.6.1.min.js"></script>
19 </head>20 </head>