~stephen-stewart/snapweb/hide-installer-for-oem

« back to all changes in this revision

Viewing changes to www/src/js/models/snap.js

  • Committer: Snappy Tarmac
  • Author(s): Stephen Stewart
  • Date: 2015-05-06 23:51:42 UTC
  • mfrom: (110.3.4 json-responses)
  • Revision ID: snappy_tarmac-20150506235142-mdgnhx88p32f08cx
handle 500's, use the response to set the model state by stephen-stewart approved by sergiusens

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
var _ = require('lodash');
4
4
var Backbone = require('backbone');
 
5
var Radio = require('backbone.radio');
5
6
var CONF = require('../config.js');
 
7
var chan = Radio.channel('root');
6
8
 
7
9
/** Snap Model
8
10
 *
29
31
 
30
32
  initialize: function() {
31
33
 
32
 
    this.on('error', function(model, response, opts) {
33
 
      var httpStatus = opts.xhr.status;
34
 
    });
35
 
 
36
34
    this.on('add sync', function(model, response, opts) {
37
35
      var status = model.get('status') || opts.xhr.status;
38
36
 
39
 
      if (status === 202 ||
40
 
          status === CONF.INSTALL_STATE.INSTALLING ||
41
 
          status === CONF.INSTALL_STATE.UNINSTALLING) {
 
37
      if (
 
38
        status === CONF.INSTALL_STATE.INSTALLING ||
 
39
        status === CONF.INSTALL_STATE.UNINSTALLING
 
40
      ) {
42
41
        _.delay(function(model) {
43
42
          model.fetch();
44
43
        }, CONF.INSTALL_POLL_WAIT, model);
47
46
    });
48
47
 
49
48
    this.on('error', function(model, response, opts) {
50
 
      var status = model.get('status') || opts.xhr.status;
51
 
      model.set({
52
 
        'status': model.previous('status'),
53
 
        'message': response.statusText
54
 
      });
 
49
      this.set(this.parse(response.responseJSON));
 
50
      chan.command('alert:error', model);
55
51
    });
56
52
 
 
53
    this.on('change:message', this.onMessageChange);
 
54
 
57
55
    this.on('add change:status', this.handleStatusChange);
58
56
  },
59
57
 
 
58
  onMessageChange: function(model) {
 
59
    console.log('message:', model.get('message'));
 
60
  },
 
61
 
60
62
  handleStatusChange: function(model) {
61
63
    this.setInstallActionString(model);
62
64
    this.setInstallHTMLClass(model);