Advertisement
Guest User

Untitled

a guest
Sep 15th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.11 KB | None | 0 0
  1. var app = {
  2. data: {},
  3. jsf: {
  4. extend: function (o) {
  5. $.extend(true, app.data, o);
  6. }
  7. },
  8. msg: function(key){
  9. return (typeof app.data.msg[key] === 'undefined')? 'Message undefined' : app.data.msg[key];
  10. },
  11. property: {
  12. add: {
  13. init: function() {
  14. app.library.validate('registrationForm', {
  15. file_upload_new: {
  16. required: true
  17. }
  18. },
  19. {
  20. file_upload_new: {
  21. required: app.msg('Property.add.required')
  22. }
  23. }
  24. );
  25. }
  26. },
  27. edit: {
  28. init: function() {
  29. app.library.validate('editForm', {
  30. property_name: {
  31. required: function(element){
  32. return $("#file_upload_edit").val()=="";
  33. },
  34. maxlength: 255
  35. },
  36. property_address: {
  37. required: function(element){
  38. return $("#file_upload_edit").val()=="";
  39. },
  40. maxlength: 255
  41. }
  42. },
  43. {
  44. property_name: {
  45. required: app.msg('Property.name.required'),
  46. maxlength: app.msg('Property.name.max')
  47. },
  48. property_address: {
  49. required: app.msg('Property.address.required'),
  50. maxlength: app.msg('Property.address.max')
  51. }
  52. }
  53. );
  54. }
  55. },
  56. search: {
  57. init: function () {
  58. app.library.validate('searchForm', {
  59. property_id: {
  60. hankaku:true
  61. }
  62. },
  63. {
  64. property_id: {
  65. hankaku:app.msg('registration.propertyNo.hankaku')
  66. }
  67. }
  68. );
  69. }
  70. }
  71. },
  72. resident: {
  73. edit: {
  74. init: function () {
  75. app.library.validate('residentForm',{
  76. email1: {
  77. emailallownull: true,
  78. maxlength: 255
  79. },
  80. email2: {
  81. emailallownull: true,
  82. maxlength: 255
  83. },
  84. email3: {
  85. emailallownull: true,
  86. maxlength: 255
  87. },
  88. card_no1: {
  89. digits: true,
  90. rangelength: [5, 10]
  91. },
  92. card_no2: {
  93. digits: true,
  94. rangelength: [5, 10]
  95. },
  96. card_no3: {
  97. digits: true,
  98. rangelength: [5, 10]
  99. },
  100. credit_card: {
  101. regex: /^$|^[a-zA-Z0-9-]+$/,
  102. rangelength: [1, 16],
  103. },
  104. tel: {
  105. digits: true,
  106. maxlength: 11
  107.  
  108. },
  109. name: {
  110. maxlength: 255
  111. },
  112. note: {
  113. maxlength: 255
  114. }
  115. },{
  116. email1: {
  117. maxlength: app.msg('residentinfo.email1.max'),
  118. emailallownull: app.msg('residentinfo.email1.email')
  119. },
  120. email2: {
  121. maxlength: app.msg('residentinfo.email2.max'),
  122. emailallownull: app.msg('residentinfo.email2.email')
  123. },
  124. email3: {
  125. maxlength: app.msg('residentinfo.email3.max'),
  126. emailallownull: app.msg('residentinfo.email3.email')
  127. },
  128. card_no1: {
  129. rangelength: app.msg('residentinfo.card_no1.max'),
  130. digits: app.msg('residentinfo.card_no1.number')
  131. },
  132. card_no2: {
  133. rangelength: app.msg('residentinfo.card_no2.max'),
  134. digits: app.msg('residentinfo.card_no2.number')
  135. },
  136. card_no3: {
  137. rangelength: app.msg('residentinfo.card_no3.max'),
  138. digits: app.msg('residentinfo.card_no3.number')
  139. },
  140. credit_card: {
  141. rangelength: app.msg('residentinfo.credit_card.max'),
  142. regex: app.msg('residentinfo.credit_card.format')
  143. },
  144. tel: {
  145. maxlength: app.msg('residentinfo.tel.max'),
  146. digits: app.msg('residentinfo.tel.number')
  147. },
  148. name: {
  149. maxlength: app.msg('residentinfo.name.max')
  150. },
  151. note: {
  152. maxlength: app.msg('residentinfo.note.max')
  153. }
  154. });
  155. }
  156. },
  157. registration: {
  158. init: function () {
  159. app.library.validate('searchForm',{
  160. no: {
  161. required: true,
  162. hankaku:true
  163. }
  164. },{
  165. no: {
  166. required: app.msg('registration.propertyNo.notEmpty'),
  167. hankaku: app.msg('registration.propertyNo.hankaku')
  168. }
  169. }, 'errorSearch');
  170.  
  171. app.library.validate('createForm',{
  172. property_no: {
  173. required: true,
  174. maxlength: 9,
  175. hankaku:true
  176. },
  177. csv: {
  178. required: true
  179. }
  180. },{
  181. property_no: {
  182. required: app.msg('registration.propertyNo.notEmpty'),
  183. maxlength: app.msg('registration.propertyNo.maxLength'),
  184. hankaku: app.msg('registration.propertyNo.hankaku')
  185. },
  186. csv: {
  187. required: app.msg('registration.csv.notEmpty')
  188. }
  189. });
  190. }
  191. }
  192. },
  193. user: {
  194. login:{
  195. init: function () {
  196. app.library.validate('loginForm',{
  197. login_id: {
  198. required: true
  199. },
  200. password: {
  201. required: true
  202. }
  203. },{
  204. login_id: {
  205. required: app.msg('login.id.notEmpty')
  206. },
  207. password: {
  208. required: app.msg('login.pwd.notEmpty')
  209. }
  210. });
  211. }
  212. },
  213. edit:{
  214. init: function(){
  215. app.library.validate('editForm',{
  216. username: {
  217. required: true,
  218. maxlength: 255
  219. },
  220. email: {
  221. required: true,
  222. email: true,
  223. maxlength: 255
  224. }
  225. },{
  226. username:{
  227. required: app.msg('users.username.notEmpty'),
  228. maxlength: app.msg('users.username.max')
  229. },
  230. email:{
  231. required: app.msg('users.email.notEmpty'),
  232. email: app.msg('users.email.format'),
  233. maxlength: app.msg('users.email.max')
  234. }
  235. });
  236. }
  237. },
  238. add:{
  239. init: function(){
  240. app.library.validate('addForm',{
  241. login_id: {
  242. required: true,
  243. maxlength: 255
  244. },
  245. username: {
  246. required: true,
  247. maxlength: 255
  248. },
  249. email: {
  250. required: true,
  251. emailallownull: true,
  252. maxlength: 255
  253. },
  254. password: {
  255. required: true,
  256. minlength: 8,
  257. regex: /^$|^[a-zA-Z0-9]+$/,
  258. maxlength: 10
  259. },
  260. confirm_password: {
  261. required: true,
  262. equalTo: "#password"
  263. }
  264. },{
  265. login_id: {
  266. required: app.msg('users.login_id.notEmpty'),
  267. maxlength: app.msg('users.login_id.max')
  268. },
  269. username:{
  270. required: app.msg('users.username.notEmpty'),
  271. maxlength: app.msg('users.username.max')
  272. },
  273. email:{
  274. required: app.msg('users.email.notEmpty'),
  275. emailallownull: app.msg('users.email.format'),
  276. maxlength: app.msg('users.email.max')
  277. },
  278. password:{
  279. required: app.msg('users.password.required'),
  280. minlength: app.msg('users.password.range'),
  281. maxlength: app.msg('users.password.range'),
  282. regex: app.msg('users.password.format')
  283. },
  284. confirm_password: {
  285. required: app.msg('users.confirm_password.required'),
  286. equalTo: app.msg('users.password.notmatch')
  287. }
  288. });
  289. }
  290. },
  291. pwd:{
  292. init: function () {
  293. app.library.validate('changePwd', {
  294. oldPASS: {
  295. required: true
  296. },
  297. newPASS: {
  298. required: true,
  299. minlength: 8,
  300. maxlength: 10,
  301. regex: /^[a-zA-Z0-9]{8,10}$/
  302. }
  303. }, {
  304. oldPASS: {
  305. required: app.msg('changepwd.oldPASS.notEmpty')
  306. },
  307. newPASS: {
  308. required: app.msg('changepwd.newPASS.notEmpty'),
  309. minlength: app.msg('changepwd.newPASS.min'),
  310. maxlength: app.msg('changepwd.newPASS.max'),
  311. regex: app.msg('changepwd.newPASS.regex')
  312. }
  313. });
  314. }
  315. }
  316. },
  317. ajax: {
  318. result: {},
  319. html: function (url, data, container, call_back) {
  320. var error = false;
  321. $.ajax({
  322. type: "POST",
  323. url: url,
  324. data: data,
  325. dataType: "html",
  326. async: true,
  327. success: function (html) {
  328. if (app.library.is_json(html)) {
  329. app.ajax.result = app.library.parse_json(html);
  330. if (app.ajax.result.error) {
  331. error = true;
  332. alert(app.ajax.result.error.msg);
  333. }
  334. } else {
  335. $(container).html(html);
  336. if (typeof call_back == 'function') {
  337. call_back.call();
  338. }
  339. }
  340. },
  341. error: function (error) {}
  342. });
  343. return app.ajax.result;
  344. },
  345. json: function (url, data, call_back) {
  346. $.ajax({
  347. type: "POST",
  348. url: url,
  349. data: data,
  350. dataType: "json",
  351. async: true,
  352. success: function (json) {
  353. try {
  354. app.ajax.result = json;
  355. if (app.ajax.result.error) {
  356. alert(app.ajax.result.error.msg);
  357. } else {
  358. if (typeof call_back == 'function') {
  359. call_back.call();
  360. }
  361. }
  362. } catch (e) {
  363. alert(json);
  364. }
  365. },
  366. error: function (error) {}
  367. });
  368. return app.ajax.result;
  369. },
  370. xml: function () {
  371. $.ajax({
  372. type: "POST",
  373. url: url,
  374. data: data,
  375. dataType: "xml",
  376. async: false,
  377. success: function (xml) {},
  378. error: function (error) {}
  379. });
  380. }
  381. },
  382. library: {
  383. parse_json:function(json){return $.parseJSON(json);},
  384. is_json:function(b){try{$.parseJSON(b)}catch(a){return false}return true},
  385. array_intersect:function(d,c){return $.grep(d,function(a){return $.inArray(a,c)>-1})},
  386. is_empty:function(a){if(!$.trim(a)){return true}else{return false}},
  387. validate:function(form,rules,messages,place='error') {
  388. $("#"+form).validate({
  389. rules: rules,
  390. messages: messages,
  391. onfocusin: false,
  392. onfocusout: false,
  393. onkeyup: false,
  394. onclick: false,
  395. errorPlacement: function (error, element) {
  396. $('#'+place).text(error.text());
  397. },
  398. showErrors: function (errorMap, errorList) {
  399. var map = {};
  400. var error = new Array(1);
  401. if (this.numberOfInvalids() > 1) {
  402. error[0] = errorList[0];
  403. errorList = error;
  404. $.each(errorMap, function (i, v) {
  405. map[i] = v;
  406. errorMap = map;
  407. return false;
  408. });
  409. }
  410. this.errorList = errorList;
  411. this.errorMap = errorMap;
  412. this.defaultShowErrors();
  413. },
  414. errorElement: 'div',
  415. submitHandler: function (a) {
  416. if ($(a).valid()) {
  417. a.submit();
  418. } else {
  419. return false;
  420. }
  421. }
  422. });
  423. }
  424. }
  425. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement