How to use the phoenix/controllers/promise.create function in phoenix

To help you get started, we’ve selected a few phoenix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alphasights / ember-scrollable / app / services / interaction-cancellation.js View on Github external
cancel: function(model, successCallback, withdrawFromCompliance = false) {
    var params = `withdraw_from_compliance=${withdrawFromCompliance}`;

    var requestPromise = PromiseController.create({
      promise: request({
        url: `${EmberENV.apiBaseUrl}/interests/${model.get('id')}?${params}`,
        type: 'DELETE'
      }).then(successCallback, () => {
        notify('The interaction could not be cancelled.', 'error');
      })
    });

    return requestPromise;
  }
});
github alphasights / ember-scrollable / app / controllers / dashboard / interaction.js View on Github external
amendCompletion: function() {
      let completionForm = this.get('completionForm');
      let completion = completionForm.get('model');
      let requestParams = `interaction_completion_id=${completion.get('id')}`;

      PromiseController.create({
        promise: request({
          url: `${EmberENV.apiBaseUrl}/interaction_completion_amendments?${requestParams}`,
          type: 'POST'
        }).then((response) => {
          this.store.pushPayload(response);
          let newCompletion = this.store.createRecord('interactionCompletion', {
            interaction: this.get('model')
          });
          this.set('completionForm.model', newCompletion);
          completionForm.set('editingDisabled', false);
        }, () => {
          notify('There has been an error amending the interaction.', 'error');
        })
      });
    },
github alphasights / ember-scrollable / app / controllers / dashboard / interaction.js View on Github external
reschedule: function() {
      var model = this.get('model');

      this.transitionToRoute('dashboard.schedule-interaction', this.get('model.id'));
      model.set('scheduledCallTime', null);
      model.set('actioned', false);

      this.set('requestPromise', PromiseController.create({
        promise: model.save().then(() => {
          this.get('dashboard').propertyDidChange('scheduledInteractions');
          this.get('dashboard').propertyDidChange('interactionsToSchedule');
        }, () => {
          notify('There has been an error rescheduling the interaction.', 'error');
          model.rollback();
          this.transitionToRoute('dashboard.interaction', this.get('model.id'));
        })
      }));
    },
github alphasights / ember-scrollable / app / components / as-quick-jump.js View on Github external
_queryDidChange: function() {
    var query = this.get('query');

    if (query && query.length > 2) {
      var requestPromise = PromiseController.create({
        promise: request(`${EmberENV.apiBaseUrl}/quick_jumps`, {
          data: { q: query }
        }).then(response => {
          if (requestPromise !== this.get('requestPromise')) { return; }

          this.set('results', _.chain(response.responses)
            .map(function(response) {
              if (Ember.isBlank(response.hits)) {
                return [];
              } else {
                return response.hits.hits;
              }
            })
            .flatten()
            .value()
          );
github alphasights / ember-scrollable / app / forms / form.js View on Github external
save: function() {
    if (this.get('isValid')) {
      this.setPersistedValues();

      var requestPromise = PromiseController.create({
        promise: this.get('model').save().catch(() => {
          if (this.get('model.errors.length') > 0) {
            this.set('errors', this.get('model.errors'));
          } else {
            notify(this.get('genericErrorMessage'), 'error');
          }

          return Ember.RSVP.Promise.reject();
        })
      });

      this.set('requestPromise', requestPromise);

      return requestPromise;
    } else {
      return Ember.RSVP.Promise.reject('Form validation failed');