operations.category.Edit.js
4.65 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
webpackJsonp([73],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
/**
* Created by ty on 2016/5/31.
*/
var $ = __webpack_require__(1),
common = __webpack_require__(2),
Category = __webpack_require__(40);
var edit = new common.edit2(".row", {bucket:"yhb-img01"});
var type = $("#info-content").attr("type");
var action = $("#info-content").attr("action");
var id = window.location.href.substring(location.href.lastIndexOf("/") + 1);
var categories = [];
var sortsArr = ["firstSortId", "secondSortId", "threadSortId"];
var Bll = {
__render: function () {
//初始化页面
$("#info-content").html(common.util.__template2($("#content-template").html(), Category));
Bll.__renderCategories();
edit.init();
edit.on("file_onComplete", function (obj) {
var name = obj.field;
Category[name] = obj.data;
});
},
__renderCategories: function () {
$("#categories-content").html(common.util.__template2($("#categories-template").html(), Category));
new common.edit2("#categories-content").init();
new common.dropDown({el: "#firstSortId"});
new common.dropDown({el: "#secondSortId"});
new common.dropDown({el: "#threadSortId"});
//$("#firstSortId").change();
//$("#secondSortId").change();
//$("#threadSortId").change();
}
};
common.util.__ajax({
async: false,
url: "/category/getCategories",
data: {}
}, function (res) {
categories = res.data;
},true);
if(type == "edit") {
common.util.__ajax({
async: false,
url: "/category/getOneCategory",
data: {id:id}
}, function (res) {
Category = res.data;
var sorts = Category.sortCode.split(",");
for(var i = 0; i < Category.sortLevel*1-1; i++) {
Category[sortsArr[i]] = sorts[i];
}
},true);
}
Category.categories = $.extend(true, {}, categories);
Bll.__render();
$(document).on("change", ".observe", function() {
var $this = $(this);
var name = $this.data("field");
Category[name] = $this.val();
if(name == "firstSortId") {
Category.secondSortId = "";
Category.threadSortId = "";
Bll.__renderCategories();
} else if(name == "secondSortId") {
Category.threadSortId = "";
Bll.__renderCategories();
}
});
$(document).on("click", "#addUrl", function () {
var urlIndex = '","url":"';
var val = $("#sortUrl").val();
var action = val.substring('{"action":"'.length, val.indexOf(urlIndex));
console.log(action);
var url = val.substring(val.indexOf(urlIndex) + urlIndex.length, val.length - 2);
common.dialog.confirm("添加链接", common.util.__template2($("#template2").html(), {action: action, url: url}), function () {
var url = JSON.stringify({
action: $("#goTo").val(),
url: $("#goToUrl").val()
});
$("#sortUrl").val(url);
Category.sortUrl = url;
});
new common.edit2("#action-row").init();
});
$(document).on("click", "#saveBtn", function () {
if(!edit.validate()) {
return false;
}
var isNew = $("#isNew").val();
var isHot = $("#isHot").val();
var separativeSign = $("#separativeSign").val();
var isNewPage = $("#isNewPage").val();
var platform = $("#platform").val();
Category.isNew = !!isNew ? isNew : Category.isNew;
Category.isHot = !!isHot ? isHot : Category.isHot;
Category.separativeSign = !!separativeSign ? separativeSign : Category.separativeSign;
Category.isNewPage = !!isNewPage ? isNewPage : Category.isNewPage;
Category.platform = platform.replace(/\|/g, ",");
delete Category.categories;
//console.log(Category);
common.util.__ajax2({
url: action,
data: Category
}, function () {
common.util.__tip("保存成功","success");
setTimeout(function () {
window.location.href = "/operations/category/index";
},600);
}, function () {
common.util.__tip("保存失败");
Category.categories = $.extend(true, {}, categories);
});
});
/***/ },
/***/ 40:
/***/ function(module, exports) {
/**
* Created by ty on 2016/5/31.
*/
var Category = {
id:"",
sortName:"",
sortNameEn:"",
sortIco:"",
sortIcoBig:"",
sortUrl:"",
firstSortId:"",
secondSortId:"",
threadSortId:"",
platform:"",
orderBy:"",
isNew:"N",
isHot:"N",
contentCode:"0",
separativeSign:"N",
sortNameColor:"",
isNewPage:"N"
};
module.exports = Category;
/***/ }
});