service.hrmbrowser.result_wev8.js
5.09 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
define("mService/hrmbrowser/result", ["mUtil"], function(mUtil) {
function a($page, success, closeCallback, _parentResult) {
this.$page = $page;
this.selectedData = [];
this.$resultWrap = $(".result-wrap", $page);
this.$okBtn = $(".ok-btn", $page);
this.success = success;
this.closeCallback = closeCallback;
this.isReady = false;
this.initSelectedIds = "";
this._parentResult = _parentResult;
}
a.prototype = {
addSelectedData : function(d){
this.selectedData.push(d);
},
indexOfSelectedData : function(id){
var index = -1;
for(var i = 0; i < this.selectedData.length; i++){
if(this.selectedData[i].id == id){
index = i;
break;
}
}
return index;
},
removeSelectedData : function(id){
var dIndex = this.indexOfSelectedData(id);
if(dIndex != -1){
this.selectedData.splice(dIndex, 1);
}
},
getSelectedNum : function(){
return this.selectedData.length;
},
getSelectedIds : function(){
var that = this;
if(!that.isReady){
return that.initSelectedIds;
}else{
var ids = "";
for(var i = 0; i < that.selectedData.length; i++){
ids += that.selectedData[i].id + ",";
}
if(ids != ""){
ids = ids.substring(0, ids.length - 1);
}
return ids;
}
},
init: function(selectedIds){
var that = this;
that.initSelectedIds = selectedIds;
if(selectedIds != ""){
var url = mUtil.jionActionUrl("com.api.mobilemode.web.mobile.browser.HrmBrowserAction", "action=getSelectedDatas");
mUtil.getJSON(url, {"selectedIds": selectedIds}, function(result){
var datas = result["datas"];
$.each(datas, function(i, d){
that.innerAdd(d);
});
initOkBtn();
that.isReady = true;
});
}else{
initOkBtn();
that.isReady = true;
}
function initOkBtn(){
that.$okBtn.click(function(){
var id = "";
var text = "";
var datas = that.selectedData;
for(var i = 0; i < datas.length; i++){
id += datas[i].id;
text += datas[i].lastname;
if(i != (datas.length - 1)){
id += ",";
text += ",";
}
}
that.onOk(id, text);
});
}
},
add: function(data){
var that = this;
if(!that.isReady){
return;
}
that.innerAdd(data, true);
if(that._parentResult){
that._parentResult.add(data);
}
},
innerAdd: function(data, moveToit){
var that = this;
that.addSelectedData(data);
var id = data["id"];
var avatar = {};
if (data.hasOwnProperty("avatar")){
avatar = data.avatar;
}
$(".wev-table-view-cell[data-id='"+id+"']", that.$page).addClass("selected");
var html = "<div data-id=\""+id+"\">";
var headFormat = data["headformat"] || avatar["headFormat"];
if (headFormat == "1" || headFormat == "3"){
html += "<div style='background: "+ (data["background"] || avatar["background"]) +"; color: "+ (data["fontcolor"] || avatar["fontColor"]) +"'>"+(data["shortname"] || avatar["shortname"])+"</div>";
} else {
html += "<img src=\""+ (data["messagerurl"] || avatar["messagerUrls"]) +"\">";
}
html += "</div>";
var $r = $(html).css("opacity", "0");
that.$resultWrap.append($r);
if(moveToit){
$r[0].scrollIntoView(false);
}
setTimeout(function(){
$r.css("opacity", "1");
}, 1);
$r.click(function(){
that.remove(data);
});
that.refreshOkBtn();
},
remove: function(data){
var that = this;
var id = data["id"];
$("div[data-id='"+id+"']", that.$resultWrap).remove();
$(".wev-table-view-cell[data-id='"+id+"']", that.$page).removeClass("selected");
that.removeSelectedData(id);
that.refreshOkBtn();
if(that._parentResult){
that._parentResult.remove(data);
}
},
refreshOkBtn: function(){
var that = this;
var n = that.getSelectedNum();
$("span", that.$okBtn).html(n > 0 ? "("+n+")" : "");
},
onOk: function(id, text){
var that = this;
var callback = that.success;
callback && callback(id, text);
var closeCallback = that.closeCallback;
closeCallback && closeCallback();
if(id == ""){
return;
}
var storeName = "mobilemode_hrm_history";
var hd = localStorage.getItem(storeName);
if(hd == null || hd == ""){
hd = [];
}else{
hd = JSON.parse(hd);
}
var idArr = String(id).split(",");
$.each(idArr, function(i, d){
var index;
if((index = hd.indexOf(d)) != -1){
hd.splice(index, 1);
}
if(hd.length >= 20){
hd.pop();
}
hd.unshift(d);
});
localStorage.setItem(storeName, JSON.stringify(hd));
}
};
return function($page, success, closeCallback, _parentResult){return new a($page, success, closeCallback, _parentResult);};
});