"use strict"; angular.module('app.service') .factory('BaseTicketBridge', ['BaseBridge', 'staticData', function (BaseBridge, staticData) { /** * @name BaseTicketBridge * @constructor */ var BaseTicketBridge = function () { BaseBridge.apply(this, arguments); }; BaseTicketBridge.prototype = _.create(BaseBridge.prototype); BaseTicketBridge.prototype.constructor = BaseTicketBridge; BaseTicketBridge.prototype.loadStatusInfo = function () { return this.post('status-list').then(function (response) { var data = response.data; return { statusInfo: _.merge(_.cloneDeep(staticData.ticketStatusInfo), _.indexBy(data.statusList, 'id')), statusList: data.statusList }; }); }; /** * Read ticket data * @param ticketId * @returns {promise} */ BaseTicketBridge.prototype.read = function (ticketId) { return this.get('read', {id: ticketId}); }; /** * Save ticket data (without relations) * @param {{id: Number, description: String}} data * @returns {promise} */ BaseTicketBridge.prototype.save = function (data) { return this.post('update', data); }; BaseTicketBridge.prototype.setStatus = function (ticketId, status) { return this.post('set-status', {id: ticketId, status: status}); }; /** * Reads list for autocomplete * @param {String} type geo|tag * @param {String} ticketId * @param {String} part * @returns {promise} */ BaseTicketBridge.prototype.recommend = function (type, ticketId, part) { return this.post('recommend-' + type, {id: ticketId, part: part}); }; /** * Link ticket to specified to specified tag * @param {String} type geo|tag * @param {String} ticketId * @param {String} tagId * @returns {promise} */ BaseTicketBridge.prototype.link = function (type, ticketId, tagId) { return this.post('link-' + type, {id: ticketId, tagId: tagId}); }; /** * Unlink ticker from specified tag * @param {String} type geo|tag * @param {String} ticketId * @param {String} tagId * @returns {promise} */ BaseTicketBridge.prototype.unlink = function (type, ticketId, tagId) { return this.post('unlink-' + type, {id: ticketId, tagId: tagId}); }; BaseTicketBridge.prototype.saveAttribute = function (ticketId, tagId, value) { return this.post('save-attribute', {id: ticketId, tagId: tagId, value: value}); }; BaseTicketBridge.prototype.saveGeoAttribute = function (ticketId, tagId, value) { return this.post('save-geo-attribute', {id: ticketId, tagId: tagId, value: value}); }; /** * Read ticket data * @param {Number} ticketId * @param {?Object} params * @returns {promise} */ BaseTicketBridge.prototype.newRead = function (ticketId, params) { return this.get('new-read', angular.extend({id: ticketId}, params || {})); }; return BaseTicketBridge; }]);