diff --git a/package.json b/package.json
index 7cac3ff..a3d5fce 100755
--- a/package.json
+++ b/package.json
@@ -75,6 +75,7 @@
},
"main": "node_modules/docpad/bin/docpad-server",
"scripts": {
- "start": "node ./node_modules/docpad/bin/docpad run --port 9779"
+ "start": "node ./node_modules/docpad/bin/docpad run --port 9779",
+ "test": "bash tests/create_page_static_check.sh"
}
}
diff --git a/src/documents/index.html.coffee b/src/documents/index.html.coffee
index d376ff3..548cec6 100644
--- a/src/documents/index.html.coffee
+++ b/src/documents/index.html.coffee
@@ -67,6 +67,35 @@ aside '.app', ->
button '.button.button-cancel', ->
'Cancel'
+ section '.page-add.modal.main.show-site', ->
+ header ->
+ span '.title', -> 'Create Page'
+
+ div '.body', ->
+ form '.page-add-form', action:'', method:'PUT', ->
+ div '.field.field-title', ->
+ label -> 'Title'
+ input type:'text', placeholder:'New page', required:'required', ->
+
+ div '.field.field-path', ->
+ label -> 'Path'
+ input type:'text', value:'new-page.html.md', required:'required', ->
+
+ div '.field.field-collection', ->
+ label -> 'Type'
+ select ->
+ option -> 'pages'
+
+ div '.field.field-layout', ->
+ label -> 'Layout'
+ select ->
+ option -> 'default'
+
+ input '.button.button-save', type:'submit', value:'Create'
+
+ button '.button.button-cancel', ->
+ 'Cancel'
+
aside '.site-list-container', -> \
section '.site-list.main.show-admin', ->
diff --git a/src/documents/scripts/models/base.js.coffee b/src/documents/scripts/models/base.js.coffee
index 3ceaf6f..543d61f 100644
--- a/src/documents/scripts/models/base.js.coffee
+++ b/src/documents/scripts/models/base.js.coffee
@@ -1,5 +1,6 @@
# Import
Backbone = window.Backbone
+_ = window._
queryEngine = require('query-engine')
{wait, thrower, extractData, ignoreSync} = require('../util')
{TaskGroup} = require('taskgroup')
@@ -122,7 +123,9 @@ class Collection extends queryEngine.QueryCollection
return next(err)
# Save
- opts.model.save opts, (err) =>
+ modelOpts = _.extend({}, opts)
+ delete modelOpts.method
+ opts.model.sync modelOpts, (err) =>
# Add
return next(err) if err
@add(opts.model)
diff --git a/src/documents/scripts/models/file.js.coffee b/src/documents/scripts/models/file.js.coffee
index 62868fb..607acc8 100644
--- a/src/documents/scripts/models/file.js.coffee
+++ b/src/documents/scripts/models/file.js.coffee
@@ -21,6 +21,7 @@ class File extends Model
layout: null
author: null
site: null # The model of the site this is for
+ fileCollection: null # The collection this file should be synced through
constructor: ->
@metaAttributes ?= ['title', 'content', 'date', 'author', 'layout']
@@ -39,8 +40,10 @@ class File extends Model
site = file.get('site')
siteUrl = site.get('url')
siteToken = site.get('token')
+ fileCollection = file.get('fileCollection')
+ fileCollectionName = fileCollection?.get?('name') or file.get('collection') or 'database'
- return "#{siteUrl}/restapi/collection/database/#{fileRelativePath}?securityToken=#{siteToken}"
+ return "#{siteUrl}/restapi/collection/#{fileCollectionName}/#{fileRelativePath}?securityToken=#{siteToken}"
reset: ->
data = {}
@@ -52,16 +55,18 @@ class File extends Model
@
toJSON: ->
- return _.omit(super(), ['site'])
+ return _.omit(super(), ['site', 'fileCollection'])
parse: ->
# Prepare
data = super
+ data ?= {}
# Apply meta directly
- for own key,value of data.meta
- data[key] = value
- delete data.meta
+ if data.meta
+ for own key,value of data.meta
+ data[key] = value
+ delete data.meta
# Fix date
data.date = new Date(data.date) if data.date
@@ -100,4 +105,4 @@ File.collection = new Files([], {
})
# Export
-module.exports = {File, Files}
\ No newline at end of file
+module.exports = {File, Files}
diff --git a/src/documents/scripts/views/app.js.coffee b/src/documents/scripts/views/app.js.coffee
index 926654e..1e8de16 100644
--- a/src/documents/scripts/views/app.js.coffee
+++ b/src/documents/scripts/views/app.js.coffee
@@ -2,6 +2,7 @@
$ = window.$
{View, Route} = require('./base')
{Site} = require('../models/site')
+{File} = require('../models/file')
{SiteListItem} = require('./site')
{FileEditItem, FileListItem} = require('./file')
{wait, thrower} = require('../util')
@@ -26,6 +27,12 @@ class App extends View
'.content-row-file': '$files'
'.content-row-site': '$sites'
'.page-edit-container': '$pageEditContainer'
+ '.page-add.modal': '$pageAddModal'
+ '.page-add-form': '$pageAddForm'
+ '.page-add .field-title :input': '$pageAddTitle'
+ '.page-add .field-path :input': '$pageAddPath'
+ '.page-add .field-collection :input': '$pageAddCollection'
+ '.page-add .field-layout :input': '$pageAddLayout'
events:
'click .sites .content-cell-name': 'clickSite'
@@ -36,8 +43,16 @@ class App extends View
'click .menu .button': 'clickMenuButton'
'click .button-login': 'clickLogin'
'click .button-add-site': 'clickAddSite'
+ 'click .button-add-document': 'clickAddDocument'
+ 'keyup .page-add .field-title :input': 'changePageAddTitle'
+ 'change .page-add .field-title :input': 'changePageAddTitle'
+ 'keyup .page-add .field-path :input': 'changePageAddPath'
+ 'change .page-add .field-path :input': 'changePageAddPath'
+ 'change .page-add .field-collection :input': 'changePageAddCollection'
'submit .site-add-form': 'submitSite'
'click .site-add-form .button-cancel': 'submitSiteCancel'
+ 'submit .page-add-form': 'submitDocument'
+ 'click .page-add-form .button-cancel': 'submitDocumentCancel'
constructor: ->
# Super
@@ -309,6 +324,150 @@ class App extends View
# Chain
@
+ getPageAddCollections: ->
+ customFileCollections = @currentSite?.get('customFileCollections')
+ collections = []
+ customFileCollections?.each (customFileCollection) ->
+ name = customFileCollection.get('name')
+ collections.push(customFileCollection) unless name in ['layouts', 'authors']
+ collections.push(@currentFileCollection) if collections.length is 0 and @currentFileCollection
+ return collections
+
+ getPageAddLayouts: ->
+ return @currentSite?.getCollectionFiles('layouts')?.models or []
+
+ getPageAddSlug: (title) ->
+ slug = (title or '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
+ return slug or 'new-page'
+
+ getPageAddDefaultPath: ->
+ title = @$pageAddTitle.val() or ''
+ "#{@getPageAddSlug(title)}.html.md"
+
+ fillPageAddForm: ->
+ collections = @getPageAddCollections()
+ layouts = @getPageAddLayouts()
+
+ @$pageAddCollection.empty()
+ for collection in collections
+ @$pageAddCollection.append $('