Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/204#discussion_r22097350
  
    --- Diff: app/addons/documents/views-doceditor.js ---
    @@ -398,77 +307,88 @@ 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 () {
    +      var that = this;
    +
    +      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: that.deleteDocument
    +      }));
         },
     
    -    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 () {
    +      var saveDoc = this.saveDoc;
    --- End diff --
    
    This needs to change to use `_.bind`


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to