|
|
|
|
|
define(function(require, exports, module) {
|
|
|
var Window = require('system/views/pages/window');
|
|
|
var tpl = require('text!apps/edp/frs/frs008/send.tpl');
|
|
|
var UploadWindow = require('system/views/pages/uploadwindow/uploadwindow');
|
|
|
var ImageWindow = require('system/views/pages/imagewindow/imagewindow');
|
|
|
require('vendor/ckedit/ckeditor');
|
|
|
|
|
|
function SendWindow(options, callback) {
|
|
|
this.options = {
|
|
|
title: '写信',
|
|
|
content: tpl,
|
|
|
width: 800,
|
|
|
height: 600,
|
|
|
modal: true,
|
|
|
closed: true,
|
|
|
closable: true,
|
|
|
draggable: true,
|
|
|
data: null
|
|
|
}
|
|
|
this.callback = callback;
|
|
|
_.extend(this.options, options);
|
|
|
Window.call(this, this.options);
|
|
|
}
|
|
|
|
|
|
inherits(SendWindow, Window);
|
|
|
|
|
|
SendWindow.prototype.init = function($container) {};
|
|
|
|
|
|
SendWindow.prototype.customerize = function($container) {
|
|
|
var self = this;
|
|
|
this.$emailSend = this.getElement('button.send');
|
|
|
this.$emailSave = this.getElement('button.save');
|
|
|
//邮件发送完成按
|
|
|
|
|
|
this.$Addressee = this.getElement('select.Addressee');
|
|
|
this.$theme = this.getElement('input.theme');
|
|
|
this.$FileUpList = this.getElement('div.FileUpList');
|
|
|
this.$fileup = this.getElement('button.upload');
|
|
|
|
|
|
self.ckeditinit();
|
|
|
self.Addresseeinit();
|
|
|
if (self.options.data != null) {
|
|
|
//回复消息页面
|
|
|
if (self.options.data.re === 1) {
|
|
|
self.options.title = "回复";
|
|
|
self.$theme.textbox({
|
|
|
"value": self.options.data.theme
|
|
|
});
|
|
|
self.$Addressee.combobox('setValue', self.options.data.sender[0].userid);
|
|
|
self.$Addressee.combobox('setText', self.options.data.sender[0].username);
|
|
|
if (self.options.data.content) {
|
|
|
CKEDITOR.instances.edp4EmailEditContent.setData(self.options.data.content);
|
|
|
}
|
|
|
}
|
|
|
//草稿消息重新发送页面
|
|
|
if (self.options.data.draft === 1) {
|
|
|
self.options.title = "草稿";
|
|
|
self.$theme.textbox({
|
|
|
"value": self.options.data.theme
|
|
|
});
|
|
|
var values = [];
|
|
|
var text = "";
|
|
|
$.each(self.options.data.addresseeList, function(i) {
|
|
|
values.push(self.options.data.addresseeList[i].addresseeid);
|
|
|
text += self.options.data.addresseeList[i].addresseename;
|
|
|
if (i < self.options.data.addresseeList.length - 1) {
|
|
|
text += ',';
|
|
|
}
|
|
|
});
|
|
|
self.$Addressee.combobox('setValues', values);
|
|
|
self.$Addressee.combobox('setText', text);
|
|
|
|
|
|
if (self.options.data.accessoryList != undefined) {
|
|
|
var FileUpListText = "";
|
|
|
var AccessoryJson = self.options.data.accessoryList;
|
|
|
$.each(AccessoryJson, function(i) {
|
|
|
FileUpListText += "<div ><span id='" + AccessoryJson[i].fileid +
|
|
|
"' name='" + AccessoryJson[i].filename + "''>" + AccessoryJson[i].filename +
|
|
|
"</span><a class='edp_efile_del'> 删除</a></div>";
|
|
|
});
|
|
|
self.$FileUpList.append(FileUpListText);
|
|
|
}
|
|
|
if (self.options.data.content) {
|
|
|
CKEDITOR.instances.edp4EmailEditContent.setData(self.options.data.content);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//发送、存草稿(State:状态;1-已发送;0-草稿)
|
|
|
this.$emailSend.click(function() {
|
|
|
self.acceptclick(1)
|
|
|
});
|
|
|
|
|
|
//存草稿
|
|
|
this.$emailSave.click(function() {
|
|
|
self.acceptclick(0)
|
|
|
});
|
|
|
|
|
|
//文件上传
|
|
|
this.$fileup.click(function() {
|
|
|
self.fileupload();
|
|
|
});
|
|
|
|
|
|
self.delTest();
|
|
|
|
|
|
};
|
|
|
|
|
|
SendWindow.prototype.Addresseeinit = function() {
|
|
|
var self = this;
|
|
|
Store.services.getUser({}, function(isok, data) {
|
|
|
if (isok) {
|
|
|
self.$Addressee.combobox('loadData', data.userlist);
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || "收件人加载出错");
|
|
|
}
|
|
|
}); //getUser
|
|
|
};
|
|
|
|
|
|
SendWindow.prototype.ckeditinit = function() {
|
|
|
var self = this;
|
|
|
CKEDITOR.replace("edp4EmailEditContent", {
|
|
|
width: 700,
|
|
|
height: 380,
|
|
|
on: {
|
|
|
focus: function() {
|
|
|
self.$Addressee.combobox("hidePanel");
|
|
|
},
|
|
|
},
|
|
|
toolbar: [
|
|
|
['Cut', 'Copy', 'Paste', 'PasteFromWord', '-', 'Undo', 'Redo'],
|
|
|
['Bold', 'Italic', 'Strike', '-', 'RemoveFormat', '-', 'Format'],
|
|
|
['NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-',
|
|
|
'Table', 'HorizontalRule', 'SpecialChar'
|
|
|
],
|
|
|
],
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SendWindow.prototype.beforeUpload = function(data, file) {
|
|
|
// data.hasFileId = '1';
|
|
|
// data.fileId = file.name.replace(/(\.[^.]+)$/, '');
|
|
|
// }
|
|
|
SendWindow.prototype.fileupload = function() {
|
|
|
var self = this;
|
|
|
option = {
|
|
|
data: {
|
|
|
dir: 'email_fileserver_plat',
|
|
|
hasFileId: '0',
|
|
|
// multiple: true,
|
|
|
// hasUserDir: '0',
|
|
|
},
|
|
|
// onBeforeUpload: function(data, file) {
|
|
|
// self.beforeUpload(data, file);
|
|
|
// }
|
|
|
}
|
|
|
uploadwindow = new UploadWindow(option, function(response) {
|
|
|
//回调
|
|
|
var data = JSON.parse(response);
|
|
|
if (data.isSucceed) {
|
|
|
var file = data.returnData;
|
|
|
var FileUpListText = "<div ><span id='" + file.fileId +
|
|
|
"' name='" + file.filename + "''>" + file.filename + "</span><a class='edp_efile_del'> 删除</a></div>"
|
|
|
if (data.returnData.iscover != "1") {
|
|
|
self.$FileUpList.append(FileUpListText);
|
|
|
}
|
|
|
|
|
|
/* self.$FileUpList.find('div a').unbind("click").click(function() {
|
|
|
var self = $(this);
|
|
|
Store.messager.confirm("上传文件,是否删除?", function(replace) {
|
|
|
if (replace) {
|
|
|
var fileId = self.parent('div').find('span').attr('id');
|
|
|
params = {
|
|
|
fileId: fileId,
|
|
|
type: '1',
|
|
|
};
|
|
|
Store.services.fileDelete(
|
|
|
params,
|
|
|
function(isok, data) {
|
|
|
if (isok) {
|
|
|
Store.messager.tip('文件删除成功');
|
|
|
self.parent('div').remove();
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || '文件删除失败');
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
|
|
|
});*/
|
|
|
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || "上传失败,请重传");
|
|
|
}
|
|
|
});
|
|
|
uploadwindow.open();
|
|
|
};
|
|
|
|
|
|
/* SendWindow.prototype.deletef = function(fileId) {
|
|
|
params = {
|
|
|
fileId: fileId,
|
|
|
type: '1',
|
|
|
};
|
|
|
Store.services.fileDelete(
|
|
|
params,
|
|
|
function(isok, data) {
|
|
|
if (isok) {
|
|
|
Store.messager.tip('文件删除成功');
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || '文件删除失败');
|
|
|
}
|
|
|
})
|
|
|
};*/
|
|
|
SendWindow.prototype.delTest = function() {
|
|
|
var self = this;
|
|
|
self.$FileUpList.delegate('a', 'click', function() {
|
|
|
var self = $(this);
|
|
|
Store.messager.confirm("上传文件,是否删除?", function(replace) {
|
|
|
if (replace) {
|
|
|
var fileId = self.parent('div').find('span').attr('id');
|
|
|
params = {
|
|
|
fileId: fileId,
|
|
|
type: '1',
|
|
|
};
|
|
|
Store.services.fileDelete(
|
|
|
params,
|
|
|
function(isok, data) {
|
|
|
if (isok) {
|
|
|
Store.messager.tip('文件删除成功');
|
|
|
self.parent('div').remove();
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || '文件删除失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
});
|
|
|
})
|
|
|
};
|
|
|
//send start
|
|
|
SendWindow.prototype.acceptclick = function(State) {
|
|
|
var self = this;
|
|
|
var AccessoryList = new Array();
|
|
|
self.$FileUpList.find("div span").each(function() {
|
|
|
var Accessory = {
|
|
|
fileId: $(this).attr('id'),
|
|
|
fileName: $(this).attr('name')
|
|
|
};
|
|
|
AccessoryList.push(Accessory);
|
|
|
});
|
|
|
|
|
|
var AddresseeList = new Array();
|
|
|
var listUserId = self.$Addressee.combobox('getValues');
|
|
|
var listUserName = self.$Addressee.combobox('getText').split(",");
|
|
|
for (i = 0; i < listUserId.length; i++) {
|
|
|
var Addressee = {
|
|
|
addresseeId: listUserId[i],
|
|
|
addresseeName: listUserName[i]
|
|
|
};
|
|
|
AddresseeList.push(Addressee);
|
|
|
}
|
|
|
|
|
|
if (AddresseeList.length == 0) {
|
|
|
Store.messager.tip('请选择收件人!');
|
|
|
} else {
|
|
|
var content = CKEDITOR.instances.edp4EmailEditContent.getData();
|
|
|
var params = {
|
|
|
state: State, //状态;1-已发送;0-草稿
|
|
|
theme: !this.$theme.val() ? '空主题' : this.$theme.val(), //主题
|
|
|
//content: (content == '' || content==null) ? '空内容' : this.$theme.val(), //内容
|
|
|
content: !content ? '空内容' : content, //内容
|
|
|
addresseeList: AddresseeList, //收件人
|
|
|
accessoryList: AccessoryList, //附件
|
|
|
}
|
|
|
if (self.options.data != null && self.options.data.emailid != undefined) {
|
|
|
_.extend(params, {
|
|
|
emailid: self.options.data.emailid
|
|
|
});
|
|
|
}
|
|
|
|
|
|
Store.services.sendEmail(
|
|
|
params,
|
|
|
function(isok, data) {
|
|
|
if (isok) {
|
|
|
if (State) {
|
|
|
Store.messager.tip('邮件发送成功');
|
|
|
} else {
|
|
|
Store.messager.tip('邮件保存成功');
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
Store.showError(data.returnMessage || '邮件发送失败');
|
|
|
}
|
|
|
})
|
|
|
CKEDITOR.instances.edp4EmailEditContent.destroy();
|
|
|
self.close();
|
|
|
}
|
|
|
};
|
|
|
//send end
|
|
|
return SendWindow;
|
|
|
}); |