couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From benkeen <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: Update full page document editor
Date Thu, 25 Dec 2014 19:27:56 GMT
Github user benkeen commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/204#discussion_r22275146
  
    --- Diff: app/addons/documents/views-doceditor.js ---
    @@ -398,77 +308,89 @@ function (app, FauxtonAPI, Components, Documents, Databases, prettify)
{
                 msg: 'Save failed: ' + responseText,
                 type: 'error',
                 fade: false,
    -            clear: true,
    -            selector: '#doc .errors-container'
    +            clear: true
               });
             });
           } else if(this.model.validationError && this.model.validationError ===
'Cannot change a documents id.') {
    -          FauxtonAPI.addNotification({
    -            msg: 'Cannot save: ' + 'Cannot change a documents _id, try Duplicate doc
instead!',
    -            type: 'error',
    -            selector: '#doc .errors-container',
    -            clear:  true
    -          });
    +        FauxtonAPI.addNotification({
    +          msg: 'Cannot save. Cannot change a documents _id, try Clone Document instead!',
    +          type: 'error',
    +          clear:  true
    +        });
             delete this.model.validationError;
           } else {
             FauxtonAPI.addNotification({
    -          msg: 'Please fix the JSON errors and try again.',
    +          msg: 'Please fix the JSON errors and try saving again.',
               type: 'error',
    -          selector: '#doc .errors-container',
               clear:  true
             });
           }
         },
     
         getDocFromEditor: function () {
    -      var json;
    -
           if (!this.hasValidCode()) {
             return false;
           }
    -
    -      json = JSON.parse(this.editor.getValue());
    -
    +      var json = JSON.parse(this.editor.getValue());
           this.model.clear().set(json, {validate: true});
           if (this.model.validationError) {
             return false;
           }
    -
           return this.model;
         },
     
    -    hasValidCode: function () {
    -      var errors = this.editor.getAnnotations();
    -      return errors.length === 0;
    +    beforeRender: function () {
    +      this.uploadModal = this.setView('#upload-modal', new this.components.uploadModal({
model: this.model }));
    +      this.duplicateModal = this.setView('#duplicate-modal', new this.components.duplicateDocModal({
model: this.model }));
    +      this.confirmDeleteModal = this.setView('#delete-doc-modal', new this.components.confirmModal({
    +        text: 'Are you sure you want to delete this document?',
    +        action: this.deleteDocument
    +      }));
    +
    +      // ensures it's initialized only once
    +      this.stringEditModal = this.stringEditModal || this.setView('#string-edit-modal',
new Views.StringEditModal());
         },
     
    -    serialize: function () {
    -      return {
    -        doc: this.model,
    -        attachments: this.getAttachments()
    -      };
    +    updateValues: function () {
    +      if (this.model.changedAttributes()) {
    +        FauxtonAPI.addNotification({
    +          msg: 'Document saved successfully.',
    +          type: 'success',
    +          clear: true
    +        });
    +        this.editor.setValue(this.model.prettyJSON());
    +      }
         },
     
    -    getAttachments: function () {
    -      var attachments = this.model.get('_attachments');
    +    establish: function () {
    +      var promise = this.model.fetch(),
    +          deferred = $.Deferred(),
    +          that = this;
     
    -      if (!attachments) { return false; }
    +      promise.then(function () {
    +        deferred.resolve();
    +      }, function (xhr, reason, msg) {
    +        if (xhr.status === 404) {
    +          FauxtonAPI.addNotification({
    +            msg: 'The document does not exist',
    +            type: 'error',
    +            clear: true
    +          });
    +          that.goBack();
    +        }
    +        deferred.reject();
    +     });
     
    -      return _.map(attachments, function (att, key) {
    -        return {
    -          fileName: key,
    -          size: att.length,
    -          contentType: att.content_type,
    -          url: this.model.url() + '/' + app.utils.safeURLName(key)
    -        };
    -      }, this);
    +      return deferred;
         },
     
    -    afterRender: function () {
    -      var saveDoc = this.saveDoc,
    -          editor,
    -          model;
    +    hasValidCode: function () {
    +      var errors = this.editor.getAnnotations();
    +      return errors.length === 0;
    +    },
     
    +    afterRender: function () {
    +      _.bind(this.saveDoc, this);
    --- End diff --
    
    Thanks for the info! After playing around with it, it turns out it didn't need to be bound
at all. Will commit shortly. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message