Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Page management

  • Loading branch information...
commit 6030e17e9195f39ce62209c3072ab69132214629 1 parent 03db44c
@fakedarren authored
View
36 backend/controllers/backend/content.js
@@ -36,7 +36,7 @@ api = {
method: 'get'
},
updatePage: {
- url: '/cms/pages',
+ url: '/cms/pages/:id',
method: 'put'
},
deletePage: {
@@ -117,15 +117,29 @@ api = {
},
readPage: function(req, res){
- res.json({
- id: req.params.id,
- title: 'My Page'
+ var pages = mongoose.model('pages'),
+ query;
+
+ query = {
+ _id: req.params.id
+ };
+
+ pages.findOne(query, function(err, docs){
+ res.json(docs);
});
},
updatePage: function(req, res){
- res.statusCode = 200;
- res.send("OK\n");
+ var query = {
+ _id: req.params._id
+ };
+
+ Page.findOneAndUpdate(query, {
+ title: req.params.title
+ }, function(err){
+ res.statusCode = 200;
+ res.send("OK\n");
+ });
},
deletePage: function(req, res){
@@ -136,7 +150,7 @@ api = {
readAllGrids: function(req, res){
var grids = mongoose.model('grids');
- grids.find({}, function(err, docs){
+ grids.findOne({}, function(err, docs){
res.json(docs);
});
},
@@ -168,6 +182,10 @@ module.exports = _.merge(api, {
url: '/cms/content/new-page',
method: 'get'
},
+ editPage: {
+ url: '/cms/content/pages/:id',
+ method: 'get'
+ },
newSection: {
url: '/cms/content/new-section',
method: 'get'
@@ -194,6 +212,10 @@ module.exports = _.merge(api, {
res.render('backend/content/new-page');
},
+ editPage: function(req, res){
+ res.render('backend/content/edit-page');
+ },
+
newSection: function(req, res){
res.render('backend/content/new-section');
},
View
4 public/backend/css/backend.css
@@ -4,4 +4,8 @@ body {
#images-library .media-object {
max-width: 100px;
+}
+
+.table-col-small {
+ width: 60px;
}
View
16 public/backend/js/app/helpers/URL.js
@@ -0,0 +1,16 @@
+define([
+], function(
+){
+
+ return {
+
+ last: function(){
+ var url = window.location.href,
+ parts = url.split('/');
+
+ return parts[parts.length - 1];
+ }
+
+ }
+
+});
View
11 public/backend/js/app/models/Page.js
@@ -5,11 +5,14 @@ define([
){
return Backbone.Model.extend({
- url: '/cms/pages',
+ url: function(){
+ return this.isNew() ? '/cms/pages' : '/cms/pages/' + this.id;
+ },
+
+ idAttribute: '_id',
+
defaults: {
- id: null,
- sectionID: '',
- title: ''
+ _id: null
}
});
View
13 public/backend/js/app/pages-edit.js
@@ -0,0 +1,13 @@
+require([
+ 'Bootstrap',
+ 'views/PageEdit'
+], function(
+ Bootstrap,
+ PageEditView
+){
+
+ new PageEditView({
+ el: '#pages-edit-content'
+ })
+
+});
View
44 public/backend/js/app/views/PageEdit.js
@@ -0,0 +1,44 @@
+define([
+ 'Backbone',
+ 'Handlebars',
+ 'helpers/URL',
+ 'models/Page'
+], function(
+ Backbone,
+ Handlebars,
+ URL,
+ Page
+){
+
+ return Backbone.View.extend({
+
+ events: {
+ 'submit #edit-page': 'update'
+ },
+
+ initialize: function(){
+ this.model = new Page({
+ _id: URL.last()
+ });
+ this.model.fetch();
+ this.model.on('sync', this.render, this);
+ },
+
+ render: function(){
+ var source = $('#template-page-edit-form').html(),
+ template = Handlebars.compile(source),
+ html = template(this.model.toJSON());
+
+ this.$el.html(html);
+ },
+
+ update: function(evt){
+ evt.preventDefault();
+
+ this.model.set('title', $('#edit-page [type=text]').val());
+ this.model.save();
+ }
+
+ });
+
+});
View
31 views/backend/content/edit-page.jade
@@ -0,0 +1,31 @@
+extends ../backend-layout
+
+block content
+
+ div.container
+ div.row
+
+ div.span12#pages-edit-content
+
+block scripts
+ script(src="/backend/js/app/pages-edit.js")
+
+block templates
+
+ script#template-page-edit-form(type="text/template")
+ div.page-header
+ h1 Edit page '{{this.title}}'
+
+ form.form-horizontal#edit-page(action="#")
+ fieldset
+ div.control-group
+ label.control-label Section
+ div.controls
+ select
+ div.control-group
+ label.control-label Page Name
+ div.controls
+ input(type="text", value="{{this.title}}")
+ div.control-group
+ div.controls
+ button.btn.btn-primary(type="submit") Edit Page
View
22 views/backend/content/pages.jade
@@ -37,8 +37,22 @@ block templates
div.tab-content
{{#each this}}
div.tab-pane(id="section-\{{this._id}}")
- ul
- {{#each pages}}
- li {{this.title}}
- {{/each}}
+
+ table.table.table-striped.table-hover.table-condensed
+ thead
+ tr
+ th Title
+ th.table-col-small Edit
+ th.table-col-small Remove
+ tbody
+ {{#each pages}}
+ tr
+ td {{this.title}}
+ td
+ a.icon-edit.pull-right(href="/cms/content/pages/{{this._id}}")
+ span.hide Edit
+ td
+ a.icon-remove.pull-right(href="#")
+ span.hide Remove
+ {{/each}}
{{/each}}
Please sign in to comment.
Something went wrong with that request. Please try again.