resourceContentManage.js
6.26 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
var $ = require('jquery'),
common = require('../common/common');
var Button=require('./partials/Button1');
/*获取数据*/
var ViewModel={};
var param = location.href.substring(location.href.lastIndexOf("/") + 1);
common.util.__ajax({
url: "/resource/content/resContentIndex",
data: {id: param},
async:false
},function(res) {
ViewModel = res.data;
},true);
/*配置模块*/
var edit = new common.edit(".modal-body", {
bucket: "goodsimg"
});
var Bll={
__render:function(selecter,templater,data){
$(selecter).html(common.util.__template2($("#"+templater).html(),data) );
},
contentDatas:[],
module: null,
toast: function(index, module) {
var d = new common.dialog({
title: (!!~index ? "修改" : "添加") + module.contentData.template_intro,
content: common.util.__template2($("#" + module.contentData.dialog).html(), module),
width: '70%',
button: [{
value: "保存",
callback: function() {
if (edit.validate()) {
//TODO
!!~index ? Bll.contentDatas[index] = module : Bll.contentDatas.push(module);
Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
console.log(Bll.contentDatas);
d.close();
}
return false;
},
css: "btn-primary"
}]
});
Bll.__editRender();
},
renderDialog:function(templater){
Bll.__render(".modal-body",templater,Bll.module);
Bll.__editRender();
},
__editRender:function(){
edit.init();
edit.on("callback", function(obj) {
if (/^file_onComplete/.test(obj.key)) {
var names=obj.field;
Bll.module.contentData.data=common.util.__buildobj(names, '.', Bll.module.contentData.data, function(o, name) {
o[name] = obj.data;
});
console.log(Bll.module.contentData.data);
}
});
}
}
/*第一步,基础模板*/
Bll.__render("#content-list","content-template",ViewModel);
Bll.__render(".contents","template_content_btns",{btns:Button});
/*第二部,把楼层数据转化成数组*/
ViewModel.contentData.forEach(function(item,index){
item.contentData=common.util.__ObjToArray(JSON.parse(item.contentData));
Bll.contentDatas.push(item);
});
console.log("Bll.contentDatas",Bll.contentDatas);
//console.log(Bll.contentDatas);
/*第三部解析楼层*/
Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
/*第四部 操作按钮 添加 删除 修改*/
$(document).on("click", ".add_btn", function() {
var item = Button[$(this).data("index")];
Bll.module={};
Bll.module.contentData = $.extend(true, {}, item);
Bll.toast(-1, Bll.module);
});
//$(document).on("click", ".del", function() {
// Bll.contentDatas.splice($(this).data("index"), 1);
// Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
//});
$(document).on("click", ".del", function () {//删除
var index = $(this).data("index");
console.log(Bll.contentDatas);
common.dialog.confirm("警告",
common.util.__template2("是否确认删除?", {}),
function() {
if(Bll.contentDatas[index].id) {
common.util.__ajax({
url: "/resource/content/delResContent",
data: {id: Bll.contentDatas[index].id}
});
}
Bll.contentDatas.splice(index, 1);
Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
});
//$("#index_" + index).remove();
});
$(document).on("click", ".edit", function() {
var index = $(this).data("index");
var item = Bll.contentDatas[index];
console.log(Bll.contentDatas);
Bll.module = $.extend(true, {}, item);
Bll.toast(index, Bll.module);
});
/*第五步 绑定监听事件*/
$(document).on("change", ".observe", function() {
var $this = $(this);
var name = $this.data("field");
Bll.module.contentData.data=common.util.__buildobj(name, '.', Bll.module.contentData.data, function(obj, name) {
obj[name] = $this.val();
});
});
$(document).on("click", '#multiLabelImage-addImage', function() {
Bll.module.contentData.data.image.push({
"src": "",
"url": {
"action": "",
"url": ""
}
});
Bll.renderDialog("multiLabelImage-template");
});
$(document).on("click", '#multiLabelImage-addOne', function() {
Bll.module.contentData.data.label_list.push({
"src": "",
"url": {
"action": "",
"url": ""
}
});
Bll.renderDialog("multiLabelImage-template");
});
$(document).on("click", '#matchImage-addOne', function() {
Bll.module.contentData.data.list.push({
"title": "",
"url": {
"action": "",
"url": ""
}
});
Bll.renderDialog("matchImage-template");
});
//添加一个图标
$(document).on("click", '#icon-addOne', function() {
Bll.module.contentData.data.push({
//"title": "",
"url": {
"action": "",
"url": ""
}
});
Bll.renderDialog("icon-template");
});
//删除一个图标
$(document).on("click", '#icon-delOne', function() {
var index = $(this).data("index");
Bll.module.contentData.data.splice(index,1);
Bll.renderDialog("icon-template");
});
$(document).on("click", "#sub_btn", function() {
var data = {
"content": {},
"data_id": {},
"rId": ""
};
for(var i = 0; i < Bll.contentDatas.length; i++) {
data.content[i]=JSON.stringify(common.util.__ArrayToObj(Bll.contentDatas[i].contentData));
if(Bll.contentDatas[i].id) {
data.data_id[i] = "id_"+Bll.contentDatas[i].id;
}
}
data.rId = param;
data.content = JSON.stringify(data.content);
data.data_id = JSON.stringify(data.data_id);
console.log(data);
common.util.__ajax({
url: "/resource/content/addResContent",
data: data
},function(res) {
console.log(res.data);
window.location.href=window.location.href;
});
});