1'use strict'; 2if(!window.$ajapp) window.$ajapp = {}; 3 4/*AUTO GENERATED over gen-cc-file.js 5 DO NOT EDIT!*/ 6/******************************************************************************************/ 7/*** import /cls/main/_res/handlebarExtensions.js ***/ 8/******************************************************************************************/ 9 10Handlebars.registerHelper('l_eventanmeldemodal', function(str) { 11 if(arguments.length > 2){ 12 var pargs = []; 13 for(var i = 0; i < arguments.length - 1; i++){ 14 pargs.push(arguments[i]); 15 } 16 return $ajapp.eventanmeldemodal.lang.apply($ajapp.eventanmeldemodal, pargs); 17 } 18 return $ajapp.eventanmeldemodal.lang(str); 19}); 20 21Handlebars.registerHelper('_bo', function(str) { 22 return '{{'; 23}); 24 25Handlebars.registerHelper('_bc', function(str) { 26 return '}}'; 27}); 28 29Handlebars.registerHelper('_json', function(ob) { 30 if(ob){ 31 var ret = JSON.stringify(ob); 32 return ret; 33 } 34 return ''; 35}); 36 37Handlebars.registerHelper('_compile_eventanmeldemodal', function(tname, _ob, map) { 38 var ob = _ob; 39 if(typeof ob === "string" && ob === "{null}"){ 40 ob = {}; 41 } 42 if(tname && ob){ 43 if(typeof map === "string" && map){ 44 ob = $ajapp.eventanmeldemodal.run(map, ob); 45 } 46 return new Handlebars.SafeString($ajapp.eventanmeldemodal.compileElement(tname, ob)); 47 } 48 return ''; 49}); 50 51 52Handlebars.registerHelper('_template_eventanmeldemodal', function(tname, _ob, map, prefix) { 53 var ob = _ob; 54 if(typeof ob === "string" && ob === "{null}"){ 55 ob = {}; 56 } 57 if(tname && ob){ 58 if(typeof map === "string" && map){ 59 ob = $ajapp.eventanmeldemodal.run(map, ob); 60 } 61 if(typeof prefix === "string" && prefix){ 62 tname = prefix + "." + tname; 63 } 64 var runner = $ajapp.eventanmeldemodal.template[tname]; 65 if(!runner){ 66 $.log("MISSIN TEMPLATE " + tname, 0, 1); 67 return ""; 68 } 69 return new Handlebars.SafeString(runner(ob)); 70 } 71 return ''; 72}); 73 74 75Handlebars.registerHelper('_run_eventanmeldemodal', function(cmd) { 76 //var args = Array.prototype.splice.call(arguments, 1); 77 var ret = $ajapp.eventanmeldemodal.run.apply($ajapp.eventanmeldemodal, arguments); 78 if(!ret) return ""; 79 return new Handlebars.SafeString(ret); 80}); 81 82 83Handlebars.registerHelper('_concat', function(v1, v2) { 84 return '' + v1 + v2; 85}); 86 87 88Handlebars.registerHelper('_prop', function(obj, p) { 89 if(obj && obj[p]) return obj[p]; 90 return ""; 91}); 92 93 94Handlebars.registerHelper('_onlyOne', function(obj) { 95 var ret = false; 96 if(obj && obj.length && obj.length == 1){ 97 ret = true; 98 } 99 return ret; 100}); 101 102 103 104 105Handlebars.registerHelper('_rt_value', function(val) { 106 if(!val) return ""; 107 return new Handlebars.SafeString(val.replace(/<[\/]{0,1}body>/gi, "")); 108}); 109 110Handlebars.registerHelper('_date', function(val, format, inFormat) { 111 if(!val) return ""; 112 var m; 113 if(typeof inFormat === "string"){ 114 m = moment(val, inFormat); 115 }else{ 116 m = moment(val); 117 } 118 var f = typeof format === "string" ? format : "DD.MM.YYYY"; 119 return "" + m.format(f); 120}); 121 122 123Handlebars.registerHelper('_number', function(val, format_, locale_) { 124 //TODO implement this 125 //http://numeraljs.com/#use-it is already included 126 var l = typeof locale_ === "string" ? locale_ : "de"; 127 var f = typeof format_ === "string" ? format_ : "0,0.00"; 128 var ret = numeral(val).format(f); 129 if(l != 'en'){ 130 ret = ret.replace(/\./g, 'x').replace(/\,/g, '.').replace(/x/g, ','); 131 } 132 return ret; 133 /*if(!val && val != 0) return ""; 134 var format = typeof format_ === "string" ? format_ : "#,##0.00"; 135 var locale = (typeof locale_ === "string" ? locale_ : (data["j-db-lang"] ? data["j-db-lang"] : "de")); 136 var fval = parseFloat(val); 137 var myFormat = new java.text.DecimalFormat(format); 138 var dc = new java.text.DecimalFormatSymbols(new java.util.Locale(locale)); 139 myFormat.setDecimalFormatSymbols(dc); 140 return "" + myFormat.format(fval);*/ 141}); 142 143Handlebars.registerHelper('_img_src_eventanmeldemodal', function(img) { 144 var path = ""; 145 if($ajapp.eventanmeldemodal.isPhoneGap){ 146 path = "TODO: set local imapge path here for phone"; 147 }else{ 148 path = $ajapp.eventanmeldemodal.srvImgPath; 149 } 150 var imgSrc = ""; 151 if(img){ 152 if(img.indexOf(":") !== -1){ 153 imgSrc = img.split(":")[1]; 154 }else{ 155 imgSrc = img; 156 } 157 imgSrc = path + "/" + imgSrc; 158 } 159 return imgSrc; 160}); 161 162 163Handlebars.registerHelper('_ifCond', function (v1, operator, v2, options) { 164 switch (operator) { 165 case '==': 166 return (v1 == v2) ? options.fn(this) : options.inverse(this); 167 case '===': 168 return (v1 === v2) ? options.fn(this) : options.inverse(this); 169 case '!=': 170 return (v1 != v2) ? options.fn(this) : options.inverse(this); 171 case '<': 172 return (v1 < v2) ? options.fn(this) : options.inverse(this); 173 case '<=': 174 return (v1 <= v2) ? options.fn(this) : options.inverse(this); 175 case '>': 176 return (v1 > v2) ? options.fn(this) : options.inverse(this); 177 case '>=': 178 return (v1 >= v2) ? options.fn(this) : options.inverse(this); 179 case '&&': 180 return (v1 && v2) ? options.fn(this) : options.inverse(this); 181 case '||': 182 return (v1 || v2) ? options.fn(this) : options.inverse(this); 183 default: 184 return options.inverse(this); 185 } 186}); 187 188 189 190/******************************************************************************************/ 191/*** import /cls/main/_res/functions.js ***/ 192/******************************************************************************************/ 193 194/*$.log = function(msg){ 195 if($ajapp.eventanmeldemodal.enableLog) console.log(msg); 196}*/ 197 198$.fn.serializeObject = function(){ 199 var o = {}; 200 var a = this.serializeArray(); 201 $.each(a, function() { 202 if (o[this.name] !== undefined) { 203 if (!o[this.name].push) { 204 o[this.name] = [o[this.name]]; 205 } 206 o[this.name].push(this.value || ''); 207 } else { 208 o[this.name] = this.value || ''; 209 } 210 });
211 return o; 212}; 213 214function $filter(sel, el){ 215 return $(el).find(sel).addBack(sel); 216} 217 218$.uid = function(_len){ 219 var ret = ""; 220 var len = _len ? _len : 2; 221 for(var i = 0; i < len; i++){ 222 ret += (ret ? "X" : "R") + (((1+Math.random())*0x10000000)|0).toString(16).substring(1); 223 } 224 return ret; 225}; 226 227$.fn.isOnScreen = function(Cor){ 228 var win = $(window); 229 230 231 var viewport = { 232 top : win.scrollTop() + (Cor ? Cor : 0), 233 //left : win.scrollLeft() + (Cor ? Cor : 0) 234 }; 235 236 //viewport.right = viewport.left + win.outerWidth(); 237 viewport.bottom = viewport.top + win.outerHeight(); 238 239 var bounds = this.offset(); 240 //bounds.right = bounds.left + this.outerWidth(); 241 bounds.bottom = bounds.top + this.outerHeight(); 242 243 244 return (!(viewport.bottom < bounds.top)); 245 246}; 247 248 249 250 251 252 253var $instance = null; 254 255$ajapp.eventanmeldemodal = { 256 enableCodeHints: false, 257 template: {}, 258 templateSource: {}, 259 datasrc: {}, 260 config: {}, 261 langdata: {}, 262 devmode: null, 263 timedDelay: 10000, 264 missingLang: {}, 265 enableLog: true, 266 logMissingLang: false, 267 drawTo: "#master", 268 channelReadyState: "C1A1", 269 270 absPath: "", 271 appname: "", 272 273 274 "___info: ajAppC.js": function(){ 275 /*** 276 * general app functions 277 * 278 * 279 * */ 280 }, 281 282 _startJsDocu: function(objTo){ 283 var me = this; 284 if(!this.isReady){ 285 setTimeout(function(){ 286 me._startJsDocu(objTo); 287 }, 5); 288 return; 289 } 290 objTo.runJsDocu(this); 291 }, 292 293 294 registerChannel: function(channel, cb){ 295 if($.jartWebsocket){ 296 $.jartWebsocket.registerChannel(this.myId, channel, cb); 297 } 298 }, 299 300 unregisterChannel: function(channel, cb){ 301 if($.jartWebsocket){ 302 $.jartWebsocket.unregisterChannel(this.myId, channel); 303 } 304 }, 305 306 onChannel: function(data, channel){ 307 $.log("global channel data arrived, please implement onChannel: function(data, channel). channel: " + channel + ", data: " + data); 308 }, 309 310 getWebsocketClientId: function(){ 311 if($.jartWebsocket) return $.jartWebsocket.clientId; 312 return null; 313 }, 314 315 316 loadAjapp: function(url, _prop, _mode){ 317 var clsName = url.substr(url.lastIndexOf("/") + 1); 318 clsName = clsName.substr(0, clsName.indexOf('.jartc')); 319 var mode = _mode ? _mode : "start"; 320 var prop = _prop ? _prop : {}; 321 if(!$ajapp[clsName]){ 322 var path = url.substr(0, url.indexOf('.jartc')); 323 $('<link rel="stylesheet" href="' + path + '.css">').appendTo("head"); 324 $('<script src="' + url + '?cmd=getJS"></script>').appendTo("body"); 325 //var propStr = JSON.stringify(prop); 326 var propId = "loadAjappPROP_" + $.uid(); 327 $[propId] = prop; 328 $('<script type="text/javascript">$ajapp.' + clsName + '._init("' + this.curlang + '")._' + mode + '($.' + propId + '); delete $.' + propId + '; </script>').appendTo("body"); 329 } else { 330 $ajapp[clsName]["_" + mode](prop); 331 } 332 }, 333 334 onWsStateChanged: function(wst){ 335 /*** 336 * implement in your ajapp to react on websocket state changes 337 * wst is a string value representig the different socket states in 338 * format type char and 0 for false or 1 for true. 339 * type chars: 340 ** C = connection 341 ** A = all ready 342 ** S = stopped by user or function 343 ** L = login ok if login was required 344 * 345 * Examples: 346 ** "C0A0S0L0" is currently conneting 347 ** "C1A1S0L0" connected an not logged in 348 ** "C1A1S0L1" connected an logged in 349 ** "C0A0S1L0" manually diskonneted 350 * **/ 351 }, 352 353 wsStateChanged: function(wst){ 354 this.onWsStateChanged(wst); 355 }, 356 357 run: function(cmd){ 358 if(this[cmd]){ 359 var args = Array.prototype.splice.call(arguments, 1); 360 return this[cmd].apply(this, args); 361 } 362 $.log("run MISSING FUNCTION: " + cmd); 363 364 }, 365 366 handleData: function(data){ 367 368 }, 369 370 jvalidationChecks: {}, 371 372 routing: { 373 374 }, 375 376 silentRouting: false, 377 378 _go: function(r, rpath, _data, el, oldR){ 379 var data = _data ? _data : {}; 380 if(r.length > 0){ 381 var cstep = r.shift(); 382 var oldStep = oldR.length > 0 ? oldR.shift() : ""; 383 var checkNew = cstep; 384 var checkOld = oldStep; 385 rpath.push(cstep); 386 $.each($ajapp.eventanmeldemodalRouting.routing, function(i, v){ 387 delete v.lastStepwiseHash; 388 }); 389 var rt = $ajapp.eventanmeldemodalRouting.routing[rpath.join("/")]; 390 if(rt.args){ 391 var args = rt.args.split(","); 392 if(rt.target && !rt.targetkeep) rt.targetkeep = rt.target; 393 rt.target = rt.targetkeep; 394 data = {}; 395 for(var i = 0; i < args.length; i++){ 396 var a = r.shift(); 397 checkNew += "/" + a; 398 var aOld = oldR.length > 0 ? oldR.shift() : ""; 399 checkOld += "/" + aOld; 400 data[args[i]] = decodeURIComponent(a); 401 if(rt.target) rt.target = rt.target.replace("$" + (i + 1), a); 402 } 403 } 404 //$.log(checkOld + " > " + checkNew); 405 //$.log(r); 406 if(checkOld == checkNew){ 407 this._go(r, rpath, data, el, oldR); 408 } else { 409 if(rt){ 410 rt.prc = rt.process.split(","); 411 this._nextStep(rt, r, rpath, data, el, cstep, oldR); 412 } 413 } 414 } 415 }, 416 417 _nextStep: function(rt, r, rpath, data, el, cstep, oldR){ 418 var curProcess = rt.prc.shift(); 419 if(curProcess){ 420 this._goStep(curProcess, rt, r, rpath, data, el, cstep, oldR); 421 } else { 422 this._go(r, rpath, data, el, oldR); 423 } 424 }, 425 426 useStepwiseScrollLoader: true, 427 428 _goStep: function(curProcess, rt, r, rpath, data, el, cstep, oldR){ 429 //$.log("run step " + rpath + " : " + curProcess); 430 if(curProcess == "fnc"){ 431 this[rt.fnc ? rt.fnc : cstep](data); 432 this._nextStep(rt, r, rpath, data, el, cstep, oldR); 433 } else if(curProcess == "draw"){ 434 this.draw(rt.draw ? rt.draw : cstep, data, rt.target, rt.drawMode); 435 this._nextStep(rt, r, rpath, data, el, cstep, oldR); 436 } else if(curProcess == "request"){ 437 if(!rt.lastStepwiseHash){ 438 $("form[name='" + rt.path + "']").each(function(){ 439 var f = $(this); 440 if(rt.args) $.each(rt.args.split(","), function(i, v){ 441 $("[name='" + v + "']", f).val(data[v]); 442 }); 443 }); 444 } 445 var cbN = "R" + $.uid(); 446 var checkHash = $ajapp.eventanmeldemodal.lastRoutingHash; 447 var cdata = data; 448 this[cbN] = function(data){ 449 if($ajapp.eventanmeldemodal.lastRoutingHash != checkHash){ 450 delete this[cbN]; 451 return; 452 } 453 if(rt.loadStepwise && data._hasMore){ 454 var setPrc = rt.prc.slice(0); 455 //var setPrc = [...rt.prc]; 456 setTimeout(function(){ 457 rt.prc = setPrc; 458 if(rt.lastStepwiseHash != $ajapp.eventanmeldemodal.lastRoutingHash) return; 459 if($ajapp.eventanmeldemodal.useStepwiseScrollLoader){ 460 var nel = $("<div>", {"class": "scollLoader"}).appendTo(rt.target); 461 nel.data("args", [curProcess, rt, r, rpath, cdata, el, cstep, oldR]); 462 nel.data("appname", $ajapp.eventanmeldemodal.appname); 463 window.onscroll(); 464 } else { 465 $ajapp.eventanmeldemodal._goStep(curProcess, rt, r, rpath, cdata, el, cstep, oldR); 466 } 467 }, 1); 468 } 469 this._nextStep(rt, r, rpath, data, el, cstep, oldR); 470 delete this[cbN]; 471 }; 472 if(rt.loadStepwise){ 473 if(checkHash != rt.lastStepwiseHash){ 474 rt.start = 0; 475 rt.lastStepwiseHash = checkHash; 476 rt.drawMode = ""; 477 } else { 478 rt.start += rt.loadStepwise; 479 rt.drawMode = "append"; 480 } 481 data._start = rt.start; 482 data._stepSize = rt.loadStepwise; 483 } 484 $.log(rt.request ? rt.request : cstep); 485 this.send(rt.request ? rt.request : cstep, cbN, data); 486 } else { 487 488 } 489 }, 490 491 boundFormKeyUpDelay: 150, 492 493 bindFormToRouting: function(el){ 494 var r = this.appname + el.attr("name"); 495 var rt = $ajapp.eventanmeldemodalRouting.routing[r]; 496 el.data("rt", rt); 497 el.data("rtPath", r); 498 el.submit(function(){ 499 var el = $(this);
500 var hasError = el.hasClass("validation-error") || $(".has-error", el).length > 0 || $(".field_error", el).length > 0; 501 var data = {}; 502 if(!hasError){ 503 $ajapp.eventanmeldemodal.serializeObject(el, data); 504 } 505 var rt = el.data("rt"); 506 var newHash = el.data("rtPath"); 507 $.each(rt.args.split(","), function(i, v){ 508 newHash += "/" + encodeURIComponent(data[v]); 509 }); 510 $ajapp.eventanmeldemodal.goRouting(newHash); 511 return false; 512 }); 513 $.each(rt.args.split(","), function(i, v){ 514 $("[name='" + v + "']", el).each(function(){ 515 if($(this).hasClass("submitOnKeyUp")){ 516 $(this).keyup(function(){ 517 var e = $(this); 518 var ev = $(this).val(); 519 setTimeout(function(){ 520 if(ev == e.val()) e.closest("form").submit(); 521 }, $ajapp.eventanmeldemodal.boundFormKeyUpDelay); 522 523 }); 524 } 525 if($(this).hasClass("submitOnChange")){ 526 $(this).change(function(){ 527 $(this).closest("form").submit(); 528 }); 529 } 530 }); 531 }); 532 533 }, 534 535 setAnchorHash: function(el, data){ 536 this.goRouting(el.attr("href"), el, data); 537 }, 538 539 lastRoutingHash: "", 540 541 goRouting: function(_r, data, el){ 542 this.lastRoutingHash = "" + _r; 543 if(this.silentRouting){ 544 $ajapp.eventanmeldemodalRouting.goRouting(_r, data, el); 545 } else { 546 document.location.hash = _r; 547 } 548 }, 549 550 setRouting: function(){ 551 if(!$ajapp.eventanmeldemodalRouting){ 552 553 $ajapp.eventanmeldemodalRouting = { 554 routing: {}, 555 556 goRouting: function(_r, data, el){ 557 var r = _r.split("/"); 558 var app = r.shift(); 559 if(app.indexOf("#") == 0) app = app.substr(1); 560 var rpath = [app]; 561 if($ajapp[app]){ 562 var a = $ajapp[app]; 563 //$.log("***** " + _r); 564 var oldR = (a.lastRouting ? a.lastRouting : "").split("/"); 565 var oldApp = oldR.shift(); 566 a.lastRouting = _r; 567 if(oldApp != app) { 568 oldR = []; 569 } 570 $ajapp[app]._go(r, rpath, data, el, oldR); 571 } else { 572 $.log("load app have to be implemented"); 573 } 574 } 575 576 }; 577 578 window.onhashchange = function(evt){ 579 $ajapp.eventanmeldemodalRouting.goRouting("" + document.location.hash.substr(1)); 580 }; 581 582 window.onscroll = function(evt){ 583 $(".scollLoader").each(function(){ 584 var ckTop = $(window).scrollTop() + $(window).height() + 800; 585 if($(this).offset().top < ckTop){ 586 $ajapp[$(this).data("appname")]._goStep.apply($ajapp[$(this).data("appname")], $(this).data("args")); 587 $(this).remove(); 588 } 589 590 }); 591 }; 592 } 593 594 for(var n in this.routing){ 595 this.routing[n].path = n; 596 $ajapp.eventanmeldemodalRouting.routing[this.appname + n] = this.routing[n]; 597 } 598 }, 599 600 _init: function(lang, p){ 601 if(p) $.extend(this, p); 602 this.setRouting(); 603 this.jvalidation.checks = this.jvalidationChecks; 604 this.jvalidation.checks.__self = this; 605 var appname = this.appname; 606 this.addTemplate("_draw_" + appname, "{{#each this}}{{#if this._template}}{{_template_" + appname + " this._template this this._map}}{{/if}}{{/each}"); 607 this.addTemplate("_sub_" + appname, "{{_template_" + appname + " '_draw_" + appname + "' this._sub}}"); 608 this.addTemplate("_compileSub_" + appname, "{{#each sub__data}}{{_compile_" + appname + " element__type this}}{{/each}}"); 609 //if(this.enableCodeHints && !this.isPhoneGap) startCodeHints("ajapp"); 610 this.curlang = lang; 611 this.localPath = "/jart" + this.absPath; 612 this.appCall = this.localPath + "/" + this.appname + ".jart"; 613 this.initA(); 614 return this; 615 }, 616 617 618 _start: function(p){ 619 if(p) $.extend(this, p); 620 this.jvalidation.checks.__self = this; 621 var me = this; 622 if(this.reloadFormFieldData && this.formFieldLoadByNew){ 623 this.formFieldLoadByNew(function(){ 624 me._start(); 625 }); 626 return; 627 } 628 if(!this.isReady){ 629 setTimeout(function(){ 630 me._start(); 631 }, 5);
632 return; 633 } 634 if($.jartWebsocket) $.jartWebsocket.register(this.myId, this); 635 $(this.drawTo).addClass("__instance"); 636 $(this.drawTo).data("__instance", this); 637 if(this.start) { 638 this.start(); 639 } else { 640 if(document.location.hash && ("" + document.location.hash) !== "#" && ("" + document.location.hash) !== ""){ 641 $ajapp.eventanmeldemodalRouting.goRouting("" + document.location.hash.substr(1)); 642 } else { 643 this.goRouting(this.appname + "/start"); 644 } 645 } 646 return true; 647 }, 648 649 _skip: function(p){ 650 if(p) $.extend(this, p); 651 }, 652 653 _remove: function(){ 654 if($.jartWebsocket) $.jartWebsocket.unregister(this.myId); 655 $(this.drawTo).html(""); 656 }, 657 658 _new: function(_p, cb){ 659 if(!this.isReady){ 660 var me = this; 661 setTimeout(function(){ 662 me._new(_p, cb); 663 }, 5); 664 return; 665 } 666 var newInstance = $.extend(true, {}, this, _p ? _p : {}); 667 newInstance.myId = this.appname + ":" + $.uid(); 668 newInstance.jvalidation.checks.__self = newInstance; 669 if(cb){ 670 cb(newInstance); 671 } else { 672 newInstance._start(); 673 } 674 }, 675 676 drawRunData: function(el, data){ 677 this.drawData(data); 678 }, 679 680 drawData: function(data){ 681 this.draw(data.__template, data, data.__target ? this.$(data.__target) : this.drawTo, data.__mode); 682 }, 683 684 saveForm: function(el, data){ 685 var cmd = el.attr("name"); 686 $("button[type=submit]", el).prop("disabled", true); 687 this.send(cmd, "", data); 688 }, 689 690 send: function(cmd, cb, data){ 691 if($.jartWebsocket && $.jartWebsocket.allReady){ 692 if(!this.sendWS(cmd, cb, data)){ 693 this.sendHttp(cmd, cb, data); 694 } 695 } else { 696 this.sendHttp(cmd, cb, data); 697 } 698 }, 699 700 postToBlank: function(cmd, data){ 701 $("#postform").remove(); 702 var pf = $("<form>", {action: this.appCall, method: "POST", target: "_blank", id:"postform"}).appendTo("body"); 703 $("<input>", {type: "hidden", name: "cmd", value: cmd}).appendTo(pf); 704 $("<input>", {type: "hidden", name: "data", value: JSON.stringify(data ? data : {})}).appendTo(pf); 705 pf.submit(); 706 }, 707 708 sendWS: function(cmd, cb, data){ 709 if(typeof cb === 'object'){ 710 data = cb; 711 cb = ""; 712 } 713 if(typeof cb === 'function'){ 714 var cbName = "___CB___" + $.uid(); 715 var cbFnc = cb; 716 cb = cbName; 717 this[cbName] = function(data){ 718 delete this[cbName]; 719 cbFnc.apply(this, [data]); 720 }; 721 } 722 var d = data ? data : {}; 723 d.__lang = this.curlang; 724 this.initSendData(d); 725 if(!$.jartWebsocket || !$.jartWebsocket.allReady){ 726 $.log("ERROR Websocket not ready!"); 727 return; 728 } 729 var clsCall = this.appCall.substr(5); 730 return $.jartWebsocket.send(clsCall, cmd, $.extend({__cbObject: this.myId, __cbCommand: cb ? cb : ""}, d)); 731 }, 732 733 sendWSTo: function(endpoint, cmd, cb, data){ 734 if(typeof cb === 'object'){ 735 data = cb; 736 cb = ""; 737 } 738 if(typeof cb === 'function'){ 739 var cbName = "___CB___" + $.uid(); 740 var cbFnc = cb; 741 cb = cbName; 742 this[cbName] = function(data){ 743 delete this[cbName]; 744 cbFnc.apply(this, [data]); 745 }; 746 } 747 var d = data ? data : {}; 748 if(this['j-language-file']){ 749 d['__j-language-file'] = this['j-language-file']; 750 } 751 d.__lang = this.curlang; 752 this.initSendData(d); 753 if(!$.jartWebsocket || !$.jartWebsocket.allReady){ 754 $.log("ERROR Websocket not ready!"); 755 return; 756 } 757 //var clsCall = this.appCall.substr(5); 758 return $.jartWebsocket.send(endpoint, cmd, $.extend({__cbObject: this.myId, __cbCommand: cb ? cb : ""}, d)); 759 }, 760 761 initSendData: function(data){ 762 /*** 763 * set data properties before sending over http or ws 764 * */ 765 }, 766 767 sendHttp: function(cmd, cb, data){ 768 if(typeof cb === 'object'){ 769 data = cb; 770 cb = ""; 771 } 772 if(typeof cb === 'function'){ 773 var cbName = "___CB___" + $.uid(); 774 var cbFnc = cb; 775 cb = cbName; 776 this[cbName] = function(data){ 777 delete this[cbName]; 778 cbFnc.apply(this, [data]); 779 }; 780 } 781 var d = data ? data : {}; 782 if(this['j-language-file']){ 783 d['__j-language-file'] = this['j-language-file']; 784 } 785 d.__lang = this.curlang; 786 this.initSendData(d); 787 this.req(cmd, d, function(result, rText){ 788 if(!result && rText){ 789 $.log("Unexpected HTTP Result: " + rText); 790 return; 791 } 792 if(result && result.__cbCommand){ 793 this.run(result.__cbCommand, result); 794 return; 795 } 796 this.run(cb, result); 797 }); 798 }, 799 800 getEventObject: function(e){
801 if(e.originalEvent) return e.originalEvent; 802 return e; 803 }, 804 805 getEventAbsPos: function(e){ 806 var eObj = this.getEventObject(e); 807 return {target: eObj.target, x: eObj.clientX, y: eObj.clientY}; 808 }, 809 810 req: function(cmd, data, _cb, _type){ 811 var cb = _cb ? _cb : this.handleData; 812 var type = _type ? _type : "json"; 813 var me = this; 814 var params = {cmd: cmd, data: data ? JSON.stringify(data) : JSON.stringify({})}; 815 $.ajax({ 816 url: this.appCall, 817 method: 'POST', 818 dataType: type, 819 data: params, 820 success: function(_data){ 821 cb.apply(me, [_data]); 822 }, 823 error: function(eOb){ 824 cb.apply(me, [null, eOb.responseText]); 825 } 826 }); 827 }, 828 829 addTemplateFile: function(name, v){ 830 var code = v; 831 var pos1 = code.indexOf("<!---###"); 832 if(pos1 > -1){ 833 var ncode = code.substr(pos1 + 8); 834 code = code.substr(0, pos1); 835 var pos2 = ncode.indexOf("###--->"); 836 var nname = ncode.substr(0, pos2); 837 ncode = ncode.substr(pos2 + 7); 838 code = code.replace(/[\r\n\t]/g, ""); 839 this.addTemplate(name, code); 840 this.addTemplateFile(nname, ncode); 841 } else { 842 code = code.replace(/[\r\n\t]/g, ""); 843 this.addTemplate(name, code); 844 } 845 }, 846 847 loadLocal: function(url, cb, _ltype){ 848 //$.log(url); 849 var _url = url; 850 var ltype = _ltype ? _ltype : "json"; 851 var me = this; 852 if(url.indexOf("/jart/") === 0){ 853 } else if(url.indexOf("/") === 0){ 854 _url = "/jart" + url; 855 } else { 856 _url = this.localPath + "/" + url; 857 } 858 $.ajax({
859 url: _url, 860 method: 'POST', 861 dataType: ltype, 862 success: function(_data){ 863 cb.apply(me, [_data]); 864 }, 865 error: function(){ 866 cb.apply(me, [null]); 867 } 868 }); 869 }, 870 871 initLocalValue: function(name, value){ 872 if(typeof localStorage[name] === 'undefined') localStorage[name] = value; 873 }, 874 875 appAlert: function(msg){ 876 alert(msg); 877 }, 878 879 appConfirm: function(msg){ 880 return confirm(msg); 881 }, 882 883 $: function(sel){ 884 return $(sel, this.drawTo); 885 }, 886 887 lang: function(str){ 888 if(!str) return ""; 889 var k = str.replace(/[^a-zA-Z0-9\.\-]/g, '').replace(/^[0-9\.\-]*/g, ''); 890 if(k.length > 25) k = k.substr(0, 25) + "." + k.length; 891 if(this.langdata[k]) return this.langdata[k]; 892 if(this.logMissingLang){ 893 if(!this.missingLang[str]) this.missingLang[str] = true; 894 var out = ""; 895 for(var n in this.missingLang){ 896 out += (out ? "\n" : "") + n; 897 } 898 $.log("*** missing lang *****************************\n" + out); 899 } 900 return str; 901 }, 902 903 getLocalStorageRef: function(){ 904 return this.localPath + "/" + this.appname + ":"; 905 }, 906 907 globalLanguageFile: "", 908 909 loadGobalLanguageData: function(useLS, LSName){ 910 this.loadLocal(this.globalLanguageFile + "." + this.curlang + ".json", function(data){ 911 this.langdata = $.extend(this.langdata, data); 912 this.loadLanguageData(useLS, LSName); 913 }); 914 }, 915 916 loadLanguageData: function(useLS, LSName){ 917 this.loadLocal(this.appname + ".lang." + this.curlang + ".json", function(data){ 918 this.langdata = $.extend(this.langdata, data); 919 if(useLS){ 920 localStorage[LSName] = JSON.stringify(data); 921 localStorage[LSName + ".version"] = this.appVersion; 922 } 923 this.initB(); 924 }); 925 }, 926 927 initA: function(data){ 928 if(!window.$instance) $instance = function(el, smd, e){ 929 $(el).closest(".__instance").each(function(){ 930 var data = null; 931 $(el).closest("[data-data]").each(function(){ 932 data = $(this).data("data"); 933 }); 934 $(this).data("__instance").run(smd, $(el), data, e); 935 }); 936 }; 937 this.appCall += "c"; 938 this.myId = this.appname; 939 940 var LSName = this.getLocalStorageRef() + "lang." + this.curlang; 941 var useLS = false; 942 var doLoad = true; 943 if(this.appVersion && localStorage){ 944 useLS = true; 945 if(localStorage[LSName + ".version"] == this.appVersion){ 946 this.langdata = JSON.parse(localStorage[LSName]); 947 doLoad = false; 948 } 949 } 950 if(doLoad){ 951 if(this.globalLanguageFile){ 952 this.loadGobalLanguageData(useLS, LSName); 953 } else { 954 this.loadLanguageData(useLS, LSName); 955 } 956 } else { 957 this.initB(); 958 } 959 }, 960 961 initB: function(data){ 962 var LSName = this.getLocalStorageRef() + "html"; 963 var useLS = false; 964 var doLoad = true; 965 if(this.appVersion && localStorage){ 966 useLS = true; 967 if(localStorage[LSName + ".version"] == this.appVersion){ 968 var templateData = localStorage[LSName]; 969 this.addTemplateFile("__dummy", templateData); 970 doLoad = false; 971 this.initFin(); 972 return; 973 } 974 } 975 if(doLoad){ 976 this.req("getHTML", {}, function(data){ 977 if(data){ 978 if(data.substr(0, 1) == '{'){ 979 if(data.indexOf('"__cbCommand"') > -1){ 980 var c = JSON.parse(data); 981 this[c.__cbCommand](data); 982 return; 983 } 984 } 985 if(useLS){ 986 localStorage[LSName] = data; 987 localStorage[LSName + ".version"] = this.appVersion; 988 }
989 this.addTemplateFile("__dummy", data); 990 } 991 this.initFin(); 992 }, "text"); 993 } 994 }, 995 996 997 998 initFin: function(){ 999 if(this.routing){ 1000 if(this.init) { 1001 this.init(); 1002 } else { 1003 this.isReady = true; 1004 } 1005 } else { 1006 if(this.init){ 1007 if(this.init()){ 1008 this.draw("main", this, "#" + this.appname); 1009 } 1010 } else { 1011 this.draw("main", this, "#" + this.appname); 1012 } 1013 } 1014 1015 }, 1016 1017 runTimed: function(){ 1018 }, 1019 1020 1021 getTemplate: function(_template, part){ 1022 if(typeof _template === "string"){ 1023 return (part && _template.indexOf(".") === -1 ? part.name + "." : "") + _template; 1024 } 1025 if($.isArray(_template)){ 1026 for(var i = 0; i < _template.length; i++){ 1027 var ck = part && _template[i].indexOf(".") === -1 ? part.name + "." + _template[i] : _template[i]; 1028 if(this.template[ck]){ 1029 return ck; 1030 } 1031 } 1032 return ""; 1033 } else if($.isFunction(_template)){ 1034 return _template(data, target, mode); 1035 } 1036 return ""; 1037 }, 1038 1039 compileElement: function(template, data){ 1040 var tmpl = template; 1041 if(this.compliePrefix && !this.template[template]) this.each(this.compliePrefix, function(i, v){ 1042 if(this.template[v + tmpl]){ 1043 tmpl = v + tmpl; 1044 } 1045 }); 1046 if(!this.template[tmpl]){ 1047 var tstr = template; 1048 if(this.compliePrefix) this.each(this.compliePrefix, function(i, v){ 1049 tstr += " or " + v + template; 1050 }); 1051 $.log("MISSING TEMPLATE: " + this.appname + " : " + tstr); 1052 //$.log("MISSING TEMPLATE: " + tstr); 1053 return ""; 1054 } 1055 return this.template[tmpl](data); 1056 }, 1057 1058 draw: function(template, data, _target, mode, disableEvents){ 1059 var target = _target ? _target : this.drawTo; 1060 if(!this.template[template]){ 1061 //$.log("MISSING TEMPLATE: " + template); 1062 $.log("MISSING TEMPLATE: " + this.appname + " : " + template); 1063 return; 1064 } 1065 if(!mode) $(target).html(''); 1066 var ret = $(this.template[template](data)); 1067 //$.log({template: template, data: data, ret: ret}); 1068 if(mode == 'prepend'){ 1069 ret.prependTo(target); 1070 } else if(mode == 'replace'){ 1071 ret.insertAfter(target); 1072 target.remove(); 1073 } else { 1074 ret.appendTo(target); 1075 } 1076 if(!disableEvents) this.setEvents(ret, data); 1077 return ret; 1078 }, 1079 1080 serializeObject: function(el, data){ 1081 $(">[name]", el).each(function(){ 1082 var e = $(this); 1083 var nn = e.prop("tagName"); 1084 var n = e.attr("name"); 1085 var nt = n + ".text"; 1086 var v = ""; 1087 var tv = ""; 1088 var t = e.attr("type"); 1089 if(t === "radio" || t === "checkbox"){ 1090 if(e.prop("checked")){ 1091 v = e.attr("value"); 1092 tv = e.parent().text(); 1093 } 1094 } else { 1095 v = e.val(); 1096 } 1097 if(v && nn === "SELECT"){ 1098 tv = $("option", e)[e[0].selectedIndex].innerHTML; 1099 } 1100 if(!data[n]) data[n] = ""; 1101 if(v){ 1102 data[n] += (data[n] ? "," : "") + v; 1103 if(tv){ 1104 if(!data[nt]) data[nt] = ""; 1105 data[nt] += (data[nt] ? ", " : "") + tv; 1106 } 1107 } 1108 }); 1109 $(">:not('.repeater')", el).each(function(){ 1110 $ajapp.eventanmeldemodal.serializeObject($(this), data); 1111 }); 1112 $(">.repeater", el).each(function(){ 1113 var dn = $(this).data("dataname"); 1114 var ndata = []; 1115 data[dn] = ndata; 1116 $(">.repeateritem", $(this)).each(function(){ 1117 var nnd = {}; 1118 $ajapp.eventanmeldemodal.serializeObject($(this), nnd); 1119 ndata.push(nnd); 1120 }); 1121 }); 1122 /*$(".repeater", el).each(function(){ 1123 var newa = []; 1124 var dname = $(this).data("dataname"); 1125 data[dname] = newa; 1126 $.each(">.repeateritem", function(){ 1127 1128 }); 1129 });*/ 1130 }, 1131 1132 jvalidation: { 1133 1134 isMsgChanged: function(m1){ 1135 var ret = $ajapp.eventanmeldemodal.lang(m1); 1136 if(m1 == ret){ 1137 return null; 1138 } 1139 return ret; 1140 }, 1141 1142 getMessageValue: function(nname, nob, fname, params){ 1143 if(params.message) return $ajapp.eventanmeldemodal.lang(params.message); 1144 var msg = this.isMsgChanged(nname + "." + nob + "." + fname); 1145 if(msg === null) msg = this.isMsgChanged(nname + "." + fname); 1146 if(msg === null) msg = this.isMsgChanged(nname + "." + nob); 1147 if(msg === null) msg = this.isMsgChanged(nname); 1148 if(msg === null && window.jvalidation_messages) msg = window.jvalidation_messages[nname]; 1149 if(!msg) msg = $ajapp.eventanmeldemodal.lang("please provide a valid value for this field"); 1150 return msg; 1151 } 1152 }, 1153 1154 setEvents: function(toEl, data){ 1155 var me = this; 1156 /*$filter("[name]", toEl).each(function(){ 1157 var e = $(this); 1158 if(data && data[$(this).attr("name")]){ 1159 if(e.attr("type") && e.attr("type") == "checkbox" && data[e.attr("name")].indexOf(e.val()) > -1){ 1160 e.prop("checked", true); 1161 } else if(e.attr("type") && e.attr("type") == "radio" && data[e.attr("name")] == e.val()){ 1162 e.prop("checked", true); 1163 } else { 1164 e.val(data[e.attr("name")]); 1165 } 1166 } 1167 });*/ 1168 $filter("select", toEl).each(function(){ 1169 $(this).val($(this).data("value")); 1170 }); 1171 $filter(".optionkeeper", toEl).each(function(){ 1172 var v = $(this).data("value"); 1173 $("input[value='" + v + "']", this).prop("checked", true); 1174 }); 1175 $filter(".checkboxkeeper", toEl).each(function(){ 1176 var v = "," + $(this).data("value") + ","; 1177 $("input", this).each(function(){ 1178 if(v.indexOf("," + $(this).attr("value") + ",") > -1){ 1179 $(this).prop("checked", true); 1180 } 1181 }); 1182 $("input[value='" + v + "']", this).prop("checked", true); 1183 }); 1184 $filter("form:not([data-run])", toEl).each(function(){ 1185 var cur = $(this); 1186 if(cur.jvalidation) cur.jvalidation(me.jvalidation); 1187 }); 1188 $filter("[data-run]", toEl).each(function(){ 1189 var cur = $(this); 1190 if(cur.attr("data-toggle") == "tab") return; 1191 var tag = cur.prop("tagName").toUpperCase(); 1192 if(tag == "FORM"){ 1193 if(cur.jvalidation) cur.jvalidation(me.jvalidation); 1194 cur.submit(function(){ 1195 var el = $(this);
1196 var hasError = el.hasClass("validation-error") || $(".has-error", el).length > 0 || $(".field_error", el).length > 0; 1197 if(!hasError){ 1198 //var data = el.serializeObject(); 1199 var data = {}; 1200 $ajapp.eventanmeldemodal.serializeObject(el, data); 1201 me.run(el.data("run"), el, data); 1202 return false; 1203 } else { 1204 //$.log("val error"); 1205 if(el.data("on-validation-error")){ 1206 me.run(el.data("on-validation-error"), el, {}); 1207 } 1208 } 1209 return false; 1210 }); 1211 } else if(cur.prop("contenteditable") == "true"){ 1212 cur.data("curdata", cur.html()); 1213 cur.data("curtxt", cur.text()); 1214 cur.blur(function(){ 1215 var el = $(this); 1216 var oldData = el.data("curdata"); 1217 if(el.data("curdata") != el.html()){ 1218 el.data("curdata", el.html()); 1219 me.run(el.data("run"), el, {txt: el.text(), oldTxt: el.data("curtxt"), html: el.html(), oldHtml: oldData}); 1220 } else { 1221 if(el.data("cancel")) me.run(el.data("cancel"), el, {txt: el.text(), oldTxt: el.data("curtxt"), html: el.html(), oldHtml: oldData}); 1222 } 1223 return false; 1224 }); 1225 if(cur.hasClass("on-enter")){ 1226 cur.keydown(function(e){ 1227 if(e.keyCode == 13){ 1228 e.stopPropagation(); 1229 $(this).blur(); 1230 return false; 1231 } 1232 }); 1233 } 1234 cur.keyup(function(e){ 1235 if(e.keyCode == 27){ 1236 var el = $(this); 1237 el.html(el.data("curdata")); 1238 el.blur(); 1239 } 1240 }); 1241 } else if((" INPUT SELECT TEXTAREA ").indexOf(" " + tag + " ") > -1){ 1242 cur.change(function(e){ 1243 var el = $(this); 1244 me.run(el.data("run"), el, el.val(), e); 1245 return false; 1246 }); 1247 } else { 1248 if($ajapp.eventanmeldemodal.isPhoneGap && cur.tap){ 1249 cur.tap(function(e){ 1250 var el = $(this); 1251 me.run(el.data("run"), el, el.closest("[data-data]").data("data"), $(this).data(), e); 1252 if(el.closest(".mainnav").length > 0){ 1253 $(".active", el.closest(".mainnav")).removeClass("active"); 1254 el.parent().addClass("active"); 1255 } 1256 if(!el.hasClass("is-menu")) return false; 1257 }); 1258 } else { 1259 cur.click(function(e){ 1260 var el = $(this); 1261 me.run(el.data("run"), el, el.closest("[data-data]").data("data"), $(this).data(), e); 1262 if(el.closest(".mainnav").length > 0){ 1263 $(".active", el.closest(".mainnav")).removeClass("active"); 1264 el.parent().addClass("active"); 1265 } 1266 if(!el.hasClass("is-menu")){ 1267 return false; 1268 } 1269 }); 1270 } 1271 } 1272 }); 1273 $filter(".do-clickmarker a", toEl).click(function(){ 1274 $(this).closest(".do-clickmarker").each(function(){ 1275 $(".clickmarker", $(this).parent()).removeClass("clickmarker"); 1276 $(this).addClass("clickmarker"); 1277 }); 1278 }); 1279 this.handlePostDraw(toEl); 1280 $filter("[data-ondraw]", toEl).each(function(){ 1281 var r = "" + $(this).data("ondraw"); 1282 $(this).data("ondraw", ""); 1283 $(this).removeAttr("data-ondraw"); 1284 if(r){ 1285 me.run(r, $(this)); 1286 } 1287 }); 1288 }, 1289 1290 handlePostDraw: function(el){ 1291 /*** 1292 * called after drawing any element 1293 ***/ 1294 }, 1295 1296 each: function(ob, cb){ 1297 var me = this; 1298 if(ob) $.each(ob, function(i, v){ 1299 cb.apply(me, [i, v]); 1300 }); 1301 }, 1302 1303 addTemplate: function(name, code){ 1304 //$.log("compile template " + name + " code: " + code); 1305 this.templateSource[name] = code; 1306 this.template[name] = Handlebars.compile(code); 1307 } 1308 1309 1310}; 1311 1312 1313 1314 1315 1316 1317 1318$.extend($ajapp.eventanmeldemodal, { 1319 rowId: parseInt(Math.random() * 9999999999), 1320 1321 reloadFormFieldData: false, 1322 1323 getNextFormFieldId: function(){ 1324 this.nextFormFieldId = "FFID" + $.uid(); 1325 return ""; 1326 }, 1327 1328 1329 getFormFieldIsRow: function(el){ 1330 var ret = ""; 1331 if(el.field_columns && el.field_columns.indexOf(" ") > -1){ 1332 ret = " row"; 1333 } 1334 return ret; 1335 }, 1336 1337 1338 getFormFieldIsRowLabel: function(el){ 1339 var ret = ""; 1340 if(el.field_columns && el.field_columns.indexOf(" ") > -1){ 1341 ret = " col-form-label col-sm-" + el.field_columns.split(" ")[0]; 1342 if("option checkbox".indexOf(el.type) > -1){ 1343 ret += " pt-0"; 1344 } 1345 } 1346 return ret; 1347 }, 1348 1349 getFormFieldIsRowField: function(el){ 1350 var ret = ""; 1351 if(el.field_columns && el.field_columns.indexOf(" ") > -1){ 1352 ret = " col-sm-" + el.field_columns.split(" ")[1]; 1353 } 1354 return ret; 1355 }, 1356 1357 getLastFormFieldId: function(){ 1358 return this.nextFormFieldId; 1359 }, 1360 1361 drawModal: function(template, data){ 1362 var ret = this.draw(template, data, this.drawTo, "append"); 1363 ret.modal().on('hidden.bs.modal', function(){ 1364 ret.remove(); 1365 }); 1366 $("input, textarea, select, .btn-focus", ret).first().focus().select(); 1367 return ret; 1368 }, 1369 1370 openModal: function(el, data){ 1371 if(data && typeof data === 'string'){ 1372 this.drawModal(data, {}); 1373 } 1374 }, 1375 1376 closeModal: function(c){ 1377 if(c && typeof c === 'string'){ 1378 $("#" + c).modal("hide"); 1379 } else { 1380 $(".modal").modal("hide"); 1381 } 1382 }, 1383 1384 formFieldLoadByNew: function(cb, force){ 1385 if((this.reloadFormFieldData || force) && this.formFieldDataLoader && this.formFieldDataLoader.length > 0){ 1386 this.reloadFormFieldData = false; 1387 var me = this; 1388 this.formFieldLoadByNewNext(0, cb); 1389 } 1390 }, 1391 1392 formFieldLoadByNewNext: function(cnum, cb){ 1393 var me = this; 1394 this.loadFormFieldData(this.formFieldDataLoader[cnum], function(){ 1395 var ncnum = cnum + 1; 1396 if(me.formFieldDataLoader.length > ncnum){ 1397 me.formFieldLoadByNewNext(ncnum, cb); 1398 } else { 1399 cb.apply(me); 1400 } 1401 }); 1402 }, 1403 1404 formLoadTemplate: function(_tmpl, cb, useCachedData){ 1405 if(!this.formFieldDataLoader) this.formFieldDataLoader = []; 1406 var tmpl = _tmpl; 1407 var me = this; 1408 if(_tmpl.indexOf("/") == -1){ 1409 tmpl = this.localPath + "/" + _tmpl; 1410 } 1411 var myLoader = {tmpl: tmpl}; 1412 if(!useCachedData) this.formFieldDataLoader.push(myLoader); 1413 var LSName = this.getLocalStorageRef() + "tmpl." + tmpl; 1414 var useLS = false; 1415 if(this.appVersion && localStorage){ 1416 useLS = true; 1417 if(localStorage[LSName + ".version"] == this.appVersion){ 1418 myLoader.data = JSON.parse(localStorage[LSName]); 1419 this.loadFormFieldData(myLoader, cb, true, useCachedData ? useLS : false , LSName); 1420 return; 1421 } 1422 } 1423 this.loadLocal(tmpl + ".json", function(data){ 1424 myLoader.data = data; 1425 if(useLS){ 1426 localStorage[LSName] = JSON.stringify(data); 1427 localStorage[LSName + ".version"] = this.appVersion; 1428 } 1429 this.loadFormFieldData(myLoader, cb, false, useCachedData ? useLS : false , LSName); 1430 }); 1431 }, 1432 1433 loadFormDataParams: null, 1434 1435 loadFormFieldData: function(myLoader, cb, fromCache, useLS, LSName){ 1436 var me = this; 1437 var tmpl = myLoader.tmpl; 1438 var data = myLoader.data; 1439 if(fromCache && useLS){ 1440 var lstr = localStorage[LSName + ".cTempl"]; 1441 1442 if(lstr){ 1443 var tdata = JSON.parse(lstr); 1444 for(var i = 0; i < tdata.length; i++){ 1445 me.addTemplate(tdata[i].name, tdata[i].data); 1446 } 1447 if(cb){ 1448 cb.apply(me); 1449 } 1450 return; 1451 } 1452 } 1453 var reqDat = {params: {tfile: (tmpl.indexOf("/jart/") === 0 ? "/" + tmpl.split("/jart/")[1] : tmpl)}, __lang: this.curlang}; 1454 if(this.loadFormDataParams){ 1455 reqDat.params = $.extend(reqDat.params, this.loadFormDataParams); 1456 } 1457 this.req("getFormListData", reqDat, function(fdata){ 1458 this.formFieldData = fdata; 1459 var cTempl = []; 1460 this.compileFormTemplate(data, useLS, cTempl); 1461 if(useLS) localStorage[LSName + ".cTempl"] = JSON.stringify(cTempl); 1462 if(cb){ 1463 cb.apply(me); 1464 } 1465 }); 1466 }, 1467 1468 templateCreator: function(tname, cb, ext, force){ 1469 if(!force && this.template[tname]) return; 1470 1471 var gen = $.extend({ 1472 types: { 1473 "field": {"element__type": "field", "fieldcaption": "", "type": "string", "fieldname": ""}, 1474 "b4modal": {"element__type": "b4modal", "id": "", "backdrop": "static", "title": "Dialog", "dialogClass": "modal
1474-lg"} 1475 }, 1476 setter: { 1477 "_": function(p){ 1478 if(p.c){ 1479 p["class"] = p.c; 1480 p["classes"] = p.c; 1481 delete p.c; 1482 } 1483 return p; 1484 }, 1485 "field": function(p){ 1486 if(p.n){ 1487 p.fieldname = p.n; 1488 delete p.n; 1489 } 1490 if(!p.fieldcaption) p.fieldcaption = p.fieldname; 1491 if(p.type == "hidden") p.fieldcaption = ""; 1492 return p; 1493 }, 1494 "b4modal": function(p){ 1495 if(!p.id) p.id = "DLG" + $.uid(); 1496 return p; 1497 }, 1498 } 1499 }, ext ? ext : {}); 1500 1501 var _ = function(type, _prop, sub){ 1502 var prop = $.extend({}, _prop); 1503 prop = gen.setter._(prop); 1504 prop = gen.setter[type] ? gen.setter[type](prop) : prop; 1505 var r = gen.types[type] ? gen.types[type] : {"element__type": type}; 1506 var x = $.extend({}, r, prop); 1507 x.sub__data = sub ? sub : []; 1508 return x; 1509 }; 1510 1511 var t = { 1512 "element__type": "template", 1513 "template_name": tname, 1514 "sub__data": cb.apply(this, [_]) 1515 }; 1516 1517 this.compileFormTemplate([t]); 1518 }, 1519 1520 compileFormTemplate: function(data, useLS, cTempl){ 1521 this.compliePrefix = ["hb.code:", "bootstrap.element:", "form.element:"]; 1522 this.each(data, function(i, v){ 1523 if(v.element__type === "template"){ 1524 var c = this.compileElement("_compileSub_" + this.appname, v); 1525 if(useLS) cTempl.push({name: v.template_name, data: c}); 1526 this.addTemplate(v.template_name, c); 1527 } 1528 }); 1529 }, 1530 1531 newRowId: function(){ 1532 this.rowId = parseInt(Math.random() * 9999999999); 1533 }, 1534 1535 getRowId: function(fn){ 1536 return this.rowId; 1537 }, 1538 1539 formParsedCode: function(code){ 1540 if(!code) return ""; 1541 return code.replace(/_template/g, "_template_" + this.appname).replace(/_run/g, "_run_" + this.appname); 1542 }, 1543 1544 formDrawOption: function(fname){ 1545 var ret = ""; 1546 if(this.formFieldData[fname]) this.each(this.formFieldData[fname], function(i, v){ 1547 v.caption = this.lang(v.caption); 1548 ret += this.template["form.element:field.select.option"](v); 1549 }); 1550 return ret; 1551 }, 1552 1553 formDrawRadio: function(fname, cls){ 1554 var ret = ""; 1555 if(this.formFieldData[fname]) this.each(this.formFieldData[fname], function(i, v){ 1556 v.fieldname = fname; 1557 v.class = cls; 1558 v.caption = this.lang(v.caption); 1559 ret += this.template["form.element:field.option.item"](v); 1560 }); 1561 return ret; 1562 }, 1563 1564 1565 formDrawCheckbox: function(fname, cls){ 1566 var ret = ""; 1567 if(this.formFieldData[fname]) this.each(this.formFieldData[fname], function(i, v){ 1568 v.fieldname = fname; 1569 v.class = cls; 1570 v.caption = this.lang(v.caption); 1571 ret += this.template["form.element:field.checkbox.item"](v); 1572 }); 1573 return ret; 1574 }, 1575 1576 formCheckRepeater: function(el, min, max){ 1577 var _min = min; 1578 var _max = max; 1579 if(typeof(min) == "undefined"){ 1580 _min = parseInt(el.data("min")); 1581 _max = parseInt(el.data("max")); 1582 } 1583 var cnt = 0; 1584 $(">.repeateritem", el).each(function(){ 1585 cnt++; 1586 if(cnt > _max) el.remove(); 1587 }); 1588 while(cnt < _min){ 1589 this.formAddRepeater(el); 1590 cnt++; 1591 } 1592 }, 1593 1594 formDelRepeater: function(el){ 1595 var ri = el.closest(".repeater"); 1596 var di = el.closest(".repeateritem"); 1597 di.remove(); 1598 this.formCheckRepeater(ri); 1599 }, 1600 1601 formAddRepeater: function(el, data){ 1602 var me = this; 1603 this.newRowId(); 1604 var dataname = el.data("dataname"); 1605 var template = el.data("template"); 1606 var _max = parseInt(el.data("max")); 1607 if($(">.repeateritem", el).length < _max){ 1608 var nel = me.draw("form.element:repeated.item", {dataname: dataname, template: template}, el, "append"); 1609 me.draw(template, data ? data : {}, nel); 1610 return true; 1611 } 1612 return false; 1613 } 1614 1615}); 1616 1617 1618 1619Handlebars.registerHelper('_formFieldNeedsLegend', function(dat, options) { 1620 if(dat.type == 'option' || dat.type == 'checkbox') { 1621 return options.fn(this); 1622 } else { 1623 return options.inverse(this); 1624 } 1625}); 1626 1627$.extend($ajapp.eventanmeldemodal, { 1628 logMissingLang: false, 1629 1630 init: function(){ 1631 /* this.formLoadTemplate("global", function(){this.isReady = true;}, true); */ 1632 this.isReady = true; 1633 }, 1634 1635 start: function(){ 1636 if(!this.isHttpStartup) this.draw("main", {}); 1637 }, 1638 1639 1640 1641 handleTan: function(tan){ 1642 $("#modalCheckTan").modal('show'); 1643 this.send("handleTan", "handleTanCb", {tan:tan}); 1644 }, 1645 1646 handleTanCb: function(data){ 1647 $("#modalCheckTan").modal('hide'); 1648 1649 if(data.success === "true"){ 1650 $("#modalCheckTanSuccess").modal('show'); 1651 }else{ 1652 $("#modalCheckTanFailure").modal('show'); 1653 } 1654 }, 1655 1656 1657 1658 getQueryVariable: function(variable){ 1659 var query = window.location.search.substring(1); 1660 var vars = query.split("&"); 1661 for (var i=0;i<vars.length;i++) { 1662 var pair = vars[i].split("="); 1663 if(pair[0] == variable){return pair[1];} 1664 } 1665 return(false); 1666 } 1667 1668}); 1669 1670 1671 1672/** 1673 * HANDLEBAR HELPERS 1674 */ 1675 1676Handlebars.registerHelper('_date', function(val, format, inFormat) { 1677 if(!val) return ""; 1678 var m; 1679 if(typeof inFormat === "string"){ 1680 m = moment(val, inFormat); 1681 }else{ 1682 m = moment(val); 1683 } 1684 var f = typeof format === "string" ? format : "DD.MM.YYYY"; 1685 return "" + m.format(f); 1686}); 1687 1688Handlebars.registerHelper('_number', function(val, format, options) { 1689 if(!val){ 1690 return ""; 1691 } 1692 var n = numeral(val); 1693 1694 var f = typeof format === "string" ? format : "0.00"; 1695 return new Handlebars.SafeString(n.format(f)); 1696}); 1697 1698 1699 Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) { 1700 return (arg1 == arg2) ? options.fn(this) : options.inverse(this); 1701}); 1702 1703Handlebars.registerHelper('_ifCond', function (v1, operator, v2, options) { 1704 1705 switch (operator) { 1706 case '==': 1707 return (v1 == v2) ? options.fn(this) : options.inverse(this); 1708 case '===': 1709 return (v1 === v2) ? options.fn(this) : options.inverse(this); 1710 case '<': 1711 return (v1 < v2) ? options.fn(this) : options.inverse(this); 1712 case '<=': 1713 return (v1 <= v2) ? options.fn(this) : options.inverse(this); 1714 case '>': 1715 return (v1 > v2) ? options.fn(this) : options.inverse(this); 1716 case '>=': 1717 return (v1 >= v2) ? options.fn(this) : options.inverse(this); 1718 case '&&': 1719 return (v1 && v2) ? options.fn(this) : options.inverse(this); 1720 case '||': 1721 return (v1 || v2) ? options.fn(this) : options.inverse(this); 1722 default: 1723 return options.inverse(this); 1724 } 1725}); 1726$.extend($ajapp.eventanmeldemodal, { 1727 logMissingLang: false, 1728 1729 init: function(){ 1730 this.formLoadTemplate("eventanmeldemodal", function(){ 1731 this.isReady = true; 1732 }, true); 1733 // this.isReady = true; 1734 }, 1735 1736 start: function(){ 1737 if(!this.isHttpStartup){ 1738 this.draw("main", {}); 1739 } 1740 1741 this.draw("modalDialogs", {}, "body", "append"); 1742 1743 moment.locale('de'); 1744 1745 var bestaetigung_tan = this.getQueryVariable("bestaetigung_tan"); 1746 if(bestaetigung_tan){ 1747 $.log("handling tan: " + bestaetigung_tan); 1748 this.handleTan(bestaetigung_tan); 1749 } 1750 }, 1751 1752 1753 showEventAnmeldungModal: function(el, event_id){ 1754 1755 $.log("event_id: " + event_id); 1756 1757 this.send("getEventDetails", "getEventDetailsCb", {event_id: event_id}); 1758 1759 var viewModel = { 1760 loading: true 1761 }; 1762 1763 //TODO: draw anmeldung with loading animation 1764 this.drawModal("ModalAnmeldungEvent", viewModel); 1765 }, 1766 1767 getEventDetailsCb: function(resp){ 1768 $.log("event"); 1769 $.log(resp); 1770 1771 this.model = resp.event[0]; 1772 this.model.erwachsene_anzahl = 0; 1773 this.model.kinder_anzahl = 0; 1774 1775 //SIMULATE delay so that we do not forget to style this and that the user gets enough time to read the text... 1776 var that = this; 1777 setTimeout(function(){ 1778 1779 var templateName = ""; 1780 var showSubmitButton = false; 1781 1782 $.log("event"); 1783 $.log(that.model); 1784 1785 if(that.model.state == 'OPEN'){ 1786 templateName = "eingabefelder"; 1787 showSubmitButton = true; 1788 }else if(that.model.state == 'WAITING_LIST'){ 1789 templateName = "warteliste"; 1790 showSubmitButton = false; 1791 }else if(that.model.state == 'FULLY_BOOKED'){ 1792 templateName = "ausgebucht"; 1793 showSubmitButton = false; 1794 } 1795 1796 1797 if(templateName != ""){ 1798 that.draw(templateName, that.model, ".anmelde-form-wrapper"); 1799 var $btnSave = $("#modalAnmeldungEventDlg .btnSave"); 1800 1801 $.log("show button btnsave:" + showSubmitButton); 1802 $.log($btnSave); 1803 1804 if(showSubmitButton){ 1805 $btnSave.removeClass("hidden"); 1806 }else{ 1807 $btnSave.addClass("hidden"); 1808 } 1809 }else{ 1810 $.log("missing state: " + that.model.state); 1811 } 1812 1813 }, 1000); 1814 1815 //this.draw("eingabefelder", this.model, ".anmelde-form-wrapper"); 1816 }, 1817 1818 1819 runAnmeldung: function(el, formData){ 1820 1821 $(".btnSave").prop('disabled', true); 1822 1823 $.log(formData); 1824 1825 $("#message-sending").removeClass("hidden"); 1826 $("btnSave") 1827 this.send("saveAnmeldung", "saveAnmeldungCb", formData); 1828 1829 }, 1830 1831 saveAnmeldungCb: function(resp){ 1832 $.log("saveREsp:"); 1833 $.log(resp); 1834 1835 $("#message-sending").addClass("hidden"); 1836 $(".btnSave").prop('disabled', false); 1837 1838 if(resp.success == 'true'){ 1839 this.draw("save-success", {}, "#server-msg"); 1840 $(".btnClose").removeClass("hidden"); 1841 $(".btnSave").addClass("hidden"); 1842 }else{ 1843 this.draw("save-error", resp, "#server-msg");
1844 // alert("fehler!! erwachsene_frei: " + resp.validation[0].erwachsene_frei + " | kinder_frei: " + resp.validation[0].kinder_frei); 1845 } 1846 } 1847 1848}); 1849 1850//custom jvalidation function 1851function validateAnzahl(value, params){ 1852 var valid = true; 1853 1854 var erwachsene_anzahl = $("input[name=erwachsene_anzahl]").val(); 1855 var kinder_anzahl = $("input[name=kinder_anzahl]").val(); 1856 1857 if(erwachsene_anzahl <= 0 && kinder_anzahl <= 0){ 1858 valid = false; 1859 params.message = "Bitte wählen Sie Ihre Ticketanzahl."; 1860 } 1861 1862 return valid; //here, the invertation is returned, meaning if the valus is "invalid". @aru --> why is this the case?? 1863} 1864 1865 1866 1867 1868 1869 1870 1871 1872$ajapp.eventanmeldemodal.appname = 'eventanmeldemodal'; 1873$ajapp.eventanmeldemodal.absPath = '/prj3/volkskundemuseum/app/eventanmeldemodal';
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.