Repository navigation
Expand file tree
/
Copy pathModalQueue.js
More file actions
65 lines (60 loc) · 2.61 KB
/
Copy pathModalQueue.js
File metadata and controls
65 lines (60 loc) · 2.61 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Service to keep record of modal queue. This is needed because basic workflow on
* TaskBoard application relies on this. This service is used from 'ModalService'.
*/
(function() {
'use strict';
angular.module('Taskboard.services')
.factory('ModalQueue',
[
'_',
function(_) {
// Initialize modal queue array
var queue = [];
return {
/**
* Setter method for new modal queue item. Note that this will automatically
* close currently opened modal in way that it won't fire opening another
* modal.
*
* @todo Can this be handled some "smarter" way?
*
* @param {bootstrap.modalInstance} modalInstance
* @param {string} method
* @param {*[]} parameters
*/
set: function(modalInstance, method, parameters) {
var currentModal = _.last(queue);
// Yeah, we found previous modal so close that
if (currentModal) {
currentModal.instance.close(false);
}
// Add new item to current queue
queue.push({
instance: modalInstance,
method: method,
parameters: parameters
});
},
/**
* Getter method for "previous" modal in queue. Note that we need to run
* queue.pop() twice to get the previous one. That is needed because queue
* contains current modal at this point.
*
* @returns {helper.modalQueue}
*/
get: function() {
queue.pop();
return queue.pop();
},
/**
* Queue reset method. This will just simply reset current queue.
*/
reset: function() {
queue = [];
}
};
}
]
);
}());