1 /*jshint indent:2, curly:true, eqeqeq:true, immed:true, latedef:true,
2 newcap:true, noarg:true, regexp:true, undef:true, strict:true, trailing:true,
4 /*global Globalize:true, XT:true, XM:true, Backbone:true, _:true, console:true */
14 XM.IncidentCategory = XM.Document.extend({
15 /** @scope XM.IncidentCategory.prototype */
17 recordType: 'XM.IncidentCategory',
21 enforceUpperKey: false,
40 XM.IncidentSeverity = XM.Document.extend({
41 /** @scope XM.IncidentSeverity.prototype */
43 recordType: 'XM.IncidentSeverity',
47 enforceUpperKey: false,
65 XM.IncidentResolution = XM.Document.extend({
66 /** @scope XM.IncidentResolution.prototype */
68 recordType: 'XM.IncidentResolution',
72 enforceUpperKey: false,
89 A mixin shared by incident models that share common incident status
93 /** @scope XM.IncidentStatus */
96 Returns incident status as a localized string.
100 getIncidentStatusString: function () {
102 status = this.get('status');
103 if (status === K.NEW) {
106 if (status === K.FEEDBACK) {
107 return '_feedback'.loc();
109 if (status === K.CONFIRMED) {
110 return '_confirmed'.loc();
112 if (status === K.ASSIGNED) {
113 return '_assigned'.loc();
115 if (status === K.RESOLVED) {
116 return '_resolved'.loc();
118 if (status === K.CLOSED) {
119 return '_closed'.loc();
123 isActive: function () {
125 status = this.get('status');
126 return (status !== K.CLOSED);
136 XM.Incident = XM.Document.extend({
137 /** @scope XM.Incident.prototype */
139 recordType: 'XM.Incident',
141 nameAttribute: "number",
143 numberPolicy: XM.Document.AUTO_NUMBER,
145 defaults: function () {
147 owner: XM.currentUser,
148 status: XM.Incident.NEW,
149 isPublic: XT.session.getSettings().get("IncidentPublicDefault"),
154 // ..........................................................
158 bindEvents: function () {
159 XM.Document.prototype.bindEvents.apply(this, arguments);
160 this.on('change:assignedTo', this.assignedToDidChange);
163 assignedToDidChange: function (model, value, options) {
164 if (value && this.get("status") !== XM.Incident.RESOLVED && this.get("status") !== XM.Incident.CLOSED) {
165 this.set('status', XM.Incident.ASSIGNED);
169 validate: function () {
171 if (this.get('status') === K.ASSIGNED && !this.get('assignedTo')) {
172 return XT.Error.clone('xt2001');
174 return XM.Document.prototype.validate.apply(this, arguments);
179 // Add support for sending email
180 XM.Incident = XM.Incident.extend(XM.EmailSendMixin);
181 XM.Incident = XM.Incident.extend({
182 emailDocumentName: "_incident".loc(),
183 emailProfileAttribute: "category.emailProfile",
184 emailStatusMethod: "getIncidentStatusString"
187 _.extend(XM.Incident, {
188 /** @scope XM.Incident */
252 // Incident status mixin
253 XM.Incident = XM.Incident.extend(XM.IncidentStatus);
255 // email-relevant mixin
256 XM.Incident = XM.Incident.extend({
258 getHistoryString: function () {
259 var history = this.get('history'),
262 if (history.length) {
263 // Sort by date ascending
264 history.comparator = function (a, b) {
265 var aval = a.get('created'),
266 bval = b.get('created');
267 return XT.date.compare(aval, bval);
270 _.each(history.models, function (model) {
271 var offset = (new Date()).getTimezoneOffset(), // hack: the data should include timezone
272 created = new Date(model.get('created').getTime() + offset * 60 * 1000),
273 fdate = Globalize.format(created, "d"),
274 ftime = Globalize.format(created, "t");
275 if (!isFirst) { ret += "\n"; }
277 ret += (fdate + ' ' + ftime).rightPad(' ', 24);
278 ret += model.get('createdBy').slice(0, 17).rightPad(' ', 18);
279 ret += model.get('description');
291 XM.IncidentComment = XM.Comment.extend({
292 /** @scope XM.IncidentComment.prototype */
294 recordType: 'XM.IncidentComment',
298 defaults: function () {
299 var result = XM.Comment.prototype.defaults.apply(this, arguments),
300 publicDefault = XT.session.getSettings().get('IncidentPublicDefault');
302 result.isPublic = publicDefault || false;
311 @extends XM.Characteristic
313 XM.IncidentCharacteristic = XM.CharacteristicAssignment.extend({
314 /** @scope XM.IncidentCharacteristic.prototype */
316 recordType: 'XM.IncidentCharacteristic',
327 XM.IncidentAlarm = XM.Alarm.extend({
328 /** @scope XM.IncidentAlarm.prototype */
330 recordType: 'XM.IncidentAlarm'
339 XM.IncidentHistory = XM.Model.extend({
340 /** @scope XM.IncidentAccount.prototype */
342 recordType: 'XM.IncidentHistory'
351 XM.IncidentAccount = XM.Model.extend({
352 /** @scope XM.IncidentAccount.prototype */
354 recordType: 'XM.IncidentAccount',
356 isDocumentAssignment: true
365 XM.IncidentContact = XM.Model.extend({
366 /** @scope XM.IncidentContact.prototype */
368 recordType: 'XM.IncidentContact',
370 isDocumentAssignment: true
379 XM.IncidentItem = XM.Model.extend({
380 /** @scope XM.IncidentItem.prototype */
382 recordType: 'XM.IncidentItem',
384 isDocumentAssignment: true
393 XM.IncidentFile = XM.Model.extend({
394 /** @scope XM.IncidentFile.prototype */
396 recordType: 'XM.IncidentFile',
398 isDocumentAssignment: true
407 XM.IncidentUrl = XM.Model.extend({
408 /** @scope XM.IncidentUrl.prototype */
410 recordType: 'XM.IncidentUrl',
412 isDocumentAssignment: true
421 XM.IncidentIncident = XM.Model.extend({
422 /** @scope XM.IncidentIncident.prototype */
424 recordType: 'XM.IncidentIncident',
426 isDocumentAssignment: true
435 XM.IncidentRecurrence = XM.Model.extend({
436 /** @scope XM.IncidentRecurrence.prototype */
438 recordType: 'XM.IncidentRecurrence'
447 XM.IncidentRelation = XM.Info.extend({
448 /** @scope XM.IncidentRelation.prototype */
450 recordType: 'XM.IncidentRelation',
452 editableModel: 'XM.Incident'
456 // Incident status mixin
457 XM.IncidentRelation = XM.IncidentRelation.extend(XM.IncidentStatus);
464 XM.IncidentListItem = XM.Info.extend({
465 /** @scope XM.IncidentListItem.prototype */
467 recordType: 'XM.IncidentListItem',
469 editableModel: 'XM.Incident'
478 XM.IncidentListItemCharacteristic = XM.Model.extend({
479 /** @scope XM.IncidentListItemCharacteristic.prototype */
481 recordType: 'XM.IncidentListItemCharacteristic'
485 // Incident status mixin
486 XM.IncidentListItem = XM.IncidentListItem.extend(XM.IncidentStatus);
493 XM.IncidentEmailProfile = XM.Document.extend(
494 /** @scope XM.IncidentEmailProfile.prototype */ {
496 recordType: 'XM.IncidentEmailProfile',
502 // ..........................................................
509 @extends XM.Collection
511 XM.IncidentCategoryCollection = XM.Collection.extend({
512 /** @scope XM.IncidentCategoryCollection.prototype */
514 model: XM.IncidentCategory
521 @extends XM.Collection
523 XM.IncidentSeverityCollection = XM.Collection.extend({
524 /** @scope XM.IncidentSeverityCollection.prototype */
526 model: XM.IncidentSeverity
533 @extends XM.Collection
535 XM.IncidentResolutionCollection = XM.Collection.extend({
536 /** @scope XM.IncidentResolutionCollection.prototype */
538 model: XM.IncidentResolution
545 @extends XM.Collection
547 XM.IncidentListItemCollection = XM.Collection.extend({
548 /** @scope XM.IncidentListItemCollection.prototype */
550 model: XM.IncidentListItem
557 @extends XM.Collection
559 XM.IncidentRelationCollection = XM.Collection.extend({
560 /** @scope XM.IncidentRelationCollection.prototype */
562 model: XM.IncidentRelation
569 @extends XM.Collection
571 XM.IncidentEmailProfileCollection = XM.Collection.extend({
572 /** @scope XM.IncidentEmailProfileCollection.prototype */
574 model: XM.IncidentEmailProfile