jiapeng 8 years ago
parent
commit
88b04163ec

+ 5 - 0
css/model/sys/dict/add.css

@ -0,0 +1,5 @@
1
@charset "utf-8";
2
.sys_dict_add{
3
	width:800px;
4

5
}

+ 5 - 0
css/model/sys/dict/edit.css

@ -0,0 +1,5 @@
1
@charset "utf-8";
2
.sys_dict_edit{
3
	width:800px;
4

5
}

+ 15 - 0
css/model/sys/dict/index.css

@ -0,0 +1,15 @@
1
@charset "utf-8";
2
.sys_dict_index .queryForm{
3
	position: relative;
4
}
5
.sys_dict_index .queryForm .icon-search{
6
	position: absolute;
7
	top:7px;
8
	right:15px;
9
	font-size:25px;
10
}
11
.sys_dict_index .table-opt .icon {
12
	margin: 10px;
13
	font-size: 20px;
14
}
15


+ 6 - 1
html/index.html

@ -104,7 +104,7 @@
104 104
		</div>
105 105
		<div class="page-head-right pull-right">
106 106
			<div class="logout pull-right">
107
				<i class="icon-signout"></i>
107
				<i class="icon-signout opt-logout"></i>
108 108
			</div>
109 109
			<div class="help pull-right">
110 110
				<i class="icon-question-sign"></i>
@ -141,6 +141,11 @@
141 141
<script>
142 142
		$(function() {
143 143
			$.buildSpa();
144
			$(".opt-logout").on("click",function(){
145
				$.util.get("../ajax/sys/user/logout",null,function(){
146
					window.location.href="login.html";
147
				},{});
148
			});
144 149
		});
145 150
	</script>
146 151


+ 2 - 2
html/login.html

@ -34,13 +34,13 @@
34 34
			<div class="row">
35 35
				<div class="col-5 item-caption">用户名</div>
36 36
				<div class="col-7">
37
					<div class="form-item text" defVal="" name="key"></div>
37
					<div class="form-item text" defVal="j@ekexiu.com" name="key"></div>
38 38
				</div>
39 39
			</div>
40 40
			<div class="row">
41 41
				<div class="col-5 item-caption">密码</div>
42 42
				<div class="col-7">
43
					<div class="form-item text password" defVal="" name="pw"></div>
43
					<div class="form-item text password" defVal="123456" name="pw"></div>
44 44
				</div>
45 45
			</div>
46 46
			<div class="row">

+ 48 - 0
html/model/sys/dict/add.html

@ -0,0 +1,48 @@
1
<div class="sys_dict_add centerModal">
2
	<div class="modal-ctrl">
3
		<i class="icon icon-times"></i>
4
	</div>
5
	<div class="container newForm">
6
		<div class="row">
7
			<div class="col-2 item-caption">CODE</div>
8
			<div class="col-10">
9
				<div class="form-item text" defVal="" name="code"></div>
10
			</div>
11
		</div>
12
		<div class="row">
13
			<div class="col-2 item-caption">CAPTION</div>
14
			<div class="col-10">
15
				<div class="form-item text" defVal="" name="caption"></div>
16
			</div>
17
		</div>
18
		<div class="row">
19
			<div class="col-2 item-caption">ReadOny</div>
20
			<div class="col-10">
21
				<div class="form-item select bool" defVal="" dictCode="bool" name="readonly"></div>
22
			</div>
23
		</div>
24
		<div class="row">
25
			<div class="col-2 item-caption">tree</div>
26
			<div class="col-10">
27
				<div class="form-item select bool" defVal="" dictCode="bool" name="tree"></div>
28
			</div>
29
		</div>
30
		<div class="row">
31
			<div class="col-2 item-caption">备注</div>
32
			<div class="col-10">
33
				<div class="form-item textarea" defVal="" name="descp"></div>
34
			</div>
35
		</div>
36
		<div class="row">
37
			<div class="col-10"></div>
38
			<div class="col-2">
39
				<div class="btn pull-right opt-save">
40
					<i class="icon-check"></i> SAVE
41
				</div>
42

43
			</div>
44

45
		</div>
46
	</div>
47

48
</div>

+ 48 - 0
html/model/sys/dict/edit.html

@ -0,0 +1,48 @@
1
<div class="sys_dict_edit centerModal">
2
	<div class="modal-ctrl">
3
		<i class="icon icon-times"></i>
4
	</div>
5
	<div class="container newForm">
6
		<div class="row">
7
			<div class="col-2 item-caption">CODE</div>
8
			<div class="col-10">
9
				<div class="form-item text readOnly" defVal="" name="code"></div>
10
			</div>
11
		</div>
12
		<div class="row">
13
			<div class="col-2 item-caption">CAPTION</div>
14
			<div class="col-10">
15
				<div class="form-item text" defVal="" name="caption"></div>
16
			</div>
17
		</div>
18
		<div class="row">
19
			<div class="col-2 item-caption">ReadOny</div>
20
			<div class="col-10">
21
				<div class="form-item select bool" defVal="" dictCode="bool" name="readonly"></div>
22
			</div>
23
		</div>
24
		<div class="row">
25
			<div class="col-2 item-caption">tree</div>
26
			<div class="col-10">
27
				<div class="form-item select bool" defVal="" dictCode="bool" name="tree"></div>
28
			</div>
29
		</div>
30
		<div class="row">
31
			<div class="col-2 item-caption">备注</div>
32
			<div class="col-10">
33
				<div class="form-item textarea" defVal="" name="descp"></div>
34
			</div>
35
		</div>
36
		<div class="row">
37
			<div class="col-10"></div>
38
			<div class="col-2">
39
				<div class="btn pull-right opt-save">
40
					<i class="icon-check"></i> SAVE
41
				</div>
42

43
			</div>
44

45
		</div>
46
	</div>
47

48
</div>

+ 53 - 0
html/model/sys/dict/index.html

@ -0,0 +1,53 @@
1
<div class="sys_dict_index"  loadUri="../ajax/sys/dict/pq" pageSize="10" pageNo="1" pageIndex="pi">
2
	<div class="modal-ctrl">
3
		<i class="icon icon-times"></i>
4
	</div>
5

6
	<div class="container queryForm">
7
		<div class="row">
8
			<div class="col-6">
9
				<div class="btn opt-new">
10
					<i class="icon-plus"></i>
11
					新增
12
				</div>
13
				
14
			</div>
15
			<div class="col-6 dt-form">				
16
				<div class="form-item text" name="key"></div><i class="icon icon-search opt-query"></i>
17
			</div>
18

19
		</div>
20
	</div>
21
	<div class="container dt-tpl">
22
		<table class="table table-bordered">
23
			<thead>
24
				<tr>
25
					<th>序号</th>
26
					<th>PageIndex</th>
27
					<th>code</th>
28
					<th>名称</th>
29
					<th>readonly</th>
30
					<th>tree</th>
31
					<th>操作</th>
32
				</tr>
33
			</thead>
34
			<tbody class="code-tpl code-tag-hold" code-func="data-list">
35
				<tr>
36
					<td>{{any-[]}}</td>
37
					<td>{{pi}}</td>
38
					<td>{{code}}</td>
39
					<td>{{caption}}</td>
40
					<td code="{{readonly}}">{{readonly-bool}}</td>
41
					<td code="{{tree}}">{{tree-bool}}</td>
42
					<td class="table-opt" dictCode="{{code}}"><i class="icon icon-remove-sign"></i><i class="icon icon-edit"></i><i class="icon icon-list-ul"></i><i class="icon icon-tasks"></i></td>
43
				</tr>
44
			</tbody>
45
			<tbody class="code-tpl code-tag-hold" code-func="data-emptylist">
46
				<tr>
47
					<td class="empty-desc" colspan="7">表格暂无数据</td>
48
				</tr>
49
			</tbody>
50
		</table>
51
	</div>
52
	<ul class="dt-pager"></ul>
53
</div>

+ 19 - 0
html/model/sys/dict/itemlist.html

@ -0,0 +1,19 @@
1
<div class-"sys_dict_itemlist centerModal">
2
	<dvi class="item-list">
3
		<div calss="code-tpl" code-func="data-list">
4
			<div class="item">
5
				<div class="item-code" objVal="{{code}}">{{code}}</div>
6
				<div class="item-caption" objVal="{{caption}}">{{caption}}</div>
7
				<div class="item-shortCode" objVal="{{shortCode}}">{{shortCode}}</div>
8
				<div class="item-enabled" objVal="{{enabled}}">{{enabled}}</div>
9
				<div class="item-system" objVal="{{system}}">{{code}}</div>
10
				<div class="item-data" objVal="{{code}}">{{code}}</div>
11
				
12
			</div>
13
		</div>
14
		
15
		
16
	</dvi>
17
	
18
	
19
</div>

+ 2 - 2
js/base.js

@ -1114,10 +1114,10 @@ function($) {
1114 1114
		},
1115 1115
		val: function(val) {
1116 1116
			if(arguments.length) {
1117
				select_change(this, this.isBool ? (val ? "1" : "0") : (val ? val : ""));
1117
				select_change(this, this.isBool ? (true===val ? "1" :(false===val? "0":"")) : (val ? val : ""));
1118 1118
			} else if(!this.isShowOnly) {
1119 1119
				var v = this.codeEle.val();
1120
				return this.isBool ? (v ? CK_TRUE : CK_FALSE) : (v ? v : CK_UNDEF);
1120
				return this.isBool ? (v ? (v==='1') : CK_UNDEF) : (v ? v : CK_UNDEF);
1121 1121
			}
1122 1122
		},
1123 1123
		reset: function() {

+ 386 - 330
js/codehtml.js

@ -1,348 +1,404 @@
1
(function($,doc,$body,exports){
2
	/**
3
	 * env={ ce:current Element; cd:current Data; ci:current index in
4
	 * ListElement array[ci=index] or object[ci=key] es:Element stack; Array
5
	 * ds:Data stack; Array is:index stack;Array sh:value handler
6
	 * function(env,key){return [String]} dir:directive handler
7
	 * Aarray(function(env){}.call(elementObj={},env) }
8
	 */
9
	var ch_val_buider={
10
		"c":function(/* env */){
11
			return this.k;		
12
		},
13
		"s":function(env){
14
			var v= env.cd;
15
			if(v) v= this.k?v[this.k]:v;
16
			if(v) return v;
17
			return "";			
18
		},
19
		"date":function(env){}		
20
			"date": function(env) {},
21
	simpleAttrHandler=function(env){
22
		env.ce.setAttribute(this.n,this.v);	
23
	},
24
	AttrHandler=function(env){
25
		var ret = [],va= this.v;
26
		for(var i = 0 ; i < va.length;++i){
27
			var item = va[i];
28
			ret.push[env.sh[item.h].call(this,env)];		
29
		}
30
		env.ce.setAttribute(this.n,ret.join(""));
31
	},
32
	/**
33
	 * r:array s:text value f:lslast value in array Is * Text
34
	 */
35
	strSplit_s=function(r,s,f){
36
		if(f){
37
			var tmp = r[r.length-1];
38
			tmp.k=tmp.k+s;
39
		}else{
40
			r.push({k:s,h:"c"});
41
		}
42
	},
43
	strSplit_o=function(r/* array */,shell/* trim value like {{shell}} */){
44
		var tmp = shell.split("-");
45
		var obj ={k:tmp.shift(),h:"s"};
46
		if(tmp.length){obj.h=tmp.shift();}
47
		if(tmp.length){obj.p=tmp;}
48
		r.push(obj);
49
	},
50
	strSplit=function(s){ // s.length>4
51
		var r=[],
52
		len=s.length,
53
		si=0,/* parse start index */
54
		ei,/* end shell ei = s.indexOf("}}",bi+2) */
55
		shell,/* {{shell}} */
56
		tmp,/* last shell */
57
		f/* prev is not shell */,
58
		bi=nv.indexOf("{{");	/* begin shell bi = s.indexOf("{{",si) */		
59
		if(bi>=0){
60
			ei=nv.indexOf("}}",bi);	
61
			while(si<len){
62
				if(bi>si){r.push({k:s.substring(si,bi),h:"c"});f=true;}
63
				shell = s.substring(bi+2,ei).trim();
64
				si=ei+2;
65
				if(shell.length){
66
					f=false;
67
					strSplit_o(r,shell);	
68
				}else{strSplit_s(r,s.substring(bi,si),f);f=true;}
69
				if(si>=len) return r;
70
				bi=s.indexOf("{{",si);
71
				if(bi<0){strSplit_s(r,s.substring(si),f);return r;}
72
				ei=s.indexOf("}}",bi);
73
				if(ei<0){strSplit_s(r,s.substring(si),f);return r;}
74
			}
75
		}
76
		return s;	
77
	},
78
	strCompile=function(s){
79
		var r = strSplit(s);
80
		if(typeof s !="string"){
81
			return r.length>1?r:r[0];/*
82
										 * [{k:"",h:"",p:[]},...] :
83
										 * {k:"",h:"",p:[]}
84
										 */		
85
		}
86
		return s;// String;
87
	},
88
	simpleAttrHand=function(env){
89
		env.ce.setAttribute(this.n,this.v);	
90
	},
91
	singleAttrHand=function(env){
92
		env.ce.setAttribute(this.n,env.sh[this.h].call(this.v,env));
93
	},
94
	arrayAttrHand=function(env){
95
		var item,ret =[],vs=this.v,len=vs.length;
96
		for(var i = 0 ; i < len ; ++i){
97
			item = vs[i];
98
			ret.push(env.sh[item.h].call(item,env));
99
		}
100
		env.ce.setAttribute(this.n,ret.join(""));
101
	},
102
	/* ret.h(env); attribute compiler */	
103
	attrCompile=function(attr){
104
		var s =attr.value||"",ret ={n:attr.name,v:s,h:simpleAttrHand};
105
		if(s.length>4){
106
			s = strCompile(s);
107
			if(typeof s !="string"){
108
				ret.v = s;
109
				// is Array
110
				ret.h=s.length?arrayAttrHand:singleAttrHand;
111
			}
112
		}
113
		return ret;	
114
	},
115
	simpleTextHand=function(env){
116
		env.ce.appendChild(doc.createTextNode(this.v));
117
	},
118
	singleTextHand=function(env){
119
		env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v,env)));
120
	},
121
	arrayTextHand=function(env){
122
		var item,ret =[],vs=this.v,len=vs.length;
123
		for(var i = 0 ; i < len ; ++i){
124
			item = vs[i];
125
			ret.push(env.sh[item.h].call(item,env));
126
		}
127
		env.ce.appendChild(doc.createTextNode(ret.join("")));
128
	},
129
	/* ret.h(env); textNode compiler */	
130
	textCompile=function(s/* s = textNode.nodeValue */){
131
		var len=s.length,ret={v:s,h:"_t"};
132
		if(len>4){
133
			s = textCompile(s);
134
			if(typeof s !="string"){
135
				ret.v = s;
136
				// is Array
137
				ret.h=s.length?"_at":"_st";
138
			}
139
		}
140
		return ret;		
141
	},ch_dir_container={
142
		/* simpleTextHand= */
143
		"_t":function(env){env.ce.appendChild(doc.createTextNode(this.v));},
144
		/* singleTextHand= */
145
		"_st":function(env){env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v,env)));},
146
		/* arrayTextHand= */
147
		"_at":function(env){
148
			var item,ret =[],vs=this.v,len=vs.length;
149
			for(var i = 0 ; i < len ; ++i){
150
				item = vs[i];
151
				ret.push(env.sh[item.h].call(item,env));
152
			}
153
			env.ce.appendChild(doc.createTextNode(ret.join("")));
154
		},
155
		"_":function(env){
156
			var ele = doc.createElement(this.n),as = this.as,es= this.es,item;
157
			env.ce.appendChild(ele);
158
			env.es.push(env.ce);
159
			env.ce=ele;
160
			for(var i = 0 ; i < as.length; ++i){
161
				as[i].h(env);
162
			}
163
			for(var i = 0 ; i < es.length; ++i){
164
				item=es[i];env.dir(item.h).call(item,env);
165
			}
166
			env.ce = env.es.pop();
167
		},
168
		"list":function(env){
169
			var hand=env.dir["_"],as=this.as,es=this.es,item,data = env.cd,p=this.p;
170
			if(data && p && p.length && p[0]){
171
				env.ds.push(data);
172
				data = env.cd = data[p[0]]||[];
173
				env.is.push(env.ci);
174
				for(var i = 0 ; i < data.length;++i){
175
					env.ci = i;
176
					env.cd = data[i];
177
					hand.call(this,env);
1
!(function($) {
2
	$.define(["jQuery", "doc", "body"], "code", function($, doc, $body) {
3
		/**
4
		 * env={ ce:current Element; cd:current Data; ci:current index in
5
		 * ListElement array[ci=index] or object[ci=key] es:Element stack; Array
6
		 * ds:Data stack; Array is:index stack;Array sh:value handler
7
		 * function(env,key){return [String]} dir:directive handler
8
		 * Aarray(function(env){}.call(elementObj={},env) }
9
		 */
10
		var ch_val_buider = {
11
				"c": function( /* env */ ) {
12
					return this.k;
13
				},
14
				"s": function(env) {
15
					var v = env.cd;
16
					if(v) v = this.k ? v[this.k] : v;
17
					if(v) return v;
18
					return "";
19
				},
20
				"date": function(env) {		"date": function(env) {}
21
			},
22
			simpleAttrHandler = function(env) {
23
				env.ce.setAttribute(this.n, this.v);
24
			},
25
			AttrHandler = function(env) {
26
				var ret = [],
27
					va = this.v;
28
				for(var i = 0; i < va.length; ++i) {
29
					var item = va[i];
30
					ret.push[env.sh[item.h].call(this, env)];
178 31
				}
179
				env.ci=env.is.pop();
180
				env.cd = env.ds.pop();
181
			}else if(data && data.length){
182
				env.is.push(env.ci);
183
				for(var i = 0 ; i < data.length;++i){
184
					env.ci = i;
185
					hand.call(this,env);
32
				env.ce.setAttribute(this.n, ret.join(""));
33
			},
34
			/**
35
			 * r:array s:text value f:lslast value in array Is * Text
36
			 */
37
			strSplit_s = function(r, s, f) {
38
				if(f) {
39
					var tmp = r[r.length - 1];
40
					tmp.k = tmp.k + s;
41
				} else {
42
					r.push({ k: s, h: "c" });
186 43
				}
187
				env.ci=env.is.pop();	
188
			}
189
		},"each":function(env){
190
			var hand=env.dir["_"],as=this.as,es=this.es,item,data = env.cd,p=this.p;
191
			if(data && p && p.length && p[0]){
192
				env.ds.push(data);
193
				env.is.push(env.ci);
194
				for(var i = 0 ; i < p.length;++i){
195
					env.ci = p[i];
196
					env.cd = data[env.ci];
197
					hand.call(this,env);
44
			},
45
			strSplit_o = function(r /* array */ , shell /* trim value like {{shell}} */ ) {
46
				var tmp = shell.split("-");
47
				var obj = { k: tmp.shift(), h: "s" };
48
				if(tmp.length) { obj.h = tmp.shift(); }
49
				if(tmp.length) { obj.p = tmp; 		if(tmp.length) { obj.p = tmp; }
50
				r.push(obj);
51
			},
52
			strSplit = function(s) { // s.length>4
53
				var r = [],
54
					len = s.length,
55
					si = 0,
56
					/* parse start index */
57
					ei, /* end shell ei = s.indexOf("}}",bi+2) */
58
					shell, /* {{shell}} */
59
					tmp, /* last shell */
60
					f /* prev is not shell */ ,
61
					bi = nv.indexOf("{{"); /* begin shell bi = s.indexOf("{{",si) */
62
				if(bi >= 0) {
63
					ei = nv.indexOf("}}", bi);
64
					while(si < len) {
65
						if(bi > si) { r.push({ k: s.substring(si, bi), h: "c" });
66
							f = true; }
67
						shell = s.substring(bi + 2, ei).trim();
68
						si = ei + 2;
69
						if(shell.length) {
70
							f = false;
71
							strSplit_o(r, shell);
72
						} else { strSplit_s(r, s.substring(bi, si), f);
73
							f = true; }
74
						if(si >= len) return r;
75
						bi = s.indexOf("{{", si);
76
						if(bi < 0) { strSplit_s(r, s.substring(si), f); return r; }
77
						ei = s.indexOf("}}", bi);
78
						if(ei < 0) { strSplit_s(r, s.substring(si), f); return r; }
79
					}
198 80
				}
199
				env.ci=env.is.pop();
200
				env.cd = env.ds.pop();
201
			}else if(data){
202
				env.is.push(env.ci);
203
				for(var key in data){
204
					env.ci = k;
205
					hand.call(this,env);
81
				return s;
82
			},
83
			strCompile = function(s) {
84
				var r = strSplit(s);
85
				if(typeof s != "string") {
86
					return r.length > 1 ? r : r[0];
87
					/*
88
					 * [{k:"",h:"",p:[]},...] :
89
					 * {k:"",h:"",p:[]}
90
					 */
206 91
				}
207
				env.ci=env.is.pop();	
208
			}	
209
		},"val":function(env){
210
			var hand=env.dir["_"],as=this.as,es=this.es,items,item,data = env.cd,p=this.p;
211
			if(p && p.length && p[0]){
212
				items = p[0].split("\\.");
213
				env.ds.push(data);
214
				while(items.length && data){
215
					data = data[items.shift()];
92
				return s; // String;
93
			},
94
			simpleAttrHand = function(env) {
95
				env.ce.setAttribute(this.n, this.v);
96
			},
97
			singleAttrHand = function(env) {
98
				env.ce.setAttribute(this.n, env.sh[this.h].call(this.v, env));
99
			},
100
			arrayAttrHand = function(env) {
101
				var item, ret = [],
102
					vs = this.v,
103
					len = vs.length;
104
				for(var i = 0; i < len; ++i) {
105
					item = vs[i];
106
					ret.push(env.sh[item.h].call(item, env));
216 107
				}
217
				if(items.length===0 && data){
218
					env.cd = data;
219
					hand.call(this,env);
108
				env.ce.setAttribute(this.n, ret.join(""));
109
			},
110
			/* ret.h(env); attribute compiler */
111
			attrCompile = function(attr) {
112
				var s = attr.value || "",
113
					ret = { n: attr.name, v: s, h: simpleAttrHand };
114
				if(s.length > 4) {
115
					s = strCompile(s);
116
					if(typeof s != "string") {
117
						ret.v = s;
118
						// is Array
119
						ret.h = s.length ? arrayAttrHand : singleAttrHand;
120
					}
220 121
				}
221
				env.cd = env.ds.pop();
222
			}			
223
		},"valTag":function(env){
224
			var hand=env.dir["_"],as=this.as,es=this.es,items,item,data = env.cd,p=this.p;
225
			if(p && p.length && p[0]){
226
				items = p[0].split("\\.");
227
				env.ds.push(data);
228
				while(items.length && data){
229
					data = data[items.shift()];
122
				return ret;
123
			},
124
			simpleTextHand = function(env) {
125
				env.ce.appendChild(doc.createTextNode(this.v));
126
			},
127
			singleTextHand = function(env) {
128
				env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v, env)));
129
			},
130
			arrayTextHand = function(env) {
131
				var item, ret = [],
132
					vs = this.v,
133
					len = vs.length;
134
				for(var i = 0; i < len; ++i) {
135
					item = vs[i];
136
					ret.push(env.sh[item.h].call(item, env));
230 137
				}
231
				if(items.length===0 && data){
232
					env.cd = data;
233
					var ele = doc.createElement(this.n);
138
				env.ce.appendChild(doc.createTextNode(ret.join("")));
139
			},
140
			/* ret.h(env); textNode compiler */
141
			textCompile = function(s /* s = textNode.nodeValue */ ) {
142
				var len = s.length,
143
					ret = { v: s, h: "_t" };
144
				if(len > 4) {
145
					s = textCompile(s);
146
					if(typeof s != "string") {
147
						ret.v = s;
148
						// is Array
149
						ret.h = s.length ? "_at" : "_st";
150
					}
151
				}
152
				return ret;
153
			},
154
			ch_dir_container = {
155
				/* simpleTextHand= */
156
				"_t": function(env) { env.ce.appendChild(doc.createTextNode(this.v)); },
157
				/* singleTextHand= */
158
				"_st": function(env) { env.ce.appendChild(doc.createTextNode(env.sh[this.h].call(this.v, env))); },
159
				/* arrayTextHand= */
160
				"_at": function(env) {
161
					var item, ret = [],
162
						vs = this.v,
163
						len = vs.length;
164
					for(var i = 0; i < len; ++i) {
165
						item = vs[i];
166
						ret.push(env.sh[item.h].call(item, env));
167
					}
168
					env.ce.appendChild(doc.createTextNode(ret.join("")));
169
				},
170
				"_": function(env) {
171
					var ele = doc.createElement(this.n),
172
						as = this.as,
173
						es = this.es,
174
						item;
234 175
					env.ce.appendChild(ele);
235 176
					env.es.push(env.ce);
236
					env.ce=ele;
237
					for(var i = 0 ; i < as.length; ++i){
177
					env.ce = ele;
178
					for(var i = 0; i < as.length; ++i) {
238 179
						as[i].h(env);
239 180
					}
240
					for(var i = 0 ; i < es.length; ++i){
241
						item=es[i];env.dir(item.h).call(item,env);
181
					for(var i = 0; i < es.length; ++i) {
182
						item = es[i];
183
						env.dir(item.h).call(item, env);
242 184
					}
243 185
					env.ce = env.es.pop();
186
				},
187
				"list": function(env) {
188
					var hand = env.dir["_"],
189
						as = this.as,
190
						es = this.es,
191
						item, data = env.cd,
192
						p = this.p;
193
					if(data && p && p.length && p[0]) {
194
						env.ds.push(data);
195
						data = env.cd = data[p[0]] || [];
196
						env.is.push(env.ci);
197
						for(var i = 0; i < data.length; ++i) {
198
							env.ci = i;
199
							env.cd = data[i];
200
							hand.call(this, env);
201
						}
202
						env.ci = env.is.pop();
203
						env.cd = env.ds.pop();
204
					} else if(data && data.length) {
205
						env.is.push(env.ci);
206
						for(var i = 0; i < data.length; ++i) {
207
							env.ci = i;
208
							hand.call(this, env);
209
						}
210
						env.ci = env.is.pop();
211
					}
212
				},
213
				"each": function(env) {
214
					var hand = env.dir["_"],
215
						as = this.as,
216
						es = this.es,
217
						item, data = env.cd,
218
						p = this.p;
219
					if(data && p && p.length && p[0]) {
220
						env.ds.push(data);
221
						env.is.push(env.ci);
222
						for(var i = 0; i < p.length; ++i) {
223
							env.ci = p[i];
224
							env.cd = data[env.ci];
225
							hand.call(this, env);
226
						}
227
						env.ci = env.is.pop();
228
						env.cd = env.ds.pop();
229
					} else if(data) {
230
						env.is.push(env.ci);
231
						for(var key in data) {
232
							env.ci = k;
233
							hand.call(this, env);
234
						}
235
						env.ci = env.is.pop();
236
					}
237
				},
238
				"val": function(env) {
239
					var hand = env.dir["_"],
240
						as = this.as,
241
						es = this.es,
242
						items, item, data = env.cd,
243
						p = this.p;
244
					if(p && p.length && p[0]) {
245
						items = p[0].split("\\.");
246
						env.ds.push(data);
247
						while(items.length && data) {
248
							data = data[items.shift()];
249
						}
250
						if(items.length === 0 && data) {
251
							env.cd = data;
252
							hand.call(this, env);
253
						}
254
						env.cd = env.ds.pop();
255
					}
256
				},
257
				"valTag": function(env) {
258
					var hand = env.dir["_"],
259
						as = this.as,
260
						es = this.es,
261
						items, item, data = env.cd,
262
						p = this.p;
263
					if(p && p.length && p[0]) {
264
						items = p[0].split("\\.");
265
						env.ds.push(data);
266
						while(items.length && data) {
267
							data = data[items.shift()];
268
						}
269
						if(items.length === 0 && data) {
270
							env.cd = data;
271
							var ele = doc.createElement(this.n);
272
							env.ce.appendChild(ele);
273
							env.es.push(env.ce);
274
							env.ce = ele;
275
							for(var i = 0; i < as.length; ++i) {
276
								as[i].h(env);
277
							}
278
							for(var i = 0; i < es.length; ++i) {
279
								item = es[i];
280
								env.dir(item.h).call(item, env);
281
							}
282
							env.ce = env.es.pop();
283
						}
284
						env.cd = env.ds.pop();
285
					}
244 286
				}
245
				env.cd = env.ds.pop();
246
			}
247
		}
248
	},
249
	childCompile=function(chs,ret){
250
		var lisT =false;
251
		for(var i = 0 ; i < chs.length ; ++i){
252
			var ch=chs[i];
253
			if(ch.nodeType==1){
254
				if(lisT){
287
			},
288
			childCompile = function(chs, ret) {
289
				var lisT = false;
290
				for(var i = 0; i < chs.length; ++i) {
291
					var ch = chs[i];
292
					if(ch.nodeType == 1) {
293
						if(lisT) {
294
							ret.push(textCompile(s));
295
						}
296
						ret.push(eleCompile(ch));
297
						lisT = false;
298
					} else if(ch.nodeType == 3) {
299
						s = listT ? (s + ch.nodeValue) : ch.nodeValue;
300
						listT = true;
301
					}
302
				}
303
				if(listT) {
255 304
					ret.push(textCompile(s));
256 305
				}
257
				ret.push(eleCompile(ch));
258
				lisT=false;
259
			}else if(ch.nodeType==3){
260
				s = listT?(s+ch.nodeValue):ch.nodeValue;
261
				listT=true;
262
			}
263
		}
264
		if(listT){
265
			ret.push(textCompile(s));
266
		}
267
	},
268
	/* ret.h(env) Element compiler */
269
	eleCompile=function(ele){
270
		var attrs=ele.attributes,cdir=ele.getAttribute("ch-dir")||"_", ret ={n:ele.node},as=ret.as=[],es=ret.es=[],lisT,s,ch;
271
		ch=cdir.split("-");
272
		ret.h=ch.shift();
273
		if(ch.length)ret.p=ch;		
274
		for(var i = 0 ;i < attrs.length;++i){
275
			as.push(attrCompile(attrs[i]));
276
		}
277
		childCompile(ele.children,ret.es);
278
		return tet;
279
	},parseElement=function(ele){
280
		var env={sh:{},dir:{}},chs=[];
281
		childCompile(ele.children,chs);
282
		$.extend(env.sh,ch_val_buider);
283
		$.extend(env.dir,ch_dir_container);
284
		return {
285
			"shell":function(name,hand){
286
				if(hand){
287
					env.sh[name]=hand;
288
					return this;
289
				}else return env.sh[name];
290
			},"dir":function(name,hand){
291
				if(hand){
292
					env.dir[name]=hand;
293
					return this;
294
				}else return env.dir[name];
295
			},"fill":function(pe,data){
296
				env.es=[];env.ds=[];env.is=[];env.ce=pe,env.cd=data;
297
				for(var i = 0 ; i < chs.length;++i){
298
					var ch = chs[i];
299
					env.dir[ch.h].call(ch,env);
306
			},
307
			/* ret.h(env) Element compiler */
308
			eleCompile = function(ele) {
309
				var attrs = ele.attributes,
310
					cdir = ele.getAttribute("ch-dir") || "_",
311
					ret = { n: ele.node },
312
					as = ret.as = [],
313
					es = ret.es = [],
314
					lisT, s, ch;
315
				ch = cdir.split("-");
316
				ret.h = ch.shift();
317
				if(ch.length) ret.p = ch;
318
				for(var i = 0; i < attrs.length; ++i) {
319
					as.push(attrCompile(attrs[i]));
300 320
				}
301
				return this;
302
			}
321
				childCompile(ele.children, ret.es);
322
				return tet;
323
			},
324
			parseElement = function(ele) {
325
				var env = { sh: {}, dir: {} },
326
					chs = [];
327
				childCompile(ele.children, chs);
328
				$.extend(env.sh, ch_val_buider);
329
				$.extend(env.dir, ch_dir_container);
330
				return {
331
					"shell": function(name, hand) {
332
						if(hand) {
333
							env.sh[name] = hand;
334
							return this;
335
						} else return env.sh[name];
336
					},
337
					"dir": function(name, hand) {
338
						if(hand) {
339
							env.dir[name] = hand;
340
							return this;
341
						} else return env.dir[name];
342
					},
343
					"fill": function(pe, data) {
344
						env.es = [];
345
						env.ds = [];
346
						env.is = [];
347
						env.ce = pe, env.cd = data;
348
						for(var i = 0; i < chs.length; ++i) {
349
							var ch = chs[i];
350
							env.dir[ch.h].call(ch, env);
351
						}
352
						return this;
353
					}
354
				};
355
			},
356
			defBh = function(data) { return data; },
357
			parseCode(ele) = function(ele) {
358
				var hand = parseElement(ele),
359
					$ele = $(ele),
360
					bh = defBh,
361
					lses = [];
362
				return $.extend(hand, {
363
					"val": function(data) {
364
						$ele.empty();
365
						data = bh(data);
366
						var docf = doc.createDocumentFragment();
367
						this.fill(docf, data);
368
						ele.appendChild(docf);
369
						for(var i = 0; i < lses.length; ++i) {
370
							lses[i]();
371
						}
372
						return this;
373
					},
374
					"empty": function() {
375
						$(ele).empty();
376
						return this;
377
					},
378
					"listen": function(h) {
379
						if(h) lses.push(h);
380
						return this;
381
					}
382
				});
383
			},
384
			parseHtmlTemplate = function(c) {
385
				var $div = $("<div style='display:none;'></div>");
386
				$div.appendTo($body).html(c);
387
				var h = parseCode($div[0]);
388
				$div.remove();
389
				return $.extend(h, {
390
					"appendTo": function(pe, data) {
391
						var docf = doc.createDocumentFragment();
392
						this.fill(docf, data);
393
						pe.appendChild(docf);
394
					}
395
				});
396
			};
397
		return {
398
			"parse": parseElement,
399
			"element": parseCode,
400
			"template": parseHtmlTemplate
303 401
		};
304
	},	
305
	defBh=function(data){return data;},
306
	parseCode(ele)=function(ele){
307
		var hand =parseElement(ele),$ele=$(ele),bh=defBh,lses=[];
308
		return $.extend(hand,{
309
			"val":function(data){
310
				$ele.empty();
311
				data = bh(data);
312
				var docf = doc.createDocumentFragment();
313
				this.fill(docf,data);
314
				ele.appendChild(docf);
315
				for(var i = 0; i < lses.length;++i){
316
					lses[i]();
317
				}
318
				return this;
319
			},"empty":function(){
320
				$(ele).empty();
321
				return this;
322
			},"listen":function(h){
323
				if(h) lses.push(h);
324
				return this;
325
			}
326
		});
327
	},parseHtmlTemplate=function(c){
328
		var $div=$("<div style='display:none;'></div>");
329
		$div.appendTo($body).html(c);
330
		var h =parseCode($div[0]);
331
		$div.remove();
332
		return $.extend(h,{
333
			"appendTo":function(pe,data){
334
				var docf = doc.createDocumentFragment();
335
				this.fill(docf,data);
336
				pe.appendChild(docf);
337
			}
338
		});
339
	};
340
	var codeHtml ={
341
			"parse":parseElement,
342
			"element":parseCode,
343
			"template":parseHtmlTemplate
344
	};
345
	if(exports) exports.codeHteml = codeHtml;
346
	return codeHtml;
347
})(jQuery,document,$body,window);
348
 
402
	});
403
404
})(jQuery);

+ 40 - 0
js/common.js

@ -0,0 +1,40 @@
1
if(typeof jQuery === 'undefined') {
2
	throw new Error('this JavaScript requires jQuery')
3
} +
4

5
!(function($, win, doc) {
6
	var mds = {};
7
	mds["jQuery"] = $;
8
	mds["win"] = win;
9
	mds["doc"] = doc;
10
	mds["body"] = $("body");
11
	$.define = function(deps, id, factory) {
12
		var dm = [];
13
		for(var i = 0; i < deps.length; ++i) {
14
			var dep = mds[deps[i]];
15
			if(dep) {
16
				dm.push(dep);
17
			} else {
18
				throw new Error("no found model [" + deps[i] + "]");
19
			}
20
		}
21
		try {
22
			var md = factory.apply(win, dm);
23
			mds[id] = md;
24
		} catch {
25
			throw new Error("build model[" + id + "] error");
26
		}
27
	};
28
	$.use = function(deps, handle) {
29
		var dm = [];
30
		for(var i = 0; i < deps.length; ++i) {
31
			var dep = mds[deps[i]];
32
			if(dep) {
33
				dm.push(dep);
34
			} else {
35
				throw new Error("no found model [" + deps[i] + "]");
36
			}
37
		}
38
		handle.apply(win, dm);
39
	};
40
})(jQuery, window, document);

+ 162 - 147
js/form.js

@ -1,161 +1,176 @@
1
(function($,util, exports) {
2
	var impls = [],
1
!(function($) {
3 2
4
	/* default impl */
5
	di = function(val) {
6
		var v = val, dv = null;
7
		return {
8
			val : function(data) {
9
				if (arguments.length) {
10
					v = data;
11
					return this;
12
				}
13
				return v;
3
	$.define(["jQuery", "util"], "form", function($, util) {
4
5
		var impls = [],
6
7
			/* default impl */
8
			di = function(val) {
9
				var v = val,
10
					dv = null;
11
				return {
12
					val: function(data) {
13
						if(arguments.length) {
14
							v = data;
15
							return this;
16
						}
17
						return v;
18
					},
19
					reset: function(data) {
20
						if(arguments.length) {
21
							dv = data;
22
							return this;
23
						}
24
						dv = data;
25
						validate
26
						return this;
27
					},
28
					validate: function(vds) {
29
						if(vds) {
30
							// add valid obj
31
							return this;
32
						} else {
33
							return true;
34
						}
35
					}
36
				};
14 37
			},
15
			reset : function(data) {
16
				if (arguments.length) {
17
					dv = data;
18
					return this;
38
			svd = function(items, vds) {
39
				for(key in vds) {
40
					var im = items[key],
41
						vd = vds[key];
42
					if(im && vd)
43
						im.validate(vd);
19 44
				}
20
				dv = data;
21
				validate
22 45
				return this;
23 46
			},
24
			validate : function(vds) {
25
				if (vds) {
26
					// add valid obj
27
					return this;
28
				} else {
29
					return true;
47
			vd = function(items) {
48
				for(key in items) {
49
					if(!items[key].validate())
50
						return false;
30 51
				}
31
			}
32
		};
33
	}, svd = function(items, vds) {
34
		for (key in vds) {
35
			var im = items[key], vd = vds[key];
36
			if (im && vd)
37
				im.validate(vd);
38
		}
39
		return this;
40
	}, vd = function(items) {
41
		for (key in items) {
42
			if (!items[key].validate())
43
				return false;
44
		}
45
		return true;
46
	}, vda = function(valids,form) {
47
		for (var i = 0; i < valids.length; ++i) {
48
			if (!valids[i](form))
49
				return false;
50
		}
51
		return true;
52
	},
53
54
	/* create form instance by jQuery obj */
55
	bf = function($e) {
56
		if ($e.length === 1) {
57
			var items = {}, valids = [];
58
			$e.find(".form-item").each(function() {
59
				var $this = $(this);
60
				for (var i = 0; i < impls.length; ++i) {
61
					var item = impls[i]($this);
62
					if (item && item.name) {
63
						items[item.name] = item;
64
					}
52
				return true;
53
			},
54
			vda = function(valids, form) {
55
				for(var i = 0; i < valids.length; ++i) {
56
					if(!valids[i](form))
57
						return false;
65 58
				}
66
			});
67
			return {
68
				item : function(name) {
69
					return items[name];
70
				},
71
				validate : function(vds) {
72
					if (arguments.length) {
73
						$.isArray(data) ? valids.concat(data) : svd(items, vds);
74
						return this;
75
					} else {
76
						return vd(items) ? vda(valids,this) : false;
77
					}
78
				},
79
				val : function(data) {
80
					if (arguments.length) {
81
						if (data) {
82
							for (key in data) {
83
								var ch = items[key];
84
								if (!ch) {
85
									ch = items[key] = di();
86
								}
87
								ch.val(data[key]);
59
				return true;
60
			},
61
62
			/* create form instance by jQuery obj */
63
			bf = function($e) {
64
				if($e.length === 1) {
65
					var items = {},
66
						valids = [];
67
					$e.find(".form-item").each(function() {
68
						var $this = $(this);
69
						for(var i = 0; i < impls.length; ++i) {
70
							var item = impls[i]($this);
71
							if(item && item.name) {
72
								items[item.name] = item;
88 73
							}
89 74
						}
90
						return this;
91
					}
92
					var ret = {};
93
					for (key in items) {
94
						ret[key] = items[key].val();
95
					}
96
					return ret;
97
				},
98
				reset : function(data) {
99
					if (arguments.leng) {
100
						for (key in data) {
101
							var item = itmes[key];
102
							if (item)
103
								item.reset(data[key]);
104
						}
105
					} else {
106
						for (key in items) {
107
							items[key].reset();
108
						}
109
					}
110
				},get:function(url,data,eh,config){
111
					util.get(url,data,function(rd){
112
						if(config && config.check){
113
							rd =config.ckeck(rd);
114
							if(rd){
115
								this.reset();
116
								this.val(rd);
75
					});
76
					return {
77
						item: function(name) {
78
							return items[name];
79
						},
80
						validate: function(vds) {
81
							if(arguments.length) {
82
								$.isArray(data) ? valids.concat(data) : svd(items, vds);
83
								return this;
84
							} else {
85
								return vd(items) ? vda(valids, this) : false;
117 86
							}
118
						}
119
					},eh,config);
120
				},post:function(url,data,eh,config){
121
					util.post(url,data,function(rd){
122
						if(config && config.check){
123
							rd =config.ckeck(rd);
124
							if(rd){
125
								this.reset();
126
								this.val(rd);
87
						},
88
						val: function(data) {
89
							if(arguments.length) {
90
								if(data) {
91
									for(key in data) {
92
										var ch = items[key];
93
										if(!ch) {
94
											ch = items[key] = di();
95
										}
96
										ch.val(data[key]);
97
									}
98
								}
99
								return this;
100
							}
101
							var ret = {};
102
							for(key in items) {
103
								ret[key] = items[key].val();
104
							}
105
							return ret;
106
						},
107
						reset: function(data) {
108
							if(arguments.leng) {
109
								for(key in data) {
110
									var item = itmes[key];
111
									if(item)
112
										item.reset(data[key]);
113
								}
114
							} else {
115
								for(key in items) {
116
									items[key].reset();
117
								}
118
							}
119
						},
120
						get: function(url, data, eh, config) {
121
							util.get(url, data, function(rd) {
122
								if(config && config.check) {
123
									rd = config.ckeck(rd);
124
									if(rd) {
125
										this.reset();
126
										this.val(rd);
127
									}
128
								}
129
							}, eh, config);
130
						},
131
						post: function(url, data, eh, config) {
132
							util.post(url, data, function(rd) {
133
								if(config && config.check) {
134
									rd = config.ckeck(rd);
135
									if(rd) {
136
										this.reset();
137
										this.val(rd);
138
									}
139
								}
140
							}, eh, config);
141
						},
142
						doGet: function(url, sh, eh, config) {
143
							if(this.validate()) {
144
								util.get(url, this.val(), sh, eh, config);
145
							}
146
						},
147
						doPost: function(url, sh, eh, config) {
148
							if(this.validate()) {
149
								util.post(url, this.val(), sh, eh, config);
150
							}
151
						},
152
						doPut: function(url, sh, eh, config) {
153
							if(this.validate()) {
154
								util.put(url, this.val(), sh, eh, config);
155
							}
156
						},
157
						doDel: function(url, sh, eh, config) {
158
							if(this.validate()) {
159
								util.del(url, this.val(), sh, eh, config);
127 160
							}
128 161
						}
129
					},eh,config);
130
				},doGet:function(url,sh,eh,config){
131
					if(this.validate()){
132
						util.get(url,this.val(),sh,eh,config);
133
					}
134
				},doPost:function(url,sh,eh,config){
135
					if(this.validate()){
136
						util.post(url,this.val(),sh,eh,config);
137
					}
138
				},doPut:function(url,sh,eh,config){
139
					if(this.validate()){
140
						util.put(url,this.val(),sh,eh,config);
141
					}
142
				},doDel:function(url,sh,eh,config){
143
					if(this.validate()){
144
						util.del(url,this.val(),sh,eh,config);
145
					}
162
					};
146 163
				}
147
			};
148
		}
149
		return null;
150
	}
164
				return null;
165
			}
166
167
		return {
168
			build: bf,
169
			register: function(impl) {
170
				impls.push(impl)
171
			}
172
		};
173
174
	});
151 175
152
	var ret = {
153
		build : bf,
154
		register : function(impl) {
155
			impls.push(impl)
156
		}
157
	};
158
	if (exports)
159
		exports.form = ret;
160
	return ret;
161
})(jQuery,util, window);
176
})(jQuery);

+ 24 - 0
js/model/sys/dict/add.js

@ -0,0 +1,24 @@
1
;
2
spa_define(function(spa) {
3

4
	return {
5
		modal: function(data) {
6
			var modalCtn =spa.getLastModalCtn();
7
			var root = modalCtn = modalCtn.children();	
8
			var form = root.find(".newForm").form();
9
			root.find(".modal-ctrl .icon-times").on("click",function(){
10
				spa.closeModal();
11
			});
12
			
13
			root.find(".opt-save").on("click",function(){
14
				form.doPost("../ajax/sys/dict/info",function(){
15
					spa.closeModal();
16
					if(data){
17
						data();
18
					}
19
				},{});
20
			});
21
		}
22
	};
23

24
});

+ 24 - 0
js/model/sys/dict/edit.js

@ -0,0 +1,24 @@
1
;
2
spa_define(function(spa) {
3

4
	return {
5
		modal: function(data) {
6
			var modalCtn =spa.getLastModalCtn();
7
			var root = modalCtn = modalCtn.children();	
8
			var form = root.find(".newForm").form();
9
			root.find(".modal-ctrl .icon-times").on("click",function(){
10
				spa.closeModal();
11
			});
12
			form.val(data.data);
13
			root.find(".opt-save").on("click",function(){
14
				form.doPut("../ajax/sys/dict/info",function(){
15
					spa.closeModal();
16
					if(data.hand){
17
						data.hand();
18
					}
19
				},{});
20
			});
21
		}
22
	};
23

24
});

+ 157 - 0
js/model/sys/dict/index.js

@ -0,0 +1,157 @@
1
;
2
spa_define(function(spa) {
3

4
	return {
5
		main: function() {
6
			var root = spa.mainEle.children(".sys_dict_index");
7
			var pdg = root.pdg();
8

9
			var bindDataEvent = function() {
10
				root.find(".table-opt i.icon-edit").on("click", function() {
11
					var $this = $(this);
12
					var code = $this.parent().attr("dictCode");
13
					if(code) {
14
						$.util.get("../ajax/sys/dict/info/" + code, null, function(data) {
15
							if(data.readonly) {
16
								$.util.alertMsg("只读的");
17
							} else {
18
								spa.showModal("sys_dict_edit", {
19
									data: data,
20
									hand: function() {
21
										pdg.load();
22
									}
23
								});
24
							}
25
						}, {});
26
					}
27

28
				});
29
			};
30

31
			pdg.codeRef.addValueListener($.util.dictDisplay);
32
			pdg.codeRef.addValueListener(bindDataEvent);
33
			root.find(".opt-query").on("click", function() {
34
				//				console.log("dt load")
35
				pdg.load();
36
			});
37

38
			//console.log(pdg.formRef.val());
39
			pdg.load();
40

41
			root.find(".opt-new").on("click", function() {
42
				spa.showModal("sys_dict_add", function() { pdg.load() });
43
			});
44

45
			root.find(".table-opt i.icon-edit").on("click", function() {
46
				var $this = $(this);
47
				var code = $this.parent().attr("dictCode");
48
				if(code) {
49
					$.util.get("../ajax/sys/dict/info/" + code, null, function(data) {
50
						if(data.readonly) {
51
							$.util.alert("只读的");
52
						} else {
53
							spa.showModal("sys_dict_edit", {
54
								data: data,
55
								hand: function() {
56
									pdg.load();
57
								}
58
							});
59
						}
60
					}, {});
61
				}
62

63
			});
64

65
			//			root.find(".dt-tpl").on("click", "th.opt-check>i.icon-st-check", function() {
66
			//				var $this = $(this);
67
			//				$this.toggleClass("checked");
68
			//				if($this.hasClass("checked")) {
69
			//					root.find(".dt-tpl td.opt-check>i.icon-st-check").addClass("checked");
70
			//				} else {
71
			//					root.find(".dt-tpl td.opt-check>i.icon-st-check").removeClass("checked");
72
			//				}
73
			//			});
74
			//			root.find(".dt-tpl").on("click", "td.opt-check>i.icon-st-check", function() {
75
			//				var $this = $(this);
76
			//				$this.toggleClass("checked");
77
			//			});
78
			//			root.find(".opt-edit").on("click", function() {
79
			//				var $org = root.find("td.opt-check>i.checked");
80
			//				if($org.length) {
81
			//					if($org.length > 1) {
82
			//						$.util.alertMsg("只能选择一个机构");
83
			//					} else {
84
			//						$.util.get("../ajax/sys/org/id/"+$org.attr("orgId"),null,function(rd){
85
			//							if(rd){
86
			//								spa.showModal("sys_org_edit", { data:rd, hand: function() { pdg.load() } })								
87
			//							}else{
88
			//								$.util.alertMsg("机构已不存在", function(){pdg.load();});
89
			//							}
90
			//						},{});
91
			//					}
92
			//				} else {
93
			//					$.util.alertMsg("请选择一个机构");
94
			//				}
95
			//			});
96
			//			root.find(".opt-del").on("click", function() {
97
			//				var $org = root.find("td.opt-check>i.checked");
98
			//				if($org.length) {
99
			//					var ret =[];
100
			//					$org.each(function(){
101
			//						ret.push($(this).attr("orgId"));						
102
			//					});
103
			//					$.util.boxMsg({
104
			//						title: "确认删除",
105
			//						content: "您是否要删除选中的机构信息,机构信息删除后不可恢复!!!!!!!!!!!!!!!!!!",
106
			//						btns: [{ caption: "删除", hand: function() {
107
			//							$.util.post("../ajax/sys/org/del",{ids:ret},function(){pdg.load()},{});							
108
			//						} },
109
			//							{ caption: "取消" }
110
			//						]
111
			//					});
112
			//				} else {
113
			//					$.util.alertMsg("请选择一个机构");
114
			//				}
115
			//			});
116
		},
117
		modal: function(data) {
118
			//console.log(spa.getLastModalCtn())
119
			//spa.getLastModalCtn().html(" in modal:"+(new Date()).toString());	
120
			//			var modalCtn =spa.getLastModalCtn();
121
			//			var root = modalCtn = modalCtn.children();	
122
			//			root.css("width","80%");
123
			//			root.find(".upload-btn").upload({
124
			//				uri:"/ajax/upload",
125
			//				maxSize:1048576,
126
			//				accept:"image/*",
127
			//				start:function(){console.log("start:"+JSON.stringify(this))},
128
			//				done:function(data){console.log("done:"+JSON.stringify({ref:this,data:data}))},
129
			//				fail:function(type,param){console.log("fail:"+JSON.stringify({ref:this,type:type,param:param}))},
130
			//				notity:function(total,loaded){console.log("notity:"+JSON.stringify({ref:this,total:total,loaded:loaded}))},
131
			//			});
132
			//			root.find(".icon-times").on("click",function(){
133
			//				spa.closeModal();
134
			//			});
135
			//			var pdg =root.pdg();
136
			//			pdg.codeRef.addValueListener($.util.dictDisplay);
137
			//			root.find(".query").on("click", function() {
138
			//				console.log("dt load")
139
			//				pdg.load();
140
			//			});
141
			//			root.find(".reset").on("click", function() {
142
			//				console.log("dt reset")
143
			//				pdg.formRef.reset();
144
			//			});
145
			//			console.log(pdg.formRef.val());
146
			//			pdg.load();
147

148
		},
149
		mainDestory: function() {
150

151
		},
152
		modalDestory: function() {
153

154
		}
155
	};
156

157
});

+ 7 - 1
js/text.js

@ -22,4 +22,10 @@
22 22
			
23 23
		};
24 24
	});	
25
})(jQuery,form);
25
})(jQuery,form);
26
27
28
!(function($){
29
	
30
	
31
})(jQuery);

+ 257 - 233
js/util.js

@ -1,238 +1,262 @@
1
(function($, $body, exports) {
2
	var noop = function() {
3
	}, infoDiv = $("#g_info"), errDiv = $("#g_err"), warnDiv = $("#g_warn"), msgDiv = $("#g_msg"), err_msg = {}, layer_curr = {
4
		index : 5000000,
5
		remove : noop,
6
		css : noop
7
	}, layer_remove = function() {
8
		this.shade.remove();
9
		this.ctn.empty();
10
		this.ctn.remove();
11
		this.prev.css("display", "block");
12
		_g_layer_curr = this.prev;
13
	}, fh = function(e) {
14
		$(this).parent().hide();
15
	}, bh = function($p) {
16
		$p.find(".click-hide-parent").on("click", fh);
17
	}, fillContent = function($c/* child node [String|Function|jQObj] */, $p) {
18
		if ($c) {
19
			if (typeof $c === "string") {
20
				$p.html(p);
21
			} else if (typeof p == "function") {
22
				$c.call($p);
23
			} else if ($c.jquery) {
24
				$p.append($c);
25
			}
26
		}
27
	}, modal = function(ctn) {
28
		var inx = _g_layer_curr.index + 2, ly = {
29
			index : inx,
30
			remove : layer_remove,
31
			prev : _g_layer_curr
32
		};
33
		ly.shade = $(
34
				"<div class='layer-shade layer-" + inx + "' style='z-index:"
35
						+ inx + ";'></div>").appendTo(body);
36
		++inx;
37
		ly.ctn = $(
38
				"<div class='layer-ctn layer-" + inx + "' style='z-index:"
39
						+ inx + ";'></div>").appendTo(body);
40
		ly.prev = layer_curr;
41
		layer_curr = ly;
42
		fillContent(ctn, ly.ctn);
43
		return ly;
44
	}, rmModal = function() {
45
		layer_curr.remove();
46
	},
47
48
	// function error message
49
	fem = function($c, $t) {
50
		var $e = $(
51
				"<div class='err-ctn'><i class='icon click-hide-parent'></i></div>")
52
				.appendTo(errDiv);
53
		$("<span></span>").appendTo($e).html($c);
54
		bh($e);
55
		setTimeout(function() {
56
			$e.remove()
57
		}, $t ? $t : 10000);
58
	},
59
	// function warn message
60
	fwm = function($c, $t) {
61
		var $w = $(
62
				"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
63
				.appendTo(warnDiv);
64
		$("<span></span>").appendTo($w).html($c);
65
		bh($w);
66
		setTimeout(function() {
67
			$w.remove()
68
		}, $t ? $t : 3000);
69
	}, fm = function($c, $t) {
70
		var $m = $(
71
				"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
72
				.appendTo(warnDiv);
73
		$("<span></span>").appendTo($w).html($c);
74
		bh($m);
75
		setTimeout(function() {
76
			$w.remove()
77
		}, $t ? $t : 3000);
78
	}, loadref = 0, loadingDiv = $("#g_loading"), loading = function() {
79
		++loadref;
80
		if (loadref === 1) {
81
			loadingDiv.show()
82
		}
83
	}, unLoading = function() {
84
		--loadref;
85
		if (loadref === 0) {
86
			loadingDiv.hide()
87
		}
88
	}, am = function(title, content, hand) {
89
		if (content) {
90
			if ($.isFunction(content)) {
91
				hand = content;
92
				content = title;
93
				title = "提示";
94
			}
95
		} else {
96
			content = title;
97
			title = "提示";
98
		}
99
		hand = hand || noop;
100
		var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"><button type="button" class="btn">关闭</button></div></div></div>');
101
		ly.ctn.find(".modal-title").text(title);
102
		$c = ly.ctn.find("p").text(content);
103
		ly.ctn.find("button").on("click", function() {
104
			rmModal();
105
			hand();
106
		});
107
	}, bm_addBtn = function($p, $cp, $h) {
108
		var $b = $('<button type="button" class="btn"></button>').appendTo($p);
109
		b.text($cp).on("click", function() {
110
			rmModal(), $h()
111
		});
112
	}, bm = function(obj) {
113
		var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"></div></div></div>');
114
		ly.ctn.find(".modal-title").text(obj.title || "确认");
115
		ly.ctn.find("p").text(obj.content);
116
		var m_footer = ly.ctn.find(".modal-footer"), btnH = function(btn) {
117
			var $btn = $('<button type="button" class="btn"></button>')
118
					.appendTo(m_footer);
119
			var caption = btn.caption || "未命名的", handler = btn.hand || noop;
120
			$btn.text(caption);
121
			$btn.on("click", function() {
122
				util.closeModalLayer();
123
				handler();
124
			});
125
		};
126
		for (var i = 0; i < obj.btns.length; ++i) {
127
			bm_addBtn(m_footer, btns[i].caption || "no name", btns[i].hand
128
					|| noop);
129
		}
130
	}, g_def_err_hand = function(ep) {
131
		fem("http access error:\r\n" + JSON.stirngify(ep));
132
	}, g_err = {
133
		"defErrHand" : function(ep) {
1
!(function($) {
2
	$.define(["jQuery", "body", "win"], "util", function($, $body, win) {
3
		var noop = function() {},
4
			infoDiv = $("#g_info"),
5
			errDiv = $("#g_err"),
6
			warnDiv = $("#g_warn"),
7
			msgDiv = $("#g_msg"),
8
			err_msg = {},
9
			layer_curr = {
10
				index: 5000000,
11
				remove: noop,
12
				css: noop
13
			},
14
			layer_remove = function() {
15
				this.shade.remove();
16
				this.ctn.empty();
17
				this.ctn.remove();
18
				this.prev.css("display", "block");
19
				_g_layer_curr = this.prev;
20
			},
21
			fh = function(e) {
22
				$(this).parent().hide();
23
			},
24
			bh = function($p) {
25
				$p.find(".click-hide-parent").on("click", fh);
26
			},
27
			fillContent = function($c /* child node [String|Function|jQObj] */ , $p) {
28
				if($c) {
29
					if(typeof $c === "string") {
30
						$p.html(p);
31
					} else if(typeof p == "function") {
32
						$c.call($p);
33
					} else if($c.jquery) {
34
						$p.append($c);
35
					}
36
				}
37
			},
38
			modal = function(ctn) {
39
				var inx = _g_layer_curr.index + 2,
40
					ly = {
41
						index: inx,
42
						remove: layer_remove,
43
						prev: _g_layer_curr
44
					};
45
				ly.shade = $(
46
					"<div class='layer-shade layer-" + inx + "' style='z-index:" +
47
					inx + ";'></div>").appendTo(body);
48
				++inx;
49
				ly.ctn = $(
50
					"<div class='layer-ctn layer-" + inx + "' style='z-index:" +
51
					inx + ";'></div>").appendTo(body);
52
				ly.prev = layer_curr;
53
				layer_curr = ly;
54
				fillContent(ctn, ly.ctn);
55
				return ly;
56
			},
57
			rmModal = function() {
58
				layer_curr.remove();
59
			},
134 60
135
		},
136
		"0" : "未定义的错误",
137
	},
138
	/**
139
	 * ep={code:"",msg:"",detailMsg:"",url:""} pa=function(code,msg,detailMsg)
140
	 * pa=boolean
141
	 */
142
	ajaxErrHand = function(ep, eh) {
143
		if (eh) {
144
			var pt = $.type(eh);
145
			if (pt == "booean") {
146
				g_def_err_hand(ep);
147
			} else if (pt == "function") {
148
				eh(ep);
149
			} else {
150
				var ph = eh[ep.code] || g_err[ep.code] || eh["defErrHand"]
151
						|| g_err["defErrHand"];
152
				if (typeof ph === "string") {
153
					fem(ph);
61
			// function error message
62
			fem = function($c, $t) {
63
				var $e = $(
64
						"<div class='err-ctn'><i class='icon click-hide-parent'></i></div>")
65
					.appendTo(errDiv);
66
				$("<span></span>").appendTo($e).html($c);
67
				bh($e);
68
				setTimeout(function() {
69
					$e.remove()
70
				}, $t ? $t : 10000);
71
			},
72
			// function warn message
73
			fwm = function($c, $t) {
74
				var $w = $(
75
						"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
76
					.appendTo(warnDiv);
77
				$("<span></span>").appendTo($w).html($c);
78
				bh($w);
79
				setTimeout(function() {
80
					$w.remove()
81
				}, $t ? $t : 3000);
82
			},
83
			fm = function($c, $t) {
84
				var $m = $(
85
						"<div class='warn-ctn'><i class='icon click-hide-parent'></i></div>")
86
					.appendTo(warnDiv);
87
				$("<span></span>").appendTo($w).html($c);
88
				bh($m);
89
				setTimeout(function() {
90
					$w.remove()
91
				}, $t ? $t : 3000);
92
			},
93
			loadref = 0,
94
			loadingDiv = $("#g_loading"),
95
			loading = function() {
96
				++loadref;
97
				if(loadref === 1) {
98
					loadingDiv.show()
99
				}
100
			},
101
			unLoading = function() {
102
				--loadref;
103
				if(loadref === 0) {
104
					loadingDiv.hide()
105
				}
106
			},
107
			am = function(title, content, hand) {
108
				if(content) {
109
					if($.isFunction(content)) {
110
						hand = content;
111
						content = title;
112
						title = "提示";
113
					}
154 114
				} else {
155
					ph(ep);
115
					content = title;
116
					title = "提示";
156 117
				}
157
			}
158
		}
159
	}, ajaxAccess = function(method, pUrl, pData, sh, eh, config) {
160
		config = config || {};
161
		if (false !== config.mask)
162
			loading();
163
		config.traditional = true;
164
		config.type = method;
165
		config.url = pUrl, config.data = pData;
166
		config.contentType= method ==="put" ? "application/json" : "application/x-www-form-urlencoded";
167
		config.success = function(rd) {
168
			if (rd.success) {
169
				sh(rd.data);
170
			} else {
171
				rd.code = "" + rd.code;
172
				rd.url = pUrl;
173
				ajaxErrHand(ep, eh);
174
			}
175
		};		
176
		config.error = function(jqXHR, textStatus, errorThrown) {
177
			ajaxErrHand({
178
				code : textStatus,
179
				msg : textStatus,
180
				detailMsg : textStatus,
181
				xhr : jqXHR,
182
				eObj : errorThrown,
183
				url : pUrl
184
			}, eh);
185
		};
186
		$.ajax(config).always(false !== config.mask ? unLoading : noop);
187
	};
118
				hand = hand || noop;
119
				var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"><button type="button" class="btn">关闭</button></div></div></div>');
120
				ly.ctn.find(".modal-title").text(title);
121
				$c = ly.ctn.find("p").text(content);
122
				ly.ctn.find("button").on("click", function() {
123
					rmModal();
124
					hand();
125
				});
126
			},
127
			bm_addBtn = function($p, $cp, $h) {
128
				var $b = $('<button type="button" class="btn"></button>').appendTo($p);
129
				b.text($cp).on("click", function() {
130
					rmModal(), $h()
131
				});
132
			},
133
			bm = function(obj) {
134
				var ly = modal('<div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h4 class="modal-title"></h4></div><div class="modal-body"><p></p></div><div class="modal-footer"></div></div></div>');
135
				ly.ctn.find(".modal-title").text(obj.title || "确认");
136
				ly.ctn.find("p").text(obj.content);
137
				var m_footer = ly.ctn.find(".modal-footer"),
138
					btnH = function(btn) {
139
						var $btn = $('<button type="button" class="btn"></button>')
140
							.appendTo(m_footer);
141
						var caption = btn.caption || "未命名的",
142
							handler = btn.hand || noop;
143
						$btn.text(caption);
144
						$btn.on("click", function() {
145
							util.closeModalLayer();
146
							handler();
147
						});
148
					};
149
				for(var i = 0; i < obj.btns.length; ++i) {
150
					bm_addBtn(m_footer, btns[i].caption || "no name", btns[i].hand ||
151
						noop);
152
				}
153
			},
154
			g_def_err_hand = function(ep) {
155
				fem("http access error:\r\n" + JSON.stirngify(ep));
156
			},
157
			g_err = {
158
				"defErrHand": function(ep) {
188 159
189
	ret = {
190
		showModal : modal,
191
		closeModal : rmModal,
192
		showLoading : loading,
193
		hideLoading : unLoading,
194
		listModalIndex : function() {
195
			return lay_curr.index + 1;
196
		},
197
		error : fem,
198
		warn : fwm,
199
		msg : fm,
200
		alert : am,
201
		boxMsg : bm,
202
		confirm : function(msg, yes, no) {
203
			bm({
204
				content : msg,
205
				btns : [ {
206
					caption : "取消",
207
					hand : no || noop
208
				}, {
209
					caption : "确认",
210
					hand : yes
211
				} ]
212
			});
213
		},
214
		get : function(url, data, sh, eh, config) {
215
			ajaxAccess("get", url, data, sh, eh, config);
216
		},
217
		post : function(url, data, sh, eh, config) {
218
			ajaxAccess("post", url, data, sh, eh, config);
219
		},
220
		put : function(url, data, sh, eh, config) {
221
			ajaxAccess("post", url, data ? JSON.stringify(data) : "", sh, eh,
160
				},
161
				"0": "未定义的错误",
162
			},
163
			/**
164
			 * ep={code:"",msg:"",detailMsg:"",url:""} pa=function(code,msg,detailMsg)
165
			 * pa=boolean
166
			 */
167
			ajaxErrHand = function(ep, eh) {
168
				if(eh) {
169
					var pt = $.type(eh);
170
					if(pt == "booean") {
171
						g_def_err_hand(ep);
172
					} else if(pt == "function") {
173
						eh(ep);
174
					} else {
175
						var ph = eh[ep.code] || g_err[ep.code] || eh["defErrHand"] ||
176
							g_err["defErrHand"];
177
						if(typeof ph === "string") {
178
							fem(ph);
179
						} else {
180
							ph(ep);
181
						}
182
					}
183
				}
184
			},
185
			ajaxAccess = function(method, pUrl, pData, sh, eh, config) {
186
				config = config || {};
187
				if(false !== config.mask)
188
					loading();
189
				config.traditional = true;
190
				config.type = method;
191
				config.url = pUrl, config.data = pData;
192
				config.contentType = method === "put" ? "application/json" : "application/x-www-form-urlencoded";
193
				config.success = function(rd) {
194
					if(rd.success) {
195
						sh(rd.data);
196
					} else {
197
						rd.code = "" + rd.code;
198
						rd.url = pUrl;
199
						ajaxErrHand(ep, eh);
200
					}
201
				};
202
				config.error = function(jqXHR, textStatus, errorThrown) {
203
					ajaxErrHand({
204
						code: textStatus,
205
						msg: textStatus,
206
						detailMsg: textStatus,
207
						xhr: jqXHR,
208
						eObj: errorThrown,
209
						url: pUrl
210
					}, eh);
211
				};
212
				$.ajax(config).always(false !== config.mask ? unLoading : noop);
213
			};
214
215
		return {
216
			showModal: modal,
217
			closeModal: rmModal,
218
			showLoading: loading,
219
			hideLoading: unLoading,
220
			listModalIndex: function() {
221
				return lay_curr.index + 1;
222
			},
223
			error: fem,
224
			warn: fwm,
225
			msg: fm,
226
			alert: am,
227
			boxMsg: bm,
228
			confirm: function(msg, yes, no) {
229
				bm({
230
					content: msg,
231
					btns: [{
232
						caption: "取消",
233
						hand: no || noop
234
					}, {
235
						caption: "确认",
236
						hand: yes
237
					}]
238
				});
239
			},
240
			get: function(url, data, sh, eh, config) {
241
				ajaxAccess("get", url, data, sh, eh, config);
242
			},
243
			post: function(url, data, sh, eh, config) {
244
				ajaxAccess("post", url, data, sh, eh, config);
245
			},
246
			put: function(url, data, sh, eh, config) {
247
				ajaxAccess("post", url, data ? JSON.stringify(data) : "", sh, eh,
222 248
					config);
223
		},
224
		del : function(url, sh, eh, pObj) {
225
			ajaxAccess("post", url, null, sh, eh, pOjb);
226
		},
227
		noop : noop,
228
		returnTrue : function() {
229
			return true;
230
		},
231
		returnFalse : function() {
232
			return false;
233
		}
234
	};
235
	if (exports)
236
		exports.util = ret;
237
	return ret;
238
})(jQuery, jQuery("body"), window);
249
			},
250
			del: function(url, sh, eh, pObj) {
251
				ajaxAccess("post", url, null, sh, eh, pOjb);
252
			},
253
			noop: noop,
254
			returnTrue: function() {
255
				return true;
256
			},
257
			returnFalse: function() {
258
				return false;
259
			}
260
		};
261
	});
262
})(jQuery);