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
| window.I = {}
| var basic=getpath();
| var modelview=function() {
| var self=this;
| self.filter=ko.observable();
| self.mts=ko.observableArray();
| self.mt=ko.observable({
| id:ko.observable(0),
| title:ko.observable(),
| note:ko.observable()
| });
| self.delmt=function(item){
| jQuery.post(basic+'/admin/bmenucon/mtpdel.htm', {id: item.id()}, function(data, textStatus, xhr) {
| if(data.code==1)
| {
| alert(data.errmsg);
| }else{
| self.mts.remove(item);
| }
| },'json');
| };
| self.editmt=function(item){
| $('#modal1').modal('show');
| self.mt(item);
| };
| }
| jQuery(document).ready(function($) {
| window.mtype=$('#mtype').val();
| var md=window.md=new modelview();
| ko.applyBindings(md);
| getmts(0,15,null,1,0);
|
|
| $('#ctbtn').click(function(){
| md.mt().id(0);
| md.mt().title("");
| md.mt().note("");
| $("#modal1").modal('show');
| });
| var fm1=jQuery('#fm1');
| fm1.validate({
| rules:{
| title:{
| required:true
| }
| },
| messages:{
| title:{
| required:'请输入题目'
| }
| },
| errorPlacement:function(err,element)
| {
| err.appendTo($('#errmsg'));
| }
| });
| $('#tjbtn').click(function(){
| // if(window.op==1)
| // return;
| // window.op=1;
| $('#errmsg').text("");
| if(!fm1.valid())
| return;
| var btn=$(this).button('loading');
| var tt=md.mt();
| var obj=ko.mapping.toJS(tt);
| jQuery.post(basic+'/admin/bmenucon/mtpsave.htm', obj, function(data, textStatus, xhr) {
| // window.op=0;
| btn.button('reset');
|
| if(data==null)
| return;
| if(data.code==1)
| {
| alert(data.errmsg);
| return;
| }
| if(tt.id()==0)
| {
| $('#modal1').modal('hide');
| getmts(0,15,md.filter(),1,data.nid);
| }
| },'json');
| });
|
| $("#searcha").click(function(){
| getmts(0,15,md.filter(),1,0);
| });
| });
| function getmts(page,pagesize,filter,pages,tid)
| {
| jQuery.post(basic+'/admin/bmenucon/mtps.htm', {page:page,pagesize:pagesize,filter:filter,pages:pages,tid:tid}, function(data, textStatus, xhr) {
| if(data==null)
| return;
| if(data.page!=null)
| page=data.page;
| if(data.items!=null)
| {
| window.md.mts.removeAll();
| jQuery.each(data.items, function(index, val) {
| window.md.mts.push(ko.mapping.fromJS(val));
| });
| }
| if(data.pages!=null)
| {
| $('#pagdiv').unbind('page').empty();
| if(data.pages>1)
| {
| $('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){
| getmts(num-1,pagesize,filter,0,0);
| });
| }
| }
| },'json');
| }
|
|