summaryrefslogtreecommitdiff
path: root/addons/sms/static/src/js/message.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/sms/static/src/js/message.js')
-rw-r--r--addons/sms/static/src/js/message.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/addons/sms/static/src/js/message.js b/addons/sms/static/src/js/message.js
new file mode 100644
index 00000000000..f800563fd72
--- /dev/null
+++ b/addons/sms/static/src/js/message.js
@@ -0,0 +1,73 @@
+odoo.define('sms.model.Message', function (require) {
+"use strict";
+
+var Message = require('mail.model.Message');
+
+Message.include({
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * Retrieves the list of SMS
+ *
+ * @returns {Array} Array of Array(smsID, recipientName, smsStatus)
+ */
+ getSmsIds: function () {
+ return this._smsIds;
+ },
+ /**
+ * Retrieves the SMS status
+ *
+ * @return {string}
+ */
+ getSmsStatus: function () {
+ var self = this;
+ this._smsStatus = 'sent';
+ _.each(this._smsIds, function (sms) {
+ if (sms[2] === 'bounce' || sms[2] === 'exception') {
+ self._smsStatus = 'error';
+ }
+ });
+ return this._smsStatus;
+ },
+ /**
+ * Does the message contains at least one SMS failure
+ *
+ * @returns {boolean}
+ */
+ isError: function () {
+ return this.getSmsStatus() === 'error';
+ },
+ /**
+ * Update the status of a SMS
+ *
+ * @param {integer} smsID ID of the SMS to update
+ * @param {string} smsStatus New status of the SMS
+ */
+ setSmsStatus: function (smsID, smsStatus) {
+ var self = this;
+ var sms = _.find(self._smsIds, function (sms) {
+ return sms[0] === smsID;
+ });
+ sms[2] = smsStatus;
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ * @private
+ */
+ _setInitialData: function (data) {
+ this._super.apply(this, arguments);
+ this._smsIds = data.sms_ids;
+ if (this._smsStatus === false) {
+ this._smsStatus = 'sent';
+ }
+ },
+});
+});