forked from ncolangiuli/parse_and_set_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (38 loc) · 1.14 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function() {
return {
events: {
'app.activated':'onAppActivated'
},
onAppActivated: function(app) {
if (app.firstLoad){
_.defer(this.initialize.bind(this));
}
},
initialize: function() {
var value = this.execRegexOnFields(),
key = helpers.fmt('custom_field_%@',this.setting('result_field'));
if (value && _.isEmpty(this.ticket().customField(key))){
this.ticket().customField(key, value);
}
},
execRegexOnFields: function(){
var value = '';
var ticket = this.containerContext().ticket;
var first_comment = _.last(ticket.comments);
ticket.description = first_comment.value;
_.each(this.fields(), function(field){
if (!_.isEmpty(this.containerContext().ticket[field]) &&
_.isEmpty(value)){
value = (this.containerContext().ticket[field].match(this.regexp()) || [])[1] || "";
}
}, this);
return value;
},
fields: function(){
return _.compact(this.setting('fields').split(','));
},
regexp: _.memoize(function(){
return this.setting('regexp');
})
};
}());