1 2 3 4 5(function() { 6 $.extend($.validator.messages, { 7 required: 'Täytä tämä kenttä', 8 email: 'Anna sähköpostiosoite', 9 number: 'Anna luku', 10 date: 'Anna päivämäärä', 11 min: 'Minimiarvo on {0}' 12 }); 13 14 dhtmlXCalendarObject.prototype.langData["fi"] = { 15 dateformat: "%d.%m.%Y", 16 monthesFNames: ["Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu"], 17 monthesSNames: ["Tam", "Hel", "Maa", "Huh", "Tou", "Kes", "Hei", "Elo", "Syy", "Lok", "Mar", "Jou"], 18 daysFNames: ["Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai"], 19 daysSNames: ["Su", "Ma", "Ti", "Ke", "To", "Pe", "La"], 20 weekstart: 1 21 } 22 dhtmlXCalendarObject.prototype.langData["fi_FI"] = dhtmlXCalendarObject.prototype.langData["fi"]; 23 dhtmlXCalendarObject.prototype.langData["sv"] = { 24 dateformat: "%d.%m.%Y", 25 monthesFNames: ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"], 26 monthesSNames: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"], 27 daysFNames: ["Söndag", "MÃ¥ndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag"], 28 daysSNames: ["Sö", "MÃ¥", "Ti", "On", "To", "Fr", "Lö"], 29 weekstart: 1 30 } 31 dhtmlXCalendarObject.prototype.langData["sv_SV"] = dhtmlXCalendarObject.prototype.langData["sv"]; 32 33 dhtmlXCalendarObject.prototype.lang = ""; 34}); 35 36$(function () { 37 $('body').on('click touchstart', '.navbar-collapse ul li a:not(.dropdown-toggle)', function (e) { 38 // iOS needs longer timeout 39 var isIOS = (/iPad|iPhone|iPod/.test(navigator.platform) || 40 (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) && !window.MSStream; 41 setTimeout(function() { 42 $('.navbar-toggle:visible').trigger(e.type); 43 }, isIOS ? 150 : 0); 44 }); 45}); 46 47var Common = (function() { 48 return { 49 kayttotarkoitusToCustomerSegment: function(kayttotarkoitus, huoneistomaara) { 50 function isPermanent(kayttotarkoitus, huoneistomaara) { 51 return kayttotarkoitus == 0 52 53 || (kayttotarkoitus == 3 && 1 <= huoneistomaara && huoneistomaara <= 2) 54 55 56 || (kayttotarkoitus == 4 && 1 <= huoneistomaara && huoneistomaara <= 2) 57 58 } 59 60 function isCondo(kayttotarkoitus, huoneistomaara) { 61 return kayttotarkoitus == 2 62 63 64 || (kayttotarkoitus == 3 && huoneistomaara > 2) 65 66 67 || (kayttotarkoitus == 4 && huoneistomaara > 2) 68 69 } 70 71 var pl = null; 72 if(isPermanent(kayttotarkoitus, huoneistomaara)) { 73 pl = "9XX"; 74 } else if(kayttotarkoitus == 1) { 75 pl = "9XX"; 76 } else if(isCondo(kayttotarkoitus, huoneistomaara)) { 77 pl = "9ÃÃ"; 78 } else if(kayttotarkoitus == 3) { 79 pl = "9ZZ"; 80 } else if(kayttotarkoitus == 4) { 81 pl = "9ÃÃ"; 82 } 83 return pl; 84 }, 85 86 queryParams: function() { 87 var regex = new RegExp(/[?&]([^&=]+)=?([^&]*)/g); 88 var param; 89 var result = {}; 90 while((param = regex.exec(window.location.href)) !== null) { 91 result[param[1]] = param[2]; 92 } 93 return result; 94 }, 95 96 formatNullAsEmpty: function(s) { 97 return s != null ? s : ''; 98 }, 99 100 getWeekNumber : function (d) { 101 // Copy date so don't modify original 102 d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())); 103 // Set to nearest Thursday: current date + 4 - current day number 104 // Make Sunday's day number 7 105 d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7)); 106 // Get first day of year 107 var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); 108 // Calculate full weeks to nearest Thursday 109 var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7); 110 // Return array of year and week number 111 return weekNo; 112 }, 113 114 getMondayOfFirstWeekOfYear : function () { 115 var date = null; 116 var firstDayOfTheYear = Common.getDateOnly(new Date()); 117 firstDayOfTheYear.setFullYear(firstDayOfTheYear.getFullYear(), 0, 1); 118 var weekNumber = Common.getWeekNumber(firstDayOfTheYear); 119 // jos viikko yks ota maanantai, jos viikko 52/53 ota seuraava maanantai 120 if(weekNumber == 1) 121 { 122 date = Common.getStartOfWeek(firstDayOfTheYear); 123 } 124 else 125 { 126 date = Common.getStartOfNextWeek(firstDayOfTheYear); 127 } 128 return date; 129 }, 130 131 getSundayOfLastWeekOfYear : function () { 132 var date = null; 133 var lastDayOfTheYear = Common.getDateOnly(new Date()); 134 lastDayOfTheYear.setFullYear(lastDayOfTheYear.getFullYear(), 11, 31); 135 // jos viikko yks edellinen sunnuntai, jos viikko 52/53 ota seuraava sunnuntai 136 var weekNumber = Common.getWeekNumber(lastDayOfTheYear); 137 if(weekNumber == 1) 138 { 139 date = Common.getEndOfPrevWeek(lastDayOfTheYear); 140 } 141 else 142 { 143 date = Common.getEndOfWeek(lastDayOfTheYear); 144 } 145 return date; 146 }, 147 148 getStartOfWeek: function(d) { 149 var date = new Date(d); 150 while(date.getDay() != 1) { 151 date.setDate(date.getDate() - 1); 152 } 153 return date; 154 }, 155 // This returns today if monday else next weeks monday 156 getNextStartOfWeek: function(d) { 157 var date = new Date(d); 158 while(date.getDay() != 1) { 159 date.setDate(date.getDate() + 1); 160 } 161 return date; 162 }, 163 getEndOfWeek: function(d) { 164 var date = new Date(d); 165 while(date.getDay() != 0) { 166 date.setDate(date.getDate() + 1); 167 } 168 return date; 169 }, 170 171 getStartOfNextWeek: function(d) { 172 var date = new Date(d); 173 do { 174 date.setDate(date.getDate() + 1); 175 } while(date.getDay() != 1); 176 return date; 177 }, 178 getEndOfNextWeek: function(d) { 179 var date = new Date(d); 180 do { 181 date.setDate(date.getDate() + 1); 182 } while(date.getDay() != 0); 183 return date; 184 }, 185 getStartOfPrevWeek: function(d) { 186 var date = new Date(d); 187 do { 188 date.setDate(date.getDate() - 1); 189 } while(date.getDay() != 1); 190 return date; 191 }, 192 getEndOfPrevWeekOrWeek53End: function(d) { 193 var date = new Date(d); 194 if (Common.getWeekNumber(date) == 53) 195 { 196 date = Common.getEndOfWeek(date); 197 } 198 else{ 199 do { 200 date.setDate(date.getDate() - 1); 201 } while(date.getDay() != 0); 202 } 203 return date; 204 }, 205 206 getEndOfPrevWeek: function(d) { 207 var date = new Date(d); 208 do { 209 date.setDate(date.getDate() - 1); 210 } while(date.getDay() != 0); 211 return date; 212 }, 213 214 getDateOnly: function(d) { 215 var date = new Date(d); 216 date.setHours(0); 217 date.setMinutes(0); 218 date.setSeconds(0); 219 date.setMilliseconds(0); 220 return date; 221 }, 222 // returns Monday for that week of this year or Sunday for week 53 223 // THIS FUNCTION MOST LIKELY NOT WORK 224 // THIS ASSUMES THAT FIRST MONDAY IS IN THE FIRST WEEK 225 // MOST LIKELY FIRST MONDAY OF THE YEAR IS IN SECOND WEEK, BUT EVEN THEN THAT ISN'T CERTAIN 226 getDateForWeek: function(week, year) { 227 if(!week) 228 return null; 229 230 var date = Common.getDateOnly(new Date()); 231 if(year) 232 date.setFullYear(year); 233 date.setMonth(0); 234 date.setDate(1); 235 while(date.getDay() != 1) { // find the first Monday 236 date.setDate(date.getDate() + 1); 237 } 238 239 for(var i = 1; i < Math.min(week, 52); ++i) { 240 date.setDate(date.getDate() + 7); 241 } 242 243 if(week == 53) { 244 date = Common.getEndOfWeek(date); 245 } 246 247 return date; 248 }, 249 250 // returns Monday for seeked week of this year or Sunday for week 53 251 getDateForSearchedWeek: function(week, year) { 252 if(!week) 253 return null; 254 255 var date = Common.getDateOnly(new Date()); 256 if(year) 257 date.setFullYear(year); 258 date.setMonth(0); 259 date.setDate(1); 260 261 // if searched week is 1 we have to check which week is current week 262 // and if same then we have reverse seek first day of current week 263 if (week == 1 && Common.getWeekNumber(date) == 1 ) 264 { 265 while(date.getDay() != 1) { 266 date.setDate(date.getDate() - 1); 267 } 268 return date; 269 } 270 271 while(date.getDay() != 1) { // find the first Monday 272 date.setDate(date.getDate() + 1); 273 } 274 275 // find what week monday is (might be week 1 or 2) 276 for(var i = Common.getWeekNumber(date); i < Math.min(week, 52); ++i) { 277 date.setDate(date.getDate() + 7); 278 } 279 280 if(week == 53) { 281 date = Common.getEndOfWeek(date); 282 } 283 284 return date; 285 }, 286 287 findInFormJson: function(json, findPredicate) { 288 if(Array.isArray(json)) { 289 var result = null; 290 for(var i = 0; i < json.length; ++i) {
291 result = Common.findInFormJson(json[i], findPredicate); 292 if(result !== null) { 293 break; 294 } 295 } 296 return result; 297 } else { 298 if(findPredicate(json)) { 299 return json; 300 } else { 301 if(json.list) { 302 return Common.findInFormJson(json.list, findPredicate); 303 } else if(json.options) { 304 return Common.findInFormJson(json.options, findPredicate); 305 } else { 306 return null; 307 } 308 } 309 } 310 }, 311 312 get$options: function(options) { 313 if(typeof HTMLOptionsCollection !== 'undefined' && options instanceof HTMLOptionsCollection) 314 return $(options); 315 else 316 return $(options).find('option'); 317 }, 318 319 $optionsToHtml: function($options) { 320 var optionsHtml = $('<select>').append($options).html(); 321 /* IE9 fix */ 322 if(optionsHtml.indexOf('<select') >= 0) { 323 var start = optionsHtml.indexOf('<option'); 324 var end = optionsHtml.indexOf('</select'); 325 optionsHtml = optionsHtml.substring(start, end); 326 } 327 return optionsHtml; 328 }, 329 330 isSahas: function() { 331 return $('body').is('#sahas'); 332 }, 333 334 htmlOptionsToDhtmlx: function(options) { 335 var result = []; 336 for(var i = 0; i < options.length; ++i) { 337 result.push({ 338 text: options[i].text, 339 value: options[i].value 340 }); 341 } 342 return result; 343 }, 344 345 /* Jos sääntö on undefined, eli se esimerkiksi puuttuu kokonaan, sitä ei huomioida säännöstössä. 346 * Sama pätee myös objektille. Sen sijaan null arvot testataan normaalisti. */ 347 checkRules: function(object, rules) { 348 function checkCriterion(value, criterion) { 349 if(typeof criterion === 'undefined') { 350 return true; 351 } else if(criterion instanceof RegExp) { 352 return criterion.test('' + value); 353 } else if($.isFunction(criterion) && criterion(value, object)) { 354 return true; 355 } else if($.isArray(criterion)) { 356 for(var i = 0; i < criterion.length; ++i) { 357 if($.isFunction(criterion[i]) && criterion[i](value, object)) 358 return true; 359 if(value == criterion[i]) 360 return true; 361 } 362 return false; 363 } else if($.isPlainObject(criterion)) { 364 for(var subCriterion in criterion) { 365 if(typeof value[subCriterion] === 'undefined') 366 continue; 367 else if(!checkCriterion(value[subCriterion], criterion[subCriterion])) 368 return false; 369 } 370 return true; 371 } else { 372 return value == criterion; 373 } 374 } 375 376 var result = []; 377 $.each(rules, function(i, e) { 378 var applies = true; 379 for(var prop in object) { 380 if(typeof object[prop] === 'undefined') 381 continue 382 383 if(!checkCriterion(object[prop], e[prop])) { 384 applies = false; 385 break; 386 } 387 } 388 if(applies) { 389 result.push(e); 390 } 391 }); 392 return result; 393 }, 394 395 396 // $ is wild card for any number 397 checkFieldNames: function(ruleArray, fixingIndex) 398 { 399 var correctedRules = []; 400 for (var i = 0; i < ruleArray.length; i++) 401 { 402 var rule = ruleArray[i]; 403 var newRule = jQuery.extend({}, rule); // copy values 404 for (var key in rule) { 405 var newkey = key.replace('$', fixingIndex); 406 if (newkey !== key) 407 { 408 newRule[newkey] = rule[key]; 409 // Check if special definition for certain keys (like first one) 410 if (newkey in rule) 411 { 412 newRule[newkey] = rule[newkey]; 413 } 414 415 delete newRule[key]; 416 } 417 }
418 correctedRules.push(newRule); 419 } 420 return correctedRules; 421 }, 422 423 applyRules: function(form, results){ 424 // loop all items update, if label -> update label, if note -> update note 425 426 var replaces = []; 427 428 form.forEachItem( 429 function (name){ 430 var rules = results.filter( function(rule) { return name in rule; } ).map(function(rule) { return rule[name]; }); 431 432 if (rules != null && rules.length > 0 ) 433 { 434 for (var i = 0; i < rules.length; i++) 435 { 436 var rule = rules[i]; 437 if ('note' in rule) 438 { 439 if (rule.note == null || rule.note.text == "") 440 { 441 form.clearNote(name); 442 } 443 else 444 { 445 form.setNote(name, rule.note); 446 } 447 } 448 if ('label' in rule) 449 { 450 form.setItemLabel(name, rule.label); 451 } 452 if ('hidden' in rule && rule.hidden === true) 453 { 454 form.hideItem(name); 455 } 456 457 if ('hidden' in rule && rule.hidden === false) 458 { 459 form.showItem(name); 460 } 461 462 if ('tooltip' in rule) 463 { 464 form.setTooltip(name, rule.tooltip) 465 } 466 467 if ('info' in rule) 468 { 469 // If info contains data add info mark 470 if (rule.info !== null && rule.info !== "") 471 { 472 var element = form._getItemByName(name); 473 // Remove old tooltip if it exist 474 $(element).find('.dhxform_info').remove(); 475 476 477 var info = '<span class="dhxform_info" data-toggle="tooltip" title="' 478 + rule.info +'" data-placement="top"><span class="glyphicon glyphicon-question-sign"></span></span>'; 479 480 $(element).find('label').append(info); 481 $(element).find('.dhxform_info').tooltip(); 482 } 483 // If info field is empty, remove info mark 484 else 485 { 486 var element = form._getItemByName(name); 487 $(element).find('.dhxform_info').remove(); 488 } 489 } 490 491 if ('replace' in rule) { 492 // Postpone replaces, because removing items from the form while 493 // iterating them is risky. 494 replaces.push({ 495 name: name, 496 replace: rule.replace 497 }); 498 } 499 } 500 } 501 } 502 ) 503 504 replaces.forEach(function(rule) { 505 form.removeItem(rule.name); 506 form.addItem(rule.replace.pId, rule.replace.itemData, 507 rule.replace.pos, rule.replace.insertAfter); 508 }); 509 }, 510 511 getUrl : function(path, uriParameters) 512 { 513 var url = ""; 514 if (path == null) 515 { 516 return null; 517 } 518 519 if (path[0] == '/') { 520 url = baseurl + path; 521 } 522 else if (path.indexOf("http://") == 0|| path.indexOf("https://") == 0) 523 { 524 url = path; 525 } 526 else 527 { 528 url = baseurl + '/' + path; 529 } 530 531 if(uriParameters != null) 532 { 533 var first = true; 534 for (var key in uriParameters) 535 { 536 if (first) 537 { 538 url += "?"; 539 first = false; 540 } 541 else 542 { 543 url += "&"; 544 } 545 var parameter = uriParameters[key]; 546 if(Array.isArray(parameter)) 547 { 548 url = url + key + "=" + parameter.join(','); 549 } 550 else if (parameter == null) 551 { 552 url = url + key + "=" 553 } 554 else 555 { 556 url = url + key + "=" + parameter; 557 } 558 } 559 } 560 561 return encodeURI(url); 562 }, 563 564 getUrlWithCommonParameters : function (path, type, concernIds, managerIds, invoiceIds, customerIds, communityIds, groupIds, periods, cum, time ) 565 { 566 parameters = 567 { 568 "type" : type, 569 "concernid" : concernIds, 570 "managerid": managerIds, 571 "invid" : invoiceIds, 572 "customerid" : customerIds, 573 "communityid" : communityIds, 574 "groupid" : groupIds, 575 "period" : periods, 576 "cum" : cum, 577 "time" : time 578 } 579 580 return Common.getUrl(path, parameters); 581 }, 582 583 getJSONKeysByRegEx: function(json, regex) 584 { 585 if (json == null || regex == null) 586 { 587 return null; 588 } 589 590 var results = []; 591 var keys = Object.keys(json); 592 var i = 0; 593 for(i = 0; i < keys.length; i++) 594 { 595 if (keys[i].match(regex)) 596 { 597 results.push(keys[i]); 598 } 599 } 600 601 return results; 602 }, 603 604 // Forces user only enter numbers or decimals to input field 605 isNumberOrDecimalKey: function (evt) {
606 var charCode = (evt.which) ? evt.which : evt.keyCode; 607 if (charCode > 31 && (charCode != 46 && charCode != 44 &&(charCode < 48 || charCode > 57))) 608 { 609 return false; 610 } 611 return true; 612 }, 613 614 // Forces user only enter numbers to input field 615 isNumberKey: function (evt) { 616 var charCode = (evt.which) ? evt.which : evt.keyCode; 617 if (charCode > 31 && (charCode < 48 || charCode > 57)) 618 { 619 return false; 620 } 621 return true; 622 } 623 624 }; 625})(); 626 627function eventHandlersMixin() { 628 return { 629 _handlers: {}, 630 on: function(eventName, handler) { 631 if(!(eventName in this._handlers)) { 632 this._handlers[eventName] = [handler]; 633 } else { 634 this._handlers[eventName].push(handler); 635 } 636 return this; 637 }, 638 trigger: function(eventName, context) { 639 if(!(eventName in this._handlers)) { 640 this._handlers[eventName] = []; 641 } 642 643 var args = []; 644 for(var i = 2; i < arguments.length; ++i) { 645 args.push(arguments[i]); 646 } 647 648 if(typeof context === 'undefined') { 649 context = this; 650 } 651 652 $.each(this._handlers[eventName], function() { 653 this.apply(context, args); 654 }); 655 return this; 656 } 657 }; 658} 659 660function lock($root, message) { 661 if($root.children('[data-role="lock-screen"]').length === 0) { 662 var lock = $('<div></div>').addClass('lock-screen').appendTo($root).attr('data-role', 'lock-screen'); 663 if(message != null) { 664 $('<div class="message"><span>' + message + '</span></div>').appendTo(lock); 665 } 666 } 667} 668 669function unlock($root) { 670 $root.children('[data-role="lock-screen"]').remove(); 671} 672 673function showWindow($modal, windowFunction, arguments) { 674 $modal.modal({ 675 backdrop: 'static' 676 }); 677 678 if(typeof arguments === 'undefined') { 679 arguments = []; 680 } 681 arguments.unshift($modal); 682 683 var selector = $modal.selector; 684 685 var modalName = ""; 686 687 if (selector.indexOf("-modal") != -1) 688 { 689 modalName = selector.substring(selector.lastIndexOf("#") + 1, selector.lastIndexOf("-")) + "-main-page"; 690 $('body').addClass(modalName) 691 } 692 693 return windowFunction.apply(null, arguments) 694 .always(function() { 695 $modal.modal('hide'); 696 if (modalName != null && modalName.trim().length > 0) 697 { 698 $('body').removeClass(modalName) 699 } 700 }); 701} 702 703function removeCssImportant($root) { 704 $root.find('*').each(function(i, e) { 705 var style = $(this).attr('style'); 706 if(style) 707 $(this).attr('style', style.replace('!important', '')); 708 }); 709} 710 711 712function shouldSplitName(customerData) { 713 return $.inArray(parseInt(getKayttotarkoitusCategory(customerData.kayttotarkoitus)), [0, 1]) !== -1; 714} 715 716function showSplitName(form, required, prefix, postfix) { 717 if(typeof prefix === 'undefined') 718 prefix = ''; 719 if(typeof postfix === 'undefined') 720 postfix = ''; 721 form.showItem(prefix + 'etunimi' + postfix); 722 form.showItem(prefix + 'sukunimi' + postfix); 723 if(required) { 724 form.setValidation(prefix + 'etunimi' + postfix, 'NotEmpty'); 725 form.setValidation(prefix + 'sukunimi' + postfix, 'NotEmpty'); 726 } 727 form.hideItem(prefix + 'nimi' + postfix); 728 form.clearValidation(prefix + 'nimi' + postfix); 729} 730 731function hideSplitName(form, required, prefix, postfix) { 732 if(typeof prefix === 'undefined') 733 prefix = ''; 734 if(typeof postfix === 'undefined') 735 postfix = ''; 736 form.hideItem(prefix + 'etunimi' + postfix); 737 form.hideItem(prefix + 'sukunimi' + postfix); 738 form.clearValidation(prefix + 'etunimi' + postfix); 739 form.clearValidation(prefix + 'sukunimi' + postfix); 740 form.showItem(prefix + 'nimi' + postfix); 741 if(required) { 742 form.setValidation(prefix + 'nimi' + postfix, 'NotEmpty'); 743 } 744} 745 746 747function formatCurrency(value) { 748 var string = String(+(Math.round(value + 'e+2') + 'e-2')); 749 string = string.replace('.', ','); 750 var comma = string.indexOf(','); 751 if(comma == -1) { 752 return string + ',00'; 753 } 754 while(comma > string.length - 3) {
755 string += '0'; 756 } 757 758 return string; 759} 760 761function formatInterval(secs) { 762 if(secs === null) { 763 return ''; 764 } 765 766 var days = Math.floor(secs / (60 * 60 * 24)); 767 secs %= 60 * 60 * 24; 768 var hours = Math.floor(secs / (60 * 60)); 769 secs %= 60 * 60; 770 var mins = Math.floor(secs / 60); 771 secs %= 60; 772 773 var result = ''; 774 if(days > 0) 775 result += days + ' d '; 776 if(days > 0 || hours > 0) 777 result += hours + ' h '; 778 if(days > 0 || hours > 0 || mins > 0) 779 result += mins + ' min '; 780 result += secs + ' s'; 781 return result; 782} 783 784 785$(document).on('show.bs.modal', '.modal', function () { 786 var zIndex = 1040 + (10 * $('.modal:visible').length); 787 $(this).css('z-index', zIndex); 788 setTimeout(function() { 789 $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack'); 790 }, 0); 791}); 792 793$(document).on('hidden.bs.modal', '.modal', function () { 794 $('.modal:visible').length && $(document.body).addClass('modal-open'); 795}); 796 797/* 798 * Form data collection and sending 799 */ 800 801// TODO: Does not support arrays of arrays yet! 802function createObject(source) { 803 var result = {}; 804 for(var name in source) { 805 var parts = name.split("."); 806 var iter = result; 807 for(var i = 0; i < parts.length; ++i) { 808 var ar = /^([^\[]+)(?:\[([^\]]+)\])?$/.exec(parts[i]); 809 if(i < parts.length - 1) { 810 if(!(ar[1] in iter)) { 811 if(typeof ar[2] !== 'undefined') 812 iter[ar[1]] = []; 813 else 814 iter[ar[1]] = {}; 815 } 816 if(typeof ar[2] === 'undefined') { 817 iter = iter[ar[1]]; 818 } else { 819 if(!(ar[2] in iter[ar[1]])) 820 iter[ar[1]][ar[2]] = {}; 821 iter = iter[ar[1]][ar[2]]; 822 } 823 } else { 824 if(typeof ar[2] !== 'undefined') { 825 if(!(ar[1] in iter)) 826 iter[ar[1]] = []; 827 iter[ar[1]][ar[2]] = source[name]; 828 } else 829 iter[ar[1]] = source[name]; 830 } 831 } 832 } 833 return result; 834} 835 836function collectFormData(forms) { 837 var data = {}; 838 for(var i = 0; i < forms.length; ++i) { 839 var form = forms[i]; 840 form.forEachItem(function(name, value) { 841 if(form.isItemEnabled(name, value) === false) 842 return; 843 var itemType = form.getItemType(name, value); 844 if($.inArray(itemType, ["calendar", "hidden", "week_calendar"]) !== -1) { // not select, checkbox or radio 845 if($(form.getInput(name)).prop("disabled")) 846 return; 847 if(itemType !== 'calendar') 848 data[name] = form.getItemValue(name, true); 849 else 850 data[name] = form.getCalendar(name).getFormatedDate('%Y-%m-%d'); 851 } else if(itemType === "input" || itemType === 'input5' || itemType === "password") { 852 var enabled = $(form.cont).find("input[name='" + name + "']:enabled," 853 + "textarea[name='" + name + "']:enabled"); 854 if(enabled.length === 0) 855 return; 856 if(itemType === 'input5') 857 data[name] = enabled.val(); 858 else 859 data[name] = form.getItemValue(name); 860 } else if(itemType === "select") { 861 if($(form.getSelect(name)).prop("disabled")) 862 return; 863 data[name] = form.getItemValue(name); 864 } else if(itemType === "radio" && form.isItemChecked(name, value)) { // radio 865 if(name in data)// || typeof form.getCheckedValue(name) === 'undefined') 866 return; 867 data[name] = value; 868 } else if(itemType === "checkbox") { // checkbox
869 var checkValue = form.getItemValue(name); 870 checkValue = checkValue !== null && checkValue !== '' ? checkValue : 1; 871 data[name] = form.isItemChecked(name) ? checkValue : 0; 872 } 873 }); 874 } 875 return data; 876} 877 878function sendForms(forms, url) { 879 var jsonData = createObject(collectFormData(forms)); 880 881 return $.ajax({ 882 contentType: "application/json; charset=utf-8", 883 data: JSON.stringify(jsonData), 884 url: url, 885 type: "POST" 886 }); 887} 888 889/* 890 * Form helpers 891 */ 892 893function formReloadOptions(form, item, optionsOrUrl) { 894 895 function selectIfExists(value) { 896 if($(form.getSelect(item)).find('option[value="'+oldValue+'"]').length > 0) { 897 form.setItemValue(item, value); 898 } 899 } 900 901 function addToOnGoingReloads(item, promise) { 902 formReloadOptions.onGoingReloads[item] = result; 903 $(form.getSelect(item)).data('on-going-reload', true); 904 } 905 906 function removeFromOnGoingReloads(item) { 907 formReloadOptions.onGoingReloads[item] = null; 908 $(form.getSelect(item)).data('on-going-reload', false); 909 } 910 911 var oldReload = formReloadOptions.onGoingReloads[item]; 912 if(oldReload) { 913 return oldReload.always(function() { 914 return formReloadOptions(form, item, optionsOrUrl); 915 }); 916 } 917 918 var result = $.Deferred(); 919 addToOnGoingReloads(item, result); 920 921 var oldValue = form.getItemValue(item); 922 if(typeof optionsOrUrl === 'string') { 923 var selector = 'select[name="' + item + '"]'; 924 if($(selector).parent().children(".loader").size() == 0) { 925 $(selector).parent().append('<img src="images/ajax-loader.gif" class="loader">'); 926 } 927 var eventId = form.attachEvent("onOptionsLoaded", function(name) { 928 if(name === item) { 929 $(selector).parent().children(".loader").remove(); 930 931 selectIfExists(oldValue); 932 933 form.detachEvent(eventId); 934 935 removeFromOnGoingReloads(item); 936 result.resolve($(form.getOptions(item)).clone()); 937 } 938 }); 939 optionsOrUrl = encodeURI(optionsOrUrl); 940 } 941 942 form.reloadOptions(item, optionsOrUrl); 943 if(typeof optionsOrUrl !== 'string') { 944 selectIfExists(oldValue); 945 removeFromOnGoingReloads(item); 946 result.resolve($(form.getOptions(item)).clone()); 947 } 948 949 return result; 950} 951 952formReloadOptions.onGoingReloads = {}; 953 954function focusOnFirstError(form) { 955 var errors = $(form.cont).find(".validate_error"); 956 if(errors.length == 0) 957 return; 958 959 var min = 9999999999; 960 errors.each(function() { 961 var top = $(this).offset().top; 962 if(top < min) 963 min = top; 964 }); 965 966 if($("body").scrollTop() > min) 967 $("html, body").animate({scrollTop: min}, 1000); 968} 969 970function makeServiceCombo(combo) { 971 var parent = $(combo.DOMelem); 972 parent.children('.dhx_combo_input').on('click', function() { 973 combo.setComboText(""); 974 }); 975 parent.children('.dhx_combo_img').on('click', function() { 976 combo.setComboText(""); 977 }); 978} 979 980/* 981 * Generic functions 982 */ 983 984function reduce(array, callback, initialValue) { 985 var start = 0; 986 if(typeof initialValue === 'undefined') { 987 initialValue = array[0]; 988 start = 1; 989 } 990 for(var i = start; i < array.length; ++i) { 991 initialValue = callback(initialValue, array[i], i, array); 992 } 993 return initialValue; 994} 995 996function any(array, test) { 997 for(var i = 0; i < array.length; ++i) { 998 if(test(array[i])) 999 return true; 1000 } 1001 return false; 1002} 1003 1004function optionsDefault(options, pathVarArgs, value) { 1005 if(typeof options === 'undefined') { 1006 options = {}; 1007 } 1008 var iter = options; 1009 for(var i = 1; i < arguments.length - 2; ++i) { 1010 if(typeof iter[arguments[i]] === 'undefined') { 1011 iter[arguments[i]] = {}; 1012 } 1013 iter = iter[arguments[i]]; 1014 } 1015 if(typeof iter[arguments[arguments.length - 2]] === 'undefined') { 1016 iter[arguments[arguments.length - 2]] = arguments[arguments.length - 1]; 1017 } 1018 return options; 1019} 1020 1021/* 1022 * Rule solver 1023 */ 1024 1025// givenKayttotarkoitus is only mean to solve special case when kayttotarkoitus 998 cannot be decided from company or public building 1026// NOTE!! It will only works for anonymous users, because customer data doesn't contain info givenKayttotarkoitus. 1027// If customer uses this code in their VINGO data then shared.property_usages.code_998_category must be defined 1028 1029function getKayttotarkoitusCategory(kayttotarkoitus, givenKayttotarkoitus) { 1030 var givenKayttotarkoitusStr = ''; 1031 if(givenKayttotarkoitus !== 'undefined'){ 1032 givenKayttotarkoitusStr = givenKayttotarkoitus+""; 1033 } 1034 if($.inArray(kayttotarkoitus, ['001', '011', '012', '013']) !== -1 && givenKayttotarkoitusStr !=='2') { 1035 return 0; 1036 } else if($.inArray(kayttotarkoitus, ['041', '931']) !== -1) { 1037 return 1; 1038 } else if($.inArray(kayttotarkoitus, ['021', '022', '032', '039', '012']) !== -1 && givenKayttotarkoitusStr !=='0') { 1039 return 2; 1040 } else if($.inArray(kayttotarkoitus, ["111", "112", "119", "121", "123", "124", "129", "139", "141", "151", "161", "213", "215", "219", "221", "222", "223", "229", "231", "311", "3
104012", "323", "324", "331", "351", "353", "354", "541", "691", "692", "699", "711", "712", "719"]) !== -1) { 1041 return 3; 1042 } else if(kayttotarkoitus === '131') { 1043 return 4; 1044 } else if(kayttotarkoitus === '998') { 1045 if ( false ) 1046 { 1047 return ; 1048 } 1049 1050 return givenKayttotarkoitus; 1051 } 1052 else { 1053 return getKayttotarkoitusCategoryCorrect(kayttotarkoitus, givenKayttotarkoitus); 1054 } 1055} 1056 1057 1058 1059 1060// ASRAP-5161. If getKayttotarkoitusCategory (the incorrect version!) doesn't find any category, try with correct lists. 1061function getKayttotarkoitusCategoryCorrect(kayttotarkoitus, givenKayttotarkoitus) { 1062 var givenKayttotarkoitusStr = ''; 1063 if(givenKayttotarkoitus !== 'undefined'){ 1064 givenKayttotarkoitusStr = givenKayttotarkoitus+""; 1065 } 1066 if($.inArray(kayttotarkoitus, ["001", "012", "013", "041"]) !== -1 && givenKayttotarkoitusStr !=='2') { 1067 return 0; 1068 } else if($.inArray(kayttotarkoitus, ["021", "022", "032", "039"]) !== -1) { 1069 return 1; 1070 } else if($.inArray(kayttotarkoitus, ["131", "151", "211", "213", "214", "215", "219", "221", "222", "223", "229", "231", "239", "241", "322", "331", "341", "342", "352", "354", "511", "521", "531", "532", "541", "721", "729", '012']) !== -1 && givenKayttotarkoitusStr !=='0') { 1071 return 2; 1072 } else if($.inArray(kayttotarkoitus, ["111", "112", "119", "121", "123", "124", "129", "131", "139", "141", "151", "213", "215", "219", "221", "222", "223", "229", "231", "311", "312", "323", "324", "331", "351", "353", "354", "541", "691", "692", "699", "711", "712", "719"]) !== -1) { 1073 return 3; 1074 } else if($.inArray(kayttotarkoitus, ["161", "162", "163", "164", "165", "349", "359", "369", "549", "611", "613", "722", "811", "819", "891", "892", "893", "899", "931", "941", "999"]) !== -1) { 1075 return 4; 1076 } else { 1077 return null; 1078 } 1079} 1080 1081/* 1082 * Kendo 1083 */ 1084 1085function sendKendoData(dataSource, url, extraData) { 1086 var data = dataSource.data(); 1087 var updated = []; 1088 var created = []; 1089 1090 for(var i = 0; i < data.length; ++i) { 1091 if(data[i].isNew()) { 1092 created.push(data[i].toJSON()); 1093 } else if(data[i].dirty) { 1094 updated.push(data[i].toJSON()); 1095 } 1096 } 1097 1098 var deleted = []; 1099 for(var i = 0; i < dataSource._destroyed.length; ++i) { 1100 deleted.push(dataSource._destroyed[i].toJSON()); 1101 } 1102 1103 var parameterMap = dataSource.transport.parameterMap; 1104 if(!parameterMap) { 1105 parameterMap = function(data, type) { return data; } 1106 } 1107 var sentData = {}; 1108 $.extend(sentData, { 1109 updated: parameterMap(updated, "update"), 1110 created: parameterMap(created, "create"), 1111 deleted: parameterMap(deleted, "destroy"), 1112 extraData: extraData 1113 }); 1114 1115 return $.ajax({ 1116 url: url, 1117 type: "POST", 1118 contentType: "application/json;charset=UTF-8", 1119 data: JSON.stringify(sentData) 1120 }); 1121} 1122 1123function kendoDropdownHtmlSelect(dropDown) { 1124 return function(e) { 1125 var selected = $(this).children('option:selected'); 1126 var index = $(this).children().index(selected); 1127 dropDown.select(index); 1128 dropDown.trigger('change'); 1129 } 1130} 1131 1132/* 1133 * Map 1134 */ 1135 1136function project(service, points, map) { 1137 var result = new $.Deferred(); 1138 1139 require(["dojo/Deferred", "esri/tasks/ProjectParameters"], function(Deferred, ProjectParameters) { 1140 if(points.length == 0) { 1141 result.resolve(points); 1142 return; 1143 } 1144 1145 var inSR = points[0].spatialReference; 1146 var outSR = map.spatialReference; 1147 var param = new ProjectParameters(); 1148 param.transformForward = true; 1149 if(inSR.wkid === 2393 && (outSR.wkid === 3067 || outSR.wkid === 102139 )) 1150 { 1151 var transformation = 108229; 1152 param.transformForward = true; 1153 } 1154 else if(outSR.wkid === 2393 && (inSR.wkid === 3067 || inSR.wkid === 102139 )) 1155 { 1156 var transformation = 108229; 1157 param.transformForward = false; 1158 } 1159 1160 param.geometries = points; 1161 param.outSR = outSR; 1162 param.transformation = transformation; 1163 1164 service.project(param) 1165 .then(function(projected) { 1166 result.resolve(projected); 1167 }); 1168 });
1169 1170 return result; 1171} 1172 1173function projectToCoordinates(service, points, wkid) { 1174 var result = new $.Deferred(); 1175 1176 require(["dojo/Deferred", "esri/tasks/ProjectParameters"], function(Deferred, ProjectParameters) { 1177 if(points.length == 0) { 1178 result.resolve(points); 1179 return; 1180 } 1181 1182 var inSR = points[0].spatialReference; 1183 var outSR = new esri.SpatialReference({ 1184 wkid : wkid 1185 }); 1186 var param = new ProjectParameters(); 1187 param.transformForward = true; 1188 if(inSR.wkid === 2393 && (outSR.wkid === 3067 || outSR.wkid === 102139 )) 1189 { 1190 var transformation = 108229; 1191 param.transformForward = true; 1192 } 1193 else if(outSR.wkid === 2393 && (inSR.wkid === 3067 || inSR.wkid === 102139 )) 1194 { 1195 var transformation = 108229; 1196 param.transformForward = false; 1197 } 1198 1199 param.geometries = points; 1200 param.outSR = outSR; 1201 param.transformation = transformation; 1202 1203 service.project(param) 1204 .then(function(projected) { 1205 result.resolve(projected); 1206 }); 1207 }); 1208 1209 return result; 1210} 1211 1212 1213function getExtentFromPoints(points, spatialReference) { 1214 var xmin, xmax, ymin, ymax; 1215 $.each(points, function(index, point) { 1216 if (index == 0) { 1217 xmin = point.x; 1218 xmax = point.x; 1219 ymin = point.y; 1220 ymax = point.y; 1221 } else { 1222 if (xmin > point.x && point.x > 0) { 1223 xmin = point.x; 1224 } 1225 if (xmax < point.x && point.x > 0) { 1226 xmax = point.x; 1227 } 1228 if (ymin > point.y && point.y > 0) { 1229 ymin = point.y; 1230 } 1231 if (ymax < point.y && point.y > 0) { 1232 ymax = point.y; 1233 } 1234 } 1235 }); 1236 1237 return new esri.geometry.Extent(xmin, ymin, xmax, ymax, spatialReference); 1238} 1239 1240/* 1241 * UI 1242 */ 1243 1244function makeHorizontalButtons(selector) { 1245 selector.children(".dhxform_block").hide(); 1246 var header = $('<button class="header dhxform_obj_dhx_terrace dhxform_block">Klikkaa tästä tehdäksesi muutoksia palveluun</button>').prependTo(selector); 1247 1248 header.on('click', function(e) { 1249 var content = $(this).siblings('div.dhxform_block'); 1250 if(!content.is(':visible')) { 1251 content.show(); 1252 } else { 1253 content.hide(); 1254 } 1255 }); 1256} 1257 1258function getTemplate(jquerySelector) { 1259 return jquerySelector.html().replace(/\r\n/g, "").replace(/\n/g, "").replace(/\t/g, ""); 1260} 1261 1262/* 1263 * Dhtmlx grid templates 1264 */ 1265function getImageStyle(obj) { 1266 if (window._isIE) { 1267 return "background-image: none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.img + "',sizingMethod='crop');"; 1268 } else { 1269 return "background-image:url(" + obj.img + ");"; 1270 } 1271} 1272 1273function getImageElement(obj) { 1274 return '<img src="' + obj.img + '" alt="">'; 1275} 1276 1277var __originalValidationError = undefined; 1278function showGlobalValidationError(validation, message) { 1279 var $error = $('.global-validation-error'); 1280 1281 if(!__originalValidationError) { 1282 __originalValidationError = $error.html(); 1283 } 1284 1285 if(message) { 1286 $error.html(message); 1287 } else { 1288 $error.html(__originalValidationError); 1289 } 1290 1291 if(validation) 1292 $error.hide(); 1293 else 1294 $error.show(); 1295} 1296 1297function checkIfSpecialValidationError(form) { 1298 var errors = $(form.cont).find(".validate_error"); 1299 if(errors.length == 0) 1300 return null; 1301 1302 var value = form.getItemValue(errors[0]._idd); 1303 if (value != null && value != "") 1304 { 1305 return 'Kentissä on virheellistä sisältöä'; 1306 } 1307 1308}
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.