resourceContentManage.js
4.5 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
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 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"
}]
});
edit.init();
edit.on("callback", function(obj) {
if (/^file_onComplete/.test(obj.key)) {
//(!!~index?index:0)
var _field = obj.key.replace(/^file_onComplete_file__/, '').split('-');
Bll.module.contentData.data[_field[1]].src = obj.data;
}
});
}
}
/*配置模块*/
var edit = new common.edit(".modal-body", {
bucket: "goodsimg"
});
/*第一步,基础模板*/
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("1",ViewModel.contentData);
//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"),
index = $this.data("index");
var module = (index == undefined) ? Bll.module.contentData.data : Bll.module.contentData.data[index];
console.log(module);
common.util.__buildobj(name, '.', module, function(obj, name) {
obj[name] = $this.val();
console.log(module);
});
});
$(document).on("click", '#matchImage-addOne', function() {
var length = Bll.module.contentData.data.list.length;//获得长度
Bll.module.contentData.data.list.push({
"src": "",
"url": {
"action": "",
"url": ""
}
});
Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
});