calling 'save' from an action button in a record view (not edit view)

Hi,

I've added an action button to a custom meeting detail view - The plan is that it updates a couple of fields (checkbox, geolocation and a datetime field) and saves this back to the server. I used model.set() for this.

I had previously tried the model.save and model.asyncSave calls but as, I assume, it was not in an edit view, it saved the initial values.

To work around this, I used API calls to update the server App.api.call('update', App.api.buildURL(.....)) with custom sucess and error alerts.

However, it does mean corresponding listviews are slow to update and error handling for loss of internet service is problematic. Ideally, I'd like to use the model.save call or similar. I'm afraid I do not want to bring up the editview. 

Any pointers on how to set up the model.save() parameters in detailview so this works?

Thanks

  • Hi Steven±

    I don't think there is easy and fast way you can achieve this functionality
    You will have to dive to SDK source code and implement your custom logic in your custom DetailView

    Please use edit-view.js contents for reference on how we do model validation/saving/handling backup/etc

  • Hi - I did manage to get it to work in the end. So if anyone needs anything similar:

    var self = this;
    model.set('field1', 'new_value1');
    model.set('field2', 'new_value2');
    model.set('field3', 'new_value3');
    model.set('field4', 'new_value4');
    model.save({},
            {
                    "fields": ["field1", "field2", "field3", "field4"],
                    "modelBackup": model,
                    "relate": false,
                    success: _.bind(function (updateResponse) {
                            app.alert.show('message-off-id', {
                                    level: 'success',
                                    messages: 'Updated',
                                    autoClose: true
                            });
                    }, self),
                    error: _.bind(function (updateError) {
                            model.set('field1', 'old_value1');
                            model.set('field2', 'old_value2');
                            model.set('field3', 'old_value3');
                            model.set('field4', 'old_value4');
                            app.alert.show('error-of-id', {
                                    level: 'error',
                                    messages: 'Failed',
                                    autoClose: false
                            });
                            return false;
                    }, self)
            });