From 5afefd7b21ebdd315461bc44ca43171e73727706 Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 12 Sep 2014 00:36:19 +0100 Subject: [PATCH] CouchDB sync provider part 2 --- bower.json | 3 +- couchdb/setup-db.js | 13 +- public/res/core.js | 2 +- public/res/html/bodyEditor.html | 59 +++--- public/res/layout.js | 6 +- public/res/main.js | 3 +- public/res/providers/couchdbProvider.js | 103 +++++++--- public/res/styles/alertify.less | 239 ++++++++++++++++++++++++ public/res/styles/main.less | 40 ++-- public/res/themes/default.less | 2 +- 10 files changed, 395 insertions(+), 75 deletions(-) create mode 100644 public/res/styles/alertify.less diff --git a/bower.json b/bower.json index 13bb431b..c12e07d7 100644 --- a/bower.json +++ b/bower.json @@ -32,7 +32,8 @@ "js-sequence-diagrams": "https://github.com/benweet/js-sequence-diagrams.git#d60c973aa0ff148dc588c7ceee0b41e59dff3f9f", "flowchart": "https://github.com/adrai/flowchart.js.git#~1.2.10", "monetizejs": "~0.2.0", - "MathJax": "~2.4.0" + "MathJax": "~2.4.0", + "alertify.js": "https://github.com/fabien-d/alertify.js.git#fc2e06fa39873363dda199204b8544119ab060bf" }, "main": [ "/public/res/main.js", diff --git a/couchdb/setup-db.js b/couchdb/setup-db.js index 00565dc4..6cd28dc4 100644 --- a/couchdb/setup-db.js +++ b/couchdb/setup-db.js @@ -18,6 +18,15 @@ var validate = function(newDoc) { if(!newDoc._id.match(/[a-zA-Z0-9]{24}/)) { throw({forbidden: 'Invalid ID format.'}); } + if(newDoc._deleted) { + if(newDoc.updated !== undefined || + newDoc.tags !== undefined || + newDoc.title !== undefined || + newDoc._attachments !== undefined) { + throw({forbidden: 'Deleted document must be empty.'}); + } + return; + } if(toString.call(newDoc.updated) !== '[object Number]') { throw({forbidden: 'Update time must be an integer.'}); } @@ -65,7 +74,9 @@ var validate = function(newDoc) { }; var byUpdate = function(doc) { - emit(doc.updated, null); + if(!doc.tags || !doc.tags.length) { + emit(doc.updated, null); + } }; var byTagAndUpdate = function(doc) { diff --git a/public/res/core.js b/public/res/core.js index 09894979..2cf5e6a4 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -393,7 +393,7 @@ define([ editor.focus(); // Revert to current theme when settings modal is closed applyTheme(window.theme); - }).on('keyup', '.modal', function(e) { + }).on('keypress', '.modal', function(e) { // Handle enter key in modals if(e.which == 13 && !$(e.target).is("textarea")) { $(this).find(".modal-footer a:last").click(); diff --git a/public/res/html/bodyEditor.html b/public/res/html/bodyEditor.html index dd2be731..ec971711 100644 --- a/public/res/html/bodyEditor.html +++ b/public/res/html/bodyEditor.html @@ -89,7 +89,7 @@
Synchronize
- Open/save in the Cloud + Open/Save in the Cloud