lundi 19 octobre 2015

Restore Ember Data

I have an application that displays a table of data with a publish button. You can select the rows and then click to publish them. The selected data is packaged up in the necessary json format and sent via ajax to do a quick check that none of the data has any dependencies. If there are dependencies then it returns an error message and a list of those dependencies. You must then select the dependencies plus the parent and try to publish again. The problem is after manipulating the data once to the correct json format to send for the first call, the data then seems to be unusable and missing in the model altogether...I can make the call once but not again. Any help is much appreciated! Here is my controller:

export default Ember.ArrayController.extend({
actions: {

    publishSubmit: function(){

        var checkedItems = this.get('model').filterBy('isChecked', true);

        if(checkedItems.length > 0){

            this.send('dependencyCheck', checkedItems);
        }
        else{
            this.announce.error('No items selected for publish.');
        }
    },

    dependencyCheck: function(items){
        var _this = this, data = [];

        items.forEach(function(item){
            delete item._data.isChecked;
            delete item._data.sortByDate;
            item._data.publisherId = item._data.id;
            delete item._data.id;
            item._data.updatedDate = null;
            data.push(item._data);
        });

        //data formating(required)
        data = _this.capitalizeAll(data);
        data = JSON.stringify(data);

        console.log(data);

        Ember.$.ajax({
            type: 'POST', 
            dataType: 'json',
            contentType: 'application/json',
            beforeSend : function(xhr) {
              xhr.setRequestHeader("Token", sessionStorage.getItem('authToken'));
            },
            url: config.host + '/AssessmentPublishService/DependentPublishableItems',
            data: data
        }).then(function(dependencies){

            var processDependencies = _this.processResponseData(dependencies);

            if(dependencies.Status === "Success"){

                console.log("ProccessD");
                console.log(processDependencies);

                return JSON.stringify(processDependencies);
            }
            else{
                return this.announce.error('Failed to process.');
            }
        });
    }
}
}




Aucun commentaire:

Enregistrer un commentaire