tom
2023-12-06 9e968679ed2e6937aeb7b50a6c450d5d19251f42
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
var aTopic, iTopic, aComment, iComment, iMode=2, aEmployee, iEmployee;
    
$(document).ready( onDocumentReady );
 
function onDocumentReady() {
    $("#file_picture").change(picturePrepare);
    pageInit(showCreate);
}
 
function showTopic(i) {
    iMode=i;
    var aMode=['announce', 'private', 'public'];
    menuSwitch(aMode[i]);
    loadTopic();
}
 
function loadTopic() {
    jsonRequest("discuss", "load_topic_list", {mode:iMode}, onTopicResponse, "正在获取讨论话题…请稍候");
}
 
function onTopicResponse(res) {
    aTopic=res.topic_list;
    
    var html="";
    for (var i=0; i<aTopic.length; i++) {
        var topic=aTopic[i];
        html+=div("div_topic_item",
            (topic.visited?"":div("div_topic_new",""))+
            div("div_topic_title", topic.title)+
            div("div_topic_date", topic.date)+
            div("div_topic_employee_name", topic.employee.name+" ("+topic.employee.title+")")+
            img("img_topic_employee_headimg", topic.employee.headimg)+
            div("div_topic_stats",
                div("div_topic_comment", topic.comment_num)+
                div("div_topic_visit", topic.visit_num)+
                div("div_topic_love"+(topic.loved?"d":""), topic.love_num)),
                    "iTopic="+i+"; showComment();");
    }
    $("#div_topic_group_"+iMode).html(html);
}
 
function promptTopicClose() {
    showConfirm("是否关闭这个讨论话题?", "confirmTopicClose()");
}
 
function confirmTopicClose() {
    var req={};
    req.topic_uid=aTopic[iTopic].uid;
    jsonRequest("discuss", "do_topic_close", req, onTopicCloseResponse, "正在关闭讨论话题……");
}
 
function onTopicCloseResponse(res) {
    pageBack();
    loadTopic();
}
 
function showCreate() {
    if (aPage.length==1) {
        menuSwitch("create");
    } else {
        pageGo("create");
    }
    $("#input_topic_title").val("");
    iMode=iMode || 2;
    setMode(iMode);
    $("#input_topic_title").focus();
    loadEmployeeList();
}
 
function loadEmployeeList() {
    jsonRequest("discuss", "load_employee_list", {}, onEmployeeListResponse, "正在获取员工名录……请稍候");
}
 
function onEmployeeListResponse(res) {
    aEmployee=res.employee_list;
    var html="";
    for (var i=0; i<aEmployee.length; i++) {
        var emp=aEmployee[i];
        html+=div("div_employee_item",
            img("img_employee_headimg", emp.headimg)+
            div("div_employee_code", emp.code)+
            div("div_employee_name", emp.name)+
            div("div_employee_title", emp.title)+
            div("div_employee_off","",null,"employee_"+i), "toggleEmployee("+i+")" );
    }
    $("#div_employee_group").html(html);
}
 
function setMode(i) {
    toggleSwitch("mode", i);
    iMode=i;
    if (i==1) {
        $("#div_employee_group").slideDown();
    } else {
        $("#div_employee_group").slideUp();
    }
}
 
function toggleEmployee(i) {
    aEmployee[i].selected=!aEmployee[i].selected;
    var b=aEmployee[i].selected?"on":"off";
    $("#employee_"+i).attr("class", "div_employee_"+b);
}
 
function confirmCreate() {
    var req={};
    req.topic_title=$("#input_topic_title").val();
    if (!req.topic_title) {
        alertMessage("请填写话题标题");
        return;
    }
    req.topic_mode=iMode;
    if (req.topic_mode==1) {
        req.employee_uid_list=[];
        for (var i=0; i<aEmployee.length; i++) {
            if (aEmployee[i].selected) {
                req.employee_uid_list.push(aEmployee[i].uid);
            }
        }
        if (req.employee_uid_list.length==0) {
            alertMessage("请选择话题参与人员");
            return;
        }
    }
    jsonRequest("discuss", "do_topic_add", req, onCreateResponse, "正在发布新话题……请稍候");
}
 
function onCreateResponse() {
    showTopic(0);
    aPage=["menu", "announce"];
}
 
function addLove() {
    var req={};
    req.topic_uid=aTopic[iTopic].uid;
    jsonRequest("discuss", "do_love_add", req, onCommentResponse);
}
 
function showComment() {
    pageGo("comment");
    loadComment();
    $("#div_confirm_say").hide();
}
 
function loadComment() {
    var req={};
    req.topic_uid=aTopic[iTopic].uid;
    jsonRequest("discuss", "load_comment_list", req, onCommentResponse, "正在获取话题留言……请稍候");
}
 
function onCommentResponse(res) {
    var html="";
    var topic=res.topic;
    aPicture=[];
    html+=div("div_topic_title", topic.title);
    html+=div("div_topic_date", topic.date);
    html+=div("div_topic_employee_name", topic.employee.name+" ("+topic.employee.title+")");
    html+=img("img_topic_employee_headimg", topic.employee.headimg);
    var employee=topic.employee_num>0?div("div_topic_employee", topic.employee_num, "showTopicEmployee()"):"";
    var close=topic.owner?div("div_topic_close", "关闭", "promptTopicClose()"):"";
 
    html+=div("div_topic_stats",
            div("div_topic_comment", topic.comment_num)+
            div("div_topic_visit", topic.visit_num)+
            div("div_topic_love"+(topic.loved?"d":""), topic.love_num, "addLove();")+
            employee+close);
    $("#div_comment_header").html(html);
    var html="";
    aComment=res.comment_list;
    for (var i=0; i<aComment.length; i++) {
        var comment=aComment[i];
        var close2=(topic.owner || comment.owner)?div("div_comment_close", "删除", "iComment="+i+"; promptCommentClose()"):"";
        html+=div("div_comment_item",
            div("div_comment_date", comment.date)+
            div("div_comment_name", comment.employee.name+" ("+comment.employee.title+")")+
            img("img_comment_headimg", comment.employee.headimg)+
            div("div_comment_content", comment.content)+ close2+
            htmlPicture(comment.picture_list));
    }
    $("#div_comment_group").html(html);
}
 
function promptCommentClose() {
    showConfirm("是否删除这条留言?", "confirmCommentClose()");
}
 
function confirmCommentClose() {
    var req={};
    req.comment_uid=aComment[iComment].uid;
    jsonRequest("discuss", "do_comment_close", req, onCommentCloseResponse, "正在删除留言……");
}
 
function onCommentCloseResponse(res) {
    loadComment();
}
 
function htmlPicture(list) {
    var html="", group="";
    if (list && list.length>0) {
        for (var j=0; j<list.length; j++) {
            aPicture.push(list[j]);
            group+=img("img_comment_picture", list[j].pre_name, "showBig("+(aPicture.length-1)+")");
        }
        html=div("div_comment_picture_group", group);
    }
    return html;
}
 
function showTopicEmployee() {
    pageGo("topic_employee");
    jsonRequest("discuss", "load_topic_employee_list", {topic_uid:aTopic[iTopic].uid}, onTopicEmployeeResponse, "正在获取话题参与人员……请稍候");
}
 
function onTopicEmployeeResponse(res) {
    aEmployee=res.employee_list;
    var html="";
    for (var i=0; i<aEmployee.length; i++) {
        var emp=aEmployee[i];
        var b=emp.invited?"on":"off";
        html+=div("div_employee_item",
            img("img_employee_headimg", emp.headimg)+
            div("div_employee_code", emp.code)+
            div("div_employee_name", emp.name)+
            div("div_employee_title", emp.title)+
            div("div_employee_"+b,"",null,"invite_"+i), "toggleInvite("+i+")" );
    }
    $("#div_topic_employee_group").html(html);
}
 
function toggleInvite(i) {
    aEmployee[i].invited=!aEmployee[i].invited;
    b=aEmployee[i].invited?"on":"off";
    $("#invite_"+i).attr("class", "div_employee_"+b);
}
 
function confirmTopicEmployeeUpdate() {
    var req={};
    req.topic_uid=aTopic[iTopic].uid;
    req.employee_uid_list=[];
    for (var i=0; i<aEmployee.length; i++) {
        if (aEmployee[i].invited) {
            req.employee_uid_list.push(aEmployee[i].uid);
        }
    }
    jsonRequest("discuss", "do_topic_employee_update", req, onTopicEmployeeUpdateResponse);
}
 
function onTopicEmployeeUpdateResponse(res) {
    alertMessage(res.hint);
    pageBack();
}
 
function showSay() {
    aPicture=[];
    $("#div_picture_group").empty();    
    $("#input_comment_content").val("");
    pageGo("say");
    $("#input_comment_content").focus();
}
 
function confirmSay() {
    var req={};
    req.topic_uid=aTopic[iTopic].uid;
    req.comment_content=$("#input_comment_content").val();
    req.picture_num=aPicture.length;
    if (aPicture.length>0) {
        req.picture_uid_list=[];
        for (var i=0; i<aPicture.length; i++) {
            req.picture_uid_list.push(aPicture[i].uid);
        }
    }
    if (!req.comment_content) {
        alertMessage("请填写留言内容");
    } else {    
        jsonRequest("discuss", "do_comment_add", req, onSayResponse, "正在发送留言……请稍候");
    }
}
 
function onSayResponse(res) {
    pageBack();
    onCommentResponse(res);
}
 
function pictureReady() {
    var html="";
    for (var i=0; i<aPicture.length; i++) {
        html+=div("div_picture_item", 
            img("img_picture_preview", aPicture[i].pre_name, "showBig("+i+")") );
    }
    $("#div_picture_group").html(html);    
}
 
function showBig(i) {
    var y=Math.floor((innerHeight-aPicture[i].big_height*innerWidth/aPicture[i].big_width)/2);
    $("#img_picture_big").attr("src", imgURL+aPicture[i].big_name);
    $("#img_picture_big").css({top:y+"px"});
    var name=aPicture[i].src_name;
    $("#div_picture_big_name").html(name);
    var kRaw=Math.floor(aPicture[i].raw_size/1024);
    var kBig=Math.floor(aPicture[i].big_size/1024);
    var info="原图: "+aPicture[i].raw_width+"x"+aPicture[i].raw_height+" ("+kRaw+"K)";
    info+=" &nbsp; 优化: "+aPicture[i].big_width+"x"+aPicture[i].big_height+" ("+kBig+"K)";
    $("#div_picture_big_info").html(info);
    $("#div_picture_big").fadeIn();
}
 
function hideBig() {
    $("#div_picture_big").fadeOut();
}