-
Notifications
You must be signed in to change notification settings - Fork 19
/
KanbanPolicy.js
78 lines (68 loc) · 2.81 KB
/
KanbanPolicy.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** Copyright (c) 2013 Rally Software Development Corp. All rights reserved **/
KanbanPolicy = function(rallyDataSource, callback) {
var that = this;
var workspacePrefRef, projectPrefRef, fieldName, policyDesc;
that._updatePolicyPref = function(currentPrefs) {
currentPrefs.fieldInfos[fieldName].policy = policyDesc;
that._storeValues(currentPrefs);
};
that.savePolicy = function(field, policy) {
fieldName = field;
policyDesc = dojo.trim(policy);
that._retrievePreferences(that._updatePolicyPref);
};
that._retrievePreferences = function(prefCallback) {
function getProjectOrWorkspacePref(results) {
var workspacePref, projectPref, currentPrefs;
if (results.length) {
dojo.forEach(results, function(p) {
if (p.Project) {
//projectOid is a string need both strings to compare.
var projectRef = rally.sdk.util.Ref.getOidFromRef(p.Project) + "";
if (projectRef === rallyDataSource.projectOid) {
projectPref = p;
projectPrefRef = projectPref._ref;
}
}
if (p.Workspace) {
workspacePref = p;
workspacePrefRef = p._ref;
}
});
if (projectPref) {
currentPrefs = projectPref.Value;
}
else if (workspacePref) {
currentPrefs = workspacePref.Value;
}
}
prefCallback(currentPrefs);
}
rallyDataSource.preferences.getAppPreferences(getProjectOrWorkspacePref);
};
that._storeValues = function(values) {
function successCallback(results) {
callback(policyDesc);
}
function errorProjectCallback(results) {
rally.Logger.warn(results);
if (results.Errors.length > 0) {
var error = results.Errors[0];
if (error.match(/user does not have preference write permission/i)) {
error = "You must have Editor permissions to set up the Kanban Board for the current project.";
}
rally.sdk.ui.AppHeader.showMessage("error", error, 10000);
callback(null);
}
}
if (!projectPrefRef) {
rally.sdk.ui.AppHeader.showMessage("error", "You must set up a Kanban Board before creating column policies.", 10000);
}
else {
var pref = {_ref : projectPrefRef,
Value: values
};
rallyDataSource.preferences.update(pref, successCallback, errorProjectCallback);
}
};
};