diff --git a/static/scripts/app/models/device.js b/static/scripts/app/models/device.js index d9dd25c45d..fe781169b5 100644 --- a/static/scripts/app/models/device.js +++ b/static/scripts/app/models/device.js @@ -27,6 +27,11 @@ define([ if (options.error) { options.error(xhr); } + }, + complete: function(xhr) { + if (options.complete) { + options.complete(xhr); + } } }); }, diff --git a/static/scripts/app/views/device.js b/static/scripts/app/views/device.js index 2a68e270e2..be1060e88b 100644 --- a/static/scripts/app/views/device.js +++ b/static/scripts/app/views/device.js @@ -15,7 +15,7 @@ define([ template: _.template($('#device-item-tmpl').html()), events: { - 'click .unlink-device': 'unlinkDevice' + 'click .unlink-device': 'unlinkDeviceWithConfirm' }, initialize: function() { @@ -66,8 +66,34 @@ define([ } }); return false; - } + }, + unlinkDeviceWithConfirm: function() { + var _this = this, + device_name = this.model.get('device_name'); + var title = gettext('Unlink device'); + var content = gettext('Are you sure you want to unlink this device?'); + + var yesCallback = function () { + _this.model.unlink({ + success: function() { + _this.remove(); + + var msg = gettext("Successfully unlink %(name)s.") + .replace('%(name)s', Common.HTMLescape(device_name)); + Common.feedback(msg, 'success'); + }, + error: function(xhr) { + Common.ajaxErrorHandler(xhr); + }, + complete: function() { + $.modal.close(); + } + }); + return false; + }; + Common.showConfirm(title, content, yesCallback); + } }); return DeviceView;