lundi 23 mars 2015

Ember send rest after other rests ended

I have action where i send information with attachments. If information have files they are sended thru function uploadInformationImage (rest) to server and this function returs their id in database. main function is sending rest data to store information to database.


But information is saved before files uploaded. How can i save information AFTER uploading files?



actions: {

addInformation: function() {
var that = this;
var title = $('#title1').val();
var information = '';
var blocksInOrder = $("#body_container").sortable("toArray");

blocksInOrder.forEach(function (item) {
Ember.RSVP.all([

that.uploadInformationImage(item).then(function (response) {

return response['document']['id'];

})

]).then(function (docId) {

information += '<p class="' + blocktype + '"><a href="' + docUrl + '" target="_blank">Download file</a></p>';

});

});


var dataObject = { 'title': title, 'information': information };
Ember.$.ajax({
url: ENV.apiHost + "/api/informations/add_new",
type: 'POST',
contentType: "application/json",
data: JSON.stringify(dataObject)

});




Aucun commentaire:

Enregistrer un commentaire