提交 | 用户 | 时间
|
58d006
|
1 |
window.I = {} |
A |
2 |
var basic=getpath(); |
|
3 |
pagesize=15; |
|
4 |
var modelview=function() { |
|
5 |
var self=this; |
|
6 |
self.filter=ko.observable(); |
|
7 |
self.ress=ko.observableArray(); |
|
8 |
self.res={ |
|
9 |
id:ko.observable(0), |
|
10 |
url:ko.observable(), |
|
11 |
note:ko.observable(), |
|
12 |
type:ko.observable(), |
|
13 |
module:ko.observable(0), |
|
14 |
opvalue:ko.observable(0) |
|
15 |
}; |
|
16 |
self.curRes=null; |
|
17 |
self.modules=ko.observableArray(); |
|
18 |
self.opers=ko.observableArray(); |
|
19 |
|
|
20 |
self.type=ko.observable(); |
|
21 |
self.rm=function(item){ |
|
22 |
jQuery.post(basic+'/admin/rescon/rm.htm', {id:item.id}, function(data, textStatus, xhr) { |
|
23 |
if(data==null) |
|
24 |
return; |
|
25 |
if(data.code==0) |
|
26 |
{ |
|
27 |
self.ress.remove(item); |
|
28 |
}else{ |
|
29 |
alert(data.hint); |
|
30 |
} |
|
31 |
},'json'); |
|
32 |
}; |
|
33 |
self.edit=function(item){ |
|
34 |
// self.res(item); |
|
35 |
self.curRes=item; |
|
36 |
self.res.id(item.id()); |
|
37 |
self.res.url(item.url()); |
|
38 |
self.res.note(item.note()); |
|
39 |
self.res.type(item.type()); |
|
40 |
self.res.module(item.module()); |
|
41 |
self.res.opvalue(item.opvalue()); |
|
42 |
$("#edit-ress").show(); |
|
43 |
$("#new-ress").hide(); |
|
44 |
$('#modal1').modal('show'); |
|
45 |
}; |
|
46 |
self.change=function(){ |
|
47 |
ress(0,pagesize,1,md.filter(),md.type()); |
|
48 |
}; |
|
49 |
} |
|
50 |
jQuery(document).ready(function($) { |
|
51 |
var md=window.md=new modelview(); |
|
52 |
ko.applyBindings(md); |
|
53 |
initModulesAndOps(); |
|
54 |
ress(0,pagesize,1,null,null); |
|
55 |
var fm1=$('#fm1'); |
|
56 |
fm1.validate({ |
|
57 |
rules:{ |
|
58 |
url:{ |
|
59 |
required:true |
|
60 |
} |
|
61 |
}, |
|
62 |
messages:{ |
|
63 |
url:{ |
|
64 |
required:'不能为空' |
|
65 |
} |
|
66 |
} |
|
67 |
}); |
|
68 |
$('#searcha').click(function(){ |
|
69 |
ress(0,pagesize,1,md.filter(),md.type()); |
|
70 |
}); |
|
71 |
$('#ctbtn').click(function(){ |
|
72 |
md.curRes=null; |
|
73 |
md.res.id(0); |
|
74 |
md.res.url(''); |
|
75 |
md.res.note(''); |
|
76 |
md.res.type(0); |
|
77 |
md.res.module(0); |
|
78 |
md.res.opvalue(0); |
|
79 |
$('#modal1').modal('show'); |
|
80 |
}); |
|
81 |
$('#tjbtn').click(function(){ |
|
82 |
if(fm1.valid()==false) |
|
83 |
return; |
|
84 |
if(window.save==1) |
|
85 |
return; |
|
86 |
window.save=1; |
|
87 |
var tt=md.res; |
|
88 |
var res=ko.mapping.toJS(tt); |
|
89 |
jQuery.post(basic+'/admin/rescon/save.htm', res, function(data, textStatus, xhr) { |
|
90 |
$('#modal1').modal('hide'); |
|
91 |
window.save=0; |
|
92 |
if(data==null) |
|
93 |
return; |
|
94 |
if(data.code==1) |
|
95 |
{ |
|
96 |
alert("无法保存!"); |
|
97 |
}else{ |
|
98 |
if(res.id==0) |
|
99 |
{ |
|
100 |
res.id=data.nid; |
|
101 |
window.md.ress.push(ko.mapping.fromJS(res)); |
|
102 |
}else{ |
|
103 |
md.curRes.url(tt.url()); |
|
104 |
md.curRes.note(tt.note()); |
|
105 |
md.curRes.type(tt.type()); |
|
106 |
md.curRes.module(tt.module()); |
|
107 |
md.curRes.opvalue(tt.opvalue()); |
|
108 |
} |
|
109 |
} |
|
110 |
},'json'); |
|
111 |
}); |
|
112 |
}); |
|
113 |
function ress(page,pagesize,pages,filter,type) |
|
114 |
{ |
|
115 |
jQuery.post(basic+'/admin/rescon/ress.htm', {page:page,pagesize:pagesize,pages:pages,filter:filter,type:type}, function(data, textStatus, xhr) { |
|
116 |
if(data==null) |
|
117 |
return; |
|
118 |
if(pages>0) |
|
119 |
{ |
|
120 |
$('#pagdiv').unbind('page').empty(); |
|
121 |
if(data.pages>1) |
|
122 |
{ |
|
123 |
$('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){ |
|
124 |
ress(num-1,pagesize,0,filter,type); |
|
125 |
}); |
|
126 |
} |
|
127 |
} |
|
128 |
window.md.ress.removeAll(); |
|
129 |
if(data.items!=null) |
|
130 |
{ |
|
131 |
jQuery.each(data.items, function(index, val) { |
|
132 |
var res=ko.mapping.fromJS(val); |
|
133 |
window.md.ress.push(res); |
|
134 |
}); |
|
135 |
} |
|
136 |
},'json'); |
|
137 |
} |
|
138 |
|
|
139 |
function initModulesAndOps() |
|
140 |
{ |
|
141 |
jQuery.post(basic+'/admin/modulecon/modules.htm', {page:0,pagesize:0,pages:0}, function(data, textStatus, xhr) { |
|
142 |
var md=window.md; |
|
143 |
md.modules.removeAll(); |
|
144 |
md.modules.push({id:0,name:'-请选择模块-',}); |
|
145 |
if(data.items!=null){ |
|
146 |
jQuery.each(data.items, function(index, val) { |
|
147 |
md.modules.push(val); |
|
148 |
}); |
|
149 |
} |
|
150 |
},'json'); |
|
151 |
jQuery.post(basic+'/admin/opercon/opers.htm', function(data, textStatus, xhr) { |
|
152 |
if(data.items!=null){ |
|
153 |
var md=window.md; |
|
154 |
md.opers.removeAll(); |
|
155 |
md.opers.push({value:0,title:'-请选择操作-',}); |
|
156 |
jQuery.each(data.items, function(index, val) { |
|
157 |
md.opers.push(val); |
|
158 |
}); |
|
159 |
} |
|
160 |
},'json'); |
|
161 |
} |