|
1 |
| -(function() { |
| 1 | +(function () { |
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | angular.module('theHiveControllers')
|
5 | 5 | .controller('CaseMergeModalCtrl', CaseMergeModalCtrl);
|
6 | 6 |
|
7 |
| - function CaseMergeModalCtrl($state, $modalInstance, SearchSrv, CaseSrv, UserInfoSrv, AlertSrv, caze) { |
| 7 | + function CaseMergeModalCtrl($state, $modalInstance, $q, SearchSrv, CaseSrv, UserInfoSrv, AlertSrv, caze, $http) { |
8 | 8 | var me = this;
|
9 | 9 |
|
10 | 10 | this.caze = caze;
|
| 11 | + this.pendingAsync = false; |
11 | 12 | this.search = {
|
12 |
| - caseId: null, |
| 13 | + type: 'title', |
| 14 | + placeholder: 'Search by case title', |
| 15 | + minInputLength: 1, |
| 16 | + input: null, |
13 | 17 | cases: []
|
14 | 18 | };
|
15 | 19 | this.getUserInfo = UserInfoSrv;
|
16 | 20 |
|
17 |
| - this.getCaseByNumber = function() { |
18 |
| - if (this.search.caseId && this.search.caseId !== this.caze.caseId) { |
19 |
| - SearchSrv(function(data /*, total*/ ) { |
20 |
| - console.log(data); |
21 |
| - me.search.cases = data; |
22 |
| - }, { |
23 |
| - _string: 'caseId:' + me.search.caseId |
24 |
| - }, 'case', 'all'); |
25 |
| - } else { |
26 |
| - this.search.cases = []; |
| 21 | + this.getCaseByTitle = function(type, input) { |
| 22 | + var defer = $q.defer(); |
| 23 | + |
| 24 | + SearchSrv(function (data /*, total*/ ) { |
| 25 | + defer.resolve(data); |
| 26 | + }, { |
| 27 | + _string: (type === 'title') ? ('title:"' + input + '"') : ('caseId:' + input) |
| 28 | + }, 'case', 'all'); |
| 29 | + |
| 30 | + return defer.promise; |
| 31 | + } |
| 32 | + |
| 33 | + this.format = function(caze) { |
| 34 | + if(caze) { |
| 35 | + return '#' + caze.caseId + ' - ' + caze.title; |
27 | 36 | }
|
28 |
| - }; |
| 37 | + return null; |
| 38 | + } |
| 39 | + |
| 40 | + this.clearSearch = function() { |
| 41 | + this.search.input = null; |
| 42 | + this.search.cases = []; |
| 43 | + } |
| 44 | + |
| 45 | + this.onTypeChange = function(type) { |
| 46 | + this.clearSearch(); |
29 | 47 |
|
30 |
| - this.merge = function() { |
| 48 | + this.search.placeholder = 'Search by case ' + type; |
| 49 | + |
| 50 | + if(type === 'title') { |
| 51 | + this.search.minInputLength = 3; |
| 52 | + } else if(type === 'number') { |
| 53 | + this.search.minInputLength = 1; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + this.onSelect = function(item, model, label) { |
| 58 | + this.search.cases = [item]; |
| 59 | + } |
| 60 | + |
| 61 | + this.merge = function () { |
31 | 62 | // TODO pass params as path params not query params
|
32 | 63 | CaseSrv.merge({}, {
|
33 | 64 | caseId: me.caze.id,
|
34 | 65 | mergedCaseId: me.search.cases[0].id
|
35 |
| - }, function(merged) { |
| 66 | + }, function (merged) { |
36 | 67 |
|
37 | 68 | $state.go('app.case.details', {
|
38 | 69 | caseId: merged.id
|
|
41 | 72 | $modalInstance.dismiss();
|
42 | 73 |
|
43 | 74 | AlertSrv.log('The cases have been successfully merged into a new case #' + merged.caseId, 'success');
|
44 |
| - }, function(response){ |
| 75 | + }, function (response) { |
45 | 76 | AlertSrv.error('CaseMergeModalCtrl', response.data, response.status);
|
46 | 77 | });
|
47 | 78 | };
|
48 | 79 |
|
49 |
| - this.cancel = function() { |
| 80 | + this.cancel = function () { |
50 | 81 | $modalInstance.dismiss();
|
51 |
| - }; |
| 82 | + }; |
52 | 83 | }
|
53 | 84 | })();
|
0 commit comments