myfavourite_wev8.js
39.2 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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
jQuery(document).ready(function(){
//屏蔽右键菜单
document.oncontextmenu = function(){
return false;
};
var favourite = new Favourite();
favourite.init();
/**从web IM打开时,会带有这个值,默认需要把收藏类型这个查询条件初始化**/
var _favtype = jQuery("#favtype option:selected").val();
if(_favtype != "" && _favtype != undefined){
favourite.setConditions("favtype",_favtype);
}
var favouriteDir = new FavouriteDir(favourite);
favouriteDir.init();
favouriteDir.setSelected("-1"); /**默认选中我的收藏目录*/
favourite.setConditions("dirId","-1");
registerOtherEvt(favourite);
/**回车搜索的事件*/
jQuery("#pagename").bind("keydown",function(e){
if(e.keyCode == 13){
/**
* 搜索前,先去除收藏列表下方的提示信息,搜索结果返回后再加上
*/
var loadingDiv = jQuery("#loadingDiv");
loadingDiv.html("");
favourite.search();
}
});
});
/******************************************************************
* 收藏目录的各种操作
* @author fmj
*****************************************************************/
FavouriteDir = function(fav){
this._favourite = fav;
this._instance = this;
};
FavouriteDir.prototype={
/**
* 选中的记录的id
*/
_selectid : "-1000",
/**
* 实例
*/
_instance : null,
/**
* 收藏内容的实例
*/
_favourite : null,
/**
* 初始化
*/
init : function(){
this._instance.registerEvt();
this.initMoveDirEvt();
this._instance.perfect();
},
/**
* 根据id,设定指定的目录选中
*/
setSelected : function(id){
var $this = this._instance;
var alldirs = jQuery("#leftdir div.diritem");
alldirs.each(function(){
var that = jQuery(this);
that.removeClass("selected");
that.data("selected","false");
that.data("isedit","false");
var itemid = that.data("id");
if(itemid == id){
this._selectid = id;
jQuery("#dirId").val(id);
that.addClass("selected");
that.data("selected","true");
if(itemid != "-1000" && itemid != "-1"){ //itemid=-1000为根目录,itemid=-1,表示默认的目录,都不可编辑和删除
$this.showOperation(that);
}
}else{
$this.hideOperation(that);
}
});
},
/**
* 设置指定的元素选中
* @param itemObj
* @return
*/
setItemSelected : function(itemObj){
var $this = this._instance;
var itemid = itemObj.data("id");
var alldirs = jQuery("#leftdir div.diritem");
alldirs.each(function(){
var that = jQuery(this);
that.removeClass("selected");
that.data("selected","false");
that.data("isedit","false");
var id = that.data("id");
if(itemid != id){
$this.hideOperation(that);
}
});
itemObj.addClass("selected");
itemObj.data("selected","true");
this._selectid = itemid;
jQuery("#dirId").val(itemid);
if(itemid != "-1000" && itemid != "-1"){ //itemid=-1000为根目录,itemid=-1,表示默认的目录,都不可编辑和删除
$this.showOperation(itemObj);
}
},
/**
* 注册事件
* @return
*/
registerEvt : function(){
var $this = this._instance;
var alldirs = jQuery("#leftdir div.diritem");
alldirs.each(function(i){
if(i != alldirs.length - 1){ //不是最后一个,最后一个为新建目录的操作
//取每一个目录的id等信息
var that = jQuery(this);
var dataOpts = that.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
that.data(dataOpts);
}
that.removeAttr("data-options");
that.unbind("click").bind("click",function(evt){
var dirs = jQuery("#leftdir div.diritem");
var itemid = that.data("id");
var srcEle = evt.srcElement || evt.target;
var srcObj = jQuery(srcEle);
if(srcObj.closest("div.dirop").length > 0){ //只是编辑或者删除操作,并不是选中了目录
//先其他的编辑操作隐藏掉
dirs.each(function(j){
var jthis = jQuery(this);
var selected = jthis.data("selected");
var isedit = jthis.data("isedit") || "false";
//if(selected != "true"){
$this.hideOperation(jthis);
//}
jQuery(this).data("isedit","false");
});
if(i != 0 && itemid != "-1"){ //第一个为全部目录,itemid=-1,表示默认的目录,都不可编辑和删除
$this.showOperation(that);
that.data("isedit","true");
}
}else{ //选中了目录
$this.setItemSelected(jQuery(this));
var favouriteIntance = $this._favourite;
/**
* 选中目录时,加载该目录下的数据,但是先把列表下方的提示信息去除
* 加载成功后,再显示该信息
*/
var loadingDiv = jQuery("#loadingDiv");
loadingDiv.html("");
favouriteIntance.search();
}
});
}else{
jQuery(this).unbind("click").bind("click",function(){
$this.newItem();
});
}
});
alldirs.bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
});
alldirs.each(function(i){
if(i != 0 && i != alldirs.length - 1){ //不是最后一个,最后一个为新建目录的操作
jQuery(this).bind("mouseover",function(){
var that = jQuery(this);
var itemid = that.data("id");
//每一个目录添加操作的按钮
if(itemid != "-1"){ //id=-1的为默认的目录,不可编辑和删除
$this.showOperation(that);
}
}).bind("mouseout",function(){
var that = jQuery(this);
var selected = that.data("selected");
var isedit = that.data("isedit");
isedit = (isedit == null || isedit == undefined) ? "false" : isedit;
if(/*selected == "false" &&*/ isedit == "false"){
//隐藏操作的按钮
$this.hideOperation(that);
}
});
}
});
},
/**
* 新建目录
* @return
*/
newItem : function(){
var $this = this._instance;
var _selectid = this._selectid;
var cb = function(instance,data){
jQuery("#custdirs").html(data);
instance.init();
instance.setSelected(_selectid); //选中原本的目录
instance.perfect("update");
instance.reload(); //刷新收藏移动时要显示的目录
}
var url = "/favourite/FavouriteDir.jsp";
var dialog = new window.top.Dialog();
dialog.currentWindow = window;
dialog.Title = favourite.favouritepanel.newfavourite;
dialog.Width = 400;
dialog.Height = 250;
dialog.Drag = true;
dialog.URL = url;
dialog.callbackfunParam = $this;
dialog.callbackfun = cb;
dialog.show();
},
/**
* 显示操作按钮
* @param dirObj
* @return
*/
showOperation : function(dirObj){
var $this = this._instance;
var opObjs = dirObj.find("div.dirop");
if(opObjs.length > 0){
opObjs.show();
}else{
var itemid = dirObj.data("id");
var editTitle = favourite.favouritepanel.edit;
var deleteTitle = favourite.favouritepanel.deletes;
var opstr = " <div class=\"dirop\">"
+ " <span class=\"edit\"><a title=\"" + editTitle + "\" href=\"javascript:void(0);\" ></a></span>"
+ " <span class=\"delete\"><a title=\"" + deleteTitle + "\" href=\"javascript:void(0);\" ></a></span>"
+ " </div>";
jQuery(opstr).appendTo(dirObj).show().find("span").each(function(){
var that = jQuery(this);
if(that.hasClass("edit")){
that.bind("click",function(){
$this.editItem(dirObj);
});
}else{
that.bind("click",function(){
$this.deleteItem(dirObj);
});
}
that.bind("mouseover",function(){
jQuery(this).find("a").addClass("over");
}).bind("mouseout",function(){
jQuery(this).find("a").removeClass("over");
})
});
}
},
/**
* 隐藏操作按钮
* @param dirObj
* @return
*/
hideOperation : function(dirObj){
var opObjs = dirObj.find("div.dirop");
if(opObjs.length > 0){
opObjs.hide();
}
},
/**
* 编辑目录
* @param itemObj
* @return
*/
editItem : function(itemObj){
var $this = this._instance;
var _selectid = this._selectid;
var itemId = itemObj.data("id");
var cb = function(instance,data){
jQuery("#custdirs").html(data);
instance.init();
instance.setSelected(_selectid); //选中原本的目录
instance.perfect("update");
instance.reload(); //刷新收藏移动时要显示的目录
}
var url = "/favourite/FavouriteDir.jsp?id=" + itemId;
var dialog = new window.top.Dialog();
dialog.currentWindow = window;
dialog.Title = favourite.favouritepanel.edittitle;
dialog.Width = 400;
dialog.Height = 250;
dialog.Drag = true;
dialog.URL = url;
dialog.callbackfunParam = $this;
dialog.callbackfun = cb;
dialog.show();
},
/**
* 删除目录
* @param itemObj
* @return
*/
deleteItem : function(itemObj){
var $this = this._instance;
var _selectid = this._selectid;
var itemId = itemObj.data("id");
top.Dialog.confirm(favourite.favouritepanel.deletetopic,function(){
if(itemId != "-1" && itemId != "-1000"){ //-1,我的收藏,-1000根目录“全部目录”
var postData = {action : "delete",id : itemId};
jQuery.post("/favourite/FavDirOperation.jsp",postData,function(data){
jQuery("#custdirs").html(data);
//因为重新加载过目录,因此事件需要重新初始化
$this.init();
$this.setSelected("-1");
$this.perfect("update");
$this.reload(); //刷新收藏移动时要显示的目录
/**
* 删除目录后,默认选中"我的收藏"目录,并刷新收藏的内容列表
*/
var favouriteIntance = $this._favourite;
/**
* 选中目录时,加载该目录下的数据,但是先把列表下方的提示信息去除
* 加载成功后,再显示该信息
*/
var loadingDiv = jQuery("#loadingDiv");
loadingDiv.html("");
favouriteIntance.search(); //刷新收藏
});
}
});
},
/**
* 美化
* @return
*/
perfect : function(opt){
var h1 = 0;
jQuery("#leftdir>div.diritem").each(function(){
h1 += jQuery(this).height();
});
var h2 = jQuery("#custdirs").height();
var h = h1 + h2;
jQuery("#leftdir").height(h);
//jQuery("#leftdir").css("overflow","visible");
//左侧收藏夹目录美化
if(opt == null || opt == undefined){
opt = "init";
}
if(opt == "init"){
jQuery("#scrollcontainer").perfectScrollbar();
}else{
jQuery("#scrollcontainer").perfectScrollbar(opt);
jQuery("#contentDiv").perfectScrollbar("doScrollPos");
}
},
/**
* 重新加载
* @return
*/
reload : function(){
jQuery("#movePanel").hide(); //隐藏收藏移动的目录
var $this = this;
jQuery.post("/favourite/FavDirOperation.jsp",{action:"getExcludeDir"},function(data){
if(!!data){
jQuery("#movePanel .main").html(data);
$this.initMoveDirEvt();
}
})
},
/**
* 初始化移动时要选择的目录的事件
* @return
*/
initMoveDirEvt : function(){
var movePanel = jQuery("#movePanel");
//为每一个目录添加事件
movePanel.find("li").each(function(){
var that = jQuery(this);
var dataOpts = that.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
}
that.data(dataOpts);
that.removeAttr("data-options");
that.bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
});
});
}
};
/************************************************************
* 收藏夹内容的各种操作
************************************************************/
Favourite = function(){};
Favourite.prototype = {
/**
* 初始化操作
*/
init : function(){
this.registerEvt();
this.perfect();
this.updatePage(); //先更新分页的参数,再注册分页的事件
this.updatePageEvt();
},
/**更新分页的参数*/
updatePage : function(jqHtml){
var $this = this;
var _total = 0;
var _current = 0;
var _maxId = -1;
var _isinit = this._page.isinit;
var _isreload = this._page.isreload;
if(!!jqHtml){ //从分页返回的html中解析这些值
jqHtml.each(function(){
var elename = jQuery(this).attr("name");
if(elename == "total"){ //数据总条数
_total = jQuery(this).val();
}
if(elename == "current"){ //已加载的数据条数
_current = jQuery(this).val();
}
if(elename == "maxId"){ //数据的最大id(所有数据,而非当前页的数据)
_maxId = jQuery(this).val();
}
});
}else{ //初始化加载时,从页面中解析
_total = jQuery("#total").val();
_current = jQuery("#current").val();
_maxId = jQuery("#maxId").val();
}
_total = Number(_total);
_current = Number(_current);
_maxId = Number(_maxId);
$this.setPage("current",_current);
$this.setPage("total",_total); //这个值也有可能改变,因为会删除数据
if(_isinit){ //初始化加载时,才需要更新此值
$this.setPage("maxId",_maxId);
$this.setPage("isinit",false);
}
if(_isreload){ //默认不是重新加载
$this.setPage("isreload",false);
}
},
/**
* 分页加载的事件注册
*/
updatePageEvt : function(){
var $this = this;
var loadingDiv = jQuery("#loadingDiv");
var dataOpts = loadingDiv.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
}
var loadingmsg = dataOpts.loadingmsg;
var nodata = dataOpts.nodata;
var nomoredata = dataOpts.nomoredata;
var _total = this._page.total;
var _current = this._page.current;
var _pagesize = this._page.pagesize;
if(_total <= _current && _total > 0 && _total > _pagesize){
loadingDiv.html(nomoredata);
}else if(_total == 0){
loadingDiv.html(nodata);
}else if(_total <= _pagesize){ //说明只有一页数据
loadingDiv.html("");
}
if(_current < _total && _total > 0){
jQuery("#contentDiv").unbind("scroll").bind("scroll",function(){
hideLevelPanel();
jQuery("#movePanel").hide();
var msgScrollTop = loadingDiv.offset().top;
var height = 515; //内容区域的高度
if(msgScrollTop <= height + 20){ //重新加载数据
showLoaddingMsg2();
loadingDiv.html(loadingmsg);
$this.load();
}
});
}else{
jQuery("#contentDiv").unbind("scroll").bind("scroll",function(){
hideLevelPanel();
jQuery("#movePanel").hide();
});
}
},
/**
* 存放搜索的条件
*/
_conditions : {
dirId : "-1000", /**收藏夹目录id*/
favtype : "", /**收藏类型*/
pagename : "", /**收藏标题*/
},
/**
* 分页的信息
*/
_page :{
isinit : true, /**是否初始化加载*/
isreload : false, /**是否是重新加载,重新加载会加载当前已加载的数据,而非分页加载*/
total: 0, /**总的数据条数*/
current : 0, /**当前已加载的数据条数*/
maxId : -1, /**当前查询到的数据的最大的id*/
pagesize : 10 /**每一次滚动加载的数据量*/
},
/**
* 设置条件
*/
setConditions : function(key,value){
if(key in this._conditions){
value = (value == null) ? "" : value;
this._conditions[key] = value;
}
},
/**
* 设置分页的信息
*/
setPage : function(key,value){
if(key in this._page){
value = value;
this._page[key] = value;
}
},
/**
* 重载数据
*/
reload : function(){
var $this = this;
$this.setPage("isreload",true);
$this.setPage("isinit",true);
hideLevelPanel(); //可能存在还未关闭的,先关闭
jQuery("#movePanel").hide();
//显示加载中的遮罩,避免此时做了一些操作
showLoaddingMsg();
$this.load();
},
/**
* 加载数据
* @return
*/
load : function(){
jQuery("#contentDiv").unbind("scroll"); //首先要先移除滚动的事件
var $this = this;
var data = {};
//搜索条件
for(key in this._conditions){
var value1 = this._conditions[key];
value1 = (value1 == null) ? "" : value1;
data[key] = value1;
}
//分页信息
for(key in this._page){
var value2 = this._page[key];
value2 = (value2 == null) ? "" : value2;
data[key] = value2;
}
/*****转发的临时处理方式*****/
var isshowrepeat = jQuery("#isshowrepeat").val();
data.isshowrepeat = isshowrepeat;
var _isinit = this._page.isinit;
var _isreload = this._page.isreload;
jQuery.post("/favourite/FavouriteQuery.jsp",data,function(result){
hideLoaddingMsg();
if(!!result){
//因为这些隐藏域,初始化加载时就已经有,分页加载完成,处理数据前,先删除,避免页面上存在重复的
jQuery("#total").remove();
jQuery("#count").remove();
jQuery("#current").remove();
jQuery("#maxId").remove();
jQuery("#favids").remove();
var _count = 0;
var _favids = null;
jQuery(result).each(function(){
var elename = jQuery(this).attr("name");
if(elename == "count"){ //当前页面返回的数据条数
_count = jQuery(this).val();
}
if(elename == "favids"){ //当前页所有数据的id
_favids = jQuery(this).val();
}
});
var jqHtml = jQuery(result);
$this.updatePage(jqHtml); //更新分页的参数
_count = Number(_count);
//有数据
if(_count > 0){
if(_isinit){ //初始化
jQuery("#favContents").html(result);
}else{ //分页加载
jQuery("#favContents").append(result);
}
$this.registerEvt(_favids);
$this.perfectCheckBox(_favids);
}else{
var loadingDiv = jQuery("#loadingDiv");
var dataOpts = loadingDiv.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
}
if(_isinit){ //初始化
jQuery("#favContents").html(result);
}
}
/**
* 重新处理滚动条
*/
if(_isinit && !_isreload){ //不是重载
$this.perfect("update");
}else{
$this.perfect("update",false);
}
window.setTimeout(function(){
//更新分页滚动的事件,添加在滚动条处理后,避免此时滚动条滚动,而触发滚动加载的事件
$this.updatePageEvt();
},10);
}
});
},
/**
* 搜索
* @return
*/
search : function(){
var dirid = jQuery("#dirId").val();
var favtype = jQuery("#favtype option:selected").val();
var pagename = jQuery("#pagename").val();
this.setConditions("dirId",dirid);
this.setConditions("favtype",favtype);
this.setConditions("pagename",pagename);
this.setPage("isinit",true);
this.setPage("maxId",-1);
hideLevelPanel(); //可能存在还未关闭的,先关闭
jQuery("#movePanel").hide();
//显示加载中的遮罩,避免此时做了一些操作
showLoaddingMsg();
this.load();
},
/**
* 事件注册
* @param _favids:为空时,就是所有的内容都注册事件,不为空,主要是用于每次加载一页数据时的处理
*/
registerEvt : function(_favids){
var $this = this;
var jqobjs = jQuery("#favContents div.favitem");
if(!!_favids){
var tempObjs = null;
var idarr = _favids.split(",");
for(var k = 0; k < idarr.length; k++){
if(tempObjs == null){
tempObjs = jQuery("#fav" + idarr[k]);
}else{
tempObjs = tempObjs.add(jQuery("#fav" + idarr[k]));
}
}
if(tempObjs.length > 0){
jqobjs = tempObjs;
}
}
jqobjs.each(function(){
var that = jQuery(this);
var dataOpts = that.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
that.data(dataOpts);
}
that.removeAttr("data-options");
});
//每一条记录的鼠标点击、移入、移出效果
jqobjs.bind("click",function(){
var $that = jQuery(this);
var favid = $that.data("id");
jQuery("#favContents div.favitem").each(function(){
var that = jQuery(this);
var id = that.data("id");
that.data("isclick","false");
that.removeClass("click");
if(favid != id){
that.find("div.favop").removeClass("showop").addClass("hideop");
var level = that.data("level");
if(level == "1"){ //重要级别为普通,则也需要隐藏
that.find("div.fav_level").css("visibility","hidden");
}
}
});
//点击时,也要默认将这些操作按钮显示出来
$that.data("isclick","true");
$that.addClass("click");
/*
$that.find("div.favop").removeClass("hideop").addClass("showop");
var level = $that.data("level");
if(level == "1"){ //重要级别为普通,则需要显示
$that.find("div.fav_level").css("visibility","visible");
}*/
var movePanel = jQuery("#movePanel");
var objid1 = movePanel.data("objid");
if(objid1 == null || objid1 == undefined || objid1 != favid){
jQuery("#movePanel").hide(); //隐藏收藏移动的目录
}
var levelPanel = jQuery("#levelPanel");
var objid2 = levelPanel.data("objid");
if(objid2 == null || objid2 == undefined || objid2 != favid){
hideLevelPanel(); //可能存在还未关闭的,先关闭
}
}).bind("mouseover",function(){
jQuery(this).addClass("over");
jQuery(this).find("div.favop").removeClass("hideop").addClass("showop");
var level = jQuery(this).data("level");
if(level == "1"){ //重要级别为普通,则需要显示
jQuery(this).find("div.fav_level").css("visibility","visible");
}
}).bind("mouseout",function(){
var isclick = jQuery(this).data("isclick");
var level = jQuery(this).data("level");
jQuery(this).removeClass("over");
jQuery(this).find("div.favop").removeClass("showop").addClass("hideop");
if(level == "1"){ //重要级别为普通,则也需要隐藏
jQuery(this).find("div.fav_level").css("visibility","hidden");
}
});
//操作按钮的鼠标移入、移出效果,点击事件
jqobjs.find("div.favop span").bind("mouseover",function(){
jQuery(this).find("a").addClass("over");
}).bind("mouseout",function(){
jQuery(this).find("a").removeClass("over");
}).bind("click",function(evt){
var that = jQuery(this);
var topParent = that.closest("div.favitem");
if(topParent.length > 0){
var favid = topParent.data("id");
if(that.hasClass("repeat")){
$this.operation.repeatfav(favid,$this);
}else if(that.hasClass("edit")){
$this.operation.editfav(favid,$this);
}else if(that.hasClass("move")){
$this.operation.movefav(evt,topParent,$this);
}else if(that.hasClass("delete")){
$this.operation.deletefav(favid,$this);
}
}
});
//重要程度的鼠标移入移出效果
jqobjs.find("div.fav_level span").bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
});
//重要程度的点击事件
jqobjs.each(function(){
var that = jQuery(this);
var favid = that.data("id");
that.find("div.fav_level").bind("click",function(evt){
$this.operation.editLevel(evt,favid,$this);
});
})
},
/**
* 每一条记录的各种操作
*/
operation :{
/**
* 转发
*/
repeatfav : function(favid,$instance){
var content = jQuery("#content_"+favid).val();
var favouriteObjId = jQuery("#favouriteObjid_"+favid).val();
var msgobjname = jQuery("#msgobjname_"+favid).val();
var filesize = jQuery("#filesize_"+favid).val();
var filetype = jQuery("#filetype_"+favid).val();
var favInfo = {
favouriteObjId: favouriteObjId,
msgobjname: msgobjname,
content: content,
filesize: filesize,
filetype: filetype
};
parentwin.IM_Ext.repeatFromFav(favInfo, function(issuccess){
if(issuccess){
showMsg("转发成功!");
}
});
},
/**
* 编辑
*/
editfav : function(favid,$instance){
var cb = function(instance){
instance.reload();
};
var url = "/favourite/EditSysFavourite.jsp?id=" + favid;
var dialog = new window.top.Dialog();
dialog.currentWindow = window;
dialog.Title = favourite.maingrid.editfavourite;
dialog.Width = 400;
dialog.Height = 300;
dialog.Drag = true;
dialog.URL = url;
dialog.callbackfunParam = $instance;
dialog.callbackfun = cb;
dialog.show();
},
/**
* 编辑重要程度
*/
editLevel : function(evt,id,$instance){
var levelPanel = jQuery("#levelPanel");
var objid = levelPanel.data("objid");
var favop = jQuery("#level" + id);
var favLeft = favop.position().left;
var favTop = favop.position().top;
favLeft = favLeft + 115;
favTop = favTop + 75;
var pos = {left:favLeft,top:favTop};
levelPanel.css(pos);
//为每一个选项添加事件
levelPanel.find("div.levelitem").each(function(){
var that = jQuery(this);
that.data("favid",id);
that.unbind("click").bind("click",function(){
var favid = jQuery(this).data("favid");
var level = jQuery(this).data("level");
levelPanel.hide();
var postData = {};
postData.favid = favid; //收藏的id
postData.importlevel = level; //重要程度
postData.action = "editLevel";
showLoaddingMsg(operatingMsg);
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(data){
$instance.reload(); //重新加载
});
});
});
if(!objid || objid != id){ //不同,说明点击的不是同一个
levelPanel.data("objid",id);
levelPanel.show();
}else{
levelPanel.toggle();
}
stopEvent();
//因为阻止了当前操作的事件冒泡,因此当前一条收藏记录的选中效果就没有了,需要单独去触发
var favitemObj = jQuery("#fav" + id);
$instance.operation.selectFavItem(favitemObj);
},
/**
* 移动
*/
movefav : function(evt,favitemObj,$instance){
var movePanel = jQuery("#movePanel");
var objid = movePanel.data("objid");
var favid = favitemObj.data("id");
var dirid = favitemObj.data("dirid");
var perfectPanel = function(){
var h1 = movePanel.find(".top").height();
var h2 = movePanel.find(".main").height();
var h3 = movePanel.find(".bottom").height();
var h = h1 + h2 + h3;
//movePanel.height(h);
var scrollObj = jQuery("#moveScrollContainer").perfectScrollbar("getScrollObj");
if(scrollObj.length > 0){
jQuery("#moveScrollContainer").perfectScrollbar("update");
scrollObj.doScrollPos(0,0);
}else{
jQuery("#moveScrollContainer").perfectScrollbar();
}
}
//计算位置
var _offset = favitemObj.find("div.favop span.move").position();
var _top = _offset.top + 70;
var _left = _offset.left + 105;
var h1 = movePanel.find(".top").height();
var h2 = 0;
var liObjs = movePanel.find(".main li");
if(liObjs.length > 0){
liObjs.each(function(){
var liObj = jQuery(this);
var _id = liObj.data("id");
if(_id == dirid){ //当前目录不是默认的目录,则将该目录隐藏,不允许选择
liObj.hide();
}else{
liObj.show();
liObj.data("favid",favid);
h2 += liObj.height();
//为目录添加事件
liObj.unbind("click").bind("click",function(){
jQuery("#movePanel").hide();
var $that = jQuery(this);
var $id = $that.data("id");
var $favid = $that.data("favid");
var postData = {};
postData.action = "move";
postData.dirid = $id;
postData.favid = $favid;
showLoaddingMsg(operatingMsg);
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(data){
hideLoaddingMsg();
$instance.reload(); //重新加载
});
});
}
});
}
var h3 = movePanel.find(".bottom").height();
if(h2 >= 250){
h2 = 250;
addScrollPanel();
}else{
removeScrollPanel();
}
var h = h1 + h2 + h3;
//window.console.log("top1===" + _top);
//window.console.log("h===" + h);
if(_top + h > 550){ //当top超过这个值时,下方可能会显示不全,往上方展开
_top = _top - h - 45;
}
//window.console.log("top2===" + _top);
var pos = {left:_left, top:_top};
jQuery("#movePanel").css(pos);
if(!objid || objid != favid){ //不同,说明点击的不是同一个,要新打开
movePanel.data("objid",favid);
jQuery("#movePanel").show();
//添加滚动条
perfectPanel();
}else{
jQuery("#movePanel").toggle();
}
stopEvent();
//因为阻止了当前操作的事件冒泡,因此当前一条收藏记录的选中效果就没有了,需要单独去触发
$instance.operation.selectFavItem(favitemObj);
},
/**
* 批量移动
*/
movefavs : function(evt,btnObj,$instance){
var movePanel = jQuery("#movePanel");
var objid = movePanel.data("objid");
var favid = "movebtn";
var favids = "";
jQuery("#favContents div.favitem").each(function(){
var that = jQuery(this);
var checkboxObj = that.find("div.favinfo input[type='checkbox']");
if(checkboxObj.length > 0){
var checked = checkboxObj.attr("checked");
if(checked == "true" || checked == true){
favids += "," + that.data("id");
}
}
});
if(favids.length <= 0){
top.Dialog.alert(favourite.maingrid.noselect);
return;
}
var perfectPanel = function(){
var h1 = movePanel.find(".top").height();
var h2 = movePanel.find(".main").height();
var h3 = movePanel.find(".bottom").height();
var h = h1 + h2 + h3;
//movePanel.height(h);
var scrollObj = jQuery("#moveScrollContainer").perfectScrollbar("getScrollObj");
if(scrollObj.length > 0){
jQuery("#moveScrollContainer").perfectScrollbar("update");
scrollObj.doScrollPos(0,0);
}else{
jQuery("#moveScrollContainer").perfectScrollbar();
}
}
//计算位置
var _offset = btnObj.position();
var _top = _offset.top + 30;
var _left = _offset.left + 130;
var h1 = movePanel.find(".top").height();
var h2 = 0;
//添加事件
var liObjs = movePanel.find(".main li");
if(liObjs.length > 0){
liObjs.each(function(){
var liObj = jQuery(this);
var _id = liObj.data("id");
liObj.show();
liObj.data("favids",favids);
h2 += liObj.height();
//为目录添加事件
liObj.unbind("click").bind("click",function(){
jQuery("#movePanel").hide();
var $that = jQuery(this);
var $id = $that.data("id");
var $favids = $that.data("favids");
var postData = {};
postData.action = "move";
postData.dirid = $id;
postData.favid = $favids;
showLoaddingMsg(operatingMsg);
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(data){
hideLoaddingMsg();
$instance.reload(); //重新加载
});
});
});
}
var h3 = movePanel.find(".bottom").height();
if(h2 >= 250){
h2 = 250;
addScrollPanel();
}else{
removeScrollPanel();
}
var h = h1 + h2 + h3;
//window.console.log("top1===" + _top);
//window.console.log("h===" + h);
if(_top + h > 550){ //当top超过这个值时,下方可能会显示不全,往上方展开
_top = _top - h - 45;
}
//window.console.log("top2===" + _top);
var pos = {left:_left, top:_top};
jQuery("#movePanel").css(pos);
if(!objid || objid != favid){ //不同,说明点击的不是同一个,要新打开
movePanel.data("objid",favid);
jQuery("#movePanel").show();
//添加滚动条
perfectPanel();
}else{
jQuery("#movePanel").toggle();
}
stopEvent();
},
/**
* 删除
*/
deletefav : function(favid,$instance){
var postData = {};
postData.favid = favid;
postData.action = "delete";
top.Dialog.confirm(favourite.maingrid.suredelete,function(){
showLoaddingMsg(operatingMsg);
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(data){
$instance.reload(); //重新加载
});
});
},
/**
* 批量删除
*/
deletefavs : function($instance){
var favid = "";
jQuery("#favContents div.favitem").each(function(){
var that = jQuery(this);
var checkboxObj = that.find("div.favinfo input[type='checkbox']");
if(checkboxObj.length > 0){
var checked = checkboxObj.attr("checked");
if(checked == "true" || checked == true){
favid += "," + that.data("id");
}
}
});
if(favid.length <= 0){
top.Dialog.alert(multiDeleteMsg);
return;
}
//window.console.log("favid===" + favid);
top.Dialog.confirm(favourite.maingrid.suredelete,function(){
var postData = {};
postData.favid = favid;
postData.action = "delete";
showLoaddingMsg(operatingMsg);
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(data){
$instance.reload(); //重新加载
});
});
},
/**添加收藏*/
addfavs : function(type,$instance){
//窗口的回调事件
var _callback = function(type,data){
if(data.id != "" && data.id != "0"){
var postData = {};
var ids = data.id;
var names = data.name;
postData = data;
var favouritetype = 0;
if(type == 0){ //文档
favouritetype = 1;
}else if(type == 1){ //流程
favouritetype = 2;
}else if(type == 2){ //客户
favouritetype = 4;
}else if(type == 3){ //项目
favouritetype = 3;
}
postData.favouritetype = favouritetype;
//选中的目录
var dirid = jQuery("#dirId").val();
postData.dirid = dirid;
postData.action = "add";
jQuery.post("/favourite/FavouriteOp.jsp",postData,function(backdata){
$instance.search(); //重新加载
});
}
};
var url = "";
var title = "";
if(type == 0)
{
url = "/systeminfo/BrowserMain.jsp?url=/docs/docs/MutiDocBrowser.jsp&mouldID=doc";
title = favourite.mainpanel.adddoc; //添加文档类收藏
}
else if(type == 1)
{
url = "/systeminfo/BrowserMain.jsp?url=/workflow/request/MultiRequestBrowser.jsp";
title = favourite.mainpanel.addworkflow; //添加流程类收藏
}
else if(type == 3)
{
url = "/systeminfo/BrowserMain.jsp?url=/proj/data/MultiProjectBrowser.jsp&mouldID=proj";
title = favourite.mainpanel.addproj; //添加项目类收藏
}
else if(type == 2)
{
url = "/systeminfo/BrowserMain.jsp?url=/CRM/data/MutiCustomerBrowser.jsp&mouldID=customer";
title = favourite.mainpanel.addcus; //添加客户类收藏
}
//弹出窗口
dialog = new window.top.Dialog();
dialog.currentWindow = window;
dialog.Title = title;
dialog.Width = 500;
dialog.Height = 600;
dialog.Drag = true;
dialog.URL = url;
dialog.callbackfunParam = type;
dialog.callbackfun = _callback;
//dialog.OKEvent = _callback;
dialog.show();
},
/**
* 选中一条记录
*/
selectFavItem : function(favitemObj){
var favid = favitemObj.data("id");
jQuery("#favContents div.favitem").each(function(){
var that = jQuery(this);
var id = that.data("id");
that.data("isclick","false");
that.removeClass("click");
});
favitemObj.data("isclick","true");
favitemObj.addClass("click");
}
},
/**
* 滚动条美化
* @param: opt,初始化或者更新
* @param: totop,是否保留滚动条原来滚动到的位置
*/
perfect : function(opt,totop){
var cheight = jQuery("#favContents").height();
var mheight = jQuery("#loadingDiv").height();
var theight = cheight + mheight;
jQuery("#content").height(theight);
if(opt == null || opt == undefined){
opt = "init";
}
if(totop == null || totop == undefined){
totop = true;
}
if(opt == "init"){
jQuery("#contentDiv").perfectScrollbar();
}else{
jQuery("#contentDiv").perfectScrollbar(opt);
if(totop){ //滚动到原来的位置
jQuery("#contentDiv").perfectScrollbar("getScrollObj").doScrollPos(0,0);
}
}
},
/**
* 美化check框
*/
perfectCheckBox : function(_favids){
if(!!_favids){
var tempObjs = null;
var idarr = _favids.split(",");
for(var k = 0; k < idarr.length; k++){
if(tempObjs == null){
tempObjs = jQuery("#fav" + idarr[k]);
}else{
tempObjs = tempObjs.add("#fav" + idarr[k]);
}
}
if(tempObjs.length > 0){
tempObjs.jNice();
}
}
}
};
/**
* 隐藏重要程度的div
* @return
*/
function hideLevelPanel(){
jQuery("#levelPanel").hide();
}
/**
* 显示加载中div
* @return
*/
function showLoaddingMsg(msgTxt){
if(msgTxt == null || msgTxt == undefined){
msgTxt = loaddingMsg;
}
jQuery("#loaddingCover div.text").html(msgTxt);
jQuery("#loaddingCover div.icon").show();
jQuery("#loaddingCover").show();
jQuery("#msgCover").show();
}
function showLoaddingMsg2(){
jQuery("#loaddingCover div.text").html("");
jQuery("#loaddingCover div.icon").hide();
jQuery("#loaddingCover").show();
jQuery("#msgCover").show();
}
/**
* 隐藏加载中div
* @return
*/
function hideLoaddingMsg(){
jQuery("#loaddingCover").hide();
jQuery("#msgCover").hide();
}
/**
* 注册其他的事件
* @return
*/
function registerOtherEvt(_favourite){
/**
* 添加按钮的点击、鼠标移入移出
*/
jQuery("#addbtn").bind("click",function(){
}).bind("mouseover",function(){
jQuery("#addbtn>div").addClass("click");
jQuery("#addItems").show();
jQuery("#addbtn div.bottom").show();
}).bind("mouseout",function(){
jQuery("#addbtn>div").removeClass("click");
jQuery("#addItems").hide();
jQuery("#addbtn div.bottom").hide();
});
/**
* 批量添加按钮的下拉菜单
*/
jQuery("#addItems li.addItem").each(function(i){
var that = jQuery(this);
that.bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
}).bind("click",function(){ //批量添加收藏
_favourite.operation.addfavs(i,_favourite);
jQuery("#addItems").hide();
});
});
/**
* 移动、删除按钮的鼠标移入、移出效果
*/
jQuery("div.opbtns>div").bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
});
/**
* 批量移动按钮的事件
*/
jQuery("#movebtn").bind("click",function(evt){
var that = jQuery(this);
_favourite.operation.movefavs(evt,that,_favourite);
});
/**
* 批量删除按钮的事件
*/
jQuery("#deletebtn").bind("click",function(){
_favourite.operation.deletefavs(_favourite);
});
/**
* 搜索按钮的事件
*/
jQuery("div.searchinput div.icon").bind("click",function(){
_favourite.search();
});
/**
* 修改重要程度的菜单的鼠标移入、移出效果
*/
jQuery("#levelPanel").find("div.levelitem").each(function(){
var that = jQuery(this);
var dataOpts = that.attr("data-options");
if(!!dataOpts){
dataOpts = eval("({" + dataOpts +"})");
that.data(dataOpts);
}
that.removeAttr("data-options");
}).bind("mouseover",function(){
jQuery(this).addClass("over");
}).bind("mouseout",function(){
jQuery(this).removeClass("over");
});
}
/**
* 为移动要显示的目录,添加滚动条
* @return
*/
function addScrollPanel(){
var scrollObj = jQuery("#moveScrollContainer");
if(scrollObj.length > 0){
//nothing to do
}else{
jQuery("#movePanel div.moveto").after(jQuery("<div id=\"moveScrollContainer\" style=\"overflow:hidden;height:250px;width:100px;\"></div>"));
scrollObj = jQuery("#moveScrollContainer");
jQuery("#movePanel div.main").appendTo(scrollObj);
}
}
function removeScrollPanel(){
var scrollObj = jQuery("#moveScrollContainer");
if(scrollObj.length > 0){
var mainHtml = scrollObj.html();
scrollObj.remove();
jQuery("#movePanel div.moveto").after(jQuery(mainHtml));
}
}
//阻止事件冒泡
function stopEvent() {
var event = window.event || arguments.callee.caller.arguments[0]
if(!event){
return false;
}
if (event.stopPropagation) {
// this code is for Mozilla and Opera
event.stopPropagation();
}
else if (window.event) {
// this code is for IE
window.event.cancelBubble = true;
}
return false;
}
$(document).bind('click.autoHide', function(e){
jQuery("#levelPanel").hide();
jQuery("#movePanel").hide();
});