You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/07/25 17:21:39 UTC
[2/2] git commit: updated refs/heads/master to ca7fba4
Fauxton Fix: Get new doc working again
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ca7fba46
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ca7fba46
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ca7fba46
Branch: refs/heads/master
Commit: ca7fba467bac6ed1fafd336d7f19ddb26574b3f6
Parents: c83b5e4
Author: Garren Smith <ga...@gmail.com>
Authored: Thu Jul 25 17:20:37 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Thu Jul 25 17:20:37 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/main.js | 13 ++++-
src/fauxton/app/modules/documents/resources.js | 7 ++-
src/fauxton/app/modules/documents/routes.js | 60 +++++++++++---------
src/fauxton/app/modules/documents/views.js | 13 ++++-
.../app/templates/documents/upload_modal.html | 2 +-
5 files changed, 63 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca7fba46/src/fauxton/app/main.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/main.js b/src/fauxton/app/main.js
index c06b0c4..fba4f6e 100644
--- a/src/fauxton/app/main.js
+++ b/src/fauxton/app/main.js
@@ -22,8 +22,17 @@ function(app, Router) {
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + app.root;
+ // Ensure the root is part of the anchor href, meaning it's relative.
+ if (href.prop && href.prop.slice(0, root.length) === root) {
+ // Stop the default event to ensure the link will not cause a page
+ // refresh.
+ evt.preventDefault();
+
+ // `Backbone.history.navigate` is sufficient for all Routers and will
+ // trigger the correct events. The Router's internal `navigate` method
+ // calls this anyways. The fragment is sliced from the root.
+ Backbone.history.navigate(href.attr, true);
+ }
- evt.preventDefault();
- Backbone.history.navigate(href.attr, true);
});
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca7fba46/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index bece386..0ec44ea 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -172,6 +172,10 @@ function(app, FauxtonAPI) {
url: '/' + this.database.id + '/' + this.id,
headers: {Destination: copyId}
});
+ },
+
+ isNewDoc: function () {
+ return this.get('_rev') ? false : true;
}
});
@@ -235,7 +239,8 @@ function(app, FauxtonAPI) {
});
return deferred.promise();
- }
+ },
+
});
Documents.AllDocs = Backbone.Collection.extend({
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca7fba46/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index c82cfab..9e68ae3 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -32,17 +32,11 @@ function(app, FauxtonAPI, Documents, Databases) {
var databaseName = options[0], docID = options[1];
this.database = this.database || new Databases.Model({id: databaseName});
- if (docID === "new"){
- this.doc = new Documents.NewDoc(null,{
- database: this.database
- });
- } else {
- this.doc = new Documents.Doc({
- _id: docID
- }, {
- database: this.database
- });
- }
+ this.doc = new Documents.Doc({
+ _id: docID
+ }, {
+ database: this.database
+ });
this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({
selected: "code_editor",
@@ -92,8 +86,8 @@ function(app, FauxtonAPI, Documents, Databases) {
duplicateDoc: function (newId) {
var doc = this.doc,
- docView = this.docView,
- database = this.database;
+ docView = this.docView,
+ database = this.database;
doc.copy(newId).then(function () {
doc.set({_id: newId});
@@ -117,6 +111,28 @@ function(app, FauxtonAPI, Documents, Databases) {
}
});
+ var NewDocEditorRouteObject = DocEditorRouteObject.extend({
+ initialize: function (route, masterLayout, options) {
+ var databaseName = options[0];
+
+ this.database = this.database || new Databases.Model({id: databaseName});
+ this.doc = new Documents.NewDoc(null,{
+ database: this.database
+ });
+
+ this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({
+ selected: "code_editor",
+ model: this.doc
+ }));
+
+ },
+
+ routes: {
+ "database/:database/new": "code_editor"
+ },
+
+ });
+
var DocumentsRouteObject = FauxtonAPI.RouteObject.extend({
layout: "with_tabs_sidebar",
@@ -257,7 +273,7 @@ function(app, FauxtonAPI, Documents, Databases) {
updateAllDocsFromView: function (event) {
var view = event.view,
- ddoc = event.ddoc;
+ ddoc = event.ddoc;
this.data.indexedDocs = new Documents.IndexCollection(null, {
database: this.data.database,
@@ -276,8 +292,8 @@ function(app, FauxtonAPI, Documents, Databases) {
updateAllDocsFromPreview: function (event) {
var view = event.view,
- rows = event.rows,
- ddoc = event.ddoc;
+ rows = event.rows,
+ ddoc = event.ddoc;
this.data.indexedDocs = new Documents.PouchIndexCollection(null, {
database: this.data.database,
@@ -345,17 +361,7 @@ function(app, FauxtonAPI, Documents, Databases) {
});
- /* Documents.Routes = {
- "database/:database/_design%2F:doc": function(database, doc) {
- var docID = "_design/"+doc;
- return codeEditorCallback(database, docID);
- },
-
- "database/:database/new": newDocCodeEditorCallback,
- "database/:database/new_view": newViewEditorCallback,
- };*/
-
- Documents.RouteObjects = [DocEditorRouteObject, DocumentsRouteObject, ChangesRouteObject];
+ Documents.RouteObjects = [DocEditorRouteObject, NewDocEditorRouteObject, DocumentsRouteObject, ChangesRouteObject];
return Documents;
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca7fba46/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index aa62357..2ef4d41 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -160,7 +160,10 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
type: 'POST',
beforeSend: this.beforeSend,
uploadProgress: this.uploadProgress,
- success: this.success
+ success: this.success,
+ error: function () {
+ console.log('ERR on upload', arguments);
+ }
});
},
@@ -329,6 +332,13 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
upload: function (event) {
event.preventDefault();
+ if (this.model.isNewDoc()) {
+ FauxtonAPI.addNotification({
+ msg: 'Please save the document before uploading an attachment.',
+ type: 'warning'
+ });
+ return;
+ }
this.uploadModal.showModal();
},
@@ -347,6 +357,7 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
var selected = this.selected;
return {
doc: this.model,
+ isNewDoc: this.model.isNewDoc(),
isSelectedClass: function(item) {
return item && item === selected ? "active" : "";
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca7fba46/src/fauxton/app/templates/documents/upload_modal.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/upload_modal.html b/src/fauxton/app/templates/documents/upload_modal.html
index d9cdbb0..08a14a6 100644
--- a/src/fauxton/app/templates/documents/upload_modal.html
+++ b/src/fauxton/app/templates/documents/upload_modal.html
@@ -26,7 +26,7 @@ the License.
so it's not necessary to save the document after the upload.
</p>
<input id="_attachments" type="file" name="_attachments">
- <input id="_rev" type="hidden" name="_rev" value="<%= _rev %>" >
+ <input id="_rev" type="hidden" name="_rev" value="" >
<br/>
</form>