notice-add.js
7.97 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
var selectedbg = "rgb(238, 249 ,249)";
var contentpath ;
var gid="";
var status="";
var action =null;
var noticetype=null;
var attachpath=null;
var newNewsType = null;
$(document).ready(function () {
// 获取权限
newNewsType = getPrivalige("新闻公告");
init();
loadSeleted(noticetype);
// addEvent();
});
function init(){
$.cookie("uuid", uuid());
action = $("#action").val();//获取url中的action参数
contentpath = $("#contentpath").val();
gid=$("#gid").val();
if(action=="edit"){
$.ajax({
type: 'POST',
dataType: 'json',
url: CONF_BACK_SERVERURL + global.modelctls.homepage.homePageDetail,
headers:{
"token":$.cookie('ftoken')
},
data: {gid : gid},
success: function (result) {
var data=result.Data;
var str = JSON.stringify(data);
for(var i=0;i<data.length;i++){
var map_result = data[i];
var title=map_result["公告标题"];
var content=map_result["公告内容"];
noticetype=map_result["公告类型"];
var createtime= new Date(map_result["创建时间"]);
var unit=map_result["创建单位"];
if(unit==null){unit="暂无单位";}
var docattachmentpath = map_result["附件路径"]==null?"":map_result["附件路径"];
loadSeleted(noticetype)
$("#title").val(title);
$("#content").val(content);
if(docattachmentpath==""||docattachmentpath==null){continue;}
attachpath=docattachmentpath;
var docpaths = docattachmentpath.split("/");
$.cookie("uuid",docpaths[docpaths.length-1]);
//listFiles(docattachmentpath,"列表编辑");
loadAttachment2(docattachmentpath,null,"edit");
}
}
});
}
}
/**
* 生成UUID
*
* @returns uuid
*/
function uuid(){
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the
// clock_seq_hi_and_reserved
// to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
function setSelect(noticetype){
if(noticetype=="其他"){
$("#Select1 #other").attr("selected",true);
}else if(noticetype=="路网更新"){
$("#Select1 #update").attr("selected",true);
}else if(noticetype=="通知"){
$("#Select1 #notice ").attr("selected",true);
}
}
function loadSeleted(noticetype){
$("#Select1").html("");
$.ajaxSetup({
async : false // 取消以下异步请求 即执行会按顺序执行,不会跳出最后再执行function(result)内的代码
});
$.ajax({
type: 'POST',
dataType: 'json',
url: CONF_BACK_SERVERURL + global.modelctls.kvtree.all,
headers:{
"token":$.cookie('ftoken')
},
data:{name :"公告类型" },
success: function (result) {
// 从结果中去除不可新建的类型
result = removeCanNotEsta(result);
var selected="";
var type=null;
for(var i=0;i<result.length;i++){
type=result[i];
if(noticetype==type.name){
selected=" selected='true'";
}else{
selected="";
}
$("#Select1").append("<option "+selected+" >"+type.name+"</option>" );
}
selectChange();
}
});
}
function selectChange(){
// 初始加载时 赋值默认值
var selectVal = '';
selectVal = jQuery("#Select1 option:selected").text();
if(selectVal == "信息快报"){
$("#title").val(new Date().format("yyyy-MM-dd")+"信息快报");
} else {
$("#title").val('');
}
// 改变时给title默认值
$("#Select1").change(function(){
selectVal = jQuery("#Select1 option:selected").text();
if(selectVal == "信息快报"){
$("#title").val(new Date().format("yyyy-MM-dd")+"信息快报");
} else {
$("#title").val('');
}
});
}
//格式化时间
Date.prototype.format = function(format) {
var o = {
"M+" : this.getMonth() + 1, // 月
"d+" : this.getDate(), // 天
"h+" : this.getHours(), // 时
"m+" : this.getMinutes(), // 分
"s+" : this.getSeconds(), // 秒
"S" : this.getMilliseconds() // 毫秒
}
if (/(y+)/.test(format)) { // 年
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
}
for ( var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
//function addEvent(){
// $("#confirm").click(function () {
//
// var addData=getdata();
// var dataString=JSON.stringify(addData);
// $.post(global.contextPath + global.modelctls.homepage.create,
// { data:dataString
// },
// function (result) {
// layer.msg(result,{icon: 1});
// gid=result;
// status="0";
// var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//
// parent.layer.close(index); //再执行关闭
// window.opener.location.reload();
// });
// });
//
//// $("#btnBrower").click(function () {
//// $("#fileBrower").trigger("click");
//// });
////
// fujianEvent();
//
//}
//
//function fujianEvent(){
// //显示删除图标
// $(".div-notice-attachment-item").mouseover(function (evt) {
// $(evt.currentTarget).css("background-color", selectedbg);
// $(".div-notice-add-fileremove").show("fast");
// $(evt.currentTarget).find(".div-notice-add-fileremove span").slideDown("fast", function () {
// if ($(this).parent().parent().css("background-color") == selectedbg) {
// $(this).hide("fast");
// }
// });
// });
// $(".div-notice-attachment-item").mouseleave(function (evt) {
// $(evt.currentTarget).css("background-color", "white");
// $(evt.currentTarget).find(".glyphicon-trash").hide("fast");
// $(evt.currentTarget).find(".glyphicon-eye-open").hide("fast");
// });
// //删除事件
//// $(".div-notice-add-fileremove").click(removeNotice);
//}
//获取添加的数据
function getdata(){
var announcementtype=jQuery("#Select1 option:selected").text();
var title =$("#title").val();
var content=$("#content").val();
var filepath=$("#filepath").val();
if(filepath==""&&attachpath!=null){filepath=attachpath;}
var data=null;
if(action=="add"){
data={
announcementtype:announcementtype,
title:title,
content:content,
filepath:filepath,
action:action
}
}else{
gid=$("#gid").val();
data={
announcementtype:announcementtype,
title:title,
content:content,
filepath:filepath,
action:action,
gid:gid
}
}
return data;
}
//用于查找权限并返回权限值
function getPrivalige(parent, children){
var userInfo=$.cookie('cookieuser');
userInfo=JSON.parse(userInfo);
var userid=userInfo.user.id;
var userdetail=getUserInfoByUserid(userid);
var role=userdetail.roles;
var roleIds="";
for(var i=0;i<role.length;i++){
roleIds+=role[i].id+",";
}
//加入前端缓存机制 杨亦乐 20180408
var cacheListPrivilege = null;
if(window.parent.globalLocalCache){
var obj = {roleid:roleIds,parent:parent};
if(children){
obj = {roleid:roleIds,parent:parent,children:children};
}
cacheListPrivilege = window.parent.globalLocalCache.GetCacheResult(
CONF_BACK_SERVERURL +"/mvc/privilege/user/load/getChildrenPrivilegeByRoleidAndParent.do",
obj,"");
}
return cacheListPrivilege;
}
// 移除不可新建的类型
function removeCanNotEsta(params){
var newData = [];
for(var nt in newNewsType){
for(var p in params){
if(params[p].name == newNewsType[nt].name){
newData.push(newNewsType[nt]);
}
}
}
return newData;
}
////删除通知公告
//function removeNotice() {
// //alert("1");
// //询问框
// layer.confirm('是否删除?', {
// btn: ['是', '否'] //按钮
// }, function () {
//
// }, function () {
//
// });
//}
//function onchangeFile(){}