folder_file_events.js
11.1 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
jQuery(function(){
jQuery(document).unbind("contextmenu").bind("contextmenu", function (e) { //禁用鼠标右键系统菜单
return false;
});
parent.disabledOpt(false); // 防止偶尔单击事件造成的该隐藏的按钮未隐藏的情况
jQuery(window).mousedown(function(e){ //绑定鼠标点击事件
e = e || event;
var markClick = jQuery(e.target).hasClass("maskDiv") || jQuery(e.target).parent().hasClass("itemico")
? true : false; //点击的位置是否为文件夹或者文件图标
if(e.button == "0"){
parent.hideRightClickMenu();
if(markClick){
return;
}
if(!e.ctrlKey){
jQuery(".item.select").removeClass("select");
parent.disabledOpt(false);
}
}else if(e.button == "2"){
if(markClick){
if(!jQuery(e.target).closest(".item").hasClass("select") && !e.ctrlKey){
jQuery(e.target).closest(".item").addClass("select").siblings(".item.select").removeClass("select");
parent.disabledOpt(true);
}
}else if(!e.ctrlKey){
jQuery(".item.select").removeClass("select");
}
e.preventDefault();
var _left = e.clientX;
var _top = e.clientY;
parent.showRightMenuByPosition(_left,_top);
}
});
jQuery(".item").live({ //绑定文件夹、文件所在块事件
mouseover : function(){
if(!jQuery(this).find(".itemico").children("img").attr("_dataid"))
return;
jQuery(this).addClass("hover");
},
mouseout : function(){
jQuery(this).removeClass("hover");
}
}).find(".maskDiv").live({ //绑定遮罩层事件
dblclick : function(){
jQuery(this).siblings(".itemico").find("img.canSelect").dblclick();
parent.disabledOpt(false);
},
click : function(e){
e = e || event;
imgClick(this,e);
}
}).end().find(".itemico").find("img.canSelect").live({ //绑定文件夹、文件图标
click : function(e){
e = e || event;
imgClick(this,e)
}
});
jQuery(".newFolderItem .edit-name input").live({
keypress : function(e){e = e || event;
if(e.keyCode == 13){
jQuery(this).siblings(".sure").click();
}
}
});
//标题绑定事件
if(loadfoldertype == "privateAll"){
jQuery(".item .itemtitle").live({
click : function(e){
e = e || event;
if(e.ctrlKey || jQuery(this).find("input").length > 0){
return;
}
var _title = jQuery(this).attr("fileName");
var $input = jQuery("<input name='aaa' class='editTitle' value='" + _title + "'/>");
jQuery(this).html($input);
$input.focus();
var pos = $input.val().length;
if($input[0].setSelectionRange){
$input[0].setSelectionRange(pos,pos);
}else if ($input[0].createTextRange) {
var range = $input[0].createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
});
//绑定文件夹、文件名修改input事件
jQuery(".item .editTitle").live({
blur : function(){
var _type = jQuery(this).closest(".item").attr("_datatype");
var _name = this.value;
var _title = jQuery(this).parent().attr("title");
if(_type == "file"){
_name = _title && _title.indexOf(".") > -1 ? (_name + _title.substring(_title.lastIndexOf("."))) : _name;
}
var that = this;
if(_name == ""){
top.Dialog.alert("名称不能为空!",function(){
jQuery(that).focus();
});
return;
}else if(/[\\/:*?"<>|]/.test(_name)){
top.Dialog.alert("名称不能包含下列字符:<br/>\\/:*?\"<>|",function(){
jQuery(that).focus();
});
return;
}
var _id = jQuery(this).closest(".item").attr("id").replace("ItemId","");
var _uid = parent.userInfos.guid;
var data;
var url = "";
if(_type == "file"){
url = "/rdeploy/chatproject/doc/renameImageFile.jsp"
data = {
fileName : _name,
imagefileid : _id,
uid : _uid,
categoryid : parent.getCurrentCateId()
}
}else if(_type == "folder"){
url = "/rdeploy/chatproject/doc/addSeccategory.jsp"
data = {
foldertype : "privateAll",
categoryname : _name,
categoryid : _id
}
}else{
return;
}
var that = this;
jQuery.ajax({
url : url,
type : "post",
data : data,
dataType : "json",
success : function(data){
if(data["result"] == "success"){
var doctitleWidth = getStrWidth(_name,14);
var doctitle = _name;
if(doctitleWidth/140 > 1.7)
{
while(doctitleWidth/140 > 1.7)
{
doctitle = doctitle.substring(0,doctitle.length-2);
doctitleWidth = getStrWidth(doctitle,14);
}
doctitle = doctitle.substring(0,doctitle.length-3);
doctitle = doctitle+"...";
}
jQuery(that).parent().html(doctitle).attr("title",_name).attr("fileName",that.value).prev(".itemico").children().attr("title",_name);
}else if(data["result"] == "fail"){
var $input = jQuery(that);
$input.focus();
var pos = $input.val().length;
if($input[0].setSelectionRange){
$input[0].setSelectionRange(pos,pos);
}else if ($input[0].createTextRange) {
var range = $input[0].createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}else if(data["result"] == "exist"){
top.Dialog.alert(parent.warmFont.fileNameExist);
}
}
});
}
});
}
//设置层最小高度,适用内容较少无法撑满可视窗口问题
jQuery("#itemsDiv").css("min-height",jQuery(window).height() - 53);
});
//点击文件夹、文件图标
function imgClick(thi,e){
var $item = jQuery(thi).closest(".item");
if(!$item.find(".itemico").find("img.canSelect").attr("_dataid"))
return;
if(e.ctrlKey){ //ctrl点击
$item.toggleClass("select"); //当前对象选中、不选中切换
}else{
if($item.hasClass("select")){ //当前是选中状态
if($item.siblings(".item.select").length > 0){ //还有其他选中的对象
$item.siblings(".item.select").removeClass("select"); //其他选中对象取消选中
}else{
$item.removeClass("select"); //当前对象取消选中
}
}else{
$item.addClass("select").siblings(".item.select").removeClass("select");
}
}
if($item.parent().children(".item.select").length > 0){
parent.disabledOpt(true);
}else{
parent.disabledOpt(false);
}
parent.hideRightClickMenu();
}
//获取选中文件夹、文件的id
function getselectIds(){
var folderid = "";
var fileid = "";
var shareid = "";
jQuery(".item.select").each(function(){
var _type = jQuery(this).attr("_datatype");
var _id = jQuery(this).attr("id");
var _shareid = jQuery(this).attr("_shareid");
if(_type == "folder"){
folderid += _id ? ("," + _id.replace("ItemId","")) : "";
}else if(_type == "file"){
fileid += _id ? ("," + _id.replace("ItemId","")) : "";
}
shareid += _shareid ? ("," + _shareid) : "";
});
folderid = folderid == "" ? "" : folderid.substring(1);
fileid = fileid == "" ? "" : fileid.substring(1);
shareid = shareid == "" ? "" : shareid.substring(1);
return {folderid : folderid,fileid : fileid,shareid : shareid};
}
//获取选中文件夹、文件
function getselectItems(){
var folderid = "";
var fileid = "";
var resultMap = {};
var folderArray = new Array();
var fileArray = new Array();
jQuery(".item.select").each(function(){
var _type = jQuery(this).attr("_datatype");
var _id = jQuery(this).attr("id");
var _shareid = jQuery(this).attr("_shareid");
_id = _id ? ( _id.replace("ItemId","")) : "";
var _title = jQuery(this).find(".itemtitle").attr("title");
var selectItem = {};
selectItem['id'] = _id ;
selectItem['name'] = _title;
selectItem['shareid'] = _shareid ? _shareid : "";
if(_type == "folder"){
folderArray.push(selectItem);
}else if(_type == "file"){
fileArray.push(selectItem);
}
});
resultMap['folderArray'] = folderArray;
resultMap['fileArray'] = fileArray;
return resultMap;
}
//复制事件,将复制的文件夹、文件id存放到存储对象中
function saveIdByCopy(){
return getselectItems();
}
//打开文件夹或者文件
function doOpen(){
jQuery(".item.select .itemico img").dblclick();
}
//重命名文件夹或者文件
function doRename(){
jQuery(".item.select .itemtitle").click();
}
//删除指定的文件、文件夹
function removeView(dataMap){
if(dataMap && dataMap.folderid != ""){
var ids = dataMap.folderid.split(",");
for(var i = 0 ;i < ids.length;i++){
jQuery("div#" + ids[i] + "ItemId[_datatype='folder']").remove();
}
}
if(dataMap && dataMap.fileid != ""){
var ids = dataMap.fileid.split(",");
for(var i = 0 ;i < ids.length;i++){
jQuery("div#" + ids[i] + "ItemId[_datatype='file']").remove();
}
}
}
//添加指定的文件、文件夹
function addView(dataMap){
if(!dataMap)return;
var folderArray = dataMap.folderArray;
var fileArray = dataMap.fileArray;
var emptyFlag = false;
if(folderArray){
for(var i = 0 ;i < folderArray.length;i++){
if(jQuery("#" + folderArray[i].sid + "ItemId[_datatype='folder']").length > 0)
continue;
emptyFlag = true;
if(parent.window.VIEW_MODEL == "disk"){
fullPrivateFolderItem({
sid : folderArray[i].sid,
pid : parent.getCurrentCateId(),
sname : folderArray[i].sname
},"yes");
}else if(parent.window.VIEW_MODEL == "systemDoc"){
fullFolderItem({
sid : folderArray[i].sid,
pid : parent.getCurrentCateId(),
sname : folderArray[i].sname
},"yes");
}
}
}
if(fileArray){
for(var i = 0 ;i < fileArray.length;i++){
if(jQuery("div#" + fileArray[i].imagefileId + "ItemId[_datatype='file']").length > 0)
continue;
emptyFlag = true;
if(parent.window.VIEW_MODEL == "disk"){
fullPrivateDocitem(parent.getCurrentCateId(),{
imagefileId : fileArray[i].imagefileId,
docid : fileArray[i].docid,
doctitle : fileArray[i].doctitle,
docExtendName : fileArray[i].docExtendName,
fullName : fileArray[i].fullName,
},parent.privateIdMap[parent.getCurrentCateId()],"yes");
}else if(parent.window.VIEW_MODEL == "systemDoc"){
fullDocitem(parent.getCurrentCateId(),{
imagefileId : fileArray[i].imagefileId,
docid : fileArray[i].docid,
doctitle : fileArray[i].doctitle,
docExtendName : fileArray[i].docExtendName,
fullName : fileArray[i].fullName,
},parent.publicIdMap[parent.getCurrentCateId()],"yes");
}
}
}
if(emptyFlag)
jQuery("#norecord").remove();
}
//取消未读标识(select-选中的文档,all-所有文档)
function removeNoReadMark(type){
if(type == "select"){
jQuery(".item.select[_datatype='file']").find("div[id*='newImgDiv']").remove();
}else if(type == "all"){
jQuery(".item[_datatype='file']").find("div[id*='newImgDiv']").remove();
}
}
//取消选中
function cancelSelect(){
jQuery(".item.select").removeClass("select");
}
//是否都有下载权限
function isAllDownload(docids){
var ids = docids.split(",");
for(var i = 0;i < ids.length;i++){
if(jQuery("div#" + ids[i] + "ItemId[_datatype='file'][canDownload='1']").length == 0){
return false;
}
}
return true;
}