diff --git a/.idea/simple-ads-manager.iml b/.idea/simple-ads-manager.iml index d7dc8c4..aaf65e3 100644 --- a/.idea/simple-ads-manager.iml +++ b/.idea/simple-ads-manager.iml @@ -1,13 +1,19 @@ - - - - + + + + + + + + + + diff --git a/.idea/webResources.xml b/.idea/webResources.xml index a9bf725..f6e673a 100644 --- a/.idea/webResources.xml +++ b/.idea/webResources.xml @@ -1,22 +1,3 @@ - - - - - - - - - - - - - - - - - - - - + diff --git a/ad.class.php b/ad.class.php index a891cfe..3dbceee 100644 --- a/ad.class.php +++ b/ad.class.php @@ -147,6 +147,7 @@ class SamAdPlace { public $cid = null; private $clauses; private $force; + public $sql = ''; public function __construct($args = null, $useCodes = false, $crawler = false, $clauses = null, $ajax = false) { global $SAM_Query; @@ -159,7 +160,7 @@ public function __construct($args = null, $useCodes = false, $crawler = false, $ else $this->clauses = $clauses; $this->force = $ajax; - $this->ad = $this->buildAd($this->args, $this->useCodes); + $this->ad = $this->buildAd2($this->args, $this->useCodes); } private function getSettings() { @@ -417,7 +418,7 @@ private function buildAd( $args = null, $useCodes = false ) { $output = ob_get_contents(); ob_end_clean(); } - else $output = self::prepareCodes($ad['ad_code'], $rId); + else self::prepareCodes($ad['ad_code'], $rId); } //if(!$this->crawler && !is_admin()) //$wpdb->query("UPDATE $aTable SET $aTable.ad_hits = $aTable.ad_hits+1, $aTable.ad_weight_hits = $aTable.ad_weight_hits+1 WHERE $aTable.id = {$ad['id']}"); @@ -433,6 +434,204 @@ private function buildAd( $args = null, $useCodes = false ) { elseif($useCodes) $output = $place['code_before'].$output.$place['code_after']; return $output; } + + private function buildAd2( $args = null, $useCodes = false ) { + if(is_null($args)) return ''; + if(empty($args['id']) && empty($args['name'])) return ''; + if( is_null($this->clauses) ) return ''; + + $settings = self::getSettings(); + $data = intval($useCodes); + $rId = rand(1111, 9999); + if($settings['adCycle'] == 0) $cycle = 1000; + else $cycle = $settings['adCycle']; + $el = isset($settings['errorlogFS']); + + global $wpdb; + $pTable = $wpdb->prefix . "sam_places"; + $aTable = $wpdb->prefix . "sam_ads"; + $eTable = $wpdb->prefix . "sam_errors"; + + $whereClause = $this->clauses['WC']; + $whereClauseT = $this->clauses['WCT']; + $whereClauseW = $this->clauses['WCW']; + $whereClause2W = $this->clauses['WC2W']; + + if(!empty($args['id'])) $pId = "sp.id = {$args['id']}"; + else $pId = "sp.name = '{$args['name']}'"; + + $output = ""; + + $aSql = " +SELECT + @pid := sp.id AS pid, + 0 AS aid, + sp.name, + sp.patch_source AS code_mode, + @code_before := sp.code_before AS code_before, + @code_after := sp.code_after AS code_after, + @ad_size := IF(sp.place_size = \"custom\", CONCAT(CAST(sp.place_custom_width AS CHAR), \"x\", CAST(sp.place_custom_height AS CHAR)), sp.place_size) AS ad_size, + sp.patch_code AS ad_code, + sp.patch_img AS ad_img, + \"\" AS ad_alt, + 0 AS ad_no, + sp.patch_link AS ad_target, + 0 AS ad_swf, + \"\" AS ad_swf_flashvars, + \"\" AS ad_swf_params, + \"\" AS ad_swf_attributes, + sp.patch_adserver AS ad_adserver, + sp.patch_dfp AS ad_dfp, + 0 AS count_clicks, + 0 AS code_type, + IF((sp.patch_source = 1 AND sp.patch_adserver) OR sp.patch_source = 2, -1, 1) AS ad_cycle, + @aca := IFNULL((SELECT AVG(wsa.ad_weight_hits*10/(wsa.ad_weight*$cycle)) FROM $aTable wsa WHERE wsa.pid = @pid AND wsa.trash IS NOT TRUE), 0) AS aca +FROM $pTable sp +WHERE $pId AND sp.trash IS FALSE +UNION +SELECT + sa.pid, + sa.id AS aid, + sa.name, + sa.code_mode, + @code_before AS code_before, + @code_after AS code_after, + @ad_size AS ad_size, + sa.ad_code, + sa.ad_img, + sa.ad_alt, + sa.ad_no, + sa.ad_target, + sa.ad_swf, + sa.ad_swf_flashvars, + sa.ad_swf_params, + sa.ad_swf_attributes, + 0 AS ad_adserver, + 0 AS ad_dfp, + sa.count_clicks, + sa.code_type, + IF(sa.ad_weight, (sa.ad_weight_hits*10/(sa.ad_weight*$cycle)), 0) AS ad_cycle, + @aca AS aca +FROM $aTable sa +WHERE sa.pid = @pid AND sa.trash IS FALSE AND $whereClause $whereClauseT $whereClauseW +ORDER BY ad_cycle +LIMIT 1;"; + + $ad = $wpdb->get_row($aSql, ARRAY_A); + + if($ad === false) { + if($el) self::errorWrite($eTable, $aTable, $aSql, $ad, $wpdb->last_error); + return ''; + } + + if((integer)$ad['aca'] == 1) { + $wpdb->update($aTable, array('ad_weight_hits' => 0), array('pid' => $ad['pid']), array("%d"), array("%d")); + $ad = $wpdb->get_row($aSql, ARRAY_A); + } + + $this->pid = $ad['pid']; + $this->id = $ad['aid']; + $this->cid = "c{$rId}_{$this->id}_{$this->pid}"; + //$this->sql = $aSql; + + // DFP + if($ad['code_mode'] == 2) { + if(($settings['useDFP'] == 1) && !empty($settings['dfpPub'])) { + $output = ""."\n"; + $output .= ""."\n"; + if($useCodes) + $output = (is_array($useCodes)) ? $useCodes['before'].$output.$useCodes['after'] : $ad['code_before'].$output.$ad['code_after']; + + $output = "
diff --git a/css/sam-admin-edit.css b/css/sam-admin-edit.css index 7b345f0..e36e279 100644 --- a/css/sam-admin-edit.css +++ b/css/sam-admin-edit.css @@ -196,7 +196,7 @@ input.button-primary, input.button-secondary, #users-grid, #ctt-grid, #x-ctt-grid { width: 100%; - height: 197px; + height: 240px; } .sam-section { diff --git a/css/w2ui.css b/css/w2ui.css new file mode 100644 index 0000000..1ef0860 --- /dev/null +++ b/css/w2ui.css @@ -0,0 +1,2753 @@ +/* w2ui 1.4.1 (c) http://w2ui.com, vitmalina@gmail.com */ +@font-face { + font-family: "w2ui-font"; + src: url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAWIAAoAAAAACAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAAA9AAAAEMAAABWQLxMsmNtYXAAAAE4AAAAOgAAAUriGRC2Z2x5ZgAAAXQAAAH9AAACgLu4vTRoZWFkAAADdAAAADAAAAA2AOYXBGhoZWEAAAOkAAAAIAAAACQD8wHHaG10eAAAA8QAAAAWAAAAIA7dAABsb2NhAAAD3AAAABIAAAASAngBuG1heHAAAAPwAAAAHwAAACABFQA2bmFtZQAABBAAAAEtAAACIsTQ/zJwb3N0AAAFQAAAAEgAAABi4/7ZEHicY2BkvMM4gYGVgYPRhTGNgYHBHUp/ZZBkaGFgYGJgZWbACgLSXFMYHD4yfmRnPPD/AIMe4wEGR6AwI0gOANHZC/IAeJxjYGBgZoBgGQZGBhBwAfIYwXwWBg0gzQakGRmYGBg+sv//D1LwkRFE8zNA1QMBIxvDiAcAddwGvgAAeJxFkLFv01AQxu97LrHdRImjpnaS1gnEia3IoqAktkkiEhaEOiCsDkEo8dyBDkytKpYKVWwssKKKAYmBREKMLJSFoRJ/AGJhY0NZGFgSzrUinvR+d++7T+/ePQLRci4IJ3SFCLIjG8CH+ZPwHHdwkkSS2PMXP3DGmUxpoo123lrt5nj8fjyejsc4W0zwNtl8FfHCKV5QnaOhF3IJUrUbkGPYnSGcGH6risBvGQhdVY0iVXXVkhJN1JL6/6xOIqWk4tRlJiVFiSJFSUrsZ+tkoqpEgt/6Hb/wjtZog2gonBx24AyFJUuNwMvha+/CvLi3vq1f785GsxGuTqfWc5O1N/r2+lNrOl38ZHnWpdUMr/CaLKLGZiHl4hI1+zasGB2/Dy9GSzfRbul4qaWPtHSQ0Y7SWpxmgnSc/mblMKNpmcOVEhfj+5d/8BGfqMl9bKuWFYWKaLf8YIAq9IKc5TY7ojNgTTcC7iEjaN4yPdswbM+81t8UimRLojq66YbdWq0bus375t21bwgcw/H6nmNUyhIkR/DsTasXPgx7VtV8oDx6XIxHE8vl8rMAzqlEDZ7QseUBPP6tLOQKDH5HqooKfLvB2gABa1lgflzI60VxsLd3IJj1YRn5/Wx9Syy++LvArn/JzH4e5WE98TCLer5wnBNb9WcrB5PoH084dg8AAAB4nGNgZGBgAOKMsPib8fw2Xxm4mRhA4PzjbBcY/f////1MjIwHgFwOBrA0AFcuDPF4nGNgZGBgPPD/AIMeEwMDw/9/TEwMQBEUwAEAe34EvHicY2JgYGCCYsbJCJpxO4QNABdTAesAAAAAAAAAEgAsAGgAjgC+AP4BQAAAeJxjYGRgYOBg0GJgZgABJiDmAkIGhv9gPgMADYEBTAB4nG2PTW7CMBCFXyBQFaQKtVKl7qwuuqkIPwsWHAD2LNiH4ARQEkeOQeICPUHP0DP0BF32DD1KX8IoixZbHn/z5o1/AAzwBQ/V8HBbx2q0cMPswm3SQNgnPwl30MezcJf6ULiHV8yE+3hAyBM8vzrtHk64hTu8Cbepvwv75A/hDh7xKdyl/i3cwxo/wn28eLN9ZPJhbHK30skxDW2TN7DWttybXE2CcaMtda5t6PRWbc6qPCVT52IVW5OpBas6TY0qrDnoyAU754r5aBSLHkQmwx4RDHL+Oq53hxU0EhyR8sf2Sv2/smaHRclKlStMEGB8xbekL6+9ITONLb0bnBlLnHjnlKqjW3FZ9mSkhfRqviclKxR17UAloh5gV3cVmGPEGf/xB/Ursl9uDmByAAAAeJxtwUEOgCAMBMAu0sI3SdMEIwKh8n8PXp2hQB+mf5kIAQciGIKEzFpNr6Sj7bs76xruMq3r2eJs22XZtPKIW1laiV6rCBDA") format("woff"); + font-weight: normal; + font-style: normal; +} +[class^="w2ui-icon-"]:before, +[class*=" w2ui-icon-"]:before { + font-family: "w2ui-font"; + display: inline-block; + vertical-align: middle; + line-height: 1; + font-weight: normal; + font-style: normal; + speak: none; + text-decoration: inherit; + text-transform: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +/* Icons */ +.w2ui-icon-check:before { + content: "\f101"; +} +.w2ui-icon-columns:before { + content: "\f102"; +} +.w2ui-icon-cross:before { + content: "\f103"; +} +.w2ui-icon-pencil:before { + content: "\f104"; +} +.w2ui-icon-plus:before { + content: "\f105"; +} +.w2ui-icon-reload:before { + content: "\f106"; +} +.w2ui-icon-search:before { + content: "\f107"; +} +/************************************************* +* --- Reset (used for all w2ui wdigetes) +* --- The reset is needed to coexist with other CSS +* --- on the same page (for example bootstrap) +*/ +.w2ui-reset { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; + font-family: Verdana, Arial, sans-serif; + font-size: 11px; +} +.w2ui-reset * { + color: default; + line-height: 100%; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; + margin: 0px; + padding: 0px; +} +.w2ui-reset table { + font-family: Verdana, Arial, sans-serif; + font-size: 11px; + max-width: none; + background-color: transparent; + border-collapse: separate; + border-spacing: 0; +} +.w2ui-reset input, +.w2ui-reset textarea { + width: auto; + /*height: auto;*/ + vertical-align: baseline; + padding: 4px; +} +.w2ui-reset select { + padding: 1px; + height: 23px; +} +.w2ui-centered { + position: absolute; + left: 0px; + right: 0px; + top: 50%; + -webkit-transform: translateY(-50%); + -moz-transform: translateY(-50%); + -ms-transform: translateY(-50%); + -o-transform: translateY(-50%); + transform: translateY(-50%); + max-height: 100%; + margin: 0px; + padding: 0px 10px; + text-align: center; +} +.w2ui-disabled, +.w2ui-readonly { + background-color: #f1f1f1 !important; + color: #777 !important; +} +/************************************************* +* ---- Input Controls ---- +*/ +input:not([type=button]), +select, +textarea { + padding: 4px; + /*border: 1px solid #bbbbbb; + border-radius: 3px;*/ + color: #000000; + background-color: #ffffff; +} +input:not([type=button]):focus, +select:focus, +textarea:focus { + outline-color: #72b2ff; +} +input:not([type=button]):disabled, +select:disabled, +textarea:disabled, +input:not([type=button])[readonly], +select[readonly], +textarea[readonly] { + background-color: #f1f1f1; + color: #777; +} +/* IE9-11 specific classes */ +/* needs doblue :: */ +input::-ms-clear { + display: none; +} +input:-ms-input-placeholder { + color: #aaa !important; +} +select { + padding: 2px; +} +/* On/Off switch */ +input[type="checkbox"].w2ui-toggle { + position: absolute; + opacity: 0; + width: 46px; + height: 22px; + padding: 0px; + margin: 0px; + margin-left: 2px; +} +/* Track */ +input[type="checkbox"].w2ui-toggle + div { + display: inline-block; + width: 46px; + height: 22px; + border: 1px solid #bbb; + border-radius: 30px; + background-color: #eee; + -webkit-transition-duration: .3s; + -webkit-transition-property: background-color, box-shadow; + -moz-transition-duration: .3s; + -moz-transition-property: background-color, box-shadow; + box-shadow: inset 0 0 0 0px rgba(0, 0, 0, 0.4); + margin-left: 2px; +} +input[type="checkbox"].w2ui-toggle:disabled + div { + opacity: 0.3; +} +/* Knob */ +input[type="checkbox"].w2ui-toggle + div > div { + float: left; + width: 22px; + height: 22px; + border-radius: inherit; + background: #f5f5f5; + -webkit-transition-duration: 0.3s; + -webkit-transition-property: transform, background-color, box-shadow; + -moz-transition-duration: 0.3s; + -moz-transition-property: transform, background-color; + box-shadow: 0px 0px 1px #323232, 0 0 0 1px rgba(200, 200, 200, 0.6); + pointer-events: none; + margin-top: -1px; + margin-left: -1px; +} +/* Default Green */ +input[type="checkbox"].w2ui-toggle:checked + div { + border: 1px solid #00a23f; + box-shadow: inset 0 0 0 12px #54B350; +} +input[type="checkbox"].w2ui-toggle:checked + div > div { + -webkit-transform: translate3d(24px, 0, 0); + -moz-transform: translate3d(24px, 0, 0); + background-color: #ffffff; + box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0 0 0 1px #00a23f; +} +/* Blue */ +input[type="checkbox"].w2ui-toggle.blue:checked + div { + border: 1px solid #206FAD; + box-shadow: inset 0 0 0 12px #35A6EB; +} +input[type="checkbox"].w2ui-toggle.blue:checked + div > div { + box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0px 0px 0 1px #206fad; +} +input[type=checkbox].w2ui-toggle:focus { + outline: none; +} +/************************************************* +* ---- Overlay and Bubble ---- +*/ +.w2ui-overlay { + position: absolute; + margin-top: 6px; + margin-left: -17px; + display: none; + z-index: 1300; + color: inherit; + background-color: #fbfbfb; + border: 3px solid #777777; + box-shadow: 0px 2px 10px #999999; + border-radius: 4px; + text-align: left; +} +.w2ui-overlay table td { + color: inherit; +} +.w2ui-overlay:before { + content: ""; + position: absolute; + -webkit-transform: rotate(-45deg); + -moz-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + -o-transform: rotate(-45deg); + transform: rotate(-45deg); + width: 12px; + height: 12px; + border: 3px solid #777777; + border-color: inherit; + background-color: inherit; + border-left: 1px solid transparent; + border-bottom: 1px solid transparent; + border-bottom-left-radius: 50px; + margin: -9px 0 0 30px; +} +.w2ui-overlay:after { + display: none; + content: ""; + position: absolute; + -webkit-transform: rotate(135deg); + -moz-transform: rotate(135deg); + -ms-transform: rotate(135deg); + -o-transform: rotate(135deg); + transform: rotate(135deg); + width: 12px; + height: 12px; + border: 3px solid #777777; + border-color: inherit; + background-color: inherit; + border-left: 1px solid transparent; + border-bottom: 1px solid transparent; + border-bottom-left-radius: 50px; + margin: -7px 0 0 30px; +} +.w2ui-overlay.w2ui-overlay-popup { + z-index: 1700; +} +.w2ui-tag { + position: absolute; + z-index: 1300; + opacity: 0; + -webkit-transition: opacity 0.3s; + -moz-transition: opacity 0.3s; + -ms-transition: opacity 0.3s; + -o-transition: opacity 0.3s; + transition: opacity 0.3s; +} +.w2ui-tag .w2ui-tag-body { + background-color: rgba(60, 60, 60, 0.82); + display: inline-block; + position: absolute; + border-radius: 4px; + padding: 4px 10px; + margin-left: 10px; + margin-top: 0px; + color: #ffffff !important; + box-shadow: 1px 1px 3px #000000; + line-height: 100%; + font-size: 11px; + font-family: Verdana, Arial, sans-serif; +} +.w2ui-tag .w2ui-tag-body:before { + content: ""; + position: absolute; + width: 0; + height: 0; + border-top: 5px solid transparent; + border-right: 5px solid rgba(60, 60, 60, 0.82); + border-bottom: 5px solid transparent; + margin: 2px 0 0 -15px; +} +.w2ui-tag.w2ui-tag-popup { + z-index: 1700; +} +/* +* Drop down menu +*/ +.w2ui-overlay table.w2ui-drop-menu { + width: 100%; + color: #000000; + background-color: #ffffff; + padding: 5px 0px; + cursor: default; +} +.w2ui-overlay table.w2ui-drop-menu td { + white-space: nowrap; +} +.w2ui-overlay table.w2ui-drop-menu .w2ui-item-even { + color: inherit; + background-color: #ffffff; +} +.w2ui-overlay table.w2ui-drop-menu .w2ui-item-odd { + color: inherit; + background-color: #f3f6fa; +} +.w2ui-overlay table.w2ui-drop-menu .w2ui-item-group { + color: #444; + font-weight: bold; + background-color: #ECEDF0; + border-bottom: 1px solid #D3D2D4; +} +.w2ui-overlay table.w2ui-drop-menu td.menu-icon { + padding: 3px 0px 4px 6px; + width: 20px; +} +.w2ui-overlay table.w2ui-drop-menu td.menu-text { + padding: 8px 10px 8px 5px; + width: auto; +} +.w2ui-overlay table.w2ui-drop-menu td.menu-count { + text-align: right; +} +.w2ui-overlay table.w2ui-drop-menu td.menu-count > span { + border: 1px solid #9da4af; + border-radius: 20px; + width: auto; + height: 18px; + padding: 2px 7px; + margin: 3px 5px 0px 5px; + background-color: #e7f0fc; + color: #667274; + box-shadow: 0 0 2px #ffffff; + text-shadow: 1px 1px 1px #e6e6e6; +} +.w2ui-overlay table.w2ui-drop-menu tr:hover { + color: inherit; + background-color: #e6f0ff; +} +.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected { + background-color: #b6d5fb; +} +.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected td { + color: inherit; +} +.w2ui-overlay table.w2ui-drop-menu tr.w2ui-disabled { + opacity: 0.4; + background-color: white !important; +} +.w2ui-overlay table.w2ui-drop-menu .w2ui-icon { + font-size: 14px; + color: #8d99a7; + display: inline-block; + padding-top: 4px; +} +/************************************************* +* ---- Common Classes ---- +*/ +.w2ui-marker { + color: #444; + background-color: rgba(252, 244, 161, 0.48); +} +.w2ui-spinner { + display: inline-block; + background-size: 100%; + background-repeat: no-repeat; + background-image: url(data:image/gif;base64,R0lGODlhgACAAKIAAP///93d3bu7u5mZmQAA/wAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFBQAEACwCAAIAfAB8AAAD/0i63P4wygYqmDjrzbtflvWNZGliYXiubKuloivPLlzReD7al+7/Eh5wSFQIi8hHYBkwHUmD6CD5YTJLz49USuVYraRsZ7vtar7XnQ1Kjpoz6LRHvGlz35O4nEPP2O94EnpNc2sef1OBGIOFMId/inB6jSmPdpGScR19EoiYmZobnBCIiZ95k6KGGp6ni4wvqxilrqBfqo6skLW2YBmjDa28r6Eosp27w8Rov8ekycqoqUHODrTRvXsQwArC2NLF29UM19/LtxO5yJd4Au4CK7DUNxPebG4e7+8n8iv2WmQ66BtoYpo/dvfacBjIkITBE9DGlMvAsOIIZjIUAixliv9ixYZVtLUos5GjwI8gzc3iCGghypQqrbFsme8lwZgLZtIcYfNmTJ34WPTUZw5oRxdD9w0z6iOpO15MgTh1BTTJUKos39jE+o/KS64IFVmsFfYT0aU7capdy7at27dw48qdS7eu3bt480I02vUbX2F/JxYNDImw4GiGE/P9qbhxVpWOI/eFKtlNZbWXuzlmG1mv58+gQ4seTbq06dOoU6vGQZJy0FNlMcV+czhQ7SQmYd8eMhPs5BxVdfcGEtV3buDBXQ+fURxx8oM6MT9P+Fh6dOrH2zavc13u9JXVJb520Vp8dvC76wXMuN5Sepm/1WtkEZHDefnzR9Qvsd9+/wi8+en3X0ntYVcSdAE+UN4zs7ln24CaLagghIxBaGF8kFGoIYV+Ybghh841GIyI5ICIFoklJsigihmimJOLEbLYIYwxSgigiZ+8l2KB+Ml4oo/w8dijjcrouCORKwIpnJIjMnkkksalNeR4fuBIm5UEYImhIlsGCeWNNJphpJdSTlkml1jWeOY6TnaRpppUctcmFW9mGSaZceYopH9zkjnjUe59iR5pdapWaGqHopboaYua1qije67GJ6CuJAAAIfkEBQUABAAsCgACAFcAMAAAA/9Iutz+ML5Ag7w46z0r5WAoSp43nihXVmnrdusrv+s332dt4Tyo9yOBUJD6oQBIQGs4RBlHySSKyczVTtHoidocPUNZaZAr9F5FYbGI3PWdQWn1mi36buLKFJvojsHjLnshdhl4L4IqbxqGh4gahBJ4eY1kiX6LgDN7fBmQEJI4jhieD4yhdJ2KkZk8oiSqEaatqBekDLKztBG2CqBACq4wJRi4PZu1sA2+v8C6EJexrBAD1AOBzsLE0g/V1UvYR9sN3eR6lTLi4+TlY1wz6Qzr8u1t6FkY8vNzZTxaGfn6mAkEGFDgL4LrDDJDyE4hEIbdHB6ESE1iD4oVLfLAqPETIsOODwmCDJlv5MSGJklaS6khAQAh+QQFBQAEACwfAAIAVwAwAAAD/0i63P5LSAGrvTjrNuf+YKh1nWieIumhbFupkivPBEzR+GnnfLj3ooFwwPqdAshAazhEGUXJJIrJ1MGOUamJ2jQ9QVltkCv0XqFh5IncBX01afGYnDqD40u2z76JK/N0bnxweC5sRB9vF34zh4gjg4uMjXobihWTlJUZlw9+fzSHlpGYhTminKSepqebF50NmTyor6qxrLO0L7YLn0ALuhCwCrJAjrUqkrjGrsIkGMW/BMEPJcphLgDaABjUKNEh29vdgTLLIOLpF80s5xrp8ORVONgi8PcZ8zlRJvf40tL8/QPYQ+BAgjgMxkPIQ6E6hgkdjoNIQ+JEijMsasNY0RQix4gKP+YIKXKkwJIFF6JMudFEAgAh+QQFBQAEACw8AAIAQgBCAAAD/kg0PPowykmrna3dzXvNmSeOFqiRaGoyaTuujitv8Gx/661HtSv8gt2jlwIChYtc0XjcEUnMpu4pikpv1I71astytkGh9wJGJk3QrXlcKa+VWjeSPZHP4Rtw+I2OW81DeBZ2fCB+UYCBfWRqiQp0CnqOj4J1jZOQkpOUIYx/m4oxg5cuAaYBO4Qop6c6pKusrDevIrG2rkwptrupXB67vKAbwMHCFcTFxhLIt8oUzLHOE9Cy0hHUrdbX2KjaENzey9Dh08jkz8Tnx83q66bt8PHy8/T19vf4+fr6AP3+/wADAjQmsKDBf6AOKjS4aaHDgZMeSgTQcKLDhBYPEswoA1BBAgAh+QQFBQAEACxOAAoAMABXAAAD7Ei6vPOjyUkrhdDqfXHm4OZ9YSmNpKmiqVqykbuysgvX5o2HcLxzup8oKLQQix0UcqhcVo5ORi+aHFEn02sDeuWqBGCBkbYLh5/NmnldxajX7LbPBK+PH7K6narfO/t+SIBwfINmUYaHf4lghYyOhlqJWgqDlAuAlwyBmpVnnaChoqOkpaanqKmqKgGtrq+wsbA1srW2ry63urasu764Jr/CAb3Du7nGt7TJsqvOz9DR0tPU1TIA2ACl2dyi3N/aneDf4uPklObj6OngWuzt7u/d8fLY9PXr9eFX+vv8+PnYlUsXiqC3c6PmUUgAACH5BAUFAAQALE4AHwAwAFcAAAPpSLrc/m7IAau9bU7MO9GgJ0ZgOI5leoqpumKt+1axPJO1dtO5vuM9yi8TlAyBvSMxqES2mo8cFFKb8kzWqzDL7Xq/4LB4TC6bz1yBes1uu9uzt3zOXtHv8xN+Dx/x/wJ6gHt2g3Rxhm9oi4yNjo+QkZKTCgGWAWaXmmOanZhgnp2goaJdpKGmp55cqqusrZuvsJays6mzn1m4uRAAvgAvuBW/v8GwvcTFxqfIycA3zA/OytCl0tPPO7HD2GLYvt7dYd/ZX99j5+Pi6tPh6+bvXuTuzujxXens9fr7YPn+7egRI9PPHrgpCQAAIfkEBQUABAAsPAA8AEIAQgAAA/lIutz+UI1Jq7026h2x/xUncmD5jehjrlnqSmz8vrE8u7V5z/m5/8CgcEgsGo/IpHLJbDqf0Kh0ShBYBdTXdZsdbb/Yrgb8FUfIYLMDTVYz2G13FV6Wz+lX+x0fdvPzdn9WeoJGAYcBN39EiIiKeEONjTt0kZKHQGyWl4mZdREAoQAcnJhBXBqioqSlT6qqG6WmTK+rsa1NtaGsuEu6o7yXubojsrTEIsa+yMm9SL8osp3PzM2cStDRykfZ2tfUtS/bRd3ewtzV5pLo4eLjQuUp70Hx8t9E9eqO5Oku5/ztdkxi90qPg3x2EMpR6IahGocPCxp8AGtigwQAIfkEBQUABAAsHwBOAFcAMAAAA/9Iutz+MMo36pg4682J/V0ojs1nXmSqSqe5vrDXunEdzq2ta3i+/5DeCUh0CGnF5BGULC4tTeUTFQVONYAs4CfoCkZPjFar83rBx8l4XDObSUL1Ott2d1U4yZwcs5/xSBB7dBMBhgEYfncrTBGDW4WHhomKUY+QEZKSE4qLRY8YmoeUfkmXoaKInJ2fgxmpqqulQKCvqRqsP7WooriVO7u8mhu5NacasMTFMMHCm8qzzM2RvdDRK9PUwxzLKdnaz9y/Kt8SyR3dIuXmtyHpHMcd5+jvWK4i8/TXHff47SLjQvQLkU+fG29rUhQ06IkEG4X/Rryp4mwUxSgLL/7IqFETB8eONT6ChCFy5ItqJomES6kgAQAh+QQFBQAEACwKAE4AVwAwAAAD/0i63A4QuEmrvTi3yLX/4MeNUmieITmibEuppCu3sDrfYG3jPKbHveDktxIaF8TOcZmMLI9NyBPanFKJp4A2IBx4B5lkdqvtfb8+HYpMxp3Pl1qLvXW/vWkli16/3dFxTi58ZRcChwIYf3hWBIRchoiHiotWj5AVkpIXi4xLjxiaiJR/T5ehoomcnZ+EGamqq6VGoK+pGqxCtaiiuJVBu7yaHrk4pxqwxMUzwcKbyrPMzZG90NGDrh/JH8t72dq3IN1jfCHb3L/e5ebh4ukmxyDn6O8g08jt7tf26ybz+m/W9GNXzUQ9fm1Q/APoSWAhhfkMAmpEbRhFKwsvCsmosRIHx444PoKcIXKkjIImjTzjkQAAIfkEBQUABAAsAgA8AEIAQgAAA/VIBNz+8KlJq72Yxs1d/uDVjVxogmQqnaylvkArT7A63/V47/m2/8CgcEgsGo/IpHLJbDqf0Kh0Sj0FroGqDMvVmrjgrDcTBo8v5fCZki6vCW33Oq4+0832O/at3+f7fICBdzsChgJGeoWHhkV0P4yMRG1BkYeOeECWl5hXQ5uNIAOjA1KgiKKko1CnqBmqqk+nIbCkTq20taVNs7m1vKAnurtLvb6wTMbHsUq4wrrFwSzDzcrLtknW16tI2tvERt6pv0fi48jh5h/U6Zs77EXSN/BE8jP09ZFA+PmhP/xvJgAMSGBgQINvEK5ReIZhQ3QEMTBLAAAh+QQFBQAEACwCAB8AMABXAAAD50i6DA4syklre87qTbHn4OaNYSmNqKmiqVqyrcvBsazRpH3jmC7yD98OCBF2iEXjBKmsAJsWHDQKmw571l8my+16v+CweEwum8+hgHrNbrvbtrd8znbR73MVfg838f8BeoB7doN0cYZvaIuMjY6PkJGSk2gClgJml5pjmp2YYJ6dX6GeXaShWaeoVqqlU62ir7CXqbOWrLafsrNctjIDwAMWvC7BwRWtNsbGFKc+y8fNsTrQ0dK3QtXAYtrCYd3eYN3c49/a5NVj5eLn5u3s6e7x8NDo9fbL+Mzy9/T5+tvUzdN3Zp+GBAAh+QQJBQAEACwCAAIAfAB8AAAD/0i63P4wykmrvTjrzbv/YCiOZGmeaKqubOu+cCzPdArcQK2TOL7/nl4PSMwIfcUk5YhUOh3M5nNKiOaoWCuWqt1Ou16l9RpOgsvEMdocXbOZ7nQ7DjzTaeq7zq6P5fszfIASAYUBIYKDDoaGIImKC4ySH3OQEJKYHZWWi5iZG0ecEZ6eHEOio6SfqCaqpaytrpOwJLKztCO2jLi1uoW8Ir6/wCHCxMG2x7muysukzb230M6H09bX2Nna29zd3t/g4cAC5OXm5+jn3Ons7eba7vHt2fL16tj2+QL0+vXw/e7WAUwnrqDBgwgTKlzIsKHDh2gGSBwAccHEixAvaqTYcFCjRoYeNyoM6REhyZIHT4o0qPIjy5YTTcKUmHImx5cwE85cmJPnSYckK66sSAAj0aNIkypdyrSp06dQo0qdSrWq1atYs2rdyrWr169gwxZJAAA7); +} +/* common icons */ +.w2ui-icon { + background-repeat: no-repeat; + height: 16px; + width: 16px; + overflow: hidden; + margin: 2px 2px; + display: inline-block; +} +.w2ui-icon.icon-search, +.w2ui-icon.icon-search-down { + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAgCAYAAAB+ZAqzAAACuElEQVRYw9WXSWhTQRjHR0UKLqhFaV0OUih68GAOWjyJKypCpAoV8aIiioIICiKiB1GMtE3MYmry2moXDz1UDx7sUXHBhQpSaRVxrYpWcMO9avx/8AJh/CbznHkxdeB3Cd/8589kvuUJkWcdjCTHghUgAi6DJ+AVeAqugSQIggniXywcNBJsB70g44EHYBcYXUhTM8EFj4ZkboKqQpiqAv2GprK8o7/f75t6pjn0M3gNPmri3vtycxAZA64qDvkJ2kENqAQTQQWoBg74qth3B4y3NbZDIX4fzNfsnQtuK/YfsjFVCh4pMq3Co0Y5uMVoUGkpy8aFT5xaeSzVEo45bXdBt4LeaLq1k0RXMYJfdDfFmAuAD4zWlty4UNyZEkm19MUb2zMw8Sfp1u+IWSrcIimLnTG8/SijdU6OO5poDESdtgHZVBzUHm/amhW7zoitMTS2mNHqASPk2FDCCcLMYK6p+obmulyxfiYLA4bGKFvfSnrUvkq5+Lpk8z4yRH8r3l/X4WiqJFfspSQ0CGYZGpsMnkt6L+h31Z76hpMdeOwPQ7H0NFnssST0C8wxNDaDKb6kP06150gsHahNNlVzYheZd7HJ0BiX4VRGhpmIhRixKyZilM2M1mnTArtIUbU3/qVO0H0GvmQ4CY4C3YopYYlHjXlggNG4R33Ypi2tVtwaPeTdNMkq9pVQZQdvFPs32zbx4aAjzxhDRfIAWAeWg7VgrzsY5ht/zoNJtubKwA3LITGjSKRyW3NTwaUCmKOSMd3WHH0ZJRQZZkOP1zFKZ3CB++4+aQ6kEeksWAb2a2L7qDv49S1Q6T72MOgEXa6RGFhP3wpS/B6NOWpRs0UxFg7eqTFHjX1hscxtAz/ymEuIYi0cvgF8Y0w5Ro3dZ3M1boJkTaXEUFlug6fsdsRQWzTj0cey+N/Xb2sj5lTh2M6OAAAAAElFTkSuQmCC) no-repeat center !important; + background-size: 14px 12px !important; + opacity: 0.9; +} +.w2ui-icon.icon-folder { + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGrSURBVDjLxZO7ihRBFIa/6u0ZW7GHBUV0UQQTZzd3QdhMQxOfwMRXEANBMNQX0MzAzFAwEzHwARbNFDdwEd31Mj3X7a6uOr9BtzNjYjKBJ6nicP7v3KqcJFaxhBVtZUAK8OHlld2st7Xl3DJPVONP+zEUV4HqL5UDYHr5xvuQAjgl/Qs7TzvOOVAjxjlC+ePSwe6DfbVegLVuT4r14eTr6zvA8xSAoBLzx6pvj4l+DZIezuVkG9fY2H7YRQIMZIBwycmzH1/s3F8AapfIPNF3kQk7+kw9PWBy+IZOdg5Ug3mkAATy/t0usovzGeCUWTjCz0B+Sj0ekfdvkZ3abBv+U4GaCtJ1iEm6ANQJ6fEzrG/engcKw/wXQvEKxSEKQxRGKE7Izt+DSiwBJMUSm71rguMYhQKrBygOIRStf4TiFFRBvbRGKiQLWP29yRSHKBTtfdBmHs0BUpgvtgF4yRFR+NUKi0XZcYjCeCG2smkzLAHkbRBmP0/Uk26O5YnUActBp1GsAI+S5nRJJJal5K1aAMrq0d6Tm9uI6zjyf75dAe6tx/SsWeD//o2/Ab6IH3/h25pOAAAAAElFTkSuQmCC) no-repeat center !important; +} +.w2ui-icon.icon-page { + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAINSURBVBgZBcG/r55zGAfg6/4+z3va01NHlYgzEfE7MdCIGISFgS4Gk8ViYyM2Mdlsko4GSf8Do0FLRCIkghhYJA3aVBtEz3nP89wf11VJvPDepdd390+8Nso5nESBQoq0pfvXm9fzWf19453LF85vASqJlz748vInb517dIw6EyYBIIG49u+xi9/c9MdvR//99MPPZ7+4cP4IZhhTPbwzT2d+vGoaVRRp1rRliVvHq+cfvM3TD82+7mun0o/ceO7NT+/4/KOXjwZU1ekk0840bAZzMQ2mooqh0A72d5x/6sB9D5zYnff3PoYBoWBgFKPKqDKqjCpjKr//dcu9p489dra88cydps30KswACfNEKanSaxhlntjJ8Mv12Paie+vZ+0+oeSwwQ0Iw1xAR1CiFNJkGO4wu3ZMY1AAzBI0qSgmCNJsJUEOtJSMaCTBDLyQ0CknAGOgyTyFFiLI2awMzdEcSQgSAAKVUmAeNkxvWJWCGtVlDmgYQ0GFtgg4pNtOwbBcwQy/Rife/2yrRRVI0qYCEBly8Z+P4qMEMy7JaVw72N568e+iwhrXoECQkfH91kY7jwwXMsBx1L93ZruqrK6uuiAIdSnTIKKPLPFcvay8ww/Hh+ufeznTXu49v95IMoQG3784gYXdTqvRmqn/Wpa/ADFX58MW3L71SVU9ETgEIQQQIOOzub+fhIvwPRDgeVjWDahIAAAAASUVORK5CYII=) no-repeat center !important; +} +/************************************************* +* ---- Locking portion of the screen (in grid, form, layout) +*/ +.w2ui-lock { + display: none; + position: absolute; + z-index: 1400; + top: 0px; + left: 0px; + width: 100%; + height: 100%; + opacity: 0.15; + filter: alpha(opacity=15); + background-color: #333333; +} +.w2ui-lock-msg { + display: none; + position: absolute; + z-index: 1400; + top: 45%; + left: 50%; + -webkit-transform: translateX(-50%) translateY(-50%); + -moz-transform: translateX(-50%) translateY(-50%); + -ms-transform: translateX(-50%) translateY(-50%); + -o-transform: translateX(-50%) translateY(-50%); + transform: translateX(-50%) translateY(-50%); + width: 200px; + height: 80px; + padding: 30px 8px; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + font-size: 13px; + font-family: Verdana, Arial, sans-serif; + opacity: 0.8; + filter: alpha(opacity=80); + background-color: #555555; + color: #ffffff; + text-align: center; + border-radius: 5px; + border: 2px solid #444444; +} +.w2ui-lock-msg .w2ui-spinner { + display: inline-block; + width: 24px; + height: 24px; + margin: -3px 8px -7px -10px; +} +button.btn { + display: inline-block; + border-radius: 4px; + margin: 0px 5px; + padding: 7px 12px 6px 12px !important; + color: #666; + font-size: 12px !important; + border: 1px solid #B6B6B6; + background-image: -webkit-linear-gradient(#ffffff 0%, #e7e7e7 100%); + background-image: -moz-linear-gradient(#ffffff 0%, #e7e7e7 100%); + background-image: -ms-linear-gradient(#ffffff 0%, #e7e7e7 100%); + background-image: -o-linear-gradient(#ffffff 0%, #e7e7e7 100%); + background-image: linear-gradient(#ffffff 0%, #e7e7e7 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffe7e7e7', endColorstr='#ffffffff', GradientType=0); + outline: none; + box-shadow: 0px 1px 0px white; + cursor: default; + min-width: 75px; + line-height: 100% !important; + user-select: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); +} +button.btn:hover { + text-decoration: none; + border: 1px solid #bbb; + background-image: -webkit-linear-gradient(#f7f7f7 0%, #dddddd 100%); + background-image: -moz-linear-gradient(#f7f7f7 0%, #dddddd 100%); + background-image: -ms-linear-gradient(#f7f7f7 0%, #dddddd 100%); + background-image: -o-linear-gradient(#f7f7f7 0%, #dddddd 100%); + background-image: linear-gradient(#f7f7f7 0%, #dddddd 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffdddddd', endColorstr='#fff7f7f7', GradientType=0); + color: #333; +} +button.btn:active, +button.btn.clicked { + border: 1px solid #999; + background-image: -webkit-linear-gradient(#cccccc 0%, #cccccc 100%); + background-image: -moz-linear-gradient(#cccccc 0%, #cccccc 100%); + background-image: -ms-linear-gradient(#cccccc 0%, #cccccc 100%); + background-image: -o-linear-gradient(#cccccc 0%, #cccccc 100%); + background-image: linear-gradient(#cccccc 0%, #cccccc 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffcccccc', endColorstr='#ffcccccc', GradientType=0); + text-shadow: 1px 1px 1px #eee; +} +button.btn:disabled { + border: 1px solid #bbb !important; + background: #f7f7f7 !important; + color: #bdbcbc !important; + text-shadow: none !important; +} +button.btn-blue { + color: white; + background-image: -webkit-linear-gradient(#80c0f7 0%, #269df0 100%); + background-image: -moz-linear-gradient(#80c0f7 0%, #269df0 100%); + background-image: -ms-linear-gradient(#80c0f7 0%, #269df0 100%); + background-image: -o-linear-gradient(#80c0f7 0%, #269df0 100%); + background-image: linear-gradient(#80c0f7 0%, #269df0 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff269df0', endColorstr='#ff80c0f7', GradientType=0); + border: 1px solid #538AB7; + text-shadow: 1px 1px 1px #777777; +} +button.btn-blue:hover { + color: white; + background-image: -webkit-linear-gradient(#73b6f0 0%, #2391dd 100%); + background-image: -moz-linear-gradient(#73b6f0 0%, #2391dd 100%); + background-image: -ms-linear-gradient(#73b6f0 0%, #2391dd 100%); + background-image: -o-linear-gradient(#73b6f0 0%, #2391dd 100%); + background-image: linear-gradient(#73b6f0 0%, #2391dd 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff2391dd', endColorstr='#ff73b6f0', GradientType=0); + border: 1px solid #497BA3; + text-shadow: 1px 1px 1px #777777; +} +button.btn-blue:active, +button.btn-blue.clicked { + color: white; + background-image: -webkit-linear-gradient(#1e83c9 0%, #1e83c9 100%); + background-image: -moz-linear-gradient(#1e83c9 0%, #1e83c9 100%); + background-image: -ms-linear-gradient(#1e83c9 0%, #1e83c9 100%); + background-image: -o-linear-gradient(#1e83c9 0%, #1e83c9 100%); + background-image: linear-gradient(#1e83c9 0%, #1e83c9 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff1e83c9', endColorstr='#ff1e83c9', GradientType=0); + border: 1px solid #1268A6; + text-shadow: 1px 1px 1px #777777; +} +button.btn-green { + color: white; + background-image: -webkit-linear-gradient(#81cf81 0%, #52a452 100%); + background-image: -moz-linear-gradient(#81cf81 0%, #52a452 100%); + background-image: -ms-linear-gradient(#81cf81 0%, #52a452 100%); + background-image: -o-linear-gradient(#81cf81 0%, #52a452 100%); + background-image: linear-gradient(#81cf81 0%, #52a452 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff52a452', endColorstr='#ff81cf81', GradientType=0); + border: 1px solid #479247; + text-shadow: 1px 1px 1px #777777; +} +button.btn-green:hover { + color: white; + background-image: -webkit-linear-gradient(#6abe68 0%, #3f8f3d 100%); + background-image: -moz-linear-gradient(#6abe68 0%, #3f8f3d 100%); + background-image: -ms-linear-gradient(#6abe68 0%, #3f8f3d 100%); + background-image: -o-linear-gradient(#6abe68 0%, #3f8f3d 100%); + background-image: linear-gradient(#6abe68 0%, #3f8f3d 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff3f8f3d', endColorstr='#ff6abe68', GradientType=0); + border: 1px solid #479247; + text-shadow: 1px 1px 1px #777777; +} +button.btn-green:active, +button.btn-green.clicked { + color: white; + background-image: -webkit-linear-gradient(#377d36 0%, #377d36 100%); + background-image: -moz-linear-gradient(#377d36 0%, #377d36 100%); + background-image: -ms-linear-gradient(#377d36 0%, #377d36 100%); + background-image: -o-linear-gradient(#377d36 0%, #377d36 100%); + background-image: linear-gradient(#377d36 0%, #377d36 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff377d36', endColorstr='#ff377d36', GradientType=0); + border: 1px solid #555 !important; + text-shadow: 1px 1px 1px #777777; +} +button.btn-orange { + color: white; + background-image: -webkit-linear-gradient(#fcc272 0%, #fb8822 100%); + background-image: -moz-linear-gradient(#fcc272 0%, #fb8822 100%); + background-image: -ms-linear-gradient(#fcc272 0%, #fb8822 100%); + background-image: -o-linear-gradient(#fcc272 0%, #fb8822 100%); + background-image: linear-gradient(#fcc272 0%, #fb8822 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#fffb8822', endColorstr='#fffcc272', GradientType=0); + border: 1px solid #B68B4C; + text-shadow: 1px 1px 1px #777777; +} +button.btn-orange:hover { + color: white; + background-image: -webkit-linear-gradient(#f4ad59 0%, #f1731f 100%); + background-image: -moz-linear-gradient(#f4ad59 0%, #f1731f 100%); + background-image: -ms-linear-gradient(#f4ad59 0%, #f1731f 100%); + background-image: -o-linear-gradient(#f4ad59 0%, #f1731f 100%); + background-image: linear-gradient(#f4ad59 0%, #f1731f 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#fff1731f', endColorstr='#fff4ad59', GradientType=0); + border: 1px solid #B68B4C; + text-shadow: 1px 1px 1px #777777; +} +button.btn-orange:active, +button.btn-orange.clicked { + color: white; + border: 1px solid #666; + background-image: -webkit-linear-gradient(#b98747 0%, #b98747 100%); + background-image: -moz-linear-gradient(#b98747 0%, #b98747 100%); + background-image: -ms-linear-gradient(#b98747 0%, #b98747 100%); + background-image: -o-linear-gradient(#b98747 0%, #b98747 100%); + background-image: linear-gradient(#b98747 0%, #b98747 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffb98747', endColorstr='#ffb98747', GradientType=0); + text-shadow: 1px 1px 1px #777777; +} +button.btn-red { + color: white; + background-image: -webkit-linear-gradient(#ff6e70 0%, #c72d2d 100%); + background-image: -moz-linear-gradient(#ff6e70 0%, #c72d2d 100%); + background-image: -ms-linear-gradient(#ff6e70 0%, #c72d2d 100%); + background-image: -o-linear-gradient(#ff6e70 0%, #c72d2d 100%); + background-image: linear-gradient(#ff6e70 0%, #c72d2d 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffc72d2d', endColorstr='#ffff6e70', GradientType=0); + border: 1px solid #BB3C3E; + text-shadow: 1px 1px 1px #777777; +} +button.btn-red:hover { + color: white; + background-image: -webkit-linear-gradient(#ee696c 0%, #ae2527 100%); + background-image: -moz-linear-gradient(#ee696c 0%, #ae2527 100%); + background-image: -ms-linear-gradient(#ee696c 0%, #ae2527 100%); + background-image: -o-linear-gradient(#ee696c 0%, #ae2527 100%); + background-image: linear-gradient(#ee696c 0%, #ae2527 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffae2527', endColorstr='#ffee696c', GradientType=0); + border: 1px solid #BB3C3E; + text-shadow: 1px 1px 1px #777777; +} +button.btn-red:active, +button.btn-red.clicked { + color: white; + border: 1px solid #861C1E; + background-image: -webkit-linear-gradient(#9c2123 0%, #9c2123 100%); + background-image: -moz-linear-gradient(#9c2123 0%, #9c2123 100%); + background-image: -ms-linear-gradient(#9c2123 0%, #9c2123 100%); + background-image: -o-linear-gradient(#9c2123 0%, #9c2123 100%); + background-image: linear-gradient(#9c2123 0%, #9c2123 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff9c2123', endColorstr='#ff9c2123', GradientType=0); + text-shadow: 1px 1px 1px #777777; +} +/************************************************* +* ---- Forms ---- +*/ +.w2ui-form { + position: relative; + color: #000000; + background-color: #f5f6f7; + border: 1px solid #c0c0c0; + border-radius: 3px; + padding: 0px; + overflow: hidden !important; +} +.w2ui-form > div { + position: absolute; + overflow: hidden; +} +.w2ui-form .w2ui-form-header { + position: absolute; + left: 0; + right: 0; + border-bottom: 1px solid #99bbe8 !important; + overflow: hidden; + color: #444444; + font-size: 13px; + text-align: center; + padding: 8px; + background-image: -webkit-linear-gradient(#dae6f3, #c2d5ed); + background-image: -moz-linear-gradient(#dae6f3, #c2d5ed); + background-image: -ms-linear-gradient(#dae6f3, #c2d5ed); + background-image: -o-linear-gradient(#dae6f3, #c2d5ed); + background-image: linear-gradient(#dae6f3, #c2d5ed); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3', endColorstr='#ffc2d5ed', GradientType=0); + border-top-left-radius: 3px; + border-top-right-radius: 3px; +} +.w2ui-form .w2ui-form-toolbar { + position: absolute; + left: 0px; + right: 0px; + margin: 0px; + padding: 6px 3px; + border-bottom: 1px solid #d5d8d8; +} +.w2ui-form .w2ui-form-tabs { + margin: 0px; + padding: 0px; +} +.w2ui-form .w2ui-tabs { + position: absolute; + left: 0; + right: 0; + border-top-left-radius: 3px; + border-top-right-radius: 3px; + padding-top: 5px !important; + background-color: #fafafa; +} +.w2ui-form .w2ui-tabs .w2ui-tab.active { + background-color: #f5f6f7; +} +.w2ui-form .w2ui-page { + position: absolute; + left: 0; + right: 0; + overflow: auto; + padding: 10px; + border-left: 1px solid inherit; + border-right: 1px solid inherit; + background-color: inherit; + border-radius: 3px; +} +.w2ui-form .w2ui-buttons { + position: absolute; + left: 0; + right: 0; + bottom: 0; + text-align: center; + border-top: 1px solid #d5d8d8; + border-bottom: 0px solid #d5d8d8; + background-color: #fafafa; + padding: 15px 0px !important; + border-bottom-left-radius: 3px; + border-bottom-right-radius: 3px; +} +.w2ui-form .w2ui-buttons input[type="button"], +.w2ui-form .w2ui-buttons button { + min-width: 80px; + margin-right: 5px; +} +.w2ui-form input[type=checkbox], +.w2ui-form input[type=radio] { + margin-top: 4px; + margin-bottom: 4px; +} +.w2ui-form input[type=checkbox].w2ui-toggle { + margin: 0px; +} +.w2ui-group-title { + padding: 5px 2px; + color: #8D96A2; + text-shadow: 1px 1px 2px #fdfdfd; + font-size: 120%; +} +.w2ui-group { + background-color: #ebecef; + margin: 5px 0px 10px 0px; + padding: 10px 5px; + border-top: 1px solid #cedcea; + border-bottom: 1px solid #cedcea; +} +.w2ui-field > label { + display: block; + float: left; + margin-top: 7px; + margin-bottom: 3px; + width: 120px; + padding: 0px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + text-align: right; + min-height: 20px; + color: #666; +} +.w2ui-field > div { + /* do not include width */ + margin-bottom: 3px; + margin-left: 128px; + padding: 3px; + min-height: 28px; + float: none; +} +.w2ui-field.w2ui-required > div { + position: relative; +} +.w2ui-field.w2ui-required > div::before { + content: '*'; + position: absolute; + margin-top: 5px; + margin-left: -9px; + color: #ff0000; +} +.w2ui-field.w2ui-span1 > label { + width: 20px; +} +.w2ui-field.w2ui-span1 > div { + margin-left: 28px; +} +.w2ui-field.w2ui-span2 > label { + width: 40px; +} +.w2ui-field.w2ui-span2 > div { + margin-left: 48px; +} +.w2ui-field.w2ui-span3 > label { + width: 60px; +} +.w2ui-field.w2ui-span3 > div { + margin-left: 68px; +} +.w2ui-field.w2ui-span4 > label { + width: 80px; +} +.w2ui-field.w2ui-span4 > div { + margin-left: 88px; +} +.w2ui-field.w2ui-span5 > label { + width: 100px; +} +.w2ui-field.w2ui-span5 > div { + margin-left: 108px; +} +.w2ui-field.w2ui-span6 > label { + width: 120px; +} +.w2ui-field.w2ui-span6 > div { + margin-left: 128px; +} +.w2ui-field.w2ui-span7 > label { + width: 140px; +} +.w2ui-field.w2ui-span7 > div { + margin-left: 148px; +} +.w2ui-field.w2ui-span8 > label { + width: 160px; +} +.w2ui-field.w2ui-span8 > div { + margin-left: 168px; +} +.w2ui-field.w2ui-span9 > label { + width: 180px; +} +.w2ui-field.w2ui-span9 > div { + margin-left: 188px; +} +.w2ui-field.w2ui-span10 > label { + width: 200px; +} +.w2ui-field.w2ui-span10 > div { + margin-left: 208px; +} +.w2ui-error { + border: 1px solid #ffa8a8 !important; + background-color: #fff4eb !important; +} +.w2field { + padding: 3px; + border-radius: 3px; + border: 1px solid silver; +} +.w2ui-field-helper { + position: absolute; + display: inline-block; + line-height: 100%; + /* pointer-events: none; - do not use as IE does not support it */ + user-select: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; +} +.w2ui-field-helper .w2ui-field-up { + position: absolute; + top: 0px; + padding: 2px 3px; +} +.w2ui-field-helper .w2ui-field-down { + position: absolute; + bottom: 0px; + padding: 2px 3px; +} +.w2ui-field-helper .arrow-up:hover { + border-bottom-color: #81C6FF; +} +.w2ui-field-helper .arrow-down:hover { + border-top-color: #81C6FF; +} +/* +* ARROWS +*/ +.arrow-up { + background: none; + width: 0; + height: 0; + border-left: 4px solid transparent; + /* left arrow slant */ + border-right: 4px solid transparent; + /* right arrow slant */ + border-bottom: 5px solid #777; + /* bottom, add background color here */ + font-size: 0; + line-height: 0; +} +.arrow-down { + background: none; + width: 0; + height: 0; + border-left: 4px solid transparent; + border-right: 4px solid transparent; + border-top: 5px solid #777; + font-size: 0; + line-height: 0; +} +.arrow-left { + background: none; + width: 0; + height: 0; + border-bottom: 4px solid transparent; + /* left arrow slant */ + border-top: 4px solid transparent; + /* right arrow slant */ + border-right: 5px solid #777; + /* bottom, add background color here */ + font-size: 0; + line-height: 0; +} +.arrow-right { + background: none; + width: 0; + height: 0; + border-bottom: 4px solid transparent; + /* left arrow slant */ + border-top: 4px solid transparent; + /* right arrow slant */ + border-left: 5px solid #777; + /* bottom, add background color here */ + font-size: 0; + line-height: 0; +} +/* +* COLOR overlay +*/ +.w2ui-color { + padding: 5px; + padding-top: 8px; + background-color: white; + border-radius: 3px; +} +.w2ui-color > table { + table-layout: fixed; + width: 160px; +} +.w2ui-color > table td { + width: 20px; + height: 20px; + text-align: center; +} +.w2ui-color > table td div { + cursor: pointer; + display: inline-block; + width: 16px; + height: 17px; + padding: 1px 4px; + border: 1px solid transparent; + color: white; + text-shadow: 0px 0px 2px #000; +} +.w2ui-color > table td div:hover { + outline: 1px solid #666; + border: 1px solid #fff; +} +/* +* DATE overlay +*/ +.w2ui-calendar { + margin: 0px; + padding: 1px; + line-height: 108%; +} +.w2ui-calendar .w2ui-calendar-title { + margin: 0px -1px; + padding: 7px 2px; + background-image: -webkit-linear-gradient(#f6f6f6, #d9d9d9); + background-image: -moz-linear-gradient(#f6f6f6, #d9d9d9); + background-image: -ms-linear-gradient(#f6f6f6, #d9d9d9); + background-image: -o-linear-gradient(#f6f6f6, #d9d9d9); + background-image: linear-gradient(#f6f6f6, #d9d9d9); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#fff6f6f6', endColorstr='#ffd9d9d9', GradientType=0); + border-bottom: 1px solid #bbbbbb; + color: #555555; + text-align: center; + text-shadow: 1px 1px 1px #eeeeee; + cursor: pointer; +} +.w2ui-calendar .w2ui-calendar-jump { + position: absolute; + top: 27px; + left: 0px; + right: 0px; + bottom: 0px; + background-color: #FaFaFa; +} +.w2ui-calendar .w2ui-calendar-jump > :first-child { + position: absolute; + top: 0px; + left: 0px; + bottom: 0px; + width: 110px; + overflow: hidden; + padding-top: 5px; + border-right: 1px solid #c0c0c0; +} +.w2ui-calendar .w2ui-calendar-jump > :last-child { + position: absolute; + top: 0px; + right: 0px; + bottom: 0px; + width: 88px; + overflow-x: hidden; + overflow-y: auto; + padding-top: 5px; + text-align: center; +} +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month, +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year { + display: inline-block; + padding: 5px 0px; + text-align: center; + float: left; + margin: 2px; + width: 50px; + cursor: default; + border: 1px solid transparent; + border-radius: 2px; +} +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year { + float: none; + width: 95%; +} +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month:hover, +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year:hover { + border: 1px solid #cccccc; + color: #000000; + background-color: #efefef; +} +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month.selected, +.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year.selected { + border: 1px solid #cccccc; + color: #000000; + background-color: #dadada; +} +.w2ui-calendar .w2ui-calendar-previous, +.w2ui-calendar .w2ui-calendar-next { + width: 24px; + height: 20px; + color: #666666; + border: 1px solid transparent; + border-radius: 3px; + padding: 2px 3px 1px 2px; + margin: -4px 0px 0px 0px; + cursor: default; +} +.w2ui-calendar .w2ui-calendar-previous:hover, +.w2ui-calendar .w2ui-calendar-next:hover { + border: 1px solid #c0c0c0; + background-color: #efefef; +} +.w2ui-calendar .w2ui-calendar-previous > div, +.w2ui-calendar .w2ui-calendar-next > div { + position: absolute; + border-left: 4px solid #888; + border-top: 4px solid #888; + border-right: 4px solid transparent; + border-bottom: 4px solid transparent; + width: 0px; + height: 0px; + padding: 0px; + margin: 3px 0px 0px 0px; +} +.w2ui-calendar .w2ui-calendar-previous { + float: left; +} +.w2ui-calendar .w2ui-calendar-previous > div { + -webkit-transform: rotate(-45deg); + -moz-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + -o-transform: rotate(-45deg); + transform: rotate(-45deg); + margin-left: 6px; +} +.w2ui-calendar .w2ui-calendar-next { + float: right; +} +.w2ui-calendar .w2ui-calendar-next > div { + -webkit-transform: rotate(135deg); + -moz-transform: rotate(135deg); + -ms-transform: rotate(135deg); + -o-transform: rotate(135deg); + transform: rotate(135deg); + margin-left: 2px; + margin-right: 2px; +} +.w2ui-calendar table.w2ui-calendar-days { + padding: 0px; +} +.w2ui-calendar table.w2ui-calendar-days td { + border: 1px solid #ffffff; + color: #000000; + background-color: #f9f9f9; + padding: 6px; + cursor: default; + text-align: right; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday, +.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday { + border: 1px solid #ffffff; + color: #c8493b; + background-color: #f9f9f9; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday:hover, +.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday:hover { + border: 1px solid #cccccc; + color: #000000; + background-color: #e9e9e9; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday.w2ui-blocked, +.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday.w2ui-blocked { + text-decoration: line-through; + border: 1px solid #ffffff; + color: #cccccc; + background-color: #ffffff; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-today { + border: 1px solid #8cb067; + color: #000000; + background-color: #e2f7cd; +} +.w2ui-calendar table.w2ui-calendar-days td:hover { + border: 1px solid #cccccc; + color: #000000; + background-color: #e9e9e9; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-blocked { + text-decoration: line-through; + border: 1px solid #ffffff; + color: #cccccc; + background-color: #ffffff; +} +.w2ui-calendar table.w2ui-calendar-days td.w2ui-day-empty { + border: 1px solid #ffffff; + background-color: #fdfdfd; +} +.w2ui-calendar table.w2ui-calendar-days tr.w2ui-day-title td { + border: 1px solid #ffffff; + color: #808080; + background-color: #ffffff; + text-align: center; + padding: 6px; +} +/* +* Time +*/ +.w2ui-calendar-time { + padding: 5px; + cursor: default; +} +.w2ui-calendar-time td div { + padding: 7px 10px; + text-align: center; + border: 1px solid transparent; + white-space: nowrap; +} +.w2ui-calendar-time td:nth-child(even) { + background-color: #f6f6f6; +} +.w2ui-calendar-time td div:hover { + border: 1px solid #cccccc; + color: #000000; + background-color: #e9e9e9; +} +.w2ui-calendar-time td div.w2ui-blocked { + text-decoration: line-through; + border: 1px solid #ffffff; + color: #cccccc; + background-color: #ffffff; +} +.w2ui-select { + cursor: default; + color: black !important; + background-image: -webkit-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -moz-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -ms-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -o-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); +} +/* +* ENUM items +*/ +.w2ui-list { + color: inherit; + position: absolute; + padding: 0px; + margin: 0px; + min-height: 25px; + overflow: auto; + border: 1px solid #c0c0c0; + border-radius: 3px; + font-size: 6px; + line-height: 100%; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; + background-color: #ffffff; +} +.w2ui-list input[type=text] { + -webkit-box-shadow: none; + -moz-box-shadow: none; + -ms-box-shadow: none; + -o-box-shadow: none; + box-shadow: none; +} +.w2ui-list ul { + list-style-type: none; + background-color: black; + margin: 0px; + padding: 0px; +} +.w2ui-list ul li { + float: left; + margin: 2px 1px 0px 2px; + border-radius: 3px; + width: auto; + padding: 3px 10px 1px 7px; + border: 1px solid #88b0d6; + background-color: #eff3f5; + white-space: nowrap; + cursor: default; + font-family: verdana; + font-size: 11px; + line-height: 100%; + height: 20px; + overflow: hidden; + text-overflow: ellipsis; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-list ul li:hover { + background-color: #d0dbe1; +} +.w2ui-list ul li:last-child { + border-radius: 0px; + border: 1px solid transparent; + background-color: transparent; +} +.w2ui-list ul li:last-child input { + padding: 1px; + padding-top: 0px; + margin: 0px; + border: 0px; + outline: none; + height: auto; + line-height: 100%; + font-size: inherit; + font-family: inherit; + background-color: transparent; +} +.w2ui-list ul li .w2ui-list-remove { + float: right; + width: 15px; + height: 14px; + margin: -1px -9px 0px 3px; + border-radius: 15px; +} +.w2ui-list ul li .w2ui-list-remove:hover { + background-color: #D77F7F; + color: white; +} +.w2ui-list ul li .w2ui-list-remove:before { + position: relative; + top: 0px; + padding: 0px; + margin: 0px; + left: 5px; + color: inherit; + opacity: 0.7; + text-shadow: inherit; + font-size: inherit; + font-variant: small-caps; + content: 'x'; + line-height: 100%; +} +.w2ui-list ul li > span.file-size { + pointer-events: none; + color: #777; +} +.w2ui-list .w2ui-enum-placeholder { + display: inline; + position: absolute; + pointer-events: none; + color: #999; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-list.w2ui-file-dragover { + background-color: #E4FFDA; + border: 1px solid #93E07D; +} +/************************************************* +* ---- Layout ---- +*/ +.w2ui-layout { + overflow: hidden !important; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-layout * { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-layout > div { + position: absolute; + overflow: hidden; + border: 0px; + margin: 0px; + padding: 0px; + outline: 0px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-layout > div .w2ui-panel { + display: none; + position: absolute; + z-index: 120; +} +.w2ui-layout > div .w2ui-panel .w2ui-panel-title { + padding: 5px; + background-image: -webkit-linear-gradient(#dae6f3, #c2d5ed); + background-image: -moz-linear-gradient(#dae6f3, #c2d5ed); + background-image: -ms-linear-gradient(#dae6f3, #c2d5ed); + background-image: -o-linear-gradient(#dae6f3, #c2d5ed); + background-image: linear-gradient(#dae6f3, #c2d5ed); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3', endColorstr='#ffc2d5ed', GradientType=0); + border: 1px solid #b9cee9; + border-bottom: 1px solid #99bbe8; +} +.w2ui-layout > div .w2ui-panel .w2ui-panel-tabs { + position: absolute; + left: 0px; + top: 0px; + right: 0px; + z-index: 2; + display: none; + overflow: hidden; + background-color: #fafafa; + padding: 4px 0px; +} +.w2ui-layout > div .w2ui-panel .w2ui-panel-tabs > .w2ui-tab.active { + background-color: #f5f6f7; +} +.w2ui-layout > div .w2ui-panel .w2ui-panel-toolbar { + position: absolute; + left: 0px; + top: 0px; + right: 0px; + z-index: 2; + display: none; + overflow: hidden; + background-color: #fafafa; + border-bottom: 1px solid silver; + padding: 4px; +} +.w2ui-layout > div .w2ui-panel .w2ui-panel-content { + position: absolute; + left: 0px; + top: 0px; + right: 0px; + bottom: 0px; + z-index: 1; + color: inherit; + background-color: #f5f6f7; +} +.w2ui-layout > div .w2ui-resizer { + display: none; + position: absolute; + z-index: 121; + background-color: transparent; +} +.w2ui-layout > div .w2ui-resizer:hover, +.w2ui-layout > div .w2ui-resizer.active { + background-color: #d7e4f2; +} +/************************************************* +* ---- Grid ---- +*/ +.w2ui-grid { + position: relative; + border: 1px solid #c0c0c0; + border-radius: 2px; + overflow: hidden !important; +} +.w2ui-grid > div { + position: absolute; + overflow: hidden; +} +.w2ui-grid .w2ui-grid-header { + position: absolute; + border-bottom: 1px solid #99bbe8 !important; + height: 28px; + overflow: hidden; + color: #444444; + font-size: 13px; + text-align: center; + padding: 7px; + background-image: -webkit-linear-gradient(#dae6f3, #c2d5ed); + background-image: -moz-linear-gradient(#dae6f3, #c2d5ed); + background-image: -ms-linear-gradient(#dae6f3, #c2d5ed); + background-image: -o-linear-gradient(#dae6f3, #c2d5ed); + background-image: linear-gradient(#dae6f3, #c2d5ed); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3', endColorstr='#ffc2d5ed', GradientType=0); + border-top-left-radius: 2px; + border-top-right-radius: 2px; +} +.w2ui-grid .w2ui-grid-toolbar { + position: absolute; + border-bottom: 1px solid #c0c0c0; + background-color: #eaeaea; + height: 38px; + padding: 7px 3px 4px 3px; + margin: 0px; + box-shadow: 0px 1px 2px #dddddd; +} +.w2ui-grid .w2ui-toolbar-search { + width: 160px; + margin-right: 3px; +} +.w2ui-grid .w2ui-toolbar-search .w2ui-search-all { + outline: none !important; + width: 160px; + border-radius: 10px; + line-height: normal; + height: 22px; + border: 1px solid #b9b9b9; + color: #000000; + background-color: #ffffff; + padding: 3px 18px 3px 23px; + margin: 0px; +} +.w2ui-grid .w2ui-toolbar-search .w2ui-search-down { + position: absolute; + margin-top: -7px; + margin-left: 6px; +} +.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear { + position: absolute; + width: 16px; + height: 16px; + margin-top: -8px; + margin-left: -20px; + border-radius: 15px; + cursor: default; +} +.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:hover { + background-color: #D77F7F; + color: white; +} +.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:before { + position: relative; + top: 1px; + left: 5px; + opacity: 0.6; + color: inherit; + text-shadow: inherit; + content: 'x'; + cursor: default; +} +.w2ui-grid .w2ui-grid-body { + position: absolute; + overflow: hidden; + padding: 0px; + background-color: #ffffff; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; +} +.w2ui-grid .w2ui-grid-body input, +.w2ui-grid .w2ui-grid-body select, +.w2ui-grid .w2ui-grid-body textarea { + user-select: text; + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + -o-user-select: text; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-columns { + overflow: hidden; + position: absolute; + left: 0px; + top: 0px; + right: 0px; + box-shadow: 0px 1px 4px #dddddd; + height: auto; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-columns table { + height: auto; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-columns .w2ui-resizer { + position: absolute; + z-index: 1000; + display: block; + background-image: none; + background-color: rgba(0, 0, 0, 0); + /* needed for IE */ + padding: 0px; + margin: 0px; + width: 6px; + height: 12px; + cursor: col-resize; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records { + position: absolute; + left: 0px; + right: 0px; + top: 0px; + bottom: 0px; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd { + color: inherit; + background-color: #ffffff; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover { + color: inherit; + background-color: #e6f0ff; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd.w2ui-empty-record:hover { + background-color: #ffffff; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even { + color: inherit; + background-color: #f3f6fa; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover { + color: inherit; + background-color: #e6f0ff; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even.w2ui-empty-record:hover { + background-color: #f3f6fa; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected, +.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected { + color: #000000 !important; + background-color: #b6d5ff !important; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded { + background-color: #CCDCF0 !important; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1 { + height: 0px; + border-bottom: 1px solid #b2bac0; + background-color: #CCDCF0; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1 > div { + height: 100%; + margin: 0px; + padding: 0px; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2 { + height: 0px; + border-radius: 0px; + border-bottom: 1px solid #b2bac0; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2 > div { + height: 0px; + border: 0px; + transition: height .3s, opacity .3s; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more { + border-top: 1px solid #d6d5d7; + cursor: pointer; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more > div { + text-align: center; + color: #777777; + background-color: rgba(233, 237, 243, 0.5); + padding: 10px 0px 15px 0px; + border-top: 1px solid #ffffff; +} +.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more > div:hover { + color: inherit; + background-color: #e6f0ff; +} +.w2ui-grid .w2ui-grid-body table { + border-spacing: 0px; + border-collapse: collapse; + table-layout: fixed; + width: 1px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head { + margin: 0px; + padding: 0px; + border-right: 1px solid #c5c5c5; + border-bottom: 1px solid #c5c5c5; + color: #000000; + background-image: -webkit-linear-gradient(#f9f9f9, #e4e4e4); + background-image: -moz-linear-gradient(#f9f9f9, #e4e4e4); + background-image: -ms-linear-gradient(#f9f9f9, #e4e4e4); + background-image: -o-linear-gradient(#f9f9f9, #e4e4e4); + background-image: linear-gradient(#f9f9f9, #e4e4e4); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#fff9f9f9', endColorstr='#ffe4e4e4', GradientType=0); +} +.w2ui-grid .w2ui-grid-body table .w2ui-head > div { + padding: 7px 3px; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + position: relative; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head.w2ui-col-intersection { + border-right-color: #72b2ff; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head.w2ui-reorder-cols-head:hover { + cursor: move; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker { + padding: 0; + position: absolute; + height: 100%; + top: 0; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker.left { + left: 0; + margin-left: -5px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker.right { + right: 0; + margin-right: -5px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker .top-marker { + position: absolute; + top: 0; + height: 0; + width: 0; + border-top: 5px solid #72b2ff; + border-left: 5px solid transparent; + border-right: 5px solid transparent; +} +.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker .bottom-marker { + position: absolute; + bottom: 0; + height: 0; + width: 0; + border-bottom: 5px solid #72b2ff; + border-left: 5px solid transparent; + border-right: 5px solid transparent; +} +.w2ui-grid .w2ui-grid-body table td { + border-right: 1px solid #d6d5d7; + border-bottom: 0px solid #d6d5d7; + cursor: default; + overflow: hidden; +} +.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data { + margin: 0px; + padding: 0px; +} +.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data > div { + padding: 3px 3px 3px 3px; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} +.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data > div.flexible-record { + height: auto; + overflow: visible; + white-space: normal; +} +.w2ui-grid .w2ui-grid-body table td:last-child { + border-right: 0px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-number { + width: 34px; + color: #777777; + background-color: rgba(233, 237, 243, 0.5); +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-number div { + padding: 0px 7px 0px 3px; + text-align: right; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-select { + width: 26px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-select div { + padding: 0px 0px; + text-align: center; + overflow: hidden; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-select div input[type=checkbox] { + margin-top: 2px; + position: relative; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-expand { + width: 26px; +} +.w2ui-grid .w2ui-grid-body table .w2ui-col-expand div { + padding: 0px 0px; + text-align: center; + font-weight: bold; +} +.w2ui-grid .w2ui-grid-body div.w2ui-col-header { + height: auto !important; + width: 100%; + overflow: hidden; + padding-right: 10px !important; +} +.w2ui-grid .w2ui-grid-body div.w2ui-col-header > div.w2ui-sort-up { + border: 4px solid transparent; + border-bottom: 5px solid #8D99A7; + margin-top: -2px; + margin-right: -7px; + float: right; +} +.w2ui-grid .w2ui-grid-body div.w2ui-col-header > div.w2ui-sort-down { + border: 4px solid transparent; + border-top: 5px solid #8D99A7; + margin-top: 2px; + margin-right: -7px; + float: right; +} +.w2ui-grid .w2ui-grid-body .w2ui-col-group { + text-align: center; +} +.w2ui-grid .w2ui-changed { + background: url(data:image/gif;base64,R0lGODlhCgAKAJEAALAABf///wAAAAAAACH5BAEAAAIALAAAAAAKAAoAAAIPlI8Hy8mbxIsSUnup3rQAADs=) no-repeat top right; +} +.w2ui-grid .w2ui-editable { + overflow: hidden; + height: 100% !important; + margin: 0px !important; + padding: 0px !important; +} +.w2ui-grid .w2ui-editable input { + border: 0px; + border-radius: 0px; + margin: 0px; + padding: 4px 3px; + width: 100%; + height: 100%; +} +.w2ui-grid .w2ui-editable input.w2ui-select { + outline: none !important; + background: #fff; +} +.w2ui-grid .w2ui-grid-summary { + position: absolute; + box-shadow: 0px -1px 4px #aaaaaa; +} +.w2ui-grid .w2ui-grid-summary table { + color: inherit; +} +.w2ui-grid .w2ui-grid-summary table .w2ui-odd { + background-color: #eef5eb; +} +.w2ui-grid .w2ui-grid-summary table .w2ui-even { + background-color: #f8fff5; +} +.w2ui-grid .w2ui-grid-footer { + position: absolute; + margin: 0px; + padding: 0px; + text-align: center; + height: 24px; + overflow: hidden; + user-select: text; + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + -o-user-select: text; + box-shadow: 0px -1px 4px #eeeeee; + color: #444444; + background-color: #f8f8f8; + border-top: 1px solid #dddddd; + border-bottom-left-radius: 2px; + border-bottom-right-radius: 2px; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-left { + float: left; + padding-top: 5px; + padding-left: 5px; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-right { + float: right; + padding-top: 5px; + padding-right: 5px; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-center { + padding: 2px; + text-align: center; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav { + width: 110px; + margin: 0 auto; + padding: 0px; + text-align: center; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav input[type=text] { + padding: 1px 2px 2px 2px; + border-radius: 3px; + width: 40px; + text-align: center; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn { + display: inline-block; + border-radius: 3px; + cursor: pointer; + font-size: 11px; + line-height: 16px; + padding: 1px 5px; + width: 30px; + height: 18px; + margin-top: -1px; + color: #000000; + background-color: transparent; +} +.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn:hover { + color: #000000; + background-color: #aec8ff; +} +/* SpeadSheet */ +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd, +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even, +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover, +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover { + background-color: inherit; +} +.w2ui-ss .w2ui-grid-records table td { + border-right-width: 1px; + border-bottom: 1px solid #efefef; +} +.w2ui-ss .w2ui-grid-records table tr:first-child td { + border-bottom: 0px; +} +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected, +.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected { + background-color: #EEF4FE !important; +} +.w2ui-ss .w2ui-changed { + background: inherit; +} +.w2ui-ss .w2ui-grid-body .w2ui-selection { + position: absolute; + border: 2px solid #6299DA; + /* #457FC2; */ + pointer-events: none; +} +.w2ui-ss .w2ui-grid-body .w2ui-selection .w2ui-selection-resizer { + cursor: crosshair; + position: absolute; + bottom: 0px; + right: 0px; + width: 6px; + height: 6px; + margin-right: -3px; + margin-bottom: -3px; + background-color: #457FC2; + border: 0.5px solid #fff; + outline: 1px solid white; + pointer-events: auto; +} +.w2ui-overlay .w2ui-select-field { + padding: 8px 5px; + cursor: default; +} +.w2ui-overlay .w2ui-select-field table { + font-size: 11px; + font-family: Verdana, Arial, sans-serif; + border-spacing: 0px; + border-collapse: border-collapse; +} +.w2ui-overlay .w2ui-select-field table tr:hover { + background-color: #b6d5ff; +} +.w2ui-overlay .w2ui-select-field table td:nth-child(1) { + padding: 3px 3px 3px 6px; +} +.w2ui-overlay .w2ui-select-field table td:nth-child(1) input { + margin: 3px 2px 2px 2px; +} +.w2ui-overlay .w2ui-select-field table td:nth-child(2) { + padding: 3px 15px 3px 3px; +} +.w2ui-overlay .w2ui-col-on-off { + padding: 4px 0px; +} +.w2ui-overlay .w2ui-col-on-off table { + border-spacing: 0px; + border-collapse: border-collapse; +} +.w2ui-overlay .w2ui-col-on-off table tr:hover { + background-color: #b6d5ff; +} +.w2ui-overlay .w2ui-col-on-off table td input[type=checkbox] { + margin: 3px 2px 2px 2px; +} +.w2ui-overlay .w2ui-col-on-off table td label { + display: block; + padding: 3px 0px; + padding-right: 10px; +} +.w2ui-overlay .w2ui-col-on-off table td:first-child { + padding: 4px 0px 4px 6px; +} +.w2ui-overlay .w2ui-col-on-off table td:last-child { + padding: 4px 6px 4px 0px; +} +.w2ui-overlay .w2ui-grid-searches { + text-align: left; + padding: 0px; + border-top: 0px; + background-color: #f7f6f0; +} +.w2ui-overlay .w2ui-grid-searches table { + padding: 4px; + padding-top: 12px; + border-collapse: border-collapse; +} +.w2ui-overlay .w2ui-grid-searches table td { + padding: 4px; + /* for IE */ +} +.w2ui-overlay .w2ui-grid-searches table td.close-btn { + width: 20px; + padding-right: 20px; +} +.w2ui-overlay .w2ui-grid-searches table td.close-btn button { + min-width: 24px; + height: 24px; + padding-top: 6px !important; +} +.w2ui-overlay .w2ui-grid-searches table td.caption { + text-align: right; + padding-right: 5px; + border-right: 1px solid #e8e8e3; +} +.w2ui-overlay .w2ui-grid-searches table td.operator { + text-align: left; + padding: 0px 10px; + padding-right: 5px; + border-right: 1px solid #e8e8e3; +} +.w2ui-overlay .w2ui-grid-searches table td.operator select { + width: 100%; + color: black; + padding: 0px 15px 0px 5px; + -webkit-appearance: none; + -moz-appearance: none; + -ms-appearance: none; + -o-appearance: none; + background-image: -webkit-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -moz-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -ms-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: -o-linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); + background-image: linear-gradient(top,#ffffff 20%,#f6f6f6 50%,#eeeeee 52%,#f4f4f4 100%); +} +.w2ui-overlay .w2ui-grid-searches table td.operator select::-ms-expand { + display: none; +} +.w2ui-overlay .w2ui-grid-searches table td.value { + padding-right: 5px; + padding-left: 5px; +} +.w2ui-overlay .w2ui-grid-searches table td.value input[type=text] { + border-radius: 3px; + padding: 3px; + margin-right: 3px; + height: 23px; +} +.w2ui-overlay .w2ui-grid-searches table td.value select { + padding: 3px; + margin-right: 3px; + height: 23px; +} +.w2ui-overlay .w2ui-grid-searches table td.actions { + border-right: 0px; +} +.w2ui-overlay .w2ui-grid-searches table td.actions > div { + margin: -7px; + margin-top: 15px; + padding: 13px 0px; + text-align: center; + background-color: #efefe9; + border-top: 1px solid #e8e8e3; +} +/************************************************* +* ---- Popup ---- +*/ +.w2ui-popup { + position: fixed; + z-index: 1600; + overflow: hidden; + font-family: Verdana, Arial, sans-serif; + border-radius: 6px; + padding: 0px; + margin: 0px; + border: 1px solid #777777; + background-color: #eeeeee; + box-shadow: 0px 0px 25px #555555; +} +.w2ui-popup, +.w2ui-popup * { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-popup .w2ui-msg-title { + padding: 6px; + border-radius: 6px 6px 0px 0px; + background-image: -webkit-linear-gradient(#ececec, #dfdfdf); + background-image: -moz-linear-gradient(#ececec, #dfdfdf); + background-image: -ms-linear-gradient(#ececec, #dfdfdf); + background-image: -o-linear-gradient(#ececec, #dfdfdf); + background-image: linear-gradient(#ececec, #dfdfdf); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffececec', endColorstr='#ffdfdfdf', GradientType=0); + border-bottom: 2px solid #bfbfbf; + position: absolute; + overflow: hidden; + height: 32px; + left: 0px; + right: 0px; + top: 0px; + text-overflow: ellipsis; + text-align: center; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; + cursor: move; + font-size: 15px; + color: #555555; + z-index: 300; +} +.w2ui-popup .w2ui-msg-button { + float: right; + width: 18px; + height: 18px; + cursor: pointer; + overflow: hidden; + padding: 0px; + margin: 0px 3px 0px 0px; + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAj1JREFUeNrslr9rFFEQxz/zZi/qxSgW2lsqkiYoBku5Ro1o4UFKEYkgSaxSCLYqdv5IEVPYCMJJwERWrK0CKhoQ8hdobQTjXW7njcXlYnLunQQu0YDTLOy+Nzvfme98Z8Td2ckW2OGWdMvRvYfT/RGfBPoBBVpLK0AEPgVkdGL06vt/CoB5nBaRE8AXYKXNsQIwaB4fAwOtH+88mn4m7ifN4vUYebWBKkFKqjIV3N9NjI2Uuw5ARI45fBanH+F77iFnN8JHETmS68P9NHBQNTwHL8foaSN4SqoyA/SZyL4tqQAQBVYCLOFYlNxmq0WorVLpN9Oe5LKt1CsgRVWpAOfB66phBuhTkepSdfnKVjaxNJMSWn/iawmTtpeDp6pWBpaBoqrMqoYU6AOqIbFhxGa3R4V8nfNNKLUESzXJhoCvQC+wF/gW1C5IiC+2XUbD5jA3rd4C26NR3945IA2iRzqRJgdElJJlSQocAKrAD2A/6Ev3cLajjN59MDWHyKl2voOI1zKbv3Xj2lCHJFoz+LXuBoIAjnUklEvJrDDT5LwmdhG8blkyBxRjXSu4loE0X4VEznXKV3SnoOFMB7YUolBcbcKNdxuPXUBPu8pbLXsK0ghebVjEXgNoYmXLtGLuxd6ePU+AQ20AaIrb4DpFycmSv81/7YsiMgAstB1kQgE47O4LuQmCNwGOB7VxCb/URsRSTbhkmU4ifGiZHd1Z5m7fnxoIQSaBo39YJRZj9LGb4yPzXWm1/9voX7afAwAC5tacDTA2XgAAAABJRU5ErkJggg==) no-repeat center left; + background-position: 0px 0px; + color: transparent !important; + border-radius: 3px; + border: 1px solid transparent; +} +.w2ui-popup .w2ui-msg-close { + margin-top: 0px; + background-position: -32px 0px; +} +.w2ui-popup .w2ui-msg-close:hover { + background-color: #cccccc; + border: 1px solid #aaaaaa; +} +.w2ui-popup .w2ui-msg-max { + background-position: -16px 0px; +} +.w2ui-popup .w2ui-msg-max:hover { + background-color: #cccccc; + border: 1px solid #aaaaaa; +} +.w2ui-popup .w2ui-box1, +.w2ui-popup .w2ui-box2 { + position: absolute; + left: 0px; + right: 0px; + top: 32px; + bottom: 55px; + z-index: 100; +} +.w2ui-popup .w2ui-msg-body { + font-size: 13px; + line-height: 130%; + padding: 0px 7px 7px 7px; + color: #000000; + background-color: #eeeeee; + position: absolute; + overflow: auto; + width: 100%; + height: 100%; +} +.w2ui-popup .w2ui-popup-message { + position: absolute; + z-index: 250; + background-color: #f9f9f9; + border: 1px solid #999999; + box-shadow: 0px 0px 15px #aaaaaa; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; + border-top: 0px; + border-radius: 0px 0px 6px 6px; + overflow: auto; +} +.w2ui-popup .w2ui-msg-buttons { + padding: 12px; + border-radius: 0px 0px 6px 6px; + border-top: 1px solid #d5d8d8; + background-color: #f1f1f1; + text-align: center; + position: absolute; + overflow: hidden; + height: 52px; + left: 0px; + right: 0px; + bottom: 0px; + z-index: 200; +} +.w2ui-popup .w2ui-msg-no-title { + border-top-left-radius: 6px; + border-top-right-radius: 6px; + top: 0px !important; +} +.w2ui-popup .w2ui-msg-no-buttons { + border-bottom-left-radius: 6px; + border-bottom-right-radius: 6px; + bottom: 0px !important; +} +/************************************************* +* ---- Sidebar ---- +*/ +.w2ui-sidebar { + cursor: default; + overflow: hidden !important; + background-color: #edf1f6 !important; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-sidebar * { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-sidebar > div { + position: relative; + overflow: hidden; +} +.w2ui-sidebar .w2ui-sidebar-top { + position: absolute; + z-index: 2; + top: 0px; + left: 0px; + right: 0px; +} +.w2ui-sidebar .w2ui-sidebar-bottom { + position: absolute; + z-index: 2; + bottom: 0px; + left: 0px; + right: 0px; +} +.w2ui-sidebar .w2ui-sidebar-div { + position: absolute; + z-index: 1; + overflow: auto; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; + padding: 2px 0px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; +} +.w2ui-sidebar .w2ui-sidebar-div table { + width: 100%; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node { + background-color: #edf1f6; + border-top: 1px solid transparent; + border-bottom: 1px solid transparent; + margin: 0px; + padding: 1px 0px; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node table { + pointer-events: none; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image > span, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots { + color: #000000; + text-shadow: 0px 0px 0px #ffffff; + pointer-events: none; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption:hover, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image:hover, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image > span:hover, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots:hover { + color: inherit; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node:hover { + border-top: 1px solid #f9f9f9; + border-bottom: 1px solid #f9f9f9; + background-color: #d7e1ef; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image { + width: 22px; + text-align: center; + pointer-events: none; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image > span { + color: #516173 !important; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node input { + pointer-events: auto; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover { + background-image: -webkit-linear-gradient(#69b1e0, #4a96d3); + background-image: -moz-linear-gradient(#69b1e0, #4a96d3); + background-image: -ms-linear-gradient(#69b1e0, #4a96d3); + background-image: -o-linear-gradient(#69b1e0, #4a96d3); + background-image: linear-gradient(#69b1e0, #4a96d3); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0', endColorstr='#ff4a96d3', GradientType=0); + border-top: 1px solid #5295cd; + border-bottom: 1px solid #2661a6; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-caption, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-caption, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image > span, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image > span, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected td.w2ui-node-dots, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover td.w2ui-node-dots { + color: #ffffff !important; + text-shadow: 1px 1px 2px #666666 !important; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover { + background: transparent !important; + border-top: 1px solid transparent; + border-bottom: 1px solid transparent; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-caption, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-caption, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image > span, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image > span, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled td.w2ui-node-dots, +.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover td.w2ui-node-dots { + opacity: 0.4; + filter: alpha(opacity=40); + color: #000000 !important; + text-shadow: 0px 0px 0px #ffffff !important; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-caption { + white-space: nowrap; + padding: 5px 0px 5px 3px; + margin: 1px 0px 1px 22px; + position: relative; + z-index: 1; + font-size: 12px; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group { + white-space: nowrap; + overflow: hidden; + padding: 10px 0px 10px 10px; + margin: 0px; + cursor: default; + color: #868b92; + background-color: transparent; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(1) { + /* show / hide link */ + margin-right: 10px; + float: right; + color: transparent; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(2) { + /* title text */ + font-weight: normal; + text-transform: uppercase; +} +.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-sub { + overflow: hidden; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots { + width: 18px; + padding: 0px 0px 1px 7px; + text-align: center; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots .w2ui-expand { + width: 16px; + margin-top: -3px; + pointer-events: auto; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data { + padding: 1px 1px 3px 1px; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image { + padding: 3px 0px 0px 0px; + float: left; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image > span { + font-size: 16px; + color: #000000; + text-shadow: 0px 0px 0px #ffffff; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image.w2ui-icon { + margin-top: 3px; +} +.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-count { + float: right; + border: 1px solid #9da4af; + border-radius: 20px; + width: auto; + height: 18px; + padding: 2px 7px; + margin: 3px 4px -2px 0; + background-color: #e7f0fc; + color: #667274; + box-shadow: 0 0 2px #ffffff; + text-shadow: 1px 1px 1px #e6e6e6; + position: relative; + z-index: 2; +} +/************************************************* +* ---- Tabs ---- +*/ +.w2ui-tabs { + cursor: default; + overflow: hidden !important; + background-color: #fafafa; + padding: 3px 0px; + padding-bottom: 0px !important; +} +.w2ui-tabs table { + border-bottom: 1px solid silver; + padding: 0px 7px; +} +.w2ui-tabs .w2ui-tab { + padding: 6px 20px; + text-align: center; + color: #000000; + background-color: transparent; + border: 1px solid #c0c0c0; + border-bottom: 1px solid silver; + white-space: nowrap; + margin: 1px 1px -1px 0px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + cursor: default; +} +.w2ui-tabs .w2ui-tab.active { + color: #000000; + background-color: #ffffff; + border: 1px solid #c0c0c0; + border-bottom: 1px solid transparent; +} +.w2ui-tabs .w2ui-tab.closable { + padding: 6px 28px 6px 20px; +} +.w2ui-tabs .w2ui-tab-close { + color: #555; + text-shadow: 1px 1px 1px #bbb; + float: right; + margin: 6px 4px 0px 0px; + padding: 0px 0px 0px 5px; + width: 16px; + height: 16px; + opacity: 0.9; + border: 0px; + border-top: 3px solid transparent; + border-radius: 9px; +} +.w2ui-tabs .w2ui-tab-close:hover { + background-color: #D77F7F; + color: white; +} +.w2ui-tabs .w2ui-tab-close:before { + position: relative; + top: -2px; + left: 0px; + opacity: 0.6; + color: inherit; + text-shadow: inherit; + content: 'x'; +} +/************************************************* +* ---- Toolbar ---- +*/ +.w2ui-toolbar { + margin: 0px; + padding: 2px; + outline: 0px; + background-color: #efefef; + overflow: hidden !important; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; +} +.w2ui-toolbar .disabled { + opacity: 0.3; + filter: alpha(opacity=30); +} +.w2ui-toolbar table { + table-layout: auto !important; +} +.w2ui-toolbar table td { + border: 0px !important; +} +.w2ui-toolbar table.w2ui-button { + margin: 0px 1px; + border-radius: 4px; + height: 24px; + border: 1px solid transparent; + background-color: transparent; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-image { + width: 16px; + height: 16px; + padding: 0px; + margin: 2px 4px 3px 3px !important; + border: 0px !important; + text-align: center; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-image > span { + font-size: 15px; + margin-top: 3px; + display: block; + color: #8d99a7; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-caption { + color: #000000; + padding: 0px 4px 0px 2px; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-count { + padding: 0px 4px 0px 0px; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-count > span { + border: 1px solid #9da4af; + border-radius: 20px; + width: auto; + height: 18px; + padding: 2px 7px; + background-color: #e7f0fc; + color: #667274; + box-shadow: 0 0 2px #ffffff; + text-shadow: 1px 1px 1px #e6e6e6; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-down { + padding: 3px; +} +.w2ui-toolbar table.w2ui-button .w2ui-tb-down > div { + border: 4px solid transparent; + border-top: 5px solid #8D99A7; + margin-top: 5px; +} +.w2ui-toolbar table.w2ui-button.over { + border: 1px solid #cccccc; + background-color: #eeeeee; +} +.w2ui-toolbar table.w2ui-button.over .w2ui-tb-caption { + color: #000000; +} +.w2ui-toolbar table.w2ui-button.down { + border: 1px solid #aaaaaa; + background-color: #dddddd; +} +.w2ui-toolbar table.w2ui-button.down .w2ui-tb-caption { + color: #666666; +} +.w2ui-toolbar table.w2ui-button.checked { + border: 1px solid #aaaaaa; + background-color: #ffffff; +} +.w2ui-toolbar table.w2ui-button.checked .w2ui-tb-caption { + color: #000000; +} +.w2ui-toolbar table.w2ui-button table { + height: 17px; + border-radius: 4px; + cursor: default; +} +.w2ui-toolbar .w2ui-break { + background-image: -webkit-linear-gradient(top, rgba(153, 153, 153, 0.1) 0%, #999999 40%, #999999 60%, rgba(153, 153, 153, 0.1) 100%); + background-image: -moz-linear-gradient(top, rgba(153, 153, 153, 0.1) 0%, #999999 40%, #999999 60%, rgba(153, 153, 153, 0.1) 100%); + background-image: -ms-linear-gradient(top, rgba(153, 153, 153, 0.1) 0%, #999999 40%, #999999 60%, rgba(153, 153, 153, 0.1) 100%); + background-image: -o-linear-gradient(top, rgba(153, 153, 153, 0.1) 0%, #999999 40%, #999999 60%, rgba(153, 153, 153, 0.1) 100%); + background-image: linear-gradient(top, rgba(153, 153, 153, 0.1) 0%, #999999 40%, #999999 60%, rgba(153, 153, 153, 0.1) 100%); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff999999', endColorstr='#ff999999', GradientType=0); + width: 1px !important; + height: 22px; + padding: 0px; + margin: 0px 6px; +} +.w2ui-listview { + overflow: auto !important; + background-color: #ffffff !important; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-listview * { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} +.w2ui-listview > ul { + list-style-type: none; + margin: 0; + cursor: default; +} +.w2ui-listview > ul > li { + display: inline-block; + vertical-align: top; + overflow: hidden; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; + border: 1px solid transparent; + border-radius: 4px; +} +.w2ui-listview > ul > li.w2ui-focused { + border: 1px solid #2661a6; +} +.w2ui-listview > ul > li.w2ui-selected { + border: 1px solid #2661a6; +} +.w2ui-listview > ul > li.w2ui-selected, +.w2ui-listview > ul > li.w2ui-selected.hover { + background-image: -webkit-linear-gradient(#69b1e0, #4a96d3); + background-image: -moz-linear-gradient(#69b1e0, #4a96d3); + background-image: -ms-linear-gradient(#69b1e0, #4a96d3); + background-image: -o-linear-gradient(#69b1e0, #4a96d3); + background-image: linear-gradient(#69b1e0, #4a96d3); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0', endColorstr='#ff4a96d3', GradientType=0); +} +.w2ui-listview > ul > li.w2ui-selected > div > div.caption, +.w2ui-listview > ul > li.w2ui-selected.hover > div > div.caption { + color: #ffffff; +} +.w2ui-listview > ul > li.w2ui-selected > div > div.description, +.w2ui-listview > ul > li.w2ui-selected.hover > div > div.description { + color: #dddddd; +} +.w2ui-listview > ul > li.w2ui-selected > div > div.extra > div > div, +.w2ui-listview > ul > li.w2ui-selected.hover > div > div.extra > div > div { + color: #dddddd; +} +.w2ui-listview > ul > li.hover { + background-color: #d7e1ef; + border: 1px solid #2661a6; +} +.w2ui-listview > ul > li div { + vertical-align: middle; +} +.w2ui-listview > ul > li > div > div.caption { + display: block; + text-align: center; + word-wrap: break-word; + max-height: 50px; + color: #000000; + font-size: 12px; +} +.w2ui-listview > ul > li > div > div.description { + display: none; + text-align: left; + color: #777777; + font-size: 12px; +} +.w2ui-listview > ul > li > div > div.extra { + display: none; +} +.w2ui-listview > ul > li > div > div.extra > div > div { + color: #777777; +} +.w2ui-icon-small > ul { + padding: 1px 0px 0px 1px; +} +.w2ui-icon-small > ul > li { + margin: 0px 1px 1px 0px; + padding: 2px; + width: 250px; + white-space: nowrap; +} +.w2ui-icon-small > ul > li > div > div.w2ui-listview-img { + display: inline-block; + width: 26px; + height: 22px; + font-size: 21px; + margin-right: 2px; +} +.w2ui-icon-small > ul > li > div > div.caption { + display: inline-block; +} +.w2ui-icon-medium > ul { + padding: 4px 0px 0px 4px; +} +.w2ui-icon-medium > ul > li { + margin: 0px 4px 4px 0px; + padding: 4px; + width: 100px; +} +.w2ui-icon-medium > ul > li > div > div.w2ui-listview-img { + display: block; + width: 92px; + height: 60px; + font-size: 57px; + margin-left: auto; + margin-right: auto; + background-position: center; +} +.w2ui-icon-large > ul { + padding: 4px 0px 0px 4px; +} +.w2ui-icon-large > ul > li { + margin: 0px 4px 4px 0px; + padding: 4px; + width: 160px; +} +.w2ui-icon-large > ul > li > div > div.w2ui-listview-img { + display: block; + width: 152px; + height: 120px; + font-size: 114px; + margin-left: auto; + margin-right: auto; + background-position: center; +} +.w2ui-icon-tile > ul { + padding: 1px 0px 0px 1px; +} +.w2ui-icon-tile > ul > li { + margin: 0px 1px 1px 0px; + padding: 4px; + width: 250px; + white-space: nowrap; +} +.w2ui-icon-tile > ul > li > div > div.w2ui-listview-img { + display: inline-block; + width: 72px; + height: 60px; + font-size: 57px; + float: left; + margin-right: 4px; +} +.w2ui-icon-tile > ul > li > div > div.caption { + text-align: left; +} +.w2ui-icon-tile > ul > li > div > div.description { + display: block; +} +.w2ui-table > ul { + padding: 0; +} +.w2ui-table > ul > li { + width: 100%; + padding: 2px; + border-radius: 0px; + border-bottom: 1px dotted lightgray; +} +.w2ui-table > ul > li > div { + display: inline-block; + position: relative; + width: 100%; + white-space: nowrap; + overflow: hidden; +} +.w2ui-table > ul > li > div > div.w2ui-listview-img { + display: inline-block; + width: 38px; + height: 32px; + font-size: 31px; + margin-right: 2px; +} +.w2ui-table > ul > li > div > div.caption { + display: inline-block; +} +.w2ui-table > ul > li > div > div.extra { + display: inline-block; + position: absolute; + right: 0; + height: 100%; + background-color: #ffffff; +} +.w2ui-table > ul > li > div > div.extra > div:before { + display: inline-block; + height: 100%; + width: 0; + content: ''; + vertical-align: middle; +} +.w2ui-table > ul > li > div > div.extra > div { + display: inline; +} +.w2ui-table > ul > li > div > div.extra > div > div { + display: inline-block; + font-size: 12px; +} +.w2ui-table > ul > li.w2ui-selected div.extra, +.w2ui-table > ul > li.w2ui-selected.hover div.extra { + background-image: -webkit-linear-gradient(#69b1e0, #4a96d3); + background-image: -moz-linear-gradient(#69b1e0, #4a96d3); + background-image: -ms-linear-gradient(#69b1e0, #4a96d3); + background-image: -o-linear-gradient(#69b1e0, #4a96d3); + background-image: linear-gradient(#69b1e0, #4a96d3); + filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0', endColorstr='#ff4a96d3', GradientType=0); +} +.w2ui-table > ul > li.hover div.extra { + background-color: #d7e1ef; +} +.w2ui-listview > ul > li div.icon-none { + border: 1px solid rgba(102, 102, 102, 0.35); +} diff --git a/css/w2ui.min.css b/css/w2ui.min.css index 76743fc..fd74405 100644 --- a/css/w2ui.min.css +++ b/css/w2ui.min.css @@ -1,2 +1 @@ -/* w2ui 1.3 (c) http://w2ui.com, vitmalina@gmail.com */ -.w2ui-reset{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-reset *{color:default;font-family:Verdana,Arial;font-size:11px;line-height:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0}.w2ui-reset table{max-width:none;background-color:transparent;border-collapse:separate;border-spacing:0}.w2ui-reset input,.w2ui-reset textarea{width:auto;/*height:auto;*/vertical-align:baseline;padding:4px}.w2ui-reset select{padding:1px;height:23px}.w2ui-centered{display:table;width:100%;height:100%}.w2ui-centered>div{display:table-cell;padding:10px 20px 20px 10px;text-align:center;vertical-align:middle}input[type=text],input[type=password],select,textarea{padding:4px;border:1px solid #dfdfdf;border-radius:3px;color:#000;background-color:#fff}input[type=text]:focus,input[type=password]:focus,select:focus,textarea:focus{outline-color:#72b2ff}input[type=text]:disabled,input[type=password]:disabled,select:disabled,textarea:disabled,input[type=text][readonly],input[type=password][readonly],select[readonly],textarea[readonly]{background-color:#f1f1f1;color:#888}select{padding:2px}.w2ui-overlay{position:absolute;margin-top:6px;margin-left:-17px;display:none;z-index:1300;color:inherit;background-color:#fbfbfb;border:3px solid #777;box-shadow:0 2px 10px #999;border-radius:4px;text-align:left}.w2ui-overlay table td{color:inherit}.w2ui-overlay:before{content:"";position:absolute;-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg);width:10px;height:10px;border:3px solid #777;border-color:inherit;background-color:inherit;border-left:1px solid transparent;border-bottom:1px solid transparent;border-bottom-left-radius:50px;margin:-9px 0 0 32px}.w2ui-overlay.w2ui-overlay-popup{z-index:1700}.w2ui-tag{position:absolute;z-index:1300;opacity:0;-webkit-transition:opacity .3s;-moz-transition:opacity .3s;-ms-transition:opacity .3s;-o-transition:opacity .3s;transition:opacity .3s}.w2ui-tag .w2ui-tag-body{background-color:rgba(60,60,60,.82);display:inline-block;position:absolute;border-radius:4px;padding:4px 10px;margin-left:10px;margin-top:0;color:#fff!important;box-shadow:1px 1px 3px #000;line-height:normal;font-size:11px;font-family:Verdana,Arial}.w2ui-tag .w2ui-tag-body:before{content:"";position:absolute;width:0;height:0;border-top:5px solid transparent;border-right:5px solid rgba(60,60,60,.82);border-bottom:5px solid transparent;margin:2px 0 0 -15px}.w2ui-tag.w2ui-tag-popup{z-index:1700}.w2ui-marker{color:#444;background-color:#FFF8B0}.w2ui-spinner{display:inline-block;background-size:100%;background-repeat:no-repeat;background-image:url(data:image/gif;base64,R0lGODlhgACAAKIAAP///93d3bu7u5mZmQAA/wAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFBQAEACwCAAIAfAB8AAAD/0i63P4wygYqmDjrzbtflvWNZGliYXiubKuloivPLlzReD7al+7/Eh5wSFQIi8hHYBkwHUmD6CD5YTJLz49USuVYraRsZ7vtar7XnQ1Kjpoz6LRHvGlz35O4nEPP2O94EnpNc2sef1OBGIOFMId/inB6jSmPdpGScR19EoiYmZobnBCIiZ95k6KGGp6ni4wvqxilrqBfqo6skLW2YBmjDa28r6Eosp27w8Rov8ekycqoqUHODrTRvXsQwArC2NLF29UM19/LtxO5yJd4Au4CK7DUNxPebG4e7+8n8iv2WmQ66BtoYpo/dvfacBjIkITBE9DGlMvAsOIIZjIUAixliv9ixYZVtLUos5GjwI8gzc3iCGghypQqrbFsme8lwZgLZtIcYfNmTJ34WPTUZw5oRxdD9w0z6iOpO15MgTh1BTTJUKos39jE+o/KS64IFVmsFfYT0aU7capdy7at27dw48qdS7eu3bt480I02vUbX2F/JxYNDImw4GiGE/P9qbhxVpWOI/eFKtlNZbWXuzlmG1mv58+gQ4seTbq06dOoU6vGQZJy0FNlMcV+czhQ7SQmYd8eMhPs5BxVdfcGEtV3buDBXQ+fURxx8oM6MT9P+Fh6dOrH2zavc13u9JXVJb520Vp8dvC76wXMuN5Sepm/1WtkEZHDefnzR9Qvsd9+/wi8+en3X0ntYVcSdAE+UN4zs7ln24CaLagghIxBaGF8kFGoIYV+Ybghh841GIyI5ICIFoklJsigihmimJOLEbLYIYwxSgigiZ+8l2KB+Ml4oo/w8dijjcrouCORKwIpnJIjMnkkksalNeR4fuBIm5UEYImhIlsGCeWNNJphpJdSTlkml1jWeOY6TnaRpppUctcmFW9mGSaZceYopH9zkjnjUe59iR5pdapWaGqHopboaYua1qije67GJ6CuJAAAIfkEBQUABAAsCgACAFcAMAAAA/9Iutz+ML5Ag7w46z0r5WAoSp43nihXVmnrdusrv+s332dt4Tyo9yOBUJD6oQBIQGs4RBlHySSKyczVTtHoidocPUNZaZAr9F5FYbGI3PWdQWn1mi36buLKFJvojsHjLnshdhl4L4IqbxqGh4gahBJ4eY1kiX6LgDN7fBmQEJI4jhieD4yhdJ2KkZk8oiSqEaatqBekDLKztBG2CqBACq4wJRi4PZu1sA2+v8C6EJexrBAD1AOBzsLE0g/V1UvYR9sN3eR6lTLi4+TlY1wz6Qzr8u1t6FkY8vNzZTxaGfn6mAkEGFDgL4LrDDJDyE4hEIbdHB6ESE1iD4oVLfLAqPETIsOODwmCDJlv5MSGJklaS6khAQAh+QQFBQAEACwfAAIAVwAwAAAD/0i63P5LSAGrvTjrNuf+YKh1nWieIumhbFupkivPBEzR+GnnfLj3ooFwwPqdAshAazhEGUXJJIrJ1MGOUamJ2jQ9QVltkCv0XqFh5IncBX01afGYnDqD40u2z76JK/N0bnxweC5sRB9vF34zh4gjg4uMjXobihWTlJUZlw9+fzSHlpGYhTminKSepqebF50NmTyor6qxrLO0L7YLn0ALuhCwCrJAjrUqkrjGrsIkGMW/BMEPJcphLgDaABjUKNEh29vdgTLLIOLpF80s5xrp8ORVONgi8PcZ8zlRJvf40tL8/QPYQ+BAgjgMxkPIQ6E6hgkdjoNIQ+JEijMsasNY0RQix4gKP+YIKXKkwJIFF6JMudFEAgAh+QQFBQAEACw8AAIAQgBCAAAD/kg0PPowykmrna3dzXvNmSeOFqiRaGoyaTuujitv8Gx/661HtSv8gt2jlwIChYtc0XjcEUnMpu4pikpv1I71astytkGh9wJGJk3QrXlcKa+VWjeSPZHP4Rtw+I2OW81DeBZ2fCB+UYCBfWRqiQp0CnqOj4J1jZOQkpOUIYx/m4oxg5cuAaYBO4Qop6c6pKusrDevIrG2rkwptrupXB67vKAbwMHCFcTFxhLIt8oUzLHOE9Cy0hHUrdbX2KjaENzey9Dh08jkz8Tnx83q66bt8PHy8/T19vf4+fr6AP3+/wADAjQmsKDBf6AOKjS4aaHDgZMeSgTQcKLDhBYPEswoA1BBAgAh+QQFBQAEACxOAAoAMABXAAAD7Ei6vPOjyUkrhdDqfXHm4OZ9YSmNpKmiqVqykbuysgvX5o2HcLxzup8oKLQQix0UcqhcVo5ORi+aHFEn02sDeuWqBGCBkbYLh5/NmnldxajX7LbPBK+PH7K6narfO/t+SIBwfINmUYaHf4lghYyOhlqJWgqDlAuAlwyBmpVnnaChoqOkpaanqKmqKgGtrq+wsbA1srW2ry63urasu764Jr/CAb3Du7nGt7TJsqvOz9DR0tPU1TIA2ACl2dyi3N/aneDf4uPklObj6OngWuzt7u/d8fLY9PXr9eFX+vv8+PnYlUsXiqC3c6PmUUgAACH5BAUFAAQALE4AHwAwAFcAAAPpSLrc/m7IAau9bU7MO9GgJ0ZgOI5leoqpumKt+1axPJO1dtO5vuM9yi8TlAyBvSMxqES2mo8cFFKb8kzWqzDL7Xq/4LB4TC6bz1yBes1uu9uzt3zOXtHv8xN+Dx/x/wJ6gHt2g3Rxhm9oi4yNjo+QkZKTCgGWAWaXmmOanZhgnp2goaJdpKGmp55cqqusrZuvsJays6mzn1m4uRAAvgAvuBW/v8GwvcTFxqfIycA3zA/OytCl0tPPO7HD2GLYvt7dYd/ZX99j5+Pi6tPh6+bvXuTuzujxXens9fr7YPn+7egRI9PPHrgpCQAAIfkEBQUABAAsPAA8AEIAQgAAA/lIutz+UI1Jq7026h2x/xUncmD5jehjrlnqSmz8vrE8u7V5z/m5/8CgcEgsGo/IpHLJbDqf0Kh0ShBYBdTXdZsdbb/Yrgb8FUfIYLMDTVYz2G13FV6Wz+lX+x0fdvPzdn9WeoJGAYcBN39EiIiKeEONjTt0kZKHQGyWl4mZdREAoQAcnJhBXBqioqSlT6qqG6WmTK+rsa1NtaGsuEu6o7yXubojsrTEIsa+yMm9SL8osp3PzM2cStDRykfZ2tfUtS/bRd3ewtzV5pLo4eLjQuUp70Hx8t9E9eqO5Oku5/ztdkxi90qPg3x2EMpR6IahGocPCxp8AGtigwQAIfkEBQUABAAsHwBOAFcAMAAAA/9Iutz+MMo36pg4682J/V0ojs1nXmSqSqe5vrDXunEdzq2ta3i+/5DeCUh0CGnF5BGULC4tTeUTFQVONYAs4CfoCkZPjFar83rBx8l4XDObSUL1Ott2d1U4yZwcs5/xSBB7dBMBhgEYfncrTBGDW4WHhomKUY+QEZKSE4qLRY8YmoeUfkmXoaKInJ2fgxmpqqulQKCvqRqsP7WooriVO7u8mhu5NacasMTFMMHCm8qzzM2RvdDRK9PUwxzLKdnaz9y/Kt8SyR3dIuXmtyHpHMcd5+jvWK4i8/TXHff47SLjQvQLkU+fG29rUhQ06IkEG4X/Rryp4mwUxSgLL/7IqFETB8eONT6ChCFy5ItqJomES6kgAQAh+QQFBQAEACwKAE4AVwAwAAAD/0i63A4QuEmrvTi3yLX/4MeNUmieITmibEuppCu3sDrfYG3jPKbHveDktxIaF8TOcZmMLI9NyBPanFKJp4A2IBx4B5lkdqvtfb8+HYpMxp3Pl1qLvXW/vWkli16/3dFxTi58ZRcChwIYf3hWBIRchoiHiotWj5AVkpIXi4xLjxiaiJR/T5ehoomcnZ+EGamqq6VGoK+pGqxCtaiiuJVBu7yaHrk4pxqwxMUzwcKbyrPMzZG90NGDrh/JH8t72dq3IN1jfCHb3L/e5ebh4ukmxyDn6O8g08jt7tf26ybz+m/W9GNXzUQ9fm1Q/APoSWAhhfkMAmpEbRhFKwsvCsmosRIHx444PoKcIXKkjIImjTzjkQAAIfkEBQUABAAsAgA8AEIAQgAAA/VIBNz+8KlJq72Yxs1d/uDVjVxogmQqnaylvkArT7A63/V47/m2/8CgcEgsGo/IpHLJbDqf0Kh0Sj0FroGqDMvVmrjgrDcTBo8v5fCZki6vCW33Oq4+0832O/at3+f7fICBdzsChgJGeoWHhkV0P4yMRG1BkYeOeECWl5hXQ5uNIAOjA1KgiKKko1CnqBmqqk+nIbCkTq20taVNs7m1vKAnurtLvb6wTMbHsUq4wrrFwSzDzcrLtknW16tI2tvERt6pv0fi48jh5h/U6Zs77EXSN/BE8jP09ZFA+PmhP/xvJgAMSGBgQINvEK5ReIZhQ3QEMTBLAAAh+QQFBQAEACwCAB8AMABXAAAD50i6DA4syklre87qTbHn4OaNYSmNqKmiqVqyrcvBsazRpH3jmC7yD98OCBF2iEXjBKmsAJsWHDQKmw571l8my+16v+CweEwum8+hgHrNbrvbtrd8znbR73MVfg838f8BeoB7doN0cYZvaIuMjY6PkJGSk2gClgJml5pjmp2YYJ6dX6GeXaShWaeoVqqlU62ir7CXqbOWrLafsrNctjIDwAMWvC7BwRWtNsbGFKc+y8fNsTrQ0dK3QtXAYtrCYd3eYN3c49/a5NVj5eLn5u3s6e7x8NDo9fbL+Mzy9/T5+tvUzdN3Zp+GBAAh+QQJBQAEACwCAAIAfAB8AAAD/0i63P4wykmrvTjrzbv/YCiOZGmeaKqubOu+cCzPdArcQK2TOL7/nl4PSMwIfcUk5YhUOh3M5nNKiOaoWCuWqt1Ou16l9RpOgsvEMdocXbOZ7nQ7DjzTaeq7zq6P5fszfIASAYUBIYKDDoaGIImKC4ySH3OQEJKYHZWWi5iZG0ecEZ6eHEOio6SfqCaqpaytrpOwJLKztCO2jLi1uoW8Ir6/wCHCxMG2x7muysukzb230M6H09bX2Nna29zd3t/g4cAC5OXm5+jn3Ons7eba7vHt2fL16tj2+QL0+vXw/e7WAUwnrqDBgwgTKlzIsKHDh2gGSBwAccHEixAvaqTYcFCjRoYeNyoM6REhyZIHT4o0qPIjy5YTTcKUmHImx5cwE85cmJPnSYckK66sSAAj0aNIkypdyrSp06dQo0qdSrWq1atYs2rdyrWr169gwxZJAAA7)}.w2ui-icon{background-repeat:no-repeat;height:16px;width:16px;overflow:hidden;margin:2px;display:inline-block}.w2ui-icon.icon-reload{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAI/SURBVDjLjZPbS9NhHMYH+zNidtCSQrqwQtY5y2QtT2QGrTZf13TkoYFlzsWa/tzcoR3cSc2xYUlGJfzAaIRltY0N12H5I+jaOxG8De+evhtdOP1hu3hv3sPzPO/z4SsBIPnfuvG8cbBlWiEVO5OUItA0VS8oxi9EdhXo+6yV3V3UGHRvVXHNfNv6zRfNuBZVoiFcB/3LdnQ8U+Gk+bhPVKB3qUOuf6/muaQR/qwDkZ9BRFdCmMr5EPz6BN7lMYylLGgNNaKqt3K0SKDnQ7us690t3rNsxeyvaUz+8OJpzo/QNzd8WTtcaQ7WlBmPvxhx1V2Pg7oDziIBimwwf3qAGWESkVwQ7owNujk1ztvk+cg4NnAUTT4FrrjqUKHdF9jxBfXr1rgjaSk4OlMcLrnOrJ7latxbL1V2lgvlbG9MtMTrMw1r1PImtfyn1n5q47TlBLf90n5NmalMtUdKZoyQMkLKlIGLjMyYhFpmlz3nGEVmFJlRZNaf7pIaEndM24XIjCOzjX9mm2S2JsqdkMYIqbB1j5C6yWzVk7YRFTsGFu7l+4nveExIA9aMCcOJh6DIoMigyOh+o4UryRWQOtIjaJtoziM1FD0mpE4uZcTc72gBaUyYKEI6khgqINXO3saR7kM8IZUVCRDS0Ucf+xFbCReQhr97MZ51wpWxYnhpCD3zOrT4lTisr+AJqVx0Fiiyr4/vhP4VyyMFIUWNqRrV96vWKXKckBoIqWzXYcoPDrUslDJoopuEVEpIB0sR+AuErIiZ6OqMKAAAAABJRU5ErkJggg==) no-repeat center}.w2ui-icon.icon-columns{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFwSURBVBgZpcG9apNhHMbh3/ORWiztpLSrQ86gmw6egkuXjE7i5CQ0OAZxUSj0DCxiB8/A07BDBXEoKEoGbaP45n/f9im+SwhCyXUl26wiPXjy9vG9+7svpjNv2ICEJUKBZWThCGTjCEJia627ODk5e/ru5d5h3b27ezBY38jb61zHxsUsDoDDOuucZ9NzrutX50yz//rUy4zffPT/PHz+3peotmjGR6f0JqMhven5b2JuYm7C4k+YOzubhIImY9PbvrXJoloqdZCpNzJra5Wbg0qjedDUUND7+v0ni0qGnAo1QSQTWTQK0VTLNJPRkGVKAiVwAnKiqNBIQVOloBkfndKbjIb0Us1UCRkyoMQVSTR53nX0dm5vsSgDKWdKyaScyIUr825OUx2i9+XbDxbllGgElJSwRGOJpkqimYyGLFNSoin8UwqNbJp69unz8aNX3Z4iUIiIQBLRdYyefUA2VuAwsrCERHPMpWSbVWRW9Bcyl/ydiZeC0gAAAABJRU5ErkJggg==) no-repeat center!important}.w2ui-icon.icon-search,.w2ui-icon.icon-search-down{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAgCAYAAAB+ZAqzAAACuElEQVRYw9WXSWhTQRjHR0UKLqhFaV0OUih68GAOWjyJKypCpAoV8aIiioIICiKiB1GMtE3MYmry2moXDz1UDx7sUXHBhQpSaRVxrYpWcMO9avx/8AJh/CbznHkxdeB3Cd/8589kvuUJkWcdjCTHghUgAi6DJ+AVeAqugSQIggniXywcNBJsB70g44EHYBcYXUhTM8EFj4ZkboKqQpiqAv2GprK8o7/f75t6pjn0M3gNPmri3vtycxAZA64qDvkJ2kENqAQTQQWoBg74qth3B4y3NbZDIX4fzNfsnQtuK/YfsjFVCh4pMq3Co0Y5uMVoUGkpy8aFT5xaeSzVEo45bXdBt4LeaLq1k0RXMYJfdDfFmAuAD4zWlty4UNyZEkm19MUb2zMw8Sfp1u+IWSrcIimLnTG8/SijdU6OO5poDESdtgHZVBzUHm/amhW7zoitMTS2mNHqASPk2FDCCcLMYK6p+obmulyxfiYLA4bGKFvfSnrUvkq5+Lpk8z4yRH8r3l/X4WiqJFfspSQ0CGYZGpsMnkt6L+h31Z76hpMdeOwPQ7H0NFnssST0C8wxNDaDKb6kP06150gsHahNNlVzYheZd7HJ0BiX4VRGhpmIhRixKyZilM2M1mnTArtIUbU3/qVO0H0GvmQ4CY4C3YopYYlHjXlggNG4R33Ypi2tVtwaPeTdNMkq9pVQZQdvFPs32zbx4aAjzxhDRfIAWAeWg7VgrzsY5ht/zoNJtubKwA3LITGjSKRyW3NTwaUCmKOSMd3WHH0ZJRQZZkOP1zFKZ3CB++4+aQ6kEeksWAb2a2L7qDv49S1Q6T72MOgEXa6RGFhP3wpS/B6NOWpRs0UxFg7eqTFHjX1hscxtAz/ymEuIYi0cvgF8Y0w5Ro3dZ3M1boJkTaXEUFlug6fsdsRQWzTj0cey+N/Xb2sj5lTh2M6OAAAAAElFTkSuQmCC) no-repeat center!important;background-size:14px 12px!important;opacity:.9}.w2ui-icon.icon-add{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJvSURBVDjLpZPrS5NhGIf9W7YvBYOkhlkoqCklWChv2WyKik7blnNris72bi6dus0DLZ0TDxW1odtopDs4D8MDZuLU0kXq61CijSIIasOvv94VTUfLiB74fXngup7nvrnvJABJ/5PfLnTTdcwOj4RsdYmo5glBWP6iOtzwvIKSWstI0Wgx80SBblpKtE9KQs/We7EaWoT/8wbWP61gMmCH0lMDvokT4j25TiQU/ITFkek9Ow6+7WH2gwsmahCPdwyw75uw9HEO2gUZSkfyI9zBPCJOoJ2SMmg46N61YO/rNoa39Xi41oFuXysMfh36/Fp0b7bAfWAH6RGi0HglWNCbzYgJaFjRv6zGuy+b9It96N3SQvNKiV9HvSaDfFEIxXItnPs23BzJQd6DDEVM0OKsoVwBG/1VMzpXVWhbkUM2K4oJBDYuGmbKIJ0qxsAbHfRLzbjcnUbFBIpx/qH3vQv9b3U03IQ/HfFkERTzfFj8w8jSpR7GBE123uFEYAzaDRIqX/2JAtJbDat/COkd7CNBva2cMvq0MGxp0PRSCPF8BXjWG3FgNHc9XPT71Ojy3sMFdfJRCeKxEsVtKwFHwALZfCUk3tIfNR8XiJwc1LmL4dg141JPKtj3WUdNFJqLGFVPC4OkR4BxajTWsChY64wmCnMxsWPCHcutKBxMVp5mxA1S+aMComToaqTRUQknLTH62kHOVEE+VQnjahscNCy0cMBWsSI0TCQcZc5ALkEYckL5A5noWSBhfm2AecMAjbcRWV0pUTh0HE64TNf0mczcnnQyu/MilaFJCae1nw2fbz1DnVOxyGTlKeZft/Ff8x1BRssfACjTwQAAAABJRU5ErkJggg==) no-repeat center!important}.w2ui-icon.icon-delete{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJdSURBVDjLpZP7S1NhGMf9W7YfogSJboSEUVCY8zJ31trcps6zTI9bLGJpjp1hmkGNxVz4Q6ildtXKXzJNbJRaRmrXoeWx8tJOTWptnrNryre5YCYuI3rh+8vL+/m8PA/PkwIg5X+y5mJWrxfOUBXm91QZM6UluUmthntHqplxUml2lciF6wrmdHriI0Wx3xw2hAediLwZRWRkCPzdDswaSvGqkGCfq8VEUsEyPF1O8Qu3O7A09RbRvjuIttsRbT6HHzebsDjcB4/JgFFlNv9MnkmsEszodIIY7Oaut2OJcSF68Qx8dgv8tmqEL1gQaaARtp5A+N4NzB0lMXxon/uxbI8gIYjB9HytGYuusfiPIQcN71kjgnW6VeFOkgh3XcHLvAwMSDPohOADdYQJdF1FtLMZPmslvhZJk2ahkgRvq4HHUoWHRDqTEDDl2mDkfheiDgt8pw340/EocuClCuFvboQzb0cwIZgki4KhzlaE6w0InipbVzBfqoK/qRH94i0rgokSFeO11iBkp8EdV8cfJo0yD75aE2ZNRvSJ0lZKcBXLaUYmQrCzDT6tDN5SyRqYlWeDLZAg0H4JQ+Jt6M3atNLE10VSwQsN4Z6r0CBwqzXesHmV+BeoyAUri8EyMfi2FowXS5dhd7doo2DVII0V5BAjigP89GEVAtda8b2ehodU4rNaAW+dGfzlFkyo89GTlcrHYCLpKD+V7yeeHNzLjkp24Uu1Ed6G8/F8qjqGRzlbl2H2dzjpMg1KdwsHxOlmJ7GTeZC/nesXbeZ6c9OYnuxUc3fmBuFft/Ff8xMd0s65SXIb/gAAAABJRU5ErkJggg==) no-repeat center!important}.w2ui-icon.icon-save{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAKfSURBVDjLpZPrS1NhHMf9O3bOdmwDCWREIYKEUHsVJBI7mg3FvCxL09290jZj2EyLMnJexkgpLbPUanNOberU5taUMnHZUULMvelCtWF0sW/n7MVMEiN64AsPD8/n83uucQDi/id/DBT4Dolypw/qsz0pTMbj/WHpiDgsdSUyUmeiPt2+V7SrIM+bSss8ySGdR4abQQv6lrui6VxsRonrGCS9VEjSQ9E7CtiqdOZ4UuTqnBHO1X7YXl6Daa4yGq7vWO1D40wVDtj4kWQbn94myPGkCDPdSesczE2sCZShwl8CzcwZ6NiUs6n2nYX99T1cnKqA2EKui6+TwphA5k4yqMayopU5mANV3lNQTBdCMVUA9VQh3GuDMHiVcLCS3J4jSLhCGmKCjBEx0xlshjXYhApfMZRP5CyYD+UkG08+xt+4wLVQZA1tzxthm2tEfD3JxARH7QkbD1ZuozaggdZbxK5kAIsf5qGaKMTY2lAU/rH5HW3PLsEwUYy+YCcERmIjJpDcpzb6l7th9KtQ69fi09ePUej9l7cx2DJbD7UrG3r3afQHOyCo+V3QQzE35pvQvnAZukk5zL5qRL59jsKbPzdheXoBZc4saFhBS6AO7V4zqCpiawuptwQG+UAa7Ct3UT0hh9p9EnXT5Vh6t4C22QaUDh6HwnECOmcO7K+6kW49DKqS2DrEZCtfuI+9GrNHg4fMHVSO5kE7nAPVkAxKBxcOzsajpS4Yh4ohUPPWKTUh3PaQEptIOr6BiJjcZXCwktaAGfrRIpwblqOV3YKdhfXOIvBLeREWpnd8ynsaSJoyESFphwTtfjN6X1jRO2+FxWtCWksqBApeiFIR9K6fiTpPiigDoadqCEag5YUFKl6Yrciw0VOlhOivv/Ff8wtn0KzlebrUYwAAAABJRU5ErkJggg==) no-repeat center!important}.w2ui-icon.icon-edit{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFUSURBVDjLrZM/SAJxGIZdWwuDlnCplkAEm1zkaIiGFFpyMIwGK5KGoK2lphDKkMDg3LLUSIJsSKhIi+684CokOtTiMizCGuzEU5K3vOEgKvtBDe/2Pc8H3x8NAM1fQlx4H9M3pcOWp6TXWmM8A7j0629v1nraiAVC0IrrwATKIgs5xyG5QiE+Z4iQdoeU2oAsnqCSO1NSTu+D9VhqRLD8nIB8F0Q2MgmJDyipCzjvYJkIfpN2UBLG8MpP4dxvQ3ZzGuyyBQ2H+AnOOCBd9aL6soh81A5hyYSGWyCFvxUcerqI4S+CvYVOFPMHxLAq8I3qdHVY5LbBhJzEsCrwutpRFBlUHy6wO2tEYtWAzLELPN2P03kjfj3luqDycV2F8AgefWbEnVqEHa2IznSD6BdsVDNStB0lfh0FPoQjdx8RrAqGzC0YprSgxzsUMOY2bf37N/6Ud1Vc9yYcH50CAAAAAElFTkSuQmCC) no-repeat center!important}.w2ui-icon.icon-bullet-black{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABlSURBVCjPY/jPgB8yDC4FilKKDfJXZa6KNwhKYVfQkPW/63/b/+T/XA1YFchd7fqf/j/2f+N/5qtYFUhe7fif9D/sf91/BuwKhBoS/jcBpcP/M2C3gluKrYHhKhA2MEgN2pDEDgEb0f5zlvXgVgAAAABJRU5ErkJggg==) no-repeat center!important}.w2ui-icon.icon-folder{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGrSURBVDjLxZO7ihRBFIa/6u0ZW7GHBUV0UQQTZzd3QdhMQxOfwMRXEANBMNQX0MzAzFAwEzHwARbNFDdwEd31Mj3X7a6uOr9BtzNjYjKBJ6nicP7v3KqcJFaxhBVtZUAK8OHlld2st7Xl3DJPVONP+zEUV4HqL5UDYHr5xvuQAjgl/Qs7TzvOOVAjxjlC+ePSwe6DfbVegLVuT4r14eTr6zvA8xSAoBLzx6pvj4l+DZIezuVkG9fY2H7YRQIMZIBwycmzH1/s3F8AapfIPNF3kQk7+kw9PWBy+IZOdg5Ug3mkAATy/t0usovzGeCUWTjCz0B+Sj0ekfdvkZ3abBv+U4GaCtJ1iEm6ANQJ6fEzrG/engcKw/wXQvEKxSEKQxRGKE7Izt+DSiwBJMUSm71rguMYhQKrBygOIRStf4TiFFRBvbRGKiQLWP29yRSHKBTtfdBmHs0BUpgvtgF4yRFR+NUKi0XZcYjCeCG2smkzLAHkbRBmP0/Uk26O5YnUActBp1GsAI+S5nRJJJal5K1aAMrq0d6Tm9uI6zjyf75dAe6tx/SsWeD//o2/Ab6IH3/h25pOAAAAAElFTkSuQmCC) no-repeat center!important}.w2ui-icon.icon-page{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAINSURBVBgZBcG/r55zGAfg6/4+z3va01NHlYgzEfE7MdCIGISFgS4Gk8ViYyM2Mdlsko4GSf8Do0FLRCIkghhYJA3aVBtEz3nP89wf11VJvPDepdd390+8Nso5nESBQoq0pfvXm9fzWf19453LF85vASqJlz748vInb517dIw6EyYBIIG49u+xi9/c9MdvR//99MPPZ7+4cP4IZhhTPbwzT2d+vGoaVRRp1rRliVvHq+cfvM3TD82+7mun0o/ceO7NT+/4/KOXjwZU1ekk0840bAZzMQ2mooqh0A72d5x/6sB9D5zYnff3PoYBoWBgFKPKqDKqjCpjKr//dcu9p489dra88cydps30KswACfNEKanSaxhlntjJ8Mv12Paie+vZ+0+oeSwwQ0Iw1xAR1CiFNJkGO4wu3ZMY1AAzBI0qSgmCNJsJUEOtJSMaCTBDLyQ0CknAGOgyTyFFiLI2awMzdEcSQgSAAKVUmAeNkxvWJWCGtVlDmgYQ0GFtgg4pNtOwbBcwQy/Rife/2yrRRVI0qYCEBly8Z+P4qMEMy7JaVw72N568e+iwhrXoECQkfH91kY7jwwXMsBx1L93ZruqrK6uuiAIdSnTIKKPLPFcvay8ww/Hh+ufeznTXu49v95IMoQG3784gYXdTqvRmqn/Wpa/ADFX58MW3L71SVU9ETgEIQQQIOOzub+fhIvwPRDgeVjWDahIAAAAASUVORK5CYII=) no-repeat center!important}.w2ui-lock{opacity:.15;filter:alpha(opacity=15);background-color:#333;position:absolute;z-index:1400;display:none}.w2ui-lock-msg{position:absolute;z-index:1400;width:200px;height:80px;padding:30px 8px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:13px;font-family:Verdana,Arial;opacity:.8;filter:alpha(opacity=15);background-color:#555;color:#fff;text-align:center;border-radius:5px;border:2px solid #444;display:none}.w2ui-lock-msg .w2ui-spinner{display:inline-block;width:24px;height:24px;margin:-3px 8px -7px -10px}.w2ui-form{position:relative;color:#000;background-color:#f5f6f7;border:1px solid silver;border-radius:3px;padding:0;overflow:hidden!important}.w2ui-form>div{position:absolute;overflow:hidden}.w2ui-form .w2ui-form-header{position:absolute;left:0;right:0;border-bottom:1px solid #99bbe8!important;overflow:hidden;color:#444;font-size:13px;text-align:center;padding:8px;background-image:-webkit-linear-gradient(#dae6f3,#c2d5ed);background-image:-moz-linear-gradient(#dae6f3,#c2d5ed);background-image:-ms-linear-gradient(#dae6f3,#c2d5ed);background-image:-o-linear-gradient(#dae6f3,#c2d5ed);background-image:linear-gradient(#dae6f3,#c2d5ed);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3', endColorstr='#ffc2d5ed', GradientType=0);border-top-left-radius:3px;border-top-right-radius:3px}.w2ui-form .w2ui-form-toolbar{position:absolute;left:0;right:0;margin:0;padding:6px 3px;border-bottom:1px solid #d5d8d8}.w2ui-form .w2ui-form-tabs{margin:0;padding:0}.w2ui-form .w2ui-tabs{position:absolute;left:0;right:0;border-top-left-radius:3px;border-top-right-radius:3px;padding-top:5px!important;background-color:#fafafa}.w2ui-form .w2ui-tabs .w2ui-tab.active{background-color:#f5f6f7}.w2ui-form .w2ui-page{position:absolute;left:0;right:0;overflow:auto;padding:10px;border-left:1px solid inherit;border-right:1px solid inherit;background-color:inherit;border-radius:3px}.w2ui-form .w2ui-buttons{position:absolute;left:0;right:0;bottom:0;text-align:center;border-top:1px solid #d5d8d8;border-bottom:0 solid #d5d8d8;background-color:#fafafa;padding:15px 0!important;border-bottom-left-radius:3px;border-bottom-right-radius:3px}.w2ui-form .w2ui-buttons input[type=button],.w2ui-form .w2ui-buttons button{width:80px;margin-right:5px}.w2ui-form input[type=checkbox]{margin-top:4px;margin-bottom:4px}.w2ui-group{background-color:#ebecef;margin:5px 0 10px;padding:10px 5px;border-top:1px solid #cedcea;border-bottom:1px solid #cedcea}.w2ui-label{float:left;margin-top:6px;margin-bottom:3px;width:120px;padding:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:right;min-height:20px}.w2ui-label.w2ui-span1{width:20px;float:left}.w2ui-label.w2ui-span2{width:40px;float:left}.w2ui-label.w2ui-span3{width:60px;float:left}.w2ui-label.w2ui-span4{width:80px;float:left}.w2ui-label.w2ui-span5{width:100px;float:left}.w2ui-label.w2ui-span6{width:120px;float:left}.w2ui-label.w2ui-span7{width:140px;float:left}.w2ui-label.w2ui-span8{width:160px;float:left}.w2ui-label.w2ui-span9{width:180px;float:left}.w2ui-label.w2ui-span10{width:200px;float:left}.w2ui-field{margin-bottom:3px;margin-left:128px;padding:3px;min-height:20px}.w2ui-field.w2ui-span1{margin-left:28px;float:none}.w2ui-field.w2ui-span2{margin-left:48px;float:none}.w2ui-field.w2ui-span3{margin-left:68px;float:none}.w2ui-field.w2ui-span4{margin-left:88px;float:none}.w2ui-field.w2ui-span5{margin-left:108px;float:none}.w2ui-field.w2ui-span6{margin-left:128px;float:none}.w2ui-field.w2ui-span7{margin-left:148px;float:none}.w2ui-field.w2ui-span8{margin-left:168px;float:none}.w2ui-field.w2ui-span9{margin-left:188px;float:none}.w2ui-field.w2ui-span10{margin-left:208px;float:none}.w2ui-required{position:relative}.w2ui-required::before{content:'*';position:absolute;margin-top:5px;margin-left:-9px;color:red}.w2ui-error{border:1px solid #ffa8a8!important;background-color:#fff4eb!important}.w2ui-field-helper{position:absolute;display:inline-block;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-field-helper .w2ui-field-up{position:absolute;top:0;padding:2px 3px}.w2ui-field-helper .w2ui-field-down{position:absolute;bottom:0;padding:2px 3px}.w2ui-field-helper .arrow-up:hover{border-bottom-color:#81C6FF}.w2ui-field-helper .arrow-down:hover{border-top-color:#81C6FF}.w2ui-field-helper .arrow-up{width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-bottom:5px solid #777;font-size:0;line-height:0}.w2ui-field-helper .arrow-down{width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #777;font-size:0;line-height:0}.w2ui-field-helper .arrow-left{width:0;height:0;border-bottom:4px solid transparent;border-top:4px solid transparent;border-right:5px solid #777;font-size:0;line-height:0}.w2ui-field-helper .arrow-right{width:0;height:0;border-bottom:4px solid transparent;border-top:4px solid transparent;border-left:5px solid #777;font-size:0;line-height:0}.w2ui-color{padding:5px;background-color:#fff;border-radius:3px}.w2ui-color>table{table-layout:fixed;width:160px}.w2ui-color>table td{width:20px;height:20px}.w2ui-color>table td div{cursor:pointer;display:inline-block;width:16px;height:17px;padding:1px 4px;border:1px solid transparent;color:#fff;text-shadow:0 0 2px #000}.w2ui-color>table td div:hover{outline:1px solid #666;border:1px solid #fff}.w2ui-calendar{position:absolute;z-index:1600;display:none;margin:3px 0 0 -2px;padding:0;border:1px solid #aaa;border-radius:4px;box-shadow:2px 2px 8px #bbb;line-height:108%}.w2ui-calendar .w2ui-calendar-title{padding:5px 1px 6px;border-top-left-radius:4px;border-top-right-radius:4px;background-image:-webkit-linear-gradient(#e6e6e6,#c2c4c4);background-image:-moz-linear-gradient(#e6e6e6,#c2c4c4);background-image:-ms-linear-gradient(#e6e6e6,#c2c4c4);background-image:-o-linear-gradient(#e6e6e6,#c2c4c4);background-image:linear-gradient(#e6e6e6,#c2c4c4);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffe6e6e6', endColorstr='#ffc2c4c4', GradientType=0);border-bottom:1px solid #999;color:#000;text-align:center;font-weight:700}.w2ui-calendar .w2ui-calendar-previous,.w2ui-calendar .w2ui-calendar-next{width:24px;height:20px;color:#666;border:1px solid transparent;border-radius:3px;padding:2px 3px 1px 2px;margin:-4px 0 0 0;cursor:default}.w2ui-calendar .w2ui-calendar-previous:hover,.w2ui-calendar .w2ui-calendar-next:hover{border:1px solid silver;background-color:#efefef}.w2ui-calendar .w2ui-calendar-previous{float:left}.w2ui-calendar .w2ui-calendar-next{float:right}.w2ui-calendar table.w2ui-calendar-days{border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:0}.w2ui-calendar table.w2ui-calendar-days td{border:1px solid #e8e8e8;color:#000;background-color:#f4f4fe;padding:5px;cursor:default;text-align:right}.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday,.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday{border:1px solid #e8e8e8;color:#c8493b;background-color:#f4f4fe}.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday:hover,.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday:hover{border:1px solid #aaa;color:#000;background-color:#ff0}.w2ui-calendar table.w2ui-calendar-days td.w2ui-today{border:1px solid #8cb067;color:#000;background-color:#e2f7cd}.w2ui-calendar table.w2ui-calendar-days td:hover{border:1px solid #aaa;color:#000;background-color:#ff0}.w2ui-calendar table.w2ui-calendar-days td.w2ui-blocked-date{text-decoration:line-through;border:1px solid #e8e8e8;color:gray;background-color:#e8e8e8}.w2ui-calendar table.w2ui-calendar-days td.w2ui-day-empty{border:1px solid #e8e8e8;background-color:#f4f4fe}.w2ui-calendar table.w2ui-calendar-days tr.w2ui-day-title td{border:1px solid #e8e8e8;color:gray;background-color:#e8e8e8;text-align:center;padding:5px}.w2ui-list{color:inherit;position:absolute;padding:0;margin:0;min-height:25px;overflow:auto;border:1px solid silver;border-radius:3px;font-size:6px;line-height:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;background-color:#fff}.w2ui-list input[type=text]{-webkit-box-shadow:none;-moz-box-shadow:none;-ms-box-shadow:none;-o-box-shadow:none;box-shadow:none}.w2ui-list ul{list-style-type:none;background-color:#000;margin:0;padding:0}.w2ui-list ul li{float:left;margin:2px 1px 0 2px;border-radius:3px;width:auto;padding:1px 5px;border:1px solid #88b0d6;background-color:#eff3f5;white-space:nowrap;cursor:default;font-family:verdana;font-size:11px;line-height:normal}.w2ui-list ul li:hover{background-color:#d0dbe1}.w2ui-list ul li:last-child{border-radius:0;border:1px solid transparent;background-color:transparent}.w2ui-list ul li:last-child input{padding:0;margin:0;outline:0;border:0}.w2ui-list ul li div{float:right;width:15px;height:16px;margin:-1px -3px 0 4px;border-radius:15px}.w2ui-list ul li div:hover{background-color:#D77F7F;color:#fff}.w2ui-list ul li div:before{position:relative;top:1px;left:4px;color:inherit;opacity:.6;text-shadow:inherit;content:'x'}.w2ui-list ul li input{width:10px;background-color:transparent}.w2ui-items{position:absolute;margin-top:6px;display:none;z-index:1600;background-color:#fff;border:3px solid #777;box-shadow:0 3px 8px #999;border-radius:4px;text-align:left}.w2ui-items:before{content:"";position:absolute;z-index:1601;width:0;height:0;border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid transparent;border-bottom-color:inherit;margin:-8px 0 0 5px}.w2ui-items .w2ui-items-list{border-radius:4px;padding:3px}.w2ui-items .w2ui-empty-list{padding:5px 2px;text-align:center;color:gray}.w2ui-items ul li{display:block;-webkit-transition:all .2s;-moz-transition:all .2s;-ms-transition:all .2s;-o-transition:all .2s;transition:all .2s;padding:5px;cursor:pointer}.w2ui-items ul li.w2ui-item-even{color:inherit;background-color:#fff}.w2ui-items ul li.w2ui-item-odd{color:inherit;background-color:#f3f6fa}.w2ui-items ul li.w2ui-item-group{color:#444;font-weight:700;background-color:#ECEDF0;border-bottom:1px solid #D3D2D4}.w2ui-items ul li.selected{color:inherit;background-color:#b6d5ff}.w2ui-upload{position:absolute;background-color:#fff;border:1px solid silver!important;border-radius:3px;text-align:center;overflow:auto}.w2ui-upload>span:first-child{pointer-events:none;margin:0;padding:0;font-size:14px!important;color:#999}.w2ui-upload.dragover{background-color:#D9FFD5;border:1px solid #93E07D}.w2ui-upload .file-list{margin:0;padding:0;margin-bottom:6px}.w2ui-upload .file-list li{padding:2px 5px;font-family:verdana;font-size:11px;line-height:normal;float:left;display:inline-block;border:1px solid #88b0d6;background-color:#eff3f5;border-radius:3px;margin:2px 0 2px 2px;text-align:left;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;cursor:default;width:auto;max-width:400px}.w2ui-upload .file-list li:hover{background-color:#d0dbe1}.w2ui-upload .file-list li>span.file-size{pointer-events:none;color:#777}.w2ui-upload .file-list li>span.file-name{pointer-events:none}.w2ui-upload .file-list li>div.file-delete{float:right;z-index:1;width:16px;height:16px;margin:-1px -4px 0 4px;border-radius:15px}.w2ui-upload .file-list li>div.file-delete:hover{background-color:#D77F7F;color:#fff}.w2ui-upload .file-list li>div.file-delete:before{position:relative;top:1px;left:5px;opacity:.6;color:inherit;text-shadow:inherit;content:'x'}.w2ui-layout{overflow:hidden!important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout>div{position:absolute;overflow:hidden;border:0;margin:0;padding:0;outline:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout>div .w2ui-panel{display:none;position:absolute;z-index:120}.w2ui-layout>div .w2ui-panel .w2ui-panel-tabs{position:absolute;left:0;top:0;right:0;z-index:2;display:none;overflow:hidden;background-color:#fafafa;padding:4px 0}.w2ui-layout>div .w2ui-panel .w2ui-panel-tabs>.w2ui-tab.active{background-color:#f5f6f7}.w2ui-layout>div .w2ui-panel .w2ui-panel-toolbar{position:absolute;left:0;top:0;right:0;z-index:2;display:none;overflow:hidden;background-color:#fafafa;border-bottom:1px solid silver;padding:4px}.w2ui-layout>div .w2ui-panel .w2ui-panel-content{position:absolute;left:0;top:0;right:0;bottom:0;z-index:1;color:inherit;background-color:#f5f6f7}.w2ui-layout>div .w2ui-resizer{display:none;position:absolute;z-index:121;background-color:transparent}.w2ui-layout>div .w2ui-resizer:hover,.w2ui-layout>div .w2ui-resizer.active{background-color:#d7e4f2}.w2ui-grid{position:relative;border:1px solid silver;border-radius:2px;overflow:hidden!important}.w2ui-grid>div{position:absolute;overflow:hidden}.w2ui-grid .w2ui-grid-header{position:absolute;border-bottom:1px solid #99bbe8!important;height:28px;overflow:hidden;color:#444;font-size:13px;text-align:center;padding:7px;background-image:-webkit-linear-gradient(#dae6f3,#c2d5ed);background-image:-moz-linear-gradient(#dae6f3,#c2d5ed);background-image:-ms-linear-gradient(#dae6f3,#c2d5ed);background-image:-o-linear-gradient(#dae6f3,#c2d5ed);background-image:linear-gradient(#dae6f3,#c2d5ed);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3', endColorstr='#ffc2d5ed', GradientType=0);border-top-left-radius:2px;border-top-right-radius:2px}.w2ui-grid .w2ui-grid-toolbar{position:absolute;border-bottom:1px solid silver;background-color:#dee0e4;height:38px;padding:7px 3px 4px;margin:0;box-shadow:0 1px 2px #ddd}.w2ui-grid .w2ui-toolbar-search{width:160px}.w2ui-grid .w2ui-toolbar-search .w2ui-search-all{outline:0;width:160px;border-radius:10px;line-height:100%;height:22px;border:1px solid #999;color:#000;background-color:#fff;padding:3px 18px 3px 23px;margin:0}.w2ui-grid .w2ui-toolbar-search .w2ui-search-down{position:absolute;margin-top:-7px;margin-left:6px}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear{position:absolute;width:16px;height:16px;margin-top:-8px;margin-left:-20px;border-radius:15px}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:hover{background-color:#D77F7F;color:#fff}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:before{position:relative;top:1px;left:5px;opacity:.6;color:inherit;text-shadow:inherit;content:'x'}.w2ui-grid .w2ui-grid-body{position:absolute;overflow:hidden;padding:0;background-color:#fff;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-grid .w2ui-grid-body input,.w2ui-grid .w2ui-grid-body select,.w2ui-grid .w2ui-grid-body textarea{-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;-o-user-select:text;user-select:text}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns{overflow:hidden;position:absolute;left:0;top:0;right:0;box-shadow:0 1px 4px #ddd;height:auto}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns table{height:auto}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns .w2ui-resizer{position:absolute;display:block;background-image:none;background-color:rgba(0,0,0,0);padding:0;margin:0;width:6px;height:12px;cursor:col-resize}.w2ui-grid .w2ui-grid-body .w2ui-grid-records{position:absolute;left:0;right:0;top:0;bottom:0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd{color:inherit;background-color:#fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd.w2ui-empty-record:hover{background-color:#fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even{color:inherit;background-color:#f3f6fa}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even.w2ui-empty-record:hover{background-color:#f3f6fa}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected,.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected{color:#000!important;background-color:#b6d5ff!important}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded{background-color:#CCDCF0!important}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1{height:0;border-bottom:1px solid #b2bac0;background-color:#CCDCF0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1>div{height:100%;margin:0;padding:0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2{height:0;border-radius:0;border-bottom:1px solid #b2bac0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2>div{height:0;border:0;transition:height .3s,opacity .3s}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more{border-top:1px solid #d6d5d7;cursor:pointer}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more>div{text-align:center;color:#777;background-color:rgba(233,237,243,.5);padding:10px 0 15px;border-top:1px solid #fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more>div:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body table{border-spacing:0;border-collapse:collapse;table-layout:fixed;width:1px}.w2ui-grid .w2ui-grid-body table .w2ui-head{margin:0;padding:0;border-right:1px solid #c5c5c5;border-bottom:1px solid #c5c5c5;color:#000;background-image:-webkit-linear-gradient(#f9f9f9,#e4e4e4);background-image:-moz-linear-gradient(#f9f9f9,#e4e4e4);background-image:-ms-linear-gradient(#f9f9f9,#e4e4e4);background-image:-o-linear-gradient(#f9f9f9,#e4e4e4);background-image:linear-gradient(#f9f9f9,#e4e4e4);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#fff9f9f9', endColorstr='#ffe4e4e4', GradientType=0)}.w2ui-grid .w2ui-grid-body table .w2ui-head>div{padding:7px 3px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.w2ui-grid .w2ui-grid-body table td{border-right:1px solid #d6d5d7;border-bottom:0 solid #d6d5d7;cursor:default;overflow:hidden}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data{margin:0;padding:0}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data>div{padding:3px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data>div.flexible-record{height:auto;overflow:visible;white-space:normal}.w2ui-grid .w2ui-grid-body table td:last-child{border-right:0}.w2ui-grid .w2ui-grid-body table .w2ui-col-number{width:34px;color:#777;background-color:rgba(233,237,243,.5)}.w2ui-grid .w2ui-grid-body table .w2ui-col-number div{padding:0 7px 0 3px;text-align:right}.w2ui-grid .w2ui-grid-body table .w2ui-col-select{width:26px}.w2ui-grid .w2ui-grid-body table .w2ui-col-select div{padding:0;text-align:center;overflow:hidden}.w2ui-grid .w2ui-grid-body table .w2ui-col-select div input[type=checkbox]{margin-top:2px;position:relative}.w2ui-grid .w2ui-grid-body table .w2ui-col-expand{width:26px}.w2ui-grid .w2ui-grid-body table .w2ui-col-expand div{padding:0;text-align:center;font-weight:700}.w2ui-grid .w2ui-grid-body div.w2ui-sort-up{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAICAYAAADN5B7xAAAACXBIWXMAAAOUAAADlAFKEakrAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAHRJREFUeNpi/P//PwMpgImBRMACY6QX109jZGDIxKboPyNj18yehnIUG97zMRUwMP6vx1DMxNA4q7exHMZnhPmBkZGRITQ0lFlITqOa4T9jI1xxT1MDAwMDA9yv////Z0D3eFpRXVNaSV0Dik1QdYw0DyXAAMW0LzgWrYMxAAAAAElFTkSuQmCC) no-repeat center right!important;height:auto!important;width:100%;overflow:hidden}.w2ui-grid .w2ui-grid-body div.w2ui-sort-down{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAICAYAAADN5B7xAAAACXBIWXMAAAOUAAADlAFKEakrAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAHlJREFUeNpi/P//PwMpgImBRMACYzAyMsIF04rqmhiYGP7N6mlqgInBXMIIZzAyMoSGhjILyWlUM/xnbGRgYGD4z8TQCNOEoSGssZFN6PPfCphiuMlQTTB1cCcJfvo3gYGBMRPdzYz/GOrTius5GRgYylFsoFkoAQYAPsMwVrH0kTAAAAAASUVORK5CYII=) no-repeat center right!important;height:auto!important;width:100%;overflow:hidden}.w2ui-grid .w2ui-grid-body .w2ui-col-group{text-align:center}.w2ui-grid .w2ui-changed{background:url(data:image/gif;base64,R0lGODlhCgAKAJEAALAABf///wAAAAAAACH5BAEAAAIALAAAAAAKAAoAAAIPlI8Hy8mbxIsSUnup3rQAADs=) no-repeat top right}.w2ui-grid .w2ui-editable{overflow:hidden;height:100%!important;margin:0!important;padding:0!important}.w2ui-grid .w2ui-editable input{border:0;border-radius:0;margin:0;padding:4px 3px;width:100%;height:100%}.w2ui-grid .w2ui-grid-summary{position:absolute;box-shadow:0 -1px 4px #aaa}.w2ui-grid .w2ui-grid-summary table{color:inherit}.w2ui-grid .w2ui-grid-summary table .w2ui-odd{background-color:#eef5eb}.w2ui-grid .w2ui-grid-summary table .w2ui-even{background-color:#f8fff5}.w2ui-grid .w2ui-grid-footer{position:absolute;margin:0;padding:0;text-align:center;height:24px;overflow:hidden;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;-o-user-select:text;user-select:text;box-shadow:0 -1px 4px #eee;color:#444;background-color:#f8f8f8;border-top:1px solid #ddd;border-bottom-left-radius:2px;border-bottom-right-radius:2px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-left{float:left;padding-top:5px;padding-left:5px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-right{float:right;padding-top:5px;padding-right:5px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center{padding:2px;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav{width:110px;margin:0 auto;padding:0;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav input[type=text]{padding:1px 2px 2px;border-radius:3px;width:40px;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn{display:inline-block;border-radius:3px;cursor:pointer;font-size:11px;line-height:16px;padding:1px 5px;width:30px;height:18px;margin-top:-1px;color:#000;background-color:transparent}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn:hover{color:#000;background-color:#aec8ff}.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover{background-color:inherit}.w2ui-ss .w2ui-grid-records table td{border-right-width:1px;border-bottom:1px solid #efefef}.w2ui-ss .w2ui-grid-records table tr:first-child td{border-bottom:0}.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected{background-color:#EEF4FE!important}.w2ui-ss .w2ui-changed{background:inherit}.w2ui-ss .w2ui-grid-body .w2ui-selection{position:absolute;border:2px solid #6299DA;pointer-events:none}.w2ui-ss .w2ui-grid-body .w2ui-selection .w2ui-selection-resizer{cursor:crosshair;position:absolute;bottom:0;right:0;width:6px;height:6px;margin-right:-3px;margin-bottom:-3px;background-color:#457FC2;border:.5px solid #fff;outline:1px solid #fff;pointer-events:auto}.w2ui-overlay .w2ui-select-field{padding:8px 5px;cursor:default}.w2ui-overlay .w2ui-select-field table{font-size:11px;font-family:Verdana,Arial;border-spacing:0;border-collapse:border-collapse}.w2ui-overlay .w2ui-select-field table tr:hover{background-color:#b6d5ff}.w2ui-overlay .w2ui-select-field table td:nth-child(1){padding:3px 3px 3px 6px}.w2ui-overlay .w2ui-select-field table td:nth-child(1) input{margin:3px 2px 2px}.w2ui-overlay .w2ui-select-field table td:nth-child(2){padding:3px 15px 3px 3px}.w2ui-overlay .w2ui-col-on-off{padding:4px 0}.w2ui-overlay .w2ui-col-on-off table{border-spacing:0;border-collapse:border-collapse}.w2ui-overlay .w2ui-col-on-off table tr:hover{background-color:#b6d5ff}.w2ui-overlay .w2ui-col-on-off table td input[type=checkbox]{margin:3px 2px 2px}.w2ui-overlay .w2ui-col-on-off table td label{display:block;padding:3px 0;padding-right:10px}.w2ui-overlay .w2ui-col-on-off table td:first-child{padding:4px 0 4px 6px}.w2ui-overlay .w2ui-col-on-off table td:last-child{padding:4px 6px 4px 0}.w2ui-overlay .w2ui-grid-searches{text-align:left;padding:0;border-top:0;background-color:#f3f1d9}.w2ui-overlay .w2ui-grid-searches table{padding:4px;padding-top:8px;border-collapse:border-collapse}.w2ui-overlay .w2ui-grid-searches table td{padding:4px}.w2ui-overlay .w2ui-grid-searches table td.close-btn{width:20px;padding-right:20px}.w2ui-overlay .w2ui-grid-searches table td.close-btn input{width:25px!important}.w2ui-overlay .w2ui-grid-searches table td.caption{text-align:right;padding-right:5px;border-right:1px solid silver}.w2ui-overlay .w2ui-grid-searches table td.operator{text-align:left;padding:0 10px;padding-right:5px;border-right:1px solid silver}.w2ui-overlay .w2ui-grid-searches table td.value{padding-right:5px;padding-left:5px;background-color:#f7f6f0}.w2ui-overlay .w2ui-grid-searches table td.value input[type=text]{border-radius:3px;padding:3px;margin-right:3px;height:23px}.w2ui-overlay .w2ui-grid-searches table td.value select{padding:3px;margin-right:3px;height:23px}.w2ui-overlay .w2ui-grid-searches table td.actions{border-right:0;padding:20px 0 10px;text-align:center}.w2ui-overlay .w2ui-grid-searches table td input[type=button]{width:70px;margin:0 2px}.w2ui-popup{position:fixed;z-index:1600;overflow:hidden;font-family:Verdana,Arial;border-radius:6px;padding:0;margin:0;border:1px solid #777;background-color:#eee;box-shadow:0 0 25px #555}.w2ui-popup,.w2ui-popup *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-popup .w2ui-msg-title{padding:6px;border-radius:6px 6px 0 0;background-image:-webkit-linear-gradient(#ececec,#dfdfdf);background-image:-moz-linear-gradient(#ececec,#dfdfdf);background-image:-ms-linear-gradient(#ececec,#dfdfdf);background-image:-o-linear-gradient(#ececec,#dfdfdf);background-image:linear-gradient(#ececec,#dfdfdf);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffececec', endColorstr='#ffdfdfdf', GradientType=0);border-bottom:2px solid #bfbfbf;position:absolute;overflow:hidden;height:32px;left:0;right:0;top:0;text-overflow:ellipsis;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;cursor:move;font-size:15px;color:#555;z-index:300}.w2ui-popup .w2ui-msg-button{float:right;width:18px;height:18px;cursor:pointer;overflow:hidden;padding:0;margin:0 3px 0 0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAj1JREFUeNrslr9rFFEQxz/zZi/qxSgW2lsqkiYoBku5Ro1o4UFKEYkgSaxSCLYqdv5IEVPYCMJJwERWrK0CKhoQ8hdobQTjXW7njcXlYnLunQQu0YDTLOy+Nzvfme98Z8Td2ckW2OGWdMvRvYfT/RGfBPoBBVpLK0AEPgVkdGL06vt/CoB5nBaRE8AXYKXNsQIwaB4fAwOtH+88mn4m7ifN4vUYebWBKkFKqjIV3N9NjI2Uuw5ARI45fBanH+F77iFnN8JHETmS68P9NHBQNTwHL8foaSN4SqoyA/SZyL4tqQAQBVYCLOFYlNxmq0WorVLpN9Oe5LKt1CsgRVWpAOfB66phBuhTkepSdfnKVjaxNJMSWn/iawmTtpeDp6pWBpaBoqrMqoYU6AOqIbFhxGa3R4V8nfNNKLUESzXJhoCvQC+wF/gW1C5IiC+2XUbD5jA3rd4C26NR3945IA2iRzqRJgdElJJlSQocAKrAD2A/6Ev3cLajjN59MDWHyKl2voOI1zKbv3Xj2lCHJFoz+LXuBoIAjnUklEvJrDDT5LwmdhG8blkyBxRjXSu4loE0X4VEznXKV3SnoOFMB7YUolBcbcKNdxuPXUBPu8pbLXsK0ghebVjEXgNoYmXLtGLuxd6ePU+AQ20AaIrb4DpFycmSv81/7YsiMgAstB1kQgE47O4LuQmCNwGOB7VxCb/URsRSTbhkmU4ifGiZHd1Z5m7fnxoIQSaBo39YJRZj9LGb4yPzXWm1/9voX7afAwAC5tacDTA2XgAAAABJRU5ErkJggg==) no-repeat center left;background-position:0 0;color:transparent!important;border-radius:3px;border:1px solid transparent}.w2ui-popup .w2ui-msg-close{margin-top:0;background-position:-32px 0}.w2ui-popup .w2ui-msg-close:hover{background-color:#ccc;border:1px solid #aaa}.w2ui-popup .w2ui-msg-max{background-position:-16px 0}.w2ui-popup .w2ui-msg-max:hover{background-color:#ccc;border:1px solid #aaa}.w2ui-popup .w2ui-box1,.w2ui-popup .w2ui-box2{position:absolute;left:0;right:0;top:32px;bottom:35px;z-index:100}.w2ui-popup .w2ui-msg-body{font-size:13px;line-height:130%;padding:0 7px 7px;color:#000;background-color:#eee;position:absolute;overflow:auto;width:100%;height:100%}.w2ui-popup .w2ui-popup-message{position:absolute;z-index:250;background-color:#f9f9f9;border:1px solid #999;box-shadow:0 0 15px #aaa;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;border-top:0;border-radius:0 0 6px 6px;overflow:auto}.w2ui-popup .w2ui-msg-buttons{padding:8px;border-radius:0 0 6px 6px;border-top:1px solid #d5d8d8;background-color:#f1f1f1;text-align:center;position:absolute;overflow:hidden;height:42px;left:0;right:0;bottom:0;z-index:200}.w2ui-popup .w2ui-popup-button{width:70px;margin:0 5px}.w2ui-popup .w2ui-msg-no-title{border-top-left-radius:6px;border-top-right-radius:6px;top:0!important}.w2ui-popup .w2ui-msg-no-buttons{border-bottom-left-radius:6px;border-bottom-right-radius:6px;bottom:0!important}.w2ui-sidebar{cursor:default;overflow:hidden!important;background-color:#edf1f6!important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-sidebar *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-sidebar>div{position:relative;overflow:hidden}.w2ui-sidebar .w2ui-sidebar-top{position:absolute;z-index:2;top:0;left:0;right:0}.w2ui-sidebar .w2ui-sidebar-bottom{position:absolute;z-index:2;bottom:0;left:0;right:0}.w2ui-sidebar .w2ui-sidebar-div{position:absolute;z-index:1;overflow:auto;top:0;bottom:0;left:0;right:0;padding:2px 0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-sidebar .w2ui-sidebar-div table{width:100%}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node{background-image:-webkit-linear-gradient(#edf1f6,#edf1f6);background-image:-moz-linear-gradient(#edf1f6,#edf1f6);background-image:-ms-linear-gradient(#edf1f6,#edf1f6);background-image:-o-linear-gradient(#edf1f6,#edf1f6);background-image:linear-gradient(#edf1f6,#edf1f6);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffedf1f6', endColorstr='#ffedf1f6', GradientType=0);border-top:1px solid transparent;border-bottom:1px solid transparent;margin:0;padding:1px 0}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node table{pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots{color:#000;text-shadow:0 0 0 #fff;pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots:hover{color:inherit}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node:hover{border-top:1px solid #f9f9f9;border-bottom:1px solid #f9f9f9;background-image:-webkit-linear-gradient(#d7e1ef,#d7e1ef);background-image:-moz-linear-gradient(#d7e1ef,#d7e1ef);background-image:-ms-linear-gradient(#d7e1ef,#d7e1ef);background-image:-o-linear-gradient(#d7e1ef,#d7e1ef);background-image:linear-gradient(#d7e1ef,#d7e1ef);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffd7e1ef', endColorstr='#ffd7e1ef', GradientType=0)}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image{width:22px;text-align:center;pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span{color:#516173!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover{background-image:-webkit-linear-gradient(#69b1e0,#4a96d3);background-image:-moz-linear-gradient(#69b1e0,#4a96d3);background-image:-ms-linear-gradient(#69b1e0,#4a96d3);background-image:-o-linear-gradient(#69b1e0,#4a96d3);background-image:linear-gradient(#69b1e0,#4a96d3);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0', endColorstr='#ff4a96d3', GradientType=0);border-top:1px solid #5295cd;border-bottom:1px solid #2661a6}.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected td.w2ui-node-dots,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover td.w2ui-node-dots{color:#fff!important;text-shadow:1px 1px 2px #666!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover{background-image:-webkit-linear-gradient(#edf1f6,#edf1f6);background-image:-moz-linear-gradient(#edf1f6,#edf1f6);background-image:-ms-linear-gradient(#edf1f6,#edf1f6);background-image:-o-linear-gradient(#edf1f6,#edf1f6);background-image:linear-gradient(#edf1f6,#edf1f6);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffedf1f6', endColorstr='#ffedf1f6', GradientType=0);border-top:1px solid transparent;border-bottom:1px solid transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled td.w2ui-node-dots,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover td.w2ui-node-dots{opacity:.4;filter:alpha(opacity=15);color:#000!important;text-shadow:0 0 0 #fff!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-caption{white-space:nowrap;padding:5px 0 5px 3px;margin:1px 0 1px 22px;position:relative;z-index:1;font-size:12px}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group{white-space:nowrap;overflow:hidden;padding:10px 0 10px 10px;margin:0;cursor:default;color:#868b92;background-color:transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(1){margin-right:10px;float:right;color:transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(2){font-weight:400;text-transform:uppercase}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-sub{overflow:hidden}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots{width:18px;padding:0 0 1px 7px;text-align:center}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots .w2ui-expand{width:16px;margin-top:-3px;pointer-events:auto}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data{padding:1px 1px 3px}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image{padding:3px 0 0;float:left}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image>span{font-size:16px;color:#000;text-shadow:0 0 0 #fff}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image.w2ui-icon{margin-top:3px}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-count{float:right;border:1px solid #9da4af;border-radius:20px;width:auto;height:18px;padding:2px 7px;margin:3px 4px -2px 0;background-color:#e7f0fc;color:#667274;box-shadow:0 0 2px #fff;text-shadow:1px 1px 1px #e6e6e6;position:relative;z-index:2}.w2ui-tabs{cursor:default;overflow:hidden!important;background-color:#fafafa;padding:3px 0;padding-bottom:0!important}.w2ui-tabs table{border-bottom:1px solid silver;padding:0 7px}.w2ui-tabs .w2ui-tab{padding:6px 20px;text-align:center;color:#000;background-color:transparent;border:1px solid silver;border-bottom:1px solid silver;white-space:nowrap;margin:1px 1px -1px 0;border-top-left-radius:4px;border-top-right-radius:4px;cursor:default}.w2ui-tabs .w2ui-tab.active{color:#000;background-color:#fff;border:1px solid silver;border-bottom:1px solid transparent}.w2ui-tabs .w2ui-tab.closable{padding:6px 28px 6px 20px}.w2ui-tabs .w2ui-tab-close{color:#555;text-shadow:1px 1px 1px #bbb;float:right;margin:6px 4px 0 0;padding:0 0 0 5px;width:16px;height:16px;opacity:.9;border:0;border-top:3px solid transparent;border-radius:9px}.w2ui-tabs .w2ui-tab-close:hover{background-color:#D77F7F;color:#fff}.w2ui-tabs .w2ui-tab-close:before{position:relative;top:-2px;left:0;opacity:.6;color:inherit;text-shadow:inherit;content:'x'}.w2ui-toolbar{margin:0;padding:2px;outline:0;background-color:#efefef;overflow:hidden!important;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-toolbar .disabled{opacity:.3;filter:alpha(opacity=15)}.w2ui-toolbar table{table-layout:auto!important}.w2ui-toolbar table td{border:0!important}.w2ui-toolbar table.w2ui-button{margin:0 1px;border-radius:4px;height:24px;border:1px solid transparent;background-color:transparent}.w2ui-toolbar table.w2ui-button .w2ui-tb-image{width:16px;height:16px;padding:0;margin:3px!important;border:0!important;text-align:center}.w2ui-toolbar table.w2ui-button .w2ui-tb-image>span{font-size:16px;color:#516173}.w2ui-toolbar table.w2ui-button .w2ui-tb-caption{color:#000;padding:0 4px 0 2px}.w2ui-toolbar table.w2ui-button .w2ui-tb-down{width:12px;height:24px;display:block;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAICAYAAADN5B7xAAAACXBIWXMAAAOUAAADlAFKEakrAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAHRJREFUeNpi/P//PwMpgImBRMACY6QX109jZGDIxKboPyNj18yehnIUG97zMRUwMP6vx1DMxNA4q7exHMZnhPmBkZGRITQ0lFlITqOa4T9jI1xxT1MDAwMDA9yv////Z0D3eFpRXVNaSV0Dik1QdYw0DyXAAMW0LzgWrYMxAAAAAElFTkSuQmCC) no-repeat center right}.w2ui-toolbar table.w2ui-button.over{border:1px solid #ccc;background-color:#eee}.w2ui-toolbar table.w2ui-button.over .w2ui-tb-caption{color:#000}.w2ui-toolbar table.w2ui-button.down{border:1px solid #aaa;background-color:#ddd}.w2ui-toolbar table.w2ui-button.down .w2ui-tb-caption{color:#666}.w2ui-toolbar table.w2ui-button.checked{border:1px solid #aaa;background-color:#fff}.w2ui-toolbar table.w2ui-button.checked .w2ui-tb-caption{color:#000}.w2ui-toolbar table.w2ui-button table{height:17px;border-radius:4px;cursor:default}.w2ui-toolbar .w2ui-break{background-image:-webkit-linear-gradient(top,rgba(153,153,153,.09999999999999998) 0,#999 40%,#999 60%,rgba(153,153,153,.09999999999999998) 100%);background-image:-moz-linear-gradient(top,rgba(153,153,153,.09999999999999998) 0,#999 40%,#999 60%,rgba(153,153,153,.09999999999999998) 100%);background-image:-ms-linear-gradient(top,rgba(153,153,153,.09999999999999998) 0,#999 40%,#999 60%,rgba(153,153,153,.09999999999999998) 100%);background-image:-o-linear-gradient(top,rgba(153,153,153,.09999999999999998) 0,#999 40%,#999 60%,rgba(153,153,153,.09999999999999998) 100%);background-image:linear-gradient(top,rgba(153,153,153,.09999999999999998) 0,#999 40%,#999 60%,rgba(153,153,153,.09999999999999998) 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff999999', endColorstr='#ff999999', GradientType=0);width:1px!important;height:22px;padding:0;margin:0 6px}.w2ui-overlay table.w2ui-drop-menu{width:100%;color:#000;background-color:#fff;padding:5px 0;cursor:default}.w2ui-overlay table.w2ui-drop-menu td:first-child{padding:4px 0 4px 6px}.w2ui-overlay table.w2ui-drop-menu td:last-child{padding:10px 15px 10px 5px}.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected{background-color:#d7e4f2}.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected td{color:inherit}.w2ui-overlay table.w2ui-drop-menu .w2ui-tb-image>span{font-size:16px;color:#516173;display:inline-block;padding-top:4px} +@font-face{font-family:"w2ui-font";src:url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAWIAAoAAAAACAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAAA9AAAAEMAAABWQLxMsmNtYXAAAAE4AAAAOgAAAUriGRC2Z2x5ZgAAAXQAAAH9AAACgLu4vTRoZWFkAAADdAAAADAAAAA2AOYXBGhoZWEAAAOkAAAAIAAAACQD8wHHaG10eAAAA8QAAAAWAAAAIA7dAABsb2NhAAAD3AAAABIAAAASAngBuG1heHAAAAPwAAAAHwAAACABFQA2bmFtZQAABBAAAAEtAAACIsTQ/zJwb3N0AAAFQAAAAEgAAABi4/7ZEHicY2BkvMM4gYGVgYPRhTGNgYHBHUp/ZZBkaGFgYGJgZWbACgLSXFMYHD4yfmRnPPD/AIMe4wEGR6AwI0gOANHZC/IAeJxjYGBgZoBgGQZGBhBwAfIYwXwWBg0gzQakGRmYGBg+sv//D1LwkRFE8zNA1QMBIxvDiAcAddwGvgAAeJxFkLFv01AQxu97LrHdRImjpnaS1gnEia3IoqAktkkiEhaEOiCsDkEo8dyBDkytKpYKVWwssKKKAYmBREKMLJSFoRJ/AGJhY0NZGFgSzrUinvR+d++7T+/ePQLRci4IJ3SFCLIjG8CH+ZPwHHdwkkSS2PMXP3DGmUxpoo123lrt5nj8fjyejsc4W0zwNtl8FfHCKV5QnaOhF3IJUrUbkGPYnSGcGH6risBvGQhdVY0iVXXVkhJN1JL6/6xOIqWk4tRlJiVFiSJFSUrsZ+tkoqpEgt/6Hb/wjtZog2gonBx24AyFJUuNwMvha+/CvLi3vq1f785GsxGuTqfWc5O1N/r2+lNrOl38ZHnWpdUMr/CaLKLGZiHl4hI1+zasGB2/Dy9GSzfRbul4qaWPtHSQ0Y7SWpxmgnSc/mblMKNpmcOVEhfj+5d/8BGfqMl9bKuWFYWKaLf8YIAq9IKc5TY7ojNgTTcC7iEjaN4yPdswbM+81t8UimRLojq66YbdWq0bus375t21bwgcw/H6nmNUyhIkR/DsTasXPgx7VtV8oDx6XIxHE8vl8rMAzqlEDZ7QseUBPP6tLOQKDH5HqooKfLvB2gABa1lgflzI60VxsLd3IJj1YRn5/Wx9Syy++LvArn/JzH4e5WE98TCLer5wnBNb9WcrB5PoH084dg8AAAB4nGNgZGBgAOKMsPib8fw2Xxm4mRhA4PzjbBcY/f////1MjIwHgFwOBrA0AFcuDPF4nGNgZGBgPPD/AIMeEwMDw/9/TEwMQBEUwAEAe34EvHicY2JgYGCCYsbJCJpxO4QNABdTAesAAAAAAAAAEgAsAGgAjgC+AP4BQAAAeJxjYGRgYOBg0GJgZgABJiDmAkIGhv9gPgMADYEBTAB4nG2PTW7CMBCFXyBQFaQKtVKl7qwuuqkIPwsWHAD2LNiH4ARQEkeOQeICPUHP0DP0BF32DD1KX8IoixZbHn/z5o1/AAzwBQ/V8HBbx2q0cMPswm3SQNgnPwl30MezcJf6ULiHV8yE+3hAyBM8vzrtHk64hTu8Cbepvwv75A/hDh7xKdyl/i3cwxo/wn28eLN9ZPJhbHK30skxDW2TN7DWttybXE2CcaMtda5t6PRWbc6qPCVT52IVW5OpBas6TY0qrDnoyAU754r5aBSLHkQmwx4RDHL+Oq53hxU0EhyR8sf2Sv2/smaHRclKlStMEGB8xbekL6+9ITONLb0bnBlLnHjnlKqjW3FZ9mSkhfRqviclKxR17UAloh5gV3cVmGPEGf/xB/Ursl9uDmByAAAAeJxtwUEOgCAMBMAu0sI3SdMEIwKh8n8PXp2hQB+mf5kIAQciGIKEzFpNr6Sj7bs76xruMq3r2eJs22XZtPKIW1laiV6rCBDA") format("woff");font-weight:normal;font-style:normal}[class^="w2ui-icon-"]:before,[class*=" w2ui-icon-"]:before{font-family:"w2ui-font";display:inline-block;vertical-align:middle;line-height:1;font-weight:normal;font-style:normal;speak:none;text-decoration:inherit;text-transform:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.w2ui-icon-check:before{content:""}.w2ui-icon-columns:before{content:""}.w2ui-icon-cross:before{content:""}.w2ui-icon-pencil:before{content:""}.w2ui-icon-plus:before{content:""}.w2ui-icon-reload:before{content:""}.w2ui-icon-search:before{content:""}.w2ui-reset{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;font-family:Verdana,Arial,sans-serif;font-size:11px}.w2ui-reset *{color:default;line-height:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0}.w2ui-reset table{font-family:Verdana,Arial,sans-serif;font-size:11px;max-width:none;background-color:transparent;border-collapse:separate;border-spacing:0}.w2ui-reset input,.w2ui-reset textarea{width:auto;vertical-align:baseline;padding:4px}.w2ui-reset select{padding:1px;height:23px}.w2ui-centered{position:absolute;left:0;right:0;top:50%;-webkit-transform:translateY(-50%);-moz-transform:translateY(-50%);-ms-transform:translateY(-50%);-o-transform:translateY(-50%);transform:translateY(-50%);max-height:100%;margin:0;padding:0 10px;text-align:center}.w2ui-disabled,.w2ui-readonly{background-color:#f1f1f1!important;color:#777!important}input:not([type=button]),select,textarea{padding:4px;color:#000;background-color:#fff}input:not([type=button]):focus,select:focus,textarea:focus{outline-color:#72b2ff}input:not([type=button]):disabled,select:disabled,textarea:disabled,input:not([type=button])[readonly],select[readonly],textarea[readonly]{background-color:#f1f1f1;color:#777}input::-ms-clear{display:none}input:-ms-input-placeholder{color:#aaa!important}select{padding:2px}input[type="checkbox"].w2ui-toggle{position:absolute;opacity:0;width:46px;height:22px;padding:0;margin:0;margin-left:2px}input[type="checkbox"].w2ui-toggle+div{display:inline-block;width:46px;height:22px;border:1px solid #bbb;border-radius:30px;background-color:#eee;-webkit-transition-duration:.3s;-webkit-transition-property:background-color,box-shadow;-moz-transition-duration:.3s;-moz-transition-property:background-color,box-shadow;box-shadow:inset 0 0 0 0 rgba(0,0,0,.4);margin-left:2px}input[type="checkbox"].w2ui-toggle:disabled+div{opacity:.3}input[type="checkbox"].w2ui-toggle+div>div{float:left;width:22px;height:22px;border-radius:inherit;background:#f5f5f5;-webkit-transition-duration:.3s;-webkit-transition-property:transform,background-color,box-shadow;-moz-transition-duration:.3s;-moz-transition-property:transform,background-color;box-shadow:0 0 1px #323232,0 0 0 1px rgba(200,200,200,.6);pointer-events:none;margin-top:-1px;margin-left:-1px}input[type="checkbox"].w2ui-toggle:checked+div{border:1px solid #00a23f;box-shadow:inset 0 0 0 12px #54b350}input[type="checkbox"].w2ui-toggle:checked+div>div{-webkit-transform:translate3d(24px,0,0);-moz-transform:translate3d(24px,0,0);background-color:#fff;box-shadow:0 2px 5px rgba(0,0,0,.3),0 0 0 1px #00a23f}input[type="checkbox"].w2ui-toggle.blue:checked+div{border:1px solid #206fad;box-shadow:inset 0 0 0 12px #35a6eb}input[type="checkbox"].w2ui-toggle.blue:checked+div>div{box-shadow:0 2px 5px rgba(0,0,0,.3),0 0 0 1px #206fad}input[type=checkbox].w2ui-toggle:focus{outline:none}.w2ui-overlay{position:absolute;margin-top:6px;margin-left:-17px;display:none;z-index:1300;color:inherit;background-color:#fbfbfb;border:3px solid #777;box-shadow:0 2px 10px #999;border-radius:4px;text-align:left}.w2ui-overlay table td{color:inherit}.w2ui-overlay:before{content:"";position:absolute;-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg);width:12px;height:12px;border:3px solid #777;border-color:inherit;background-color:inherit;border-left:1px solid transparent;border-bottom:1px solid transparent;border-bottom-left-radius:50px;margin:-9px 0 0 30px}.w2ui-overlay:after{display:none;content:"";position:absolute;-webkit-transform:rotate(135deg);-moz-transform:rotate(135deg);-ms-transform:rotate(135deg);-o-transform:rotate(135deg);transform:rotate(135deg);width:12px;height:12px;border:3px solid #777;border-color:inherit;background-color:inherit;border-left:1px solid transparent;border-bottom:1px solid transparent;border-bottom-left-radius:50px;margin:-7px 0 0 30px}.w2ui-overlay.w2ui-overlay-popup{z-index:1700}.w2ui-tag{position:absolute;z-index:1300;opacity:0;-webkit-transition:opacity .3s;-moz-transition:opacity .3s;-ms-transition:opacity .3s;-o-transition:opacity .3s;transition:opacity .3s}.w2ui-tag .w2ui-tag-body{background-color:rgba(60,60,60,.82);display:inline-block;position:absolute;border-radius:4px;padding:4px 10px;margin-left:10px;margin-top:0;color:#fff!important;box-shadow:1px 1px 3px #000;line-height:100%;font-size:11px;font-family:Verdana,Arial,sans-serif}.w2ui-tag .w2ui-tag-body:before{content:"";position:absolute;width:0;height:0;border-top:5px solid transparent;border-right:5px solid rgba(60,60,60,.82);border-bottom:5px solid transparent;margin:2px 0 0 -15px}.w2ui-tag.w2ui-tag-popup{z-index:1700}.w2ui-overlay table.w2ui-drop-menu{width:100%;color:#000;background-color:#fff;padding:5px 0;cursor:default}.w2ui-overlay table.w2ui-drop-menu td{white-space:nowrap}.w2ui-overlay table.w2ui-drop-menu .w2ui-item-even{color:inherit;background-color:#fff}.w2ui-overlay table.w2ui-drop-menu .w2ui-item-odd{color:inherit;background-color:#f3f6fa}.w2ui-overlay table.w2ui-drop-menu .w2ui-item-group{color:#444;font-weight:bold;background-color:#ecedf0;border-bottom:1px solid #d3d2d4}.w2ui-overlay table.w2ui-drop-menu td.menu-icon{padding:3px 0 4px 6px;width:20px}.w2ui-overlay table.w2ui-drop-menu td.menu-text{padding:8px 10px 8px 5px;width:auto}.w2ui-overlay table.w2ui-drop-menu td.menu-count{text-align:right}.w2ui-overlay table.w2ui-drop-menu td.menu-count>span{border:1px solid #9da4af;border-radius:20px;width:auto;height:18px;padding:2px 7px;margin:3px 5px 0 5px;background-color:#e7f0fc;color:#667274;box-shadow:0 0 2px #fff;text-shadow:1px 1px 1px #e6e6e6}.w2ui-overlay table.w2ui-drop-menu tr:hover{color:inherit;background-color:#e6f0ff}.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected{background-color:#b6d5fb}.w2ui-overlay table.w2ui-drop-menu tr.w2ui-selected td{color:inherit}.w2ui-overlay table.w2ui-drop-menu tr.w2ui-disabled{opacity:.4;background-color:#fff!important}.w2ui-overlay table.w2ui-drop-menu .w2ui-icon{font-size:14px;color:#8d99a7;display:inline-block;padding-top:4px}.w2ui-marker{color:#444;background-color:rgba(252,244,161,.48)}.w2ui-spinner{display:inline-block;background-size:100%;background-repeat:no-repeat;background-image:url(data:image/gif;base64,R0lGODlhgACAAKIAAP///93d3bu7u5mZmQAA/wAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFBQAEACwCAAIAfAB8AAAD/0i63P4wygYqmDjrzbtflvWNZGliYXiubKuloivPLlzReD7al+7/Eh5wSFQIi8hHYBkwHUmD6CD5YTJLz49USuVYraRsZ7vtar7XnQ1Kjpoz6LRHvGlz35O4nEPP2O94EnpNc2sef1OBGIOFMId/inB6jSmPdpGScR19EoiYmZobnBCIiZ95k6KGGp6ni4wvqxilrqBfqo6skLW2YBmjDa28r6Eosp27w8Rov8ekycqoqUHODrTRvXsQwArC2NLF29UM19/LtxO5yJd4Au4CK7DUNxPebG4e7+8n8iv2WmQ66BtoYpo/dvfacBjIkITBE9DGlMvAsOIIZjIUAixliv9ixYZVtLUos5GjwI8gzc3iCGghypQqrbFsme8lwZgLZtIcYfNmTJ34WPTUZw5oRxdD9w0z6iOpO15MgTh1BTTJUKos39jE+o/KS64IFVmsFfYT0aU7capdy7at27dw48qdS7eu3bt480I02vUbX2F/JxYNDImw4GiGE/P9qbhxVpWOI/eFKtlNZbWXuzlmG1mv58+gQ4seTbq06dOoU6vGQZJy0FNlMcV+czhQ7SQmYd8eMhPs5BxVdfcGEtV3buDBXQ+fURxx8oM6MT9P+Fh6dOrH2zavc13u9JXVJb520Vp8dvC76wXMuN5Sepm/1WtkEZHDefnzR9Qvsd9+/wi8+en3X0ntYVcSdAE+UN4zs7ln24CaLagghIxBaGF8kFGoIYV+Ybghh841GIyI5ICIFoklJsigihmimJOLEbLYIYwxSgigiZ+8l2KB+Ml4oo/w8dijjcrouCORKwIpnJIjMnkkksalNeR4fuBIm5UEYImhIlsGCeWNNJphpJdSTlkml1jWeOY6TnaRpppUctcmFW9mGSaZceYopH9zkjnjUe59iR5pdapWaGqHopboaYua1qije67GJ6CuJAAAIfkEBQUABAAsCgACAFcAMAAAA/9Iutz+ML5Ag7w46z0r5WAoSp43nihXVmnrdusrv+s332dt4Tyo9yOBUJD6oQBIQGs4RBlHySSKyczVTtHoidocPUNZaZAr9F5FYbGI3PWdQWn1mi36buLKFJvojsHjLnshdhl4L4IqbxqGh4gahBJ4eY1kiX6LgDN7fBmQEJI4jhieD4yhdJ2KkZk8oiSqEaatqBekDLKztBG2CqBACq4wJRi4PZu1sA2+v8C6EJexrBAD1AOBzsLE0g/V1UvYR9sN3eR6lTLi4+TlY1wz6Qzr8u1t6FkY8vNzZTxaGfn6mAkEGFDgL4LrDDJDyE4hEIbdHB6ESE1iD4oVLfLAqPETIsOODwmCDJlv5MSGJklaS6khAQAh+QQFBQAEACwfAAIAVwAwAAAD/0i63P5LSAGrvTjrNuf+YKh1nWieIumhbFupkivPBEzR+GnnfLj3ooFwwPqdAshAazhEGUXJJIrJ1MGOUamJ2jQ9QVltkCv0XqFh5IncBX01afGYnDqD40u2z76JK/N0bnxweC5sRB9vF34zh4gjg4uMjXobihWTlJUZlw9+fzSHlpGYhTminKSepqebF50NmTyor6qxrLO0L7YLn0ALuhCwCrJAjrUqkrjGrsIkGMW/BMEPJcphLgDaABjUKNEh29vdgTLLIOLpF80s5xrp8ORVONgi8PcZ8zlRJvf40tL8/QPYQ+BAgjgMxkPIQ6E6hgkdjoNIQ+JEijMsasNY0RQix4gKP+YIKXKkwJIFF6JMudFEAgAh+QQFBQAEACw8AAIAQgBCAAAD/kg0PPowykmrna3dzXvNmSeOFqiRaGoyaTuujitv8Gx/661HtSv8gt2jlwIChYtc0XjcEUnMpu4pikpv1I71astytkGh9wJGJk3QrXlcKa+VWjeSPZHP4Rtw+I2OW81DeBZ2fCB+UYCBfWRqiQp0CnqOj4J1jZOQkpOUIYx/m4oxg5cuAaYBO4Qop6c6pKusrDevIrG2rkwptrupXB67vKAbwMHCFcTFxhLIt8oUzLHOE9Cy0hHUrdbX2KjaENzey9Dh08jkz8Tnx83q66bt8PHy8/T19vf4+fr6AP3+/wADAjQmsKDBf6AOKjS4aaHDgZMeSgTQcKLDhBYPEswoA1BBAgAh+QQFBQAEACxOAAoAMABXAAAD7Ei6vPOjyUkrhdDqfXHm4OZ9YSmNpKmiqVqykbuysgvX5o2HcLxzup8oKLQQix0UcqhcVo5ORi+aHFEn02sDeuWqBGCBkbYLh5/NmnldxajX7LbPBK+PH7K6narfO/t+SIBwfINmUYaHf4lghYyOhlqJWgqDlAuAlwyBmpVnnaChoqOkpaanqKmqKgGtrq+wsbA1srW2ry63urasu764Jr/CAb3Du7nGt7TJsqvOz9DR0tPU1TIA2ACl2dyi3N/aneDf4uPklObj6OngWuzt7u/d8fLY9PXr9eFX+vv8+PnYlUsXiqC3c6PmUUgAACH5BAUFAAQALE4AHwAwAFcAAAPpSLrc/m7IAau9bU7MO9GgJ0ZgOI5leoqpumKt+1axPJO1dtO5vuM9yi8TlAyBvSMxqES2mo8cFFKb8kzWqzDL7Xq/4LB4TC6bz1yBes1uu9uzt3zOXtHv8xN+Dx/x/wJ6gHt2g3Rxhm9oi4yNjo+QkZKTCgGWAWaXmmOanZhgnp2goaJdpKGmp55cqqusrZuvsJays6mzn1m4uRAAvgAvuBW/v8GwvcTFxqfIycA3zA/OytCl0tPPO7HD2GLYvt7dYd/ZX99j5+Pi6tPh6+bvXuTuzujxXens9fr7YPn+7egRI9PPHrgpCQAAIfkEBQUABAAsPAA8AEIAQgAAA/lIutz+UI1Jq7026h2x/xUncmD5jehjrlnqSmz8vrE8u7V5z/m5/8CgcEgsGo/IpHLJbDqf0Kh0ShBYBdTXdZsdbb/Yrgb8FUfIYLMDTVYz2G13FV6Wz+lX+x0fdvPzdn9WeoJGAYcBN39EiIiKeEONjTt0kZKHQGyWl4mZdREAoQAcnJhBXBqioqSlT6qqG6WmTK+rsa1NtaGsuEu6o7yXubojsrTEIsa+yMm9SL8osp3PzM2cStDRykfZ2tfUtS/bRd3ewtzV5pLo4eLjQuUp70Hx8t9E9eqO5Oku5/ztdkxi90qPg3x2EMpR6IahGocPCxp8AGtigwQAIfkEBQUABAAsHwBOAFcAMAAAA/9Iutz+MMo36pg4682J/V0ojs1nXmSqSqe5vrDXunEdzq2ta3i+/5DeCUh0CGnF5BGULC4tTeUTFQVONYAs4CfoCkZPjFar83rBx8l4XDObSUL1Ott2d1U4yZwcs5/xSBB7dBMBhgEYfncrTBGDW4WHhomKUY+QEZKSE4qLRY8YmoeUfkmXoaKInJ2fgxmpqqulQKCvqRqsP7WooriVO7u8mhu5NacasMTFMMHCm8qzzM2RvdDRK9PUwxzLKdnaz9y/Kt8SyR3dIuXmtyHpHMcd5+jvWK4i8/TXHff47SLjQvQLkU+fG29rUhQ06IkEG4X/Rryp4mwUxSgLL/7IqFETB8eONT6ChCFy5ItqJomES6kgAQAh+QQFBQAEACwKAE4AVwAwAAAD/0i63A4QuEmrvTi3yLX/4MeNUmieITmibEuppCu3sDrfYG3jPKbHveDktxIaF8TOcZmMLI9NyBPanFKJp4A2IBx4B5lkdqvtfb8+HYpMxp3Pl1qLvXW/vWkli16/3dFxTi58ZRcChwIYf3hWBIRchoiHiotWj5AVkpIXi4xLjxiaiJR/T5ehoomcnZ+EGamqq6VGoK+pGqxCtaiiuJVBu7yaHrk4pxqwxMUzwcKbyrPMzZG90NGDrh/JH8t72dq3IN1jfCHb3L/e5ebh4ukmxyDn6O8g08jt7tf26ybz+m/W9GNXzUQ9fm1Q/APoSWAhhfkMAmpEbRhFKwsvCsmosRIHx444PoKcIXKkjIImjTzjkQAAIfkEBQUABAAsAgA8AEIAQgAAA/VIBNz+8KlJq72Yxs1d/uDVjVxogmQqnaylvkArT7A63/V47/m2/8CgcEgsGo/IpHLJbDqf0Kh0Sj0FroGqDMvVmrjgrDcTBo8v5fCZki6vCW33Oq4+0832O/at3+f7fICBdzsChgJGeoWHhkV0P4yMRG1BkYeOeECWl5hXQ5uNIAOjA1KgiKKko1CnqBmqqk+nIbCkTq20taVNs7m1vKAnurtLvb6wTMbHsUq4wrrFwSzDzcrLtknW16tI2tvERt6pv0fi48jh5h/U6Zs77EXSN/BE8jP09ZFA+PmhP/xvJgAMSGBgQINvEK5ReIZhQ3QEMTBLAAAh+QQFBQAEACwCAB8AMABXAAAD50i6DA4syklre87qTbHn4OaNYSmNqKmiqVqyrcvBsazRpH3jmC7yD98OCBF2iEXjBKmsAJsWHDQKmw571l8my+16v+CweEwum8+hgHrNbrvbtrd8znbR73MVfg838f8BeoB7doN0cYZvaIuMjY6PkJGSk2gClgJml5pjmp2YYJ6dX6GeXaShWaeoVqqlU62ir7CXqbOWrLafsrNctjIDwAMWvC7BwRWtNsbGFKc+y8fNsTrQ0dK3QtXAYtrCYd3eYN3c49/a5NVj5eLn5u3s6e7x8NDo9fbL+Mzy9/T5+tvUzdN3Zp+GBAAh+QQJBQAEACwCAAIAfAB8AAAD/0i63P4wykmrvTjrzbv/YCiOZGmeaKqubOu+cCzPdArcQK2TOL7/nl4PSMwIfcUk5YhUOh3M5nNKiOaoWCuWqt1Ou16l9RpOgsvEMdocXbOZ7nQ7DjzTaeq7zq6P5fszfIASAYUBIYKDDoaGIImKC4ySH3OQEJKYHZWWi5iZG0ecEZ6eHEOio6SfqCaqpaytrpOwJLKztCO2jLi1uoW8Ir6/wCHCxMG2x7muysukzb230M6H09bX2Nna29zd3t/g4cAC5OXm5+jn3Ons7eba7vHt2fL16tj2+QL0+vXw/e7WAUwnrqDBgwgTKlzIsKHDh2gGSBwAccHEixAvaqTYcFCjRoYeNyoM6REhyZIHT4o0qPIjy5YTTcKUmHImx5cwE85cmJPnSYckK66sSAAj0aNIkypdyrSp06dQo0qdSrWq1atYs2rdyrWr169gwxZJAAA7)}.w2ui-icon{background-repeat:no-repeat;height:16px;width:16px;overflow:hidden;margin:2px 2px;display:inline-block}.w2ui-icon.icon-search,.w2ui-icon.icon-search-down{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAgCAYAAAB+ZAqzAAACuElEQVRYw9WXSWhTQRjHR0UKLqhFaV0OUih68GAOWjyJKypCpAoV8aIiioIICiKiB1GMtE3MYmry2moXDz1UDx7sUXHBhQpSaRVxrYpWcMO9avx/8AJh/CbznHkxdeB3Cd/8589kvuUJkWcdjCTHghUgAi6DJ+AVeAqugSQIggniXywcNBJsB70g44EHYBcYXUhTM8EFj4ZkboKqQpiqAv2GprK8o7/f75t6pjn0M3gNPmri3vtycxAZA64qDvkJ2kENqAQTQQWoBg74qth3B4y3NbZDIX4fzNfsnQtuK/YfsjFVCh4pMq3Co0Y5uMVoUGkpy8aFT5xaeSzVEo45bXdBt4LeaLq1k0RXMYJfdDfFmAuAD4zWlty4UNyZEkm19MUb2zMw8Sfp1u+IWSrcIimLnTG8/SijdU6OO5poDESdtgHZVBzUHm/amhW7zoitMTS2mNHqASPk2FDCCcLMYK6p+obmulyxfiYLA4bGKFvfSnrUvkq5+Lpk8z4yRH8r3l/X4WiqJFfspSQ0CGYZGpsMnkt6L+h31Z76hpMdeOwPQ7H0NFnssST0C8wxNDaDKb6kP06150gsHahNNlVzYheZd7HJ0BiX4VRGhpmIhRixKyZilM2M1mnTArtIUbU3/qVO0H0GvmQ4CY4C3YopYYlHjXlggNG4R33Ypi2tVtwaPeTdNMkq9pVQZQdvFPs32zbx4aAjzxhDRfIAWAeWg7VgrzsY5ht/zoNJtubKwA3LITGjSKRyW3NTwaUCmKOSMd3WHH0ZJRQZZkOP1zFKZ3CB++4+aQ6kEeksWAb2a2L7qDv49S1Q6T72MOgEXa6RGFhP3wpS/B6NOWpRs0UxFg7eqTFHjX1hscxtAz/ymEuIYi0cvgF8Y0w5Ro3dZ3M1boJkTaXEUFlug6fsdsRQWzTj0cey+N/Xb2sj5lTh2M6OAAAAAElFTkSuQmCC) no-repeat center!important;background-size:14px 12px!important;opacity:.9}.w2ui-icon.icon-folder{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGrSURBVDjLxZO7ihRBFIa/6u0ZW7GHBUV0UQQTZzd3QdhMQxOfwMRXEANBMNQX0MzAzFAwEzHwARbNFDdwEd31Mj3X7a6uOr9BtzNjYjKBJ6nicP7v3KqcJFaxhBVtZUAK8OHlld2st7Xl3DJPVONP+zEUV4HqL5UDYHr5xvuQAjgl/Qs7TzvOOVAjxjlC+ePSwe6DfbVegLVuT4r14eTr6zvA8xSAoBLzx6pvj4l+DZIezuVkG9fY2H7YRQIMZIBwycmzH1/s3F8AapfIPNF3kQk7+kw9PWBy+IZOdg5Ug3mkAATy/t0usovzGeCUWTjCz0B+Sj0ekfdvkZ3abBv+U4GaCtJ1iEm6ANQJ6fEzrG/engcKw/wXQvEKxSEKQxRGKE7Izt+DSiwBJMUSm71rguMYhQKrBygOIRStf4TiFFRBvbRGKiQLWP29yRSHKBTtfdBmHs0BUpgvtgF4yRFR+NUKi0XZcYjCeCG2smkzLAHkbRBmP0/Uk26O5YnUActBp1GsAI+S5nRJJJal5K1aAMrq0d6Tm9uI6zjyf75dAe6tx/SsWeD//o2/Ab6IH3/h25pOAAAAAElFTkSuQmCC) no-repeat center!important}.w2ui-icon.icon-page{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAINSURBVBgZBcG/r55zGAfg6/4+z3va01NHlYgzEfE7MdCIGISFgS4Gk8ViYyM2Mdlsko4GSf8Do0FLRCIkghhYJA3aVBtEz3nP89wf11VJvPDepdd390+8Nso5nESBQoq0pfvXm9fzWf19453LF85vASqJlz748vInb517dIw6EyYBIIG49u+xi9/c9MdvR//99MPPZ7+4cP4IZhhTPbwzT2d+vGoaVRRp1rRliVvHq+cfvM3TD82+7mun0o/ceO7NT+/4/KOXjwZU1ekk0840bAZzMQ2mooqh0A72d5x/6sB9D5zYnff3PoYBoWBgFKPKqDKqjCpjKr//dcu9p489dra88cydps30KswACfNEKanSaxhlntjJ8Mv12Paie+vZ+0+oeSwwQ0Iw1xAR1CiFNJkGO4wu3ZMY1AAzBI0qSgmCNJsJUEOtJSMaCTBDLyQ0CknAGOgyTyFFiLI2awMzdEcSQgSAAKVUmAeNkxvWJWCGtVlDmgYQ0GFtgg4pNtOwbBcwQy/Rife/2yrRRVI0qYCEBly8Z+P4qMEMy7JaVw72N568e+iwhrXoECQkfH91kY7jwwXMsBx1L93ZruqrK6uuiAIdSnTIKKPLPFcvay8ww/Hh+ufeznTXu49v95IMoQG3784gYXdTqvRmqn/Wpa/ADFX58MW3L71SVU9ETgEIQQQIOOzub+fhIvwPRDgeVjWDahIAAAAASUVORK5CYII=) no-repeat center!important}.w2ui-lock{display:none;position:absolute;z-index:1400;top:0;left:0;width:100%;height:100%;opacity:.15;filter:alpha(opacity=15);background-color:#333}.w2ui-lock-msg{display:none;position:absolute;z-index:1400;top:45%;left:50%;-webkit-transform:translateX(-50%) translateY(-50%);-moz-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);-o-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);width:200px;height:80px;padding:30px 8px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:13px;font-family:Verdana,Arial,sans-serif;opacity:.8;filter:alpha(opacity=80);background-color:#555;color:#fff;text-align:center;border-radius:5px;border:2px solid #444}.w2ui-lock-msg .w2ui-spinner{display:inline-block;width:24px;height:24px;margin:-3px 8px -7px -10px}button.btn{display:inline-block;border-radius:4px;margin:0 5px;padding:7px 12px 6px 12px!important;color:#666;font-size:12px!important;border:1px solid #b6b6b6;background-image:-webkit-linear-gradient(#fff 0%,#e7e7e7 100%);background-image:-moz-linear-gradient(#fff 0%,#e7e7e7 100%);background-image:-ms-linear-gradient(#fff 0%,#e7e7e7 100%);background-image:-o-linear-gradient(#fff 0%,#e7e7e7 100%);background-image:linear-gradient(#fff 0%,#e7e7e7 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffe7e7e7',endColorstr='#ffffffff',GradientType=0);outline:none;box-shadow:0 1px 0 white;cursor:default;min-width:75px;line-height:100%!important;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}button.btn:hover{text-decoration:none;border:1px solid #bbb;background-image:-webkit-linear-gradient(#f7f7f7 0%,#ddd 100%);background-image:-moz-linear-gradient(#f7f7f7 0%,#ddd 100%);background-image:-ms-linear-gradient(#f7f7f7 0%,#ddd 100%);background-image:-o-linear-gradient(#f7f7f7 0%,#ddd 100%);background-image:linear-gradient(#f7f7f7 0%,#ddd 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdddddd',endColorstr='#fff7f7f7',GradientType=0);color:#333}button.btn:active,button.btn.clicked{border:1px solid #999;background-image:-webkit-linear-gradient(#ccc 0%,#ccc 100%);background-image:-moz-linear-gradient(#ccc 0%,#ccc 100%);background-image:-ms-linear-gradient(#ccc 0%,#ccc 100%);background-image:-o-linear-gradient(#ccc 0%,#ccc 100%);background-image:linear-gradient(#ccc 0%,#ccc 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffcccccc',endColorstr='#ffcccccc',GradientType=0);text-shadow:1px 1px 1px #eee}button.btn:disabled{border:1px solid #bbb!important;background:#f7f7f7!important;color:#bdbcbc!important;text-shadow:none!important}button.btn-blue{color:#fff;background-image:-webkit-linear-gradient(#80c0f7 0%,#269df0 100%);background-image:-moz-linear-gradient(#80c0f7 0%,#269df0 100%);background-image:-ms-linear-gradient(#80c0f7 0%,#269df0 100%);background-image:-o-linear-gradient(#80c0f7 0%,#269df0 100%);background-image:linear-gradient(#80c0f7 0%,#269df0 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff269df0',endColorstr='#ff80c0f7',GradientType=0);border:1px solid #538ab7;text-shadow:1px 1px 1px #777}button.btn-blue:hover{color:#fff;background-image:-webkit-linear-gradient(#73b6f0 0%,#2391dd 100%);background-image:-moz-linear-gradient(#73b6f0 0%,#2391dd 100%);background-image:-ms-linear-gradient(#73b6f0 0%,#2391dd 100%);background-image:-o-linear-gradient(#73b6f0 0%,#2391dd 100%);background-image:linear-gradient(#73b6f0 0%,#2391dd 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff2391dd',endColorstr='#ff73b6f0',GradientType=0);border:1px solid #497ba3;text-shadow:1px 1px 1px #777}button.btn-blue:active,button.btn-blue.clicked{color:#fff;background-image:-webkit-linear-gradient(#1e83c9 0%,#1e83c9 100%);background-image:-moz-linear-gradient(#1e83c9 0%,#1e83c9 100%);background-image:-ms-linear-gradient(#1e83c9 0%,#1e83c9 100%);background-image:-o-linear-gradient(#1e83c9 0%,#1e83c9 100%);background-image:linear-gradient(#1e83c9 0%,#1e83c9 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff1e83c9',endColorstr='#ff1e83c9',GradientType=0);border:1px solid #1268a6;text-shadow:1px 1px 1px #777}button.btn-green{color:#fff;background-image:-webkit-linear-gradient(#81cf81 0%,#52a452 100%);background-image:-moz-linear-gradient(#81cf81 0%,#52a452 100%);background-image:-ms-linear-gradient(#81cf81 0%,#52a452 100%);background-image:-o-linear-gradient(#81cf81 0%,#52a452 100%);background-image:linear-gradient(#81cf81 0%,#52a452 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff52a452',endColorstr='#ff81cf81',GradientType=0);border:1px solid #479247;text-shadow:1px 1px 1px #777}button.btn-green:hover{color:#fff;background-image:-webkit-linear-gradient(#6abe68 0%,#3f8f3d 100%);background-image:-moz-linear-gradient(#6abe68 0%,#3f8f3d 100%);background-image:-ms-linear-gradient(#6abe68 0%,#3f8f3d 100%);background-image:-o-linear-gradient(#6abe68 0%,#3f8f3d 100%);background-image:linear-gradient(#6abe68 0%,#3f8f3d 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff3f8f3d',endColorstr='#ff6abe68',GradientType=0);border:1px solid #479247;text-shadow:1px 1px 1px #777}button.btn-green:active,button.btn-green.clicked{color:#fff;background-image:-webkit-linear-gradient(#377d36 0%,#377d36 100%);background-image:-moz-linear-gradient(#377d36 0%,#377d36 100%);background-image:-ms-linear-gradient(#377d36 0%,#377d36 100%);background-image:-o-linear-gradient(#377d36 0%,#377d36 100%);background-image:linear-gradient(#377d36 0%,#377d36 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff377d36',endColorstr='#ff377d36',GradientType=0);border:1px solid #555!important;text-shadow:1px 1px 1px #777}button.btn-orange{color:#fff;background-image:-webkit-linear-gradient(#fcc272 0%,#fb8822 100%);background-image:-moz-linear-gradient(#fcc272 0%,#fb8822 100%);background-image:-ms-linear-gradient(#fcc272 0%,#fb8822 100%);background-image:-o-linear-gradient(#fcc272 0%,#fb8822 100%);background-image:linear-gradient(#fcc272 0%,#fb8822 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#fffb8822',endColorstr='#fffcc272',GradientType=0);border:1px solid #b68b4c;text-shadow:1px 1px 1px #777}button.btn-orange:hover{color:#fff;background-image:-webkit-linear-gradient(#f4ad59 0%,#f1731f 100%);background-image:-moz-linear-gradient(#f4ad59 0%,#f1731f 100%);background-image:-ms-linear-gradient(#f4ad59 0%,#f1731f 100%);background-image:-o-linear-gradient(#f4ad59 0%,#f1731f 100%);background-image:linear-gradient(#f4ad59 0%,#f1731f 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#fff1731f',endColorstr='#fff4ad59',GradientType=0);border:1px solid #b68b4c;text-shadow:1px 1px 1px #777}button.btn-orange:active,button.btn-orange.clicked{color:#fff;border:1px solid #666;background-image:-webkit-linear-gradient(#b98747 0%,#b98747 100%);background-image:-moz-linear-gradient(#b98747 0%,#b98747 100%);background-image:-ms-linear-gradient(#b98747 0%,#b98747 100%);background-image:-o-linear-gradient(#b98747 0%,#b98747 100%);background-image:linear-gradient(#b98747 0%,#b98747 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffb98747',endColorstr='#ffb98747',GradientType=0);text-shadow:1px 1px 1px #777}button.btn-red{color:#fff;background-image:-webkit-linear-gradient(#ff6e70 0%,#c72d2d 100%);background-image:-moz-linear-gradient(#ff6e70 0%,#c72d2d 100%);background-image:-ms-linear-gradient(#ff6e70 0%,#c72d2d 100%);background-image:-o-linear-gradient(#ff6e70 0%,#c72d2d 100%);background-image:linear-gradient(#ff6e70 0%,#c72d2d 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffc72d2d',endColorstr='#ffff6e70',GradientType=0);border:1px solid #bb3c3e;text-shadow:1px 1px 1px #777}button.btn-red:hover{color:#fff;background-image:-webkit-linear-gradient(#ee696c 0%,#ae2527 100%);background-image:-moz-linear-gradient(#ee696c 0%,#ae2527 100%);background-image:-ms-linear-gradient(#ee696c 0%,#ae2527 100%);background-image:-o-linear-gradient(#ee696c 0%,#ae2527 100%);background-image:linear-gradient(#ee696c 0%,#ae2527 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffae2527',endColorstr='#ffee696c',GradientType=0);border:1px solid #bb3c3e;text-shadow:1px 1px 1px #777}button.btn-red:active,button.btn-red.clicked{color:#fff;border:1px solid #861c1e;background-image:-webkit-linear-gradient(#9c2123 0%,#9c2123 100%);background-image:-moz-linear-gradient(#9c2123 0%,#9c2123 100%);background-image:-ms-linear-gradient(#9c2123 0%,#9c2123 100%);background-image:-o-linear-gradient(#9c2123 0%,#9c2123 100%);background-image:linear-gradient(#9c2123 0%,#9c2123 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff9c2123',endColorstr='#ff9c2123',GradientType=0);text-shadow:1px 1px 1px #777}.w2ui-form{position:relative;color:#000;background-color:#f5f6f7;border:1px solid silver;border-radius:3px;padding:0;overflow:hidden!important}.w2ui-form>div{position:absolute;overflow:hidden}.w2ui-form .w2ui-form-header{position:absolute;left:0;right:0;border-bottom:1px solid #99bbe8!important;overflow:hidden;color:#444;font-size:13px;text-align:center;padding:8px;background-image:-webkit-linear-gradient(#dae6f3,#c2d5ed);background-image:-moz-linear-gradient(#dae6f3,#c2d5ed);background-image:-ms-linear-gradient(#dae6f3,#c2d5ed);background-image:-o-linear-gradient(#dae6f3,#c2d5ed);background-image:linear-gradient(#dae6f3,#c2d5ed);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3',endColorstr='#ffc2d5ed',GradientType=0);border-top-left-radius:3px;border-top-right-radius:3px}.w2ui-form .w2ui-form-toolbar{position:absolute;left:0;right:0;margin:0;padding:6px 3px;border-bottom:1px solid #d5d8d8}.w2ui-form .w2ui-form-tabs{margin:0;padding:0}.w2ui-form .w2ui-tabs{position:absolute;left:0;right:0;border-top-left-radius:3px;border-top-right-radius:3px;padding-top:5px!important;background-color:#fafafa}.w2ui-form .w2ui-tabs .w2ui-tab.active{background-color:#f5f6f7}.w2ui-form .w2ui-page{position:absolute;left:0;right:0;overflow:auto;padding:10px;border-left:1px solid inherit;border-right:1px solid inherit;background-color:inherit;border-radius:3px}.w2ui-form .w2ui-buttons{position:absolute;left:0;right:0;bottom:0;text-align:center;border-top:1px solid #d5d8d8;border-bottom:0 solid #d5d8d8;background-color:#fafafa;padding:15px 0!important;border-bottom-left-radius:3px;border-bottom-right-radius:3px}.w2ui-form .w2ui-buttons input[type="button"],.w2ui-form .w2ui-buttons button{min-width:80px;margin-right:5px}.w2ui-form input[type=checkbox],.w2ui-form input[type=radio]{margin-top:4px;margin-bottom:4px}.w2ui-form input[type=checkbox].w2ui-toggle{margin:0}.w2ui-group-title{padding:5px 2px;color:#8d96a2;text-shadow:1px 1px 2px #fdfdfd;font-size:120%}.w2ui-group{background-color:#ebecef;margin:5px 0 10px 0;padding:10px 5px;border-top:1px solid #cedcea;border-bottom:1px solid #cedcea}.w2ui-field>label{display:block;float:left;margin-top:7px;margin-bottom:3px;width:120px;padding:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:right;min-height:20px;color:#666}.w2ui-field>div{margin-bottom:3px;margin-left:128px;padding:3px;min-height:28px;float:none}.w2ui-field.w2ui-required>div{position:relative}.w2ui-field.w2ui-required>div::before{content:'*';position:absolute;margin-top:5px;margin-left:-9px;color:red}.w2ui-field.w2ui-span1>label{width:20px}.w2ui-field.w2ui-span1>div{margin-left:28px}.w2ui-field.w2ui-span2>label{width:40px}.w2ui-field.w2ui-span2>div{margin-left:48px}.w2ui-field.w2ui-span3>label{width:60px}.w2ui-field.w2ui-span3>div{margin-left:68px}.w2ui-field.w2ui-span4>label{width:80px}.w2ui-field.w2ui-span4>div{margin-left:88px}.w2ui-field.w2ui-span5>label{width:100px}.w2ui-field.w2ui-span5>div{margin-left:108px}.w2ui-field.w2ui-span6>label{width:120px}.w2ui-field.w2ui-span6>div{margin-left:128px}.w2ui-field.w2ui-span7>label{width:140px}.w2ui-field.w2ui-span7>div{margin-left:148px}.w2ui-field.w2ui-span8>label{width:160px}.w2ui-field.w2ui-span8>div{margin-left:168px}.w2ui-field.w2ui-span9>label{width:180px}.w2ui-field.w2ui-span9>div{margin-left:188px}.w2ui-field.w2ui-span10>label{width:200px}.w2ui-field.w2ui-span10>div{margin-left:208px}.w2ui-error{border:1px solid #ffa8a8!important;background-color:#fff4eb!important}.w2field{padding:3px;border-radius:3px;border:1px solid silver}.w2ui-field-helper{position:absolute;display:inline-block;line-height:100%;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none}.w2ui-field-helper .w2ui-field-up{position:absolute;top:0;padding:2px 3px}.w2ui-field-helper .w2ui-field-down{position:absolute;bottom:0;padding:2px 3px}.w2ui-field-helper .arrow-up:hover{border-bottom-color:#81c6ff}.w2ui-field-helper .arrow-down:hover{border-top-color:#81c6ff}.arrow-up{background:none;width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-bottom:5px solid #777;font-size:0;line-height:0}.arrow-down{background:none;width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #777;font-size:0;line-height:0}.arrow-left{background:none;width:0;height:0;border-bottom:4px solid transparent;border-top:4px solid transparent;border-right:5px solid #777;font-size:0;line-height:0}.arrow-right{background:none;width:0;height:0;border-bottom:4px solid transparent;border-top:4px solid transparent;border-left:5px solid #777;font-size:0;line-height:0}.w2ui-color{padding:5px;padding-top:8px;background-color:#fff;border-radius:3px}.w2ui-color>table{table-layout:fixed;width:160px}.w2ui-color>table td{width:20px;height:20px;text-align:center}.w2ui-color>table td div{cursor:pointer;display:inline-block;width:16px;height:17px;padding:1px 4px;border:1px solid transparent;color:#fff;text-shadow:0 0 2px #000}.w2ui-color>table td div:hover{outline:1px solid #666;border:1px solid #fff}.w2ui-calendar{margin:0;padding:1px;line-height:108%}.w2ui-calendar .w2ui-calendar-title{margin:0 -1px;padding:7px 2px;background-image:-webkit-linear-gradient(#f6f6f6,#d9d9d9);background-image:-moz-linear-gradient(#f6f6f6,#d9d9d9);background-image:-ms-linear-gradient(#f6f6f6,#d9d9d9);background-image:-o-linear-gradient(#f6f6f6,#d9d9d9);background-image:linear-gradient(#f6f6f6,#d9d9d9);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#fff6f6f6',endColorstr='#ffd9d9d9',GradientType=0);border-bottom:1px solid #bbb;color:#555;text-align:center;text-shadow:1px 1px 1px #eee;cursor:pointer}.w2ui-calendar .w2ui-calendar-jump{position:absolute;top:27px;left:0;right:0;bottom:0;background-color:#fafafa}.w2ui-calendar .w2ui-calendar-jump>:first-child{position:absolute;top:0;left:0;bottom:0;width:110px;overflow:hidden;padding-top:5px;border-right:1px solid silver}.w2ui-calendar .w2ui-calendar-jump>:last-child{position:absolute;top:0;right:0;bottom:0;width:88px;overflow-x:hidden;overflow-y:auto;padding-top:5px;text-align:center}.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month,.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year{display:inline-block;padding:5px 0;text-align:center;float:left;margin:2px;width:50px;cursor:default;border:1px solid transparent;border-radius:2px}.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year{float:none;width:95%}.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month:hover,.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year:hover{border:1px solid #ccc;color:#000;background-color:#efefef}.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-month.selected,.w2ui-calendar .w2ui-calendar-jump .w2ui-jump-year.selected{border:1px solid #ccc;color:#000;background-color:#dadada}.w2ui-calendar .w2ui-calendar-previous,.w2ui-calendar .w2ui-calendar-next{width:24px;height:20px;color:#666;border:1px solid transparent;border-radius:3px;padding:2px 3px 1px 2px;margin:-4px 0 0 0;cursor:default}.w2ui-calendar .w2ui-calendar-previous:hover,.w2ui-calendar .w2ui-calendar-next:hover{border:1px solid silver;background-color:#efefef}.w2ui-calendar .w2ui-calendar-previous>div,.w2ui-calendar .w2ui-calendar-next>div{position:absolute;border-left:4px solid #888;border-top:4px solid #888;border-right:4px solid transparent;border-bottom:4px solid transparent;width:0;height:0;padding:0;margin:3px 0 0 0}.w2ui-calendar .w2ui-calendar-previous{float:left}.w2ui-calendar .w2ui-calendar-previous>div{-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg);margin-left:6px}.w2ui-calendar .w2ui-calendar-next{float:right}.w2ui-calendar .w2ui-calendar-next>div{-webkit-transform:rotate(135deg);-moz-transform:rotate(135deg);-ms-transform:rotate(135deg);-o-transform:rotate(135deg);transform:rotate(135deg);margin-left:2px;margin-right:2px}.w2ui-calendar table.w2ui-calendar-days{padding:0}.w2ui-calendar table.w2ui-calendar-days td{border:1px solid #fff;color:#000;background-color:#f9f9f9;padding:6px;cursor:default;text-align:right}.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday,.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday{border:1px solid #fff;color:#c8493b;background-color:#f9f9f9}.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday:hover,.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday:hover{border:1px solid #ccc;color:#000;background-color:#e9e9e9}.w2ui-calendar table.w2ui-calendar-days td.w2ui-saturday.w2ui-blocked,.w2ui-calendar table.w2ui-calendar-days td.w2ui-sunday.w2ui-blocked{text-decoration:line-through;border:1px solid #fff;color:#ccc;background-color:#fff}.w2ui-calendar table.w2ui-calendar-days td.w2ui-today{border:1px solid #8cb067;color:#000;background-color:#e2f7cd}.w2ui-calendar table.w2ui-calendar-days td:hover{border:1px solid #ccc;color:#000;background-color:#e9e9e9}.w2ui-calendar table.w2ui-calendar-days td.w2ui-blocked{text-decoration:line-through;border:1px solid #fff;color:#ccc;background-color:#fff}.w2ui-calendar table.w2ui-calendar-days td.w2ui-day-empty{border:1px solid #fff;background-color:#fdfdfd}.w2ui-calendar table.w2ui-calendar-days tr.w2ui-day-title td{border:1px solid #fff;color:gray;background-color:#fff;text-align:center;padding:6px}.w2ui-calendar-time{padding:5px;cursor:default}.w2ui-calendar-time td div{padding:7px 10px;text-align:center;border:1px solid transparent;white-space:nowrap}.w2ui-calendar-time td:nth-child(even){background-color:#f6f6f6}.w2ui-calendar-time td div:hover{border:1px solid #ccc;color:#000;background-color:#e9e9e9}.w2ui-calendar-time td div.w2ui-blocked{text-decoration:line-through;border:1px solid #fff;color:#ccc;background-color:#fff}.w2ui-select{cursor:default;color:#000!important;background-image:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-ms-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%)}.w2ui-list{color:inherit;position:absolute;padding:0;margin:0;min-height:25px;overflow:auto;border:1px solid silver;border-radius:3px;font-size:6px;line-height:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;background-color:#fff}.w2ui-list input[type=text]{-webkit-box-shadow:none;-moz-box-shadow:none;-ms-box-shadow:none;-o-box-shadow:none;box-shadow:none}.w2ui-list ul{list-style-type:none;background-color:#000;margin:0;padding:0}.w2ui-list ul li{float:left;margin:2px 1px 0 2px;border-radius:3px;width:auto;padding:3px 10px 1px 7px;border:1px solid #88b0d6;background-color:#eff3f5;white-space:nowrap;cursor:default;font-family:verdana;font-size:11px;line-height:100%;height:20px;overflow:hidden;text-overflow:ellipsis;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-list ul li:hover{background-color:#d0dbe1}.w2ui-list ul li:last-child{border-radius:0;border:1px solid transparent;background-color:transparent}.w2ui-list ul li:last-child input{padding:1px;padding-top:0;margin:0;border:0;outline:none;height:auto;line-height:100%;font-size:inherit;font-family:inherit;background-color:transparent}.w2ui-list ul li .w2ui-list-remove{float:right;width:15px;height:14px;margin:-1px -9px 0 3px;border-radius:15px}.w2ui-list ul li .w2ui-list-remove:hover{background-color:#d77f7f;color:#fff}.w2ui-list ul li .w2ui-list-remove:before{position:relative;top:0;padding:0;margin:0;left:5px;color:inherit;opacity:.7;text-shadow:inherit;font-size:inherit;font-variant:small-caps;content:'x';line-height:100%}.w2ui-list ul li>span.file-size{pointer-events:none;color:#777}.w2ui-list .w2ui-enum-placeholder{display:inline;position:absolute;pointer-events:none;color:#999;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-list.w2ui-file-dragover{background-color:#e4ffda;border:1px solid #93e07d}.w2ui-layout{overflow:hidden!important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout>div{position:absolute;overflow:hidden;border:0;margin:0;padding:0;outline:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-layout>div .w2ui-panel{display:none;position:absolute;z-index:120}.w2ui-layout>div .w2ui-panel .w2ui-panel-title{padding:5px;background-image:-webkit-linear-gradient(#dae6f3,#c2d5ed);background-image:-moz-linear-gradient(#dae6f3,#c2d5ed);background-image:-ms-linear-gradient(#dae6f3,#c2d5ed);background-image:-o-linear-gradient(#dae6f3,#c2d5ed);background-image:linear-gradient(#dae6f3,#c2d5ed);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3',endColorstr='#ffc2d5ed',GradientType=0);border:1px solid #b9cee9;border-bottom:1px solid #99bbe8}.w2ui-layout>div .w2ui-panel .w2ui-panel-tabs{position:absolute;left:0;top:0;right:0;z-index:2;display:none;overflow:hidden;background-color:#fafafa;padding:4px 0}.w2ui-layout>div .w2ui-panel .w2ui-panel-tabs>.w2ui-tab.active{background-color:#f5f6f7}.w2ui-layout>div .w2ui-panel .w2ui-panel-toolbar{position:absolute;left:0;top:0;right:0;z-index:2;display:none;overflow:hidden;background-color:#fafafa;border-bottom:1px solid silver;padding:4px}.w2ui-layout>div .w2ui-panel .w2ui-panel-content{position:absolute;left:0;top:0;right:0;bottom:0;z-index:1;color:inherit;background-color:#f5f6f7}.w2ui-layout>div .w2ui-resizer{display:none;position:absolute;z-index:121;background-color:transparent}.w2ui-layout>div .w2ui-resizer:hover,.w2ui-layout>div .w2ui-resizer.active{background-color:#d7e4f2}.w2ui-grid{position:relative;border:1px solid silver;border-radius:2px;overflow:hidden!important}.w2ui-grid>div{position:absolute;overflow:hidden}.w2ui-grid .w2ui-grid-header{position:absolute;border-bottom:1px solid #99bbe8!important;height:28px;overflow:hidden;color:#444;font-size:13px;text-align:center;padding:7px;background-image:-webkit-linear-gradient(#dae6f3,#c2d5ed);background-image:-moz-linear-gradient(#dae6f3,#c2d5ed);background-image:-ms-linear-gradient(#dae6f3,#c2d5ed);background-image:-o-linear-gradient(#dae6f3,#c2d5ed);background-image:linear-gradient(#dae6f3,#c2d5ed);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffdae6f3',endColorstr='#ffc2d5ed',GradientType=0);border-top-left-radius:2px;border-top-right-radius:2px}.w2ui-grid .w2ui-grid-toolbar{position:absolute;border-bottom:1px solid silver;background-color:#eaeaea;height:38px;padding:7px 3px 4px 3px;margin:0;box-shadow:0 1px 2px #ddd}.w2ui-grid .w2ui-toolbar-search{width:160px;margin-right:3px}.w2ui-grid .w2ui-toolbar-search .w2ui-search-all{outline:none!important;width:160px;border-radius:10px;line-height:normal;height:22px;border:1px solid #b9b9b9;color:#000;background-color:#fff;padding:3px 18px 3px 23px;margin:0}.w2ui-grid .w2ui-toolbar-search .w2ui-search-down{position:absolute;margin-top:-7px;margin-left:6px}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear{position:absolute;width:16px;height:16px;margin-top:-8px;margin-left:-20px;border-radius:15px;cursor:default}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:hover{background-color:#d77f7f;color:#fff}.w2ui-grid .w2ui-toolbar-search .w2ui-search-clear:before{position:relative;top:1px;left:5px;opacity:.6;color:inherit;text-shadow:inherit;content:'x';cursor:default}.w2ui-grid .w2ui-grid-body{position:absolute;overflow:hidden;padding:0;background-color:#fff;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-grid .w2ui-grid-body input,.w2ui-grid .w2ui-grid-body select,.w2ui-grid .w2ui-grid-body textarea{user-select:text;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;-o-user-select:text}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns{overflow:hidden;position:absolute;left:0;top:0;right:0;box-shadow:0 1px 4px #ddd;height:auto}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns table{height:auto}.w2ui-grid .w2ui-grid-body .w2ui-grid-columns .w2ui-resizer{position:absolute;z-index:1000;display:block;background-image:none;background-color:rgba(0,0,0,0);padding:0;margin:0;width:6px;height:12px;cursor:col-resize}.w2ui-grid .w2ui-grid-body .w2ui-grid-records{position:absolute;left:0;right:0;top:0;bottom:0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd{color:inherit;background-color:#fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd.w2ui-empty-record:hover{background-color:#fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even{color:inherit;background-color:#f3f6fa}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even.w2ui-empty-record:hover{background-color:#f3f6fa}.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected,.w2ui-grid .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected{color:#000!important;background-color:#b6d5ff!important}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded{background-color:#ccdcf0!important}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1{height:0;border-bottom:1px solid #b2bac0;background-color:#ccdcf0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded1>div{height:100%;margin:0;padding:0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2{height:0;border-radius:0;border-bottom:1px solid #b2bac0}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-expanded2>div{height:0;border:0;transition:height .3s,opacity .3s}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more{border-top:1px solid #d6d5d7;cursor:pointer}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more>div{text-align:center;color:#777;background-color:rgba(233,237,243,.5);padding:10px 0 15px 0;border-top:1px solid #fff}.w2ui-grid .w2ui-grid-body .w2ui-grid-records .w2ui-load-more>div:hover{color:inherit;background-color:#e6f0ff}.w2ui-grid .w2ui-grid-body table{border-spacing:0;border-collapse:collapse;table-layout:fixed;width:1px}.w2ui-grid .w2ui-grid-body table .w2ui-head{margin:0;padding:0;border-right:1px solid #c5c5c5;border-bottom:1px solid #c5c5c5;color:#000;background-image:-webkit-linear-gradient(#f9f9f9,#e4e4e4);background-image:-moz-linear-gradient(#f9f9f9,#e4e4e4);background-image:-ms-linear-gradient(#f9f9f9,#e4e4e4);background-image:-o-linear-gradient(#f9f9f9,#e4e4e4);background-image:linear-gradient(#f9f9f9,#e4e4e4);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#fff9f9f9',endColorstr='#ffe4e4e4',GradientType=0)}.w2ui-grid .w2ui-grid-body table .w2ui-head>div{padding:7px 3px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;position:relative}.w2ui-grid .w2ui-grid-body table .w2ui-head.w2ui-col-intersection{border-right-color:#72b2ff}.w2ui-grid .w2ui-grid-body table .w2ui-head.w2ui-reorder-cols-head:hover{cursor:move}.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker{padding:0;position:absolute;height:100%;top:0}.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker.left{left:0;margin-left:-5px}.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker.right{right:0;margin-right:-5px}.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker .top-marker{position:absolute;top:0;height:0;width:0;border-top:5px solid #72b2ff;border-left:5px solid transparent;border-right:5px solid transparent}.w2ui-grid .w2ui-grid-body table .w2ui-head .col-intersection-marker .bottom-marker{position:absolute;bottom:0;height:0;width:0;border-bottom:5px solid #72b2ff;border-left:5px solid transparent;border-right:5px solid transparent}.w2ui-grid .w2ui-grid-body table td{border-right:1px solid #d6d5d7;border-bottom:0 solid #d6d5d7;cursor:default;overflow:hidden}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data{margin:0;padding:0}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data>div{padding:3px 3px 3px 3px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.w2ui-grid .w2ui-grid-body table td.w2ui-grid-data>div.flexible-record{height:auto;overflow:visible;white-space:normal}.w2ui-grid .w2ui-grid-body table td:last-child{border-right:0}.w2ui-grid .w2ui-grid-body table .w2ui-col-number{width:34px;color:#777;background-color:rgba(233,237,243,.5)}.w2ui-grid .w2ui-grid-body table .w2ui-col-number div{padding:0 7px 0 3px;text-align:right}.w2ui-grid .w2ui-grid-body table .w2ui-col-select{width:26px}.w2ui-grid .w2ui-grid-body table .w2ui-col-select div{padding:0 0;text-align:center;overflow:hidden}.w2ui-grid .w2ui-grid-body table .w2ui-col-select div input[type=checkbox]{margin-top:2px;position:relative}.w2ui-grid .w2ui-grid-body table .w2ui-col-expand{width:26px}.w2ui-grid .w2ui-grid-body table .w2ui-col-expand div{padding:0 0;text-align:center;font-weight:bold}.w2ui-grid .w2ui-grid-body div.w2ui-col-header{height:auto!important;width:100%;overflow:hidden;padding-right:10px!important}.w2ui-grid .w2ui-grid-body div.w2ui-col-header>div.w2ui-sort-up{border:4px solid transparent;border-bottom:5px solid #8d99a7;margin-top:-2px;margin-right:-7px;float:right}.w2ui-grid .w2ui-grid-body div.w2ui-col-header>div.w2ui-sort-down{border:4px solid transparent;border-top:5px solid #8d99a7;margin-top:2px;margin-right:-7px;float:right}.w2ui-grid .w2ui-grid-body .w2ui-col-group{text-align:center}.w2ui-grid .w2ui-changed{background:url(data:image/gif;base64,R0lGODlhCgAKAJEAALAABf///wAAAAAAACH5BAEAAAIALAAAAAAKAAoAAAIPlI8Hy8mbxIsSUnup3rQAADs=) no-repeat top right}.w2ui-grid .w2ui-editable{overflow:hidden;height:100%!important;margin:0!important;padding:0!important}.w2ui-grid .w2ui-editable input{border:0;border-radius:0;margin:0;padding:4px 3px;width:100%;height:100%}.w2ui-grid .w2ui-editable input.w2ui-select{outline:none!important;background:#fff}.w2ui-grid .w2ui-grid-summary{position:absolute;box-shadow:0 -1px 4px #aaa}.w2ui-grid .w2ui-grid-summary table{color:inherit}.w2ui-grid .w2ui-grid-summary table .w2ui-odd{background-color:#eef5eb}.w2ui-grid .w2ui-grid-summary table .w2ui-even{background-color:#f8fff5}.w2ui-grid .w2ui-grid-footer{position:absolute;margin:0;padding:0;text-align:center;height:24px;overflow:hidden;user-select:text;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;-o-user-select:text;box-shadow:0 -1px 4px #eee;color:#444;background-color:#f8f8f8;border-top:1px solid #ddd;border-bottom-left-radius:2px;border-bottom-right-radius:2px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-left{float:left;padding-top:5px;padding-left:5px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-right{float:right;padding-top:5px;padding-right:5px}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center{padding:2px;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav{width:110px;margin:0 auto;padding:0;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav input[type=text]{padding:1px 2px 2px 2px;border-radius:3px;width:40px;text-align:center}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn{display:inline-block;border-radius:3px;cursor:pointer;font-size:11px;line-height:16px;padding:1px 5px;width:30px;height:18px;margin-top:-1px;color:#000;background-color:transparent}.w2ui-grid .w2ui-grid-footer .w2ui-footer-center .w2ui-footer-nav a.w2ui-footer-btn:hover{color:#000;background-color:#aec8ff}.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-odd:hover,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-even:hover{background-color:inherit}.w2ui-ss .w2ui-grid-records table td{border-right-width:1px;border-bottom:1px solid #efefef}.w2ui-ss .w2ui-grid-records table tr:first-child td{border-bottom:0}.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr.w2ui-selected,.w2ui-ss .w2ui-grid-body .w2ui-grid-records table tr td.w2ui-selected{background-color:#eef4fe!important}.w2ui-ss .w2ui-changed{background:inherit}.w2ui-ss .w2ui-grid-body .w2ui-selection{position:absolute;border:2px solid #6299da;pointer-events:none}.w2ui-ss .w2ui-grid-body .w2ui-selection .w2ui-selection-resizer{cursor:crosshair;position:absolute;bottom:0;right:0;width:6px;height:6px;margin-right:-3px;margin-bottom:-3px;background-color:#457fc2;border:.5px solid #fff;outline:1px solid #fff;pointer-events:auto}.w2ui-overlay .w2ui-select-field{padding:8px 5px;cursor:default}.w2ui-overlay .w2ui-select-field table{font-size:11px;font-family:Verdana,Arial,sans-serif;border-spacing:0;border-collapse:border-collapse}.w2ui-overlay .w2ui-select-field table tr:hover{background-color:#b6d5ff}.w2ui-overlay .w2ui-select-field table td:nth-child(1){padding:3px 3px 3px 6px}.w2ui-overlay .w2ui-select-field table td:nth-child(1) input{margin:3px 2px 2px 2px}.w2ui-overlay .w2ui-select-field table td:nth-child(2){padding:3px 15px 3px 3px}.w2ui-overlay .w2ui-col-on-off{padding:4px 0}.w2ui-overlay .w2ui-col-on-off table{border-spacing:0;border-collapse:border-collapse}.w2ui-overlay .w2ui-col-on-off table tr:hover{background-color:#b6d5ff}.w2ui-overlay .w2ui-col-on-off table td input[type=checkbox]{margin:3px 2px 2px 2px}.w2ui-overlay .w2ui-col-on-off table td label{display:block;padding:3px 0;padding-right:10px}.w2ui-overlay .w2ui-col-on-off table td:first-child{padding:4px 0 4px 6px}.w2ui-overlay .w2ui-col-on-off table td:last-child{padding:4px 6px 4px 0}.w2ui-overlay .w2ui-grid-searches{text-align:left;padding:0;border-top:0;background-color:#f7f6f0}.w2ui-overlay .w2ui-grid-searches table{padding:4px;padding-top:12px;border-collapse:border-collapse}.w2ui-overlay .w2ui-grid-searches table td{padding:4px}.w2ui-overlay .w2ui-grid-searches table td.close-btn{width:20px;padding-right:20px}.w2ui-overlay .w2ui-grid-searches table td.close-btn button{min-width:24px;height:24px;padding-top:6px!important}.w2ui-overlay .w2ui-grid-searches table td.caption{text-align:right;padding-right:5px;border-right:1px solid #e8e8e3}.w2ui-overlay .w2ui-grid-searches table td.operator{text-align:left;padding:0 10px;padding-right:5px;border-right:1px solid #e8e8e3}.w2ui-overlay .w2ui-grid-searches table td.operator select{width:100%;color:#000;padding:0 15px 0 5px;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;-o-appearance:none;background-image:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-ms-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-image:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%)}.w2ui-overlay .w2ui-grid-searches table td.operator select::-ms-expand{display:none}.w2ui-overlay .w2ui-grid-searches table td.value{padding-right:5px;padding-left:5px}.w2ui-overlay .w2ui-grid-searches table td.value input[type=text]{border-radius:3px;padding:3px;margin-right:3px;height:23px}.w2ui-overlay .w2ui-grid-searches table td.value select{padding:3px;margin-right:3px;height:23px}.w2ui-overlay .w2ui-grid-searches table td.actions{border-right:0}.w2ui-overlay .w2ui-grid-searches table td.actions>div{margin:-7px;margin-top:15px;padding:13px 0;text-align:center;background-color:#efefe9;border-top:1px solid #e8e8e3}.w2ui-popup{position:fixed;z-index:1600;overflow:hidden;font-family:Verdana,Arial,sans-serif;border-radius:6px;padding:0;margin:0;border:1px solid #777;background-color:#eee;box-shadow:0 0 25px #555}.w2ui-popup,.w2ui-popup *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-popup .w2ui-msg-title{padding:6px;border-radius:6px 6px 0 0;background-image:-webkit-linear-gradient(#ececec,#dfdfdf);background-image:-moz-linear-gradient(#ececec,#dfdfdf);background-image:-ms-linear-gradient(#ececec,#dfdfdf);background-image:-o-linear-gradient(#ececec,#dfdfdf);background-image:linear-gradient(#ececec,#dfdfdf);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffececec',endColorstr='#ffdfdfdf',GradientType=0);border-bottom:2px solid #bfbfbf;position:absolute;overflow:hidden;height:32px;left:0;right:0;top:0;text-overflow:ellipsis;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;cursor:move;font-size:15px;color:#555;z-index:300}.w2ui-popup .w2ui-msg-button{float:right;width:18px;height:18px;cursor:pointer;overflow:hidden;padding:0;margin:0 3px 0 0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAj1JREFUeNrslr9rFFEQxz/zZi/qxSgW2lsqkiYoBku5Ro1o4UFKEYkgSaxSCLYqdv5IEVPYCMJJwERWrK0CKhoQ8hdobQTjXW7njcXlYnLunQQu0YDTLOy+Nzvfme98Z8Td2ckW2OGWdMvRvYfT/RGfBPoBBVpLK0AEPgVkdGL06vt/CoB5nBaRE8AXYKXNsQIwaB4fAwOtH+88mn4m7ifN4vUYebWBKkFKqjIV3N9NjI2Uuw5ARI45fBanH+F77iFnN8JHETmS68P9NHBQNTwHL8foaSN4SqoyA/SZyL4tqQAQBVYCLOFYlNxmq0WorVLpN9Oe5LKt1CsgRVWpAOfB66phBuhTkepSdfnKVjaxNJMSWn/iawmTtpeDp6pWBpaBoqrMqoYU6AOqIbFhxGa3R4V8nfNNKLUESzXJhoCvQC+wF/gW1C5IiC+2XUbD5jA3rd4C26NR3945IA2iRzqRJgdElJJlSQocAKrAD2A/6Ev3cLajjN59MDWHyKl2voOI1zKbv3Xj2lCHJFoz+LXuBoIAjnUklEvJrDDT5LwmdhG8blkyBxRjXSu4loE0X4VEznXKV3SnoOFMB7YUolBcbcKNdxuPXUBPu8pbLXsK0ghebVjEXgNoYmXLtGLuxd6ePU+AQ20AaIrb4DpFycmSv81/7YsiMgAstB1kQgE47O4LuQmCNwGOB7VxCb/URsRSTbhkmU4ifGiZHd1Z5m7fnxoIQSaBo39YJRZj9LGb4yPzXWm1/9voX7afAwAC5tacDTA2XgAAAABJRU5ErkJggg==) no-repeat center left;background-position:0 0;color:transparent!important;border-radius:3px;border:1px solid transparent}.w2ui-popup .w2ui-msg-close{margin-top:0;background-position:-32px 0}.w2ui-popup .w2ui-msg-close:hover{background-color:#ccc;border:1px solid #aaa}.w2ui-popup .w2ui-msg-max{background-position:-16px 0}.w2ui-popup .w2ui-msg-max:hover{background-color:#ccc;border:1px solid #aaa}.w2ui-popup .w2ui-box1,.w2ui-popup .w2ui-box2{position:absolute;left:0;right:0;top:32px;bottom:55px;z-index:100}.w2ui-popup .w2ui-msg-body{font-size:13px;line-height:130%;padding:0 7px 7px 7px;color:#000;background-color:#eee;position:absolute;overflow:auto;width:100%;height:100%}.w2ui-popup .w2ui-popup-message{position:absolute;z-index:250;background-color:#f9f9f9;border:1px solid #999;box-shadow:0 0 15px #aaa;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;border-top:0;border-radius:0 0 6px 6px;overflow:auto}.w2ui-popup .w2ui-msg-buttons{padding:12px;border-radius:0 0 6px 6px;border-top:1px solid #d5d8d8;background-color:#f1f1f1;text-align:center;position:absolute;overflow:hidden;height:52px;left:0;right:0;bottom:0;z-index:200}.w2ui-popup .w2ui-msg-no-title{border-top-left-radius:6px;border-top-right-radius:6px;top:0!important}.w2ui-popup .w2ui-msg-no-buttons{border-bottom-left-radius:6px;border-bottom-right-radius:6px;bottom:0!important}.w2ui-sidebar{cursor:default;overflow:hidden!important;background-color:#edf1f6!important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-sidebar *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-sidebar>div{position:relative;overflow:hidden}.w2ui-sidebar .w2ui-sidebar-top{position:absolute;z-index:2;top:0;left:0;right:0}.w2ui-sidebar .w2ui-sidebar-bottom{position:absolute;z-index:2;bottom:0;left:0;right:0}.w2ui-sidebar .w2ui-sidebar-div{position:absolute;z-index:1;overflow:auto;top:0;bottom:0;left:0;right:0;padding:2px 0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-sidebar .w2ui-sidebar-div table{width:100%}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node{background-color:#edf1f6;border-top:1px solid transparent;border-bottom:1px solid transparent;margin:0;padding:1px 0}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node table{pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots{color:#000;text-shadow:0 0 0 #fff;pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-caption:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span:hover,.w2ui-sidebar .w2ui-sidebar-div .w2ui-node td.w2ui-node-dots:hover{color:inherit}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node:hover{border-top:1px solid #f9f9f9;border-bottom:1px solid #f9f9f9;background-color:#d7e1ef}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image{width:22px;text-align:center;pointer-events:none}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node .w2ui-node-image>span{color:#516173!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node input{pointer-events:auto}.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover{background-image:-webkit-linear-gradient(#69b1e0,#4a96d3);background-image:-moz-linear-gradient(#69b1e0,#4a96d3);background-image:-ms-linear-gradient(#69b1e0,#4a96d3);background-image:-o-linear-gradient(#69b1e0,#4a96d3);background-image:linear-gradient(#69b1e0,#4a96d3);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0',endColorstr='#ff4a96d3',GradientType=0);border-top:1px solid #5295cd;border-bottom:1px solid #2661a6}.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected td.w2ui-node-dots,.w2ui-sidebar .w2ui-sidebar-div .w2ui-selected:hover td.w2ui-node-dots{color:#fff!important;text-shadow:1px 1px 2px #666!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover{background:transparent!important;border-top:1px solid transparent;border-bottom:1px solid transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-caption,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover .w2ui-node-image>span,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled td.w2ui-node-dots,.w2ui-sidebar .w2ui-sidebar-div .w2ui-disabled:hover td.w2ui-node-dots{opacity:.4;filter:alpha(opacity=40);color:#000!important;text-shadow:0 0 0 #fff!important}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-caption{white-space:nowrap;padding:5px 0 5px 3px;margin:1px 0 1px 22px;position:relative;z-index:1;font-size:12px}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group{white-space:nowrap;overflow:hidden;padding:10px 0 10px 10px;margin:0;cursor:default;color:#868b92;background-color:transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(1){margin-right:10px;float:right;color:transparent}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-group :nth-child(2){font-weight:normal;text-transform:uppercase}.w2ui-sidebar .w2ui-sidebar-div .w2ui-node-sub{overflow:hidden}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots{width:18px;padding:0 0 1px 7px;text-align:center}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-dots .w2ui-expand{width:16px;margin-top:-3px;pointer-events:auto}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data{padding:1px 1px 3px 1px}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image{padding:3px 0 0 0;float:left}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image>span{font-size:16px;color:#000;text-shadow:0 0 0 #fff}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-image.w2ui-icon{margin-top:3px}.w2ui-sidebar .w2ui-sidebar-div td.w2ui-node-data .w2ui-node-count{float:right;border:1px solid #9da4af;border-radius:20px;width:auto;height:18px;padding:2px 7px;margin:3px 4px -2px 0;background-color:#e7f0fc;color:#667274;box-shadow:0 0 2px #fff;text-shadow:1px 1px 1px #e6e6e6;position:relative;z-index:2}.w2ui-tabs{cursor:default;overflow:hidden!important;background-color:#fafafa;padding:3px 0;padding-bottom:0!important}.w2ui-tabs table{border-bottom:1px solid silver;padding:0 7px}.w2ui-tabs .w2ui-tab{padding:6px 20px;text-align:center;color:#000;background-color:transparent;border:1px solid silver;border-bottom:1px solid silver;white-space:nowrap;margin:1px 1px -1px 0;border-top-left-radius:4px;border-top-right-radius:4px;cursor:default}.w2ui-tabs .w2ui-tab.active{color:#000;background-color:#fff;border:1px solid silver;border-bottom:1px solid transparent}.w2ui-tabs .w2ui-tab.closable{padding:6px 28px 6px 20px}.w2ui-tabs .w2ui-tab-close{color:#555;text-shadow:1px 1px 1px #bbb;float:right;margin:6px 4px 0 0;padding:0 0 0 5px;width:16px;height:16px;opacity:.9;border:0;border-top:3px solid transparent;border-radius:9px}.w2ui-tabs .w2ui-tab-close:hover{background-color:#d77f7f;color:#fff}.w2ui-tabs .w2ui-tab-close:before{position:relative;top:-2px;left:0;opacity:.6;color:inherit;text-shadow:inherit;content:'x'}.w2ui-toolbar{margin:0;padding:2px;outline:0;background-color:#efefef;overflow:hidden!important;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.w2ui-toolbar .disabled{opacity:.3;filter:alpha(opacity=30)}.w2ui-toolbar table{table-layout:auto!important}.w2ui-toolbar table td{border:0!important}.w2ui-toolbar table.w2ui-button{margin:0 1px;border-radius:4px;height:24px;border:1px solid transparent;background-color:transparent}.w2ui-toolbar table.w2ui-button .w2ui-tb-image{width:16px;height:16px;padding:0;margin:2px 4px 3px 3px!important;border:0!important;text-align:center}.w2ui-toolbar table.w2ui-button .w2ui-tb-image>span{font-size:15px;margin-top:3px;display:block;color:#8d99a7}.w2ui-toolbar table.w2ui-button .w2ui-tb-caption{color:#000;padding:0 4px 0 2px}.w2ui-toolbar table.w2ui-button .w2ui-tb-count{padding:0 4px 0 0}.w2ui-toolbar table.w2ui-button .w2ui-tb-count>span{border:1px solid #9da4af;border-radius:20px;width:auto;height:18px;padding:2px 7px;background-color:#e7f0fc;color:#667274;box-shadow:0 0 2px #fff;text-shadow:1px 1px 1px #e6e6e6}.w2ui-toolbar table.w2ui-button .w2ui-tb-down{padding:3px}.w2ui-toolbar table.w2ui-button .w2ui-tb-down>div{border:4px solid transparent;border-top:5px solid #8d99a7;margin-top:5px}.w2ui-toolbar table.w2ui-button.over{border:1px solid #ccc;background-color:#eee}.w2ui-toolbar table.w2ui-button.over .w2ui-tb-caption{color:#000}.w2ui-toolbar table.w2ui-button.down{border:1px solid #aaa;background-color:#ddd}.w2ui-toolbar table.w2ui-button.down .w2ui-tb-caption{color:#666}.w2ui-toolbar table.w2ui-button.checked{border:1px solid #aaa;background-color:#fff}.w2ui-toolbar table.w2ui-button.checked .w2ui-tb-caption{color:#000}.w2ui-toolbar table.w2ui-button table{height:17px;border-radius:4px;cursor:default}.w2ui-toolbar .w2ui-break{background-image:-webkit-linear-gradient(top,rgba(153,153,153,.1) 0%,#999 40%,#999 60%,rgba(153,153,153,.1) 100%);background-image:-moz-linear-gradient(top,rgba(153,153,153,.1) 0%,#999 40%,#999 60%,rgba(153,153,153,.1) 100%);background-image:-ms-linear-gradient(top,rgba(153,153,153,.1) 0%,#999 40%,#999 60%,rgba(153,153,153,.1) 100%);background-image:-o-linear-gradient(top,rgba(153,153,153,.1) 0%,#999 40%,#999 60%,rgba(153,153,153,.1) 100%);background-image:linear-gradient(top,rgba(153,153,153,.1) 0%,#999 40%,#999 60%,rgba(153,153,153,.1) 100%);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff999999',endColorstr='#ff999999',GradientType=0);width:1px!important;height:22px;padding:0;margin:0 6px}.w2ui-listview{overflow:auto!important;background-color:#fff!important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-listview *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}.w2ui-listview>ul{list-style-type:none;margin:0;cursor:default}.w2ui-listview>ul>li{display:inline-block;vertical-align:top;overflow:hidden;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;border:1px solid transparent;border-radius:4px}.w2ui-listview>ul>li.w2ui-focused{border:1px solid #2661a6}.w2ui-listview>ul>li.w2ui-selected{border:1px solid #2661a6}.w2ui-listview>ul>li.w2ui-selected,.w2ui-listview>ul>li.w2ui-selected.hover{background-image:-webkit-linear-gradient(#69b1e0,#4a96d3);background-image:-moz-linear-gradient(#69b1e0,#4a96d3);background-image:-ms-linear-gradient(#69b1e0,#4a96d3);background-image:-o-linear-gradient(#69b1e0,#4a96d3);background-image:linear-gradient(#69b1e0,#4a96d3);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0',endColorstr='#ff4a96d3',GradientType=0)}.w2ui-listview>ul>li.w2ui-selected>div>div.caption,.w2ui-listview>ul>li.w2ui-selected.hover>div>div.caption{color:#fff}.w2ui-listview>ul>li.w2ui-selected>div>div.description,.w2ui-listview>ul>li.w2ui-selected.hover>div>div.description{color:#ddd}.w2ui-listview>ul>li.w2ui-selected>div>div.extra>div>div,.w2ui-listview>ul>li.w2ui-selected.hover>div>div.extra>div>div{color:#ddd}.w2ui-listview>ul>li.hover{background-color:#d7e1ef;border:1px solid #2661a6}.w2ui-listview>ul>li div{vertical-align:middle}.w2ui-listview>ul>li>div>div.caption{display:block;text-align:center;word-wrap:break-word;max-height:50px;color:#000;font-size:12px}.w2ui-listview>ul>li>div>div.description{display:none;text-align:left;color:#777;font-size:12px}.w2ui-listview>ul>li>div>div.extra{display:none}.w2ui-listview>ul>li>div>div.extra>div>div{color:#777}.w2ui-icon-small>ul{padding:1px 0 0 1px}.w2ui-icon-small>ul>li{margin:0 1px 1px 0;padding:2px;width:250px;white-space:nowrap}.w2ui-icon-small>ul>li>div>div.w2ui-listview-img{display:inline-block;width:26px;height:22px;font-size:21px;margin-right:2px}.w2ui-icon-small>ul>li>div>div.caption{display:inline-block}.w2ui-icon-medium>ul{padding:4px 0 0 4px}.w2ui-icon-medium>ul>li{margin:0 4px 4px 0;padding:4px;width:100px}.w2ui-icon-medium>ul>li>div>div.w2ui-listview-img{display:block;width:92px;height:60px;font-size:57px;margin-left:auto;margin-right:auto;background-position:center}.w2ui-icon-large>ul{padding:4px 0 0 4px}.w2ui-icon-large>ul>li{margin:0 4px 4px 0;padding:4px;width:160px}.w2ui-icon-large>ul>li>div>div.w2ui-listview-img{display:block;width:152px;height:120px;font-size:114px;margin-left:auto;margin-right:auto;background-position:center}.w2ui-icon-tile>ul{padding:1px 0 0 1px}.w2ui-icon-tile>ul>li{margin:0 1px 1px 0;padding:4px;width:250px;white-space:nowrap}.w2ui-icon-tile>ul>li>div>div.w2ui-listview-img{display:inline-block;width:72px;height:60px;font-size:57px;float:left;margin-right:4px}.w2ui-icon-tile>ul>li>div>div.caption{text-align:left}.w2ui-icon-tile>ul>li>div>div.description{display:block}.w2ui-table>ul{padding:0}.w2ui-table>ul>li{width:100%;padding:2px;border-radius:0;border-bottom:1px dotted #d3d3d3}.w2ui-table>ul>li>div{display:inline-block;position:relative;width:100%;white-space:nowrap;overflow:hidden}.w2ui-table>ul>li>div>div.w2ui-listview-img{display:inline-block;width:38px;height:32px;font-size:31px;margin-right:2px}.w2ui-table>ul>li>div>div.caption{display:inline-block}.w2ui-table>ul>li>div>div.extra{display:inline-block;position:absolute;right:0;height:100%;background-color:#fff}.w2ui-table>ul>li>div>div.extra>div:before{display:inline-block;height:100%;width:0;content:'';vertical-align:middle}.w2ui-table>ul>li>div>div.extra>div{display:inline}.w2ui-table>ul>li>div>div.extra>div>div{display:inline-block;font-size:12px}.w2ui-table>ul>li.w2ui-selected div.extra,.w2ui-table>ul>li.w2ui-selected.hover div.extra{background-image:-webkit-linear-gradient(#69b1e0,#4a96d3);background-image:-moz-linear-gradient(#69b1e0,#4a96d3);background-image:-ms-linear-gradient(#69b1e0,#4a96d3);background-image:-o-linear-gradient(#69b1e0,#4a96d3);background-image:linear-gradient(#69b1e0,#4a96d3);filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ff69b1e0',endColorstr='#ff4a96d3',GradientType=0)}.w2ui-table>ul>li.hover div.extra{background-color:#d7e1ef}.w2ui-listview>ul>li div.icon-none{border:1px solid rgba(102,102,102,.35)} \ No newline at end of file diff --git a/js/sam-admin-edit-item.js b/js/sam-admin-edit-item.js index 5bf6db7..5d70b28 100644 --- a/js/sam-admin-edit-item.js +++ b/js/sam-admin-edit-item.js @@ -175,10 +175,15 @@ var sam = sam || {}; var iVal = vi.val(); grid.w2grid({ name: name, - show: {selectColumn: true}, + show: { + selectColumn: true, + toolbar: true, + footer: true + }, multiSelect: true, columns: gc, url: url, + limit: 10000, onSelect: function(event) { event.onComplete = function() { var out = '', recs = this.getSelection(), data; @@ -419,7 +424,7 @@ var sam = sam || {}; postAjax = samAjaxUrl + '?action=load_posts&cstr=' + samEditorOptions.data.custList + - '&sp=' + sPost + '&spg=' + sPage; + '&sp=' + sPost + '&spg=' + sPage + '&limit=10000'; buildLGrid('posts-grid', postsGrid, postsIn, 'id', models.posts, postAjax); buildLGrid('x-posts-grid', xpostsGrid, xpostsIn, 'id', models.posts, postAjax); diff --git a/js/sam-admin-edit-item.min.js b/js/sam-admin-edit-item.min.js index 18bf3d1..621a8bf 100644 --- a/js/sam-admin-edit-item.min.js +++ b/js/sam-admin-edit-item.min.js @@ -1 +1 @@ -var sam=sam||{};(function(n){var t,i=samEditorOptions.media,r=samEditorOptions.strings;sam.media=t={buttonId:"#banner-media",adUrl:"#ad_img",adImgId:"#ad_img_id",adName:"#title",adDesc:"#item_description",adAlt:"#ad_alt",init:function(){n(this.buttonId).on("click",this.openMediaDialog)},openMediaDialog:function(n){if(n.preventDefault(),this._frame){this._frame.open();return}this._frame=t.frame=wp.media({title:i.title,button:{text:i.button},multiple:!1,library:{type:"image"}});this._frame.on("ready",function(){});this._frame.state("library").on("select",function(){var n=this.get("selection").single();t.handleMediaAttachment(n)});this._frame.open()},handleMediaAttachment:function(t){var i=t.toJSON();n(this.adUrl).val(i.url);n(this.adImgId).val(i.id);""==n(this.adName).val()&&""!=i.title&&n(this.adName).val(i.title);""==n(this.adDesc).val()&&""!=i.caption&&n(this.adDesc).val(i.caption);""==n(this.adAlt).val()&&""!=i.alt&&n(this.adAlt).val(i.alt)}};n(document).ready(function(){function ar(t,i,r,u,f,e){var o=r.val();i.w2grid({name:t,show:{selectColumn:!0},multiSelect:!0,columns:f,url:e,onSelect:function(n){n.onComplete=function(){for(var f,e="",t=this.getSelection(),i,n=0;n<\/div>').appendTo(hr);n("#ad_img").val(gi.adUrl+i[0].name);n("#files").html(""+r.file+" "+i[0].name+" "+r.uploaded+"<\/p>").addClass("updated").delay(3e3).fadeOut(1e3,function(){n(this).remove()})},Error:function(t,i){n('<\/div>').appendTo(hr);n("#files").html("Error("+i.code+"): "+i.message+"<\/p>").addClass("error").delay(3e3).fadeOut(1e3,function(){n(this).remove()})}}});uf.init();n("#adv_nick").combogrid({url:w+"?action=load_combo_data",datatype:"json",munit:"px",alternate:!0,colModel:i.comboGrid,select:function(t,i){return n("#adv_nick").val(i.item.slug),n("#adv_name").val(i.item.title),n("#adv_mail").val(i.item.email),!1}});n("#add-file-button").click(function(){var t=u.url+n("select#files_list option:selected").val();return n("#ad_img").val(t),!1});e("ctt-grid",fi,su,"slug",i.customTaxes,kt.cTax);e("x-ctt-grid",ei,hu,"slug",i.customTaxes,kt.cTax);e("cust-grid",pi,du,"slug",i.customs,kt.customs);e("x-cust-grid",wi,gu,"slug",i.customs,kt.customs);nr=w+"?action=load_posts&cstr="+samEditorOptions.data.custList+"&sp="+nf+"&spg="+tf;ar("posts-grid",oi,cu,"id",i.posts,nr);ar("x-posts-grid",si,au,"id",i.posts,nr);n("#tabs").tabs({activate:function(t,i){var r=i.newPanel[0].id;r=="tabs-1"&&w2ui["posts-grid"]&&oi.w2render("posts-grid");r=="tabs-2"&&(vt.is(":visible")&&w2ui["ctt-grid"]&&fi.w2render("ctt-grid"),rt.is(":visible")&&w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid"),g.is(":visible")&&w2ui["x-posts-grid"]&&si.w2render("x-posts-grid"),at.is(":visible")&&w2ui["cats-grid"]&&hi.w2render("cats-grid"),tt.is(":visible")&&w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid"),yt.is(":visible")&&w2ui["auth-grid"]&&li.w2render("auth-grid"),ft.is(":visible")&&w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid"),pt.is(":visible")&&w2ui["tags-grid"]&&vi.w2render("tags-grid"),ot.is(":visible")&&w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid"),wt.is(":visible")&&w2ui["cust-grid"]&&pi.w2render("cust-grid"),ht.is(":visible")&&w2ui["xcust-grid"]&&wi.w2render("x-cust-grid"));r=="tabs-3"&&ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid");r=="tabs-5"&&o&&(o.destroy(),o=n.jqplot("graph",b,dt))}});n(window).resize(function(){o&&(o.destroy(),o=n.jqplot("graph",b,dt))});n("#code_mode_false").click(function(){ur.show("blind",{direction:"vertical"},500);fr.hide("blind",{direction:"vertical"},500)});n("#code_mode_true").click(function(){ur.hide("blind",{direction:"vertical"},500);fr.show("blind",{direction:"vertical"},500)});2==n("input:radio[name=view_type]:checked").val()&&(f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)),f.attr("disabled",!0));n("input:radio[name=view_type]").click(function(){var t=n("input:radio[name=view_type]:checked").val();switch(t){case"0":s.is(":hidden")&&s.show("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"1":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"2":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":hidden")&&(h.show("blind",{direction:"vertical"},500,function(){w2ui["posts-grid"]&&oi.w2render("posts-grid")}),f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)));f.attr("disabled",!0)}});vr=n.ajax({url:w,data:{action:"load_authors",level:3},type:"POST"});vr.done(function(n){tr=n;e("auth-grid",li,pu,"slug",i.authors,tr);e("x-auth-grid",ai,wu,"slug",i.authors,tr)});yr=n.ajax({url:w,data:{action:"load_users",subscriber:encodeURI(u.subscriber),contributor:encodeURI(u.contributor),author:encodeURI(u.author),editor:encodeURI(u.editor),admin:encodeURI(u.admin),sadmin:encodeURI(u.superAdmin)},type:"POST"});yr.done(function(n){pr=n;e("users-grid",lt,lu,"slug",i.users,pr)});wr=n.ajax({url:w,data:{action:"load_cats",level:3},type:"POST"});wr.done(function(n){ir=n;e("cats-grid",hi,vu,"slug",i.cats,ir);e("x-cats-grid",ci,yu,"slug",i.cats,ir)});br=n.ajax({url:w,data:{action:"load_tags",level:3},type:"POST"});br.done(function(n){rr=n;e("tags-grid",vi,bu,"slug",i.tags,rr);e("x-tags-grid",yi,ku,"slug",i.tags,rr)});f.click(function(){f.is(":checked")?2==n("input:radio[name=view_type]:checked").val()?f.attr("checked",!1):g.show("blind",{direction:"vertical"},500,function(){w2ui["x-posts-grid"]&&si.w2render("x-posts-grid")}):g.hide("blind",{direction:"vertical"},500)});n("input:radio[name=ad_users]").click(function(){var t=n("input:radio[name=ad_users]:checked").val();t=="0"?bt.is(":visible")&&bt.hide("blind",{direction:"vertical"},500):bt.is(":hidden")&&bt.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")})});er.click(function(){er.is(":checked")?or.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")}):or.hide("blind",{direction:"vertical"},500)});sr.click(function(){sr.is(":checked")?ct.show("blind",{direction:"vertical"},500,function(){w2ui["users-grid"]&<.w2render("users-grid")}):ct.hide("blind",{direction:"vertical"},500)});n("#ad_swf").click(function(){n("#ad_swf").is(":checked")?n("#swf-params").show("blind",{direction:"vertical"},500):n("#swf-params").hide("blind",{direction:"vertical"},500)});nt.is(":checked")&&c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500));nt.click(function(){nt.is(":checked")?(at.show("blind",{direction:"vertical"},500,function(){w2ui["cats-grid"]&&hi.w2render("cats-grid")}),ni.show("blind",{direction:"vertical"},500),c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500))):(at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))});c.click(function(){c.is(":checked")?(tt.show("blind",{direction:"vertical"},500,function(){w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid")}),nt.is(":checked")&&(nt.attr("checked",!1),at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))):tt.hide("blind",{direction:"vertical"},500)});it.is(":checked")&&l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500));it.click(function(){it.is(":checked")?(vt.show("blind",{direction:"vertical"},500,function(){w2ui["ctt-grid"]&&fi.w2render("ctt-grid")}),ti.show("blind",{direction:"vertical"},500),l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500))):(vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))});l.click(function(){l.is(":checked")?(rt.show("blind",{direction:"vertical"},500,function(){w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid")}),it.is(":checked")&&(it.attr("checked",!1),vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))):rt.hide("blind",{direction:"vertical"},500)});ut.is(":checked")&&a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500));ut.click(function(){ut.is(":checked")?(yt.show("blind",{direction:"vertical"},500,function(){w2ui["auth-grid"]&&li.w2render("auth-grid")}),ii.show("blind",{direction:"vertical"},500),a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500))):(yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))});a.click(function(){a.is(":checked")?(ft.show("blind",{direction:"vertical"},500,function(){w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid")}),ut.is(":checked")&&(ut.attr("checked",!1),yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))):ft.hide("blind",{direction:"vertical"},500)});et.is(":checked")&&v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500));et.click(function(){et.is(":checked")?(pt.show("blind",{direction:"vertical"},500,function(){w2ui["tags-grid"]&&vi.w2render("tags-grid")}),ri.show("blind",{direction:"vertical"},500),v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500))):(pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))});v.click(function(){v.is(":checked")?(ot.show("blind",{direction:"vertical"},500,function(){w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid")}),et.is(":checked")&&(et.attr("checked",!1),pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))):ot.hide("blind",{direction:"vertical"},500)});st.is(":checked")&&y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500));st.click(function(){st.is(":checked")?(wt.show("blind",{direction:"vertical"},500,function(){w2ui["cust-grid"]&&pi.w2render("cust-grid")}),ui.show("blind",{direction:"vertical"},500),y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500))):(wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))});y.click(function(){y.is(":checked")?(ht.show("blind",{direction:"vertical"},500,function(){w2ui["x-cust-grid"]&&wi.w2render("x-cust-grid")}),st.is(":checked")&&(st.attr("checked",!1),wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))):ht.hide("blind",{direction:"vertical"},500)});n("#ad_start_date, #ad_end_date").datepicker({dateFormat:"yy-mm-dd",showButtonPanel:!0});n("#ad_schedule").click(function(){n("#ad_schedule").is(":checked")?n("#rc-sc").show("blind",{direction:"vertical"},500):n("#rc-sc").hide("blind",{direction:"vertical"},500)});n("#limit_hits").click(function(){n("#limit_hits").is(":checked")?n("#rc-hl").show("blind",{direction:"vertical"},500):n("#rc-hl").hide("blind",{direction:"vertical"},500)});n("#limit_clicks").click(function(){n("#limit_clicks").is(":checked")?n("#rc-cl").show("blind",{direction:"vertical"},500):n("#rc-cl").hide("blind",{direction:"vertical"},500)});p=samEditorOptions.ads;p.pointer="ads";(p.enabled||""==gt.val())&>.pointer({content:""+p.title+"<\/h3>"+p.content+"<\/p>",position:"top",close:function(){n.ajax({url:ajaxurl,data:{action:"close_pointer",pointer:p.pointer},async:!0})}}).pointer("open");var k=n("#is_singular"),kr=n("#is_single"),dr=n("#is_page"),gr=n("#is_attachment"),nu=n("#is_posttype");k.click(function(){k.is(":checked")&&n("#is_single, #is_page, #is_attachment, #is_posttype").attr("checked",!0)});n("#is_single, #is_page, #is_attachment, #is_posttype").click(function(){!k.is(":checked")||kr.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&nu.is(":checked")?!k.is(":checked")&&kr.is(":checked")&&nu.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&k.attr("checked",!0):k.attr("checked",!1)});var d=n("#is_archive"),tu=n("#is_tax"),iu=n("#is_category"),ru=n("#is_tag"),uu=n("#is_author"),fu=n("#is_date"),eu=n("#is_posttype_archive"),ou=n("#is_tax, #is_category, #is_tag, #is_author, #is_date, #is_posttype_archive");return d.click(function(){d.is(":checked")&&ou.attr("checked",!0)}),ou.click(function(){!d.is(":checked")||tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")?!d.is(":checked")&&tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")&&d.attr("checked",!0):d.attr("checked",!1)}),n("#stats_month").change(function(){bi=n(this).val();n.post(cr,{action:"load_item_stats",id:lr,sm:bi}).done(function(t){n("#total_hits").text(t.total.hits);n("#total_clicks").text(t.total.clicks);b=[t.hits,t.clicks];o&&(o.destroy(),o=n.jqplot("graph",b,dt))})}),!1})})(jQuery) \ No newline at end of file +var sam=sam||{};(function(n){var t,i=samEditorOptions.media,r=samEditorOptions.strings;sam.media=t={buttonId:"#banner-media",adUrl:"#ad_img",adImgId:"#ad_img_id",adName:"#title",adDesc:"#item_description",adAlt:"#ad_alt",init:function(){n(this.buttonId).on("click",this.openMediaDialog)},openMediaDialog:function(n){if(n.preventDefault(),this._frame){this._frame.open();return}this._frame=t.frame=wp.media({title:i.title,button:{text:i.button},multiple:!1,library:{type:"image"}});this._frame.on("ready",function(){});this._frame.state("library").on("select",function(){var n=this.get("selection").single();t.handleMediaAttachment(n)});this._frame.open()},handleMediaAttachment:function(t){var i=t.toJSON();n(this.adUrl).val(i.url);n(this.adImgId).val(i.id);""==n(this.adName).val()&&""!=i.title&&n(this.adName).val(i.title);""==n(this.adDesc).val()&&""!=i.caption&&n(this.adDesc).val(i.caption);""==n(this.adAlt).val()&&""!=i.alt&&n(this.adAlt).val(i.alt)}};n(document).ready(function(){function ar(t,i,r,u,f,e){var o=r.val();i.w2grid({name:t,show:{selectColumn:!0,toolbar:!0,footer:!0},multiSelect:!0,columns:f,url:e,limit:1e4,onSelect:function(n){n.onComplete=function(){for(var f,e="",t=this.getSelection(),i,n=0;n<\/div>').appendTo(hr);n("#ad_img").val(gi.adUrl+i[0].name);n("#files").html(""+r.file+" "+i[0].name+" "+r.uploaded+"<\/p>").addClass("updated").delay(3e3).fadeOut(1e3,function(){n(this).remove()})},Error:function(t,i){n('<\/div>').appendTo(hr);n("#files").html("Error("+i.code+"): "+i.message+"<\/p>").addClass("error").delay(3e3).fadeOut(1e3,function(){n(this).remove()})}}});uf.init();n("#adv_nick").combogrid({url:w+"?action=load_combo_data",datatype:"json",munit:"px",alternate:!0,colModel:i.comboGrid,select:function(t,i){return n("#adv_nick").val(i.item.slug),n("#adv_name").val(i.item.title),n("#adv_mail").val(i.item.email),!1}});n("#add-file-button").click(function(){var t=u.url+n("select#files_list option:selected").val();return n("#ad_img").val(t),!1});e("ctt-grid",fi,su,"slug",i.customTaxes,kt.cTax);e("x-ctt-grid",ei,hu,"slug",i.customTaxes,kt.cTax);e("cust-grid",pi,du,"slug",i.customs,kt.customs);e("x-cust-grid",wi,gu,"slug",i.customs,kt.customs);nr=w+"?action=load_posts&cstr="+samEditorOptions.data.custList+"&sp="+nf+"&spg="+tf+"&limit=10000";ar("posts-grid",oi,cu,"id",i.posts,nr);ar("x-posts-grid",si,au,"id",i.posts,nr);n("#tabs").tabs({activate:function(t,i){var r=i.newPanel[0].id;r=="tabs-1"&&w2ui["posts-grid"]&&oi.w2render("posts-grid");r=="tabs-2"&&(vt.is(":visible")&&w2ui["ctt-grid"]&&fi.w2render("ctt-grid"),rt.is(":visible")&&w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid"),g.is(":visible")&&w2ui["x-posts-grid"]&&si.w2render("x-posts-grid"),at.is(":visible")&&w2ui["cats-grid"]&&hi.w2render("cats-grid"),tt.is(":visible")&&w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid"),yt.is(":visible")&&w2ui["auth-grid"]&&li.w2render("auth-grid"),ft.is(":visible")&&w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid"),pt.is(":visible")&&w2ui["tags-grid"]&&vi.w2render("tags-grid"),ot.is(":visible")&&w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid"),wt.is(":visible")&&w2ui["cust-grid"]&&pi.w2render("cust-grid"),ht.is(":visible")&&w2ui["xcust-grid"]&&wi.w2render("x-cust-grid"));r=="tabs-3"&&ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid");r=="tabs-5"&&o&&(o.destroy(),o=n.jqplot("graph",b,dt))}});n(window).resize(function(){o&&(o.destroy(),o=n.jqplot("graph",b,dt))});n("#code_mode_false").click(function(){ur.show("blind",{direction:"vertical"},500);fr.hide("blind",{direction:"vertical"},500)});n("#code_mode_true").click(function(){ur.hide("blind",{direction:"vertical"},500);fr.show("blind",{direction:"vertical"},500)});2==n("input:radio[name=view_type]:checked").val()&&(f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)),f.attr("disabled",!0));n("input:radio[name=view_type]").click(function(){var t=n("input:radio[name=view_type]:checked").val();switch(t){case"0":s.is(":hidden")&&s.show("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"1":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"2":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":hidden")&&(h.show("blind",{direction:"vertical"},500,function(){w2ui["posts-grid"]&&oi.w2render("posts-grid")}),f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)));f.attr("disabled",!0)}});vr=n.ajax({url:w,data:{action:"load_authors",level:3},type:"POST"});vr.done(function(n){tr=n;e("auth-grid",li,pu,"slug",i.authors,tr);e("x-auth-grid",ai,wu,"slug",i.authors,tr)});yr=n.ajax({url:w,data:{action:"load_users",subscriber:encodeURI(u.subscriber),contributor:encodeURI(u.contributor),author:encodeURI(u.author),editor:encodeURI(u.editor),admin:encodeURI(u.admin),sadmin:encodeURI(u.superAdmin)},type:"POST"});yr.done(function(n){pr=n;e("users-grid",lt,lu,"slug",i.users,pr)});wr=n.ajax({url:w,data:{action:"load_cats",level:3},type:"POST"});wr.done(function(n){ir=n;e("cats-grid",hi,vu,"slug",i.cats,ir);e("x-cats-grid",ci,yu,"slug",i.cats,ir)});br=n.ajax({url:w,data:{action:"load_tags",level:3},type:"POST"});br.done(function(n){rr=n;e("tags-grid",vi,bu,"slug",i.tags,rr);e("x-tags-grid",yi,ku,"slug",i.tags,rr)});f.click(function(){f.is(":checked")?2==n("input:radio[name=view_type]:checked").val()?f.attr("checked",!1):g.show("blind",{direction:"vertical"},500,function(){w2ui["x-posts-grid"]&&si.w2render("x-posts-grid")}):g.hide("blind",{direction:"vertical"},500)});n("input:radio[name=ad_users]").click(function(){var t=n("input:radio[name=ad_users]:checked").val();t=="0"?bt.is(":visible")&&bt.hide("blind",{direction:"vertical"},500):bt.is(":hidden")&&bt.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")})});er.click(function(){er.is(":checked")?or.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")}):or.hide("blind",{direction:"vertical"},500)});sr.click(function(){sr.is(":checked")?ct.show("blind",{direction:"vertical"},500,function(){w2ui["users-grid"]&<.w2render("users-grid")}):ct.hide("blind",{direction:"vertical"},500)});n("#ad_swf").click(function(){n("#ad_swf").is(":checked")?n("#swf-params").show("blind",{direction:"vertical"},500):n("#swf-params").hide("blind",{direction:"vertical"},500)});nt.is(":checked")&&c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500));nt.click(function(){nt.is(":checked")?(at.show("blind",{direction:"vertical"},500,function(){w2ui["cats-grid"]&&hi.w2render("cats-grid")}),ni.show("blind",{direction:"vertical"},500),c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500))):(at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))});c.click(function(){c.is(":checked")?(tt.show("blind",{direction:"vertical"},500,function(){w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid")}),nt.is(":checked")&&(nt.attr("checked",!1),at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))):tt.hide("blind",{direction:"vertical"},500)});it.is(":checked")&&l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500));it.click(function(){it.is(":checked")?(vt.show("blind",{direction:"vertical"},500,function(){w2ui["ctt-grid"]&&fi.w2render("ctt-grid")}),ti.show("blind",{direction:"vertical"},500),l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500))):(vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))});l.click(function(){l.is(":checked")?(rt.show("blind",{direction:"vertical"},500,function(){w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid")}),it.is(":checked")&&(it.attr("checked",!1),vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))):rt.hide("blind",{direction:"vertical"},500)});ut.is(":checked")&&a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500));ut.click(function(){ut.is(":checked")?(yt.show("blind",{direction:"vertical"},500,function(){w2ui["auth-grid"]&&li.w2render("auth-grid")}),ii.show("blind",{direction:"vertical"},500),a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500))):(yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))});a.click(function(){a.is(":checked")?(ft.show("blind",{direction:"vertical"},500,function(){w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid")}),ut.is(":checked")&&(ut.attr("checked",!1),yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))):ft.hide("blind",{direction:"vertical"},500)});et.is(":checked")&&v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500));et.click(function(){et.is(":checked")?(pt.show("blind",{direction:"vertical"},500,function(){w2ui["tags-grid"]&&vi.w2render("tags-grid")}),ri.show("blind",{direction:"vertical"},500),v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500))):(pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))});v.click(function(){v.is(":checked")?(ot.show("blind",{direction:"vertical"},500,function(){w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid")}),et.is(":checked")&&(et.attr("checked",!1),pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))):ot.hide("blind",{direction:"vertical"},500)});st.is(":checked")&&y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500));st.click(function(){st.is(":checked")?(wt.show("blind",{direction:"vertical"},500,function(){w2ui["cust-grid"]&&pi.w2render("cust-grid")}),ui.show("blind",{direction:"vertical"},500),y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500))):(wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))});y.click(function(){y.is(":checked")?(ht.show("blind",{direction:"vertical"},500,function(){w2ui["x-cust-grid"]&&wi.w2render("x-cust-grid")}),st.is(":checked")&&(st.attr("checked",!1),wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))):ht.hide("blind",{direction:"vertical"},500)});n("#ad_start_date, #ad_end_date").datepicker({dateFormat:"yy-mm-dd",showButtonPanel:!0});n("#ad_schedule").click(function(){n("#ad_schedule").is(":checked")?n("#rc-sc").show("blind",{direction:"vertical"},500):n("#rc-sc").hide("blind",{direction:"vertical"},500)});n("#limit_hits").click(function(){n("#limit_hits").is(":checked")?n("#rc-hl").show("blind",{direction:"vertical"},500):n("#rc-hl").hide("blind",{direction:"vertical"},500)});n("#limit_clicks").click(function(){n("#limit_clicks").is(":checked")?n("#rc-cl").show("blind",{direction:"vertical"},500):n("#rc-cl").hide("blind",{direction:"vertical"},500)});p=samEditorOptions.ads;p.pointer="ads";(p.enabled||""==gt.val())&>.pointer({content:""+p.title+"<\/h3>"+p.content+"<\/p>",position:"top",close:function(){n.ajax({url:ajaxurl,data:{action:"close_pointer",pointer:p.pointer},async:!0})}}).pointer("open");var k=n("#is_singular"),kr=n("#is_single"),dr=n("#is_page"),gr=n("#is_attachment"),nu=n("#is_posttype");k.click(function(){k.is(":checked")&&n("#is_single, #is_page, #is_attachment, #is_posttype").attr("checked",!0)});n("#is_single, #is_page, #is_attachment, #is_posttype").click(function(){!k.is(":checked")||kr.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&nu.is(":checked")?!k.is(":checked")&&kr.is(":checked")&&nu.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&k.attr("checked",!0):k.attr("checked",!1)});var d=n("#is_archive"),tu=n("#is_tax"),iu=n("#is_category"),ru=n("#is_tag"),uu=n("#is_author"),fu=n("#is_date"),eu=n("#is_posttype_archive"),ou=n("#is_tax, #is_category, #is_tag, #is_author, #is_date, #is_posttype_archive");return d.click(function(){d.is(":checked")&&ou.attr("checked",!0)}),ou.click(function(){!d.is(":checked")||tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")?!d.is(":checked")&&tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")&&d.attr("checked",!0):d.attr("checked",!1)}),n("#stats_month").change(function(){bi=n(this).val();n.post(cr,{action:"load_item_stats",id:lr,sm:bi}).done(function(t){n("#total_hits").text(t.total.hits);n("#total_clicks").text(t.total.clicks);b=[t.hits,t.clicks];o&&(o.destroy(),o=n.jqplot("graph",b,dt))})}),!1})})(jQuery) \ No newline at end of file diff --git a/js/sam-layout.js b/js/sam-layout.js index 028272d..876c68e 100644 --- a/js/sam-layout.js +++ b/js/sam-layout.js @@ -19,8 +19,8 @@ wc: samAjax.clauses, level: samAjax.level }, - type: 'POST', - crossDomain: true + type: 'POST'/*, + crossDomain: true*/ }).done(function(data) { $(el).replaceWith(data.ad); $.post(samAjax.ajaxurl, { diff --git a/js/sam-layout.min.js b/js/sam-layout.min.js index aa627e2..62deb23 100644 --- a/js/sam-layout.min.js +++ b/js/sam-layout.min.js @@ -1 +1 @@ -(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST",crossDomain:!0}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file +(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST"}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file diff --git a/js/w2ui.js b/js/w2ui.js index 6edd7fd..6e4bc6d 100644 --- a/js/w2ui.js +++ b/js/w2ui.js @@ -1,6938 +1,8478 @@ +/* w2ui 1.4.1 (c) http://w2ui.com, vitmalina@gmail.com */ var w2ui = w2ui || {}; var w2obj = w2obj || {}; // expose object to be able to overwrite default functions /************************************************ - * Library: Web 2.0 UI for jQuery - * - Following objects are defines - * - w2ui - object that will contain all widgets - * - w2obj - object with widget prototypes - * - w2utils - basic utilities - * - $().w2render - common render - * - $().w2destroy - common destroy - * - $().w2marker - marker plugin - * - $().w2tag - tag plugin - * - $().w2overlay - overlay plugin - * - $().w2menu - menu plugin - * - w2utils.event - generic event object - * - w2utils.keyboard - object for keyboard navigation - * - Dependencies: jQuery - * - * == NICE TO HAVE == - * - date has problems in FF new Date('yyyy-mm-dd') breaks - * - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter - * - overlay should be displayed where more space (on top or on bottom) - * - write and article how to replace certain framework functions - * - format date and time is buggy - * - onComplete should pass widget as context (this) - * - ************************************************/ +* Library: Web 2.0 UI for jQuery +* - Following objects are defines +* - w2ui - object that will contain all widgets +* - w2obj - object with widget prototypes +* - w2utils - basic utilities +* - $().w2render - common render +* - $().w2destroy - common destroy +* - $().w2marker - marker plugin +* - $().w2tag - tag plugin +* - $().w2overlay - overlay plugin +* - $().w2menu - menu plugin +* - w2utils.event - generic event object +* - w2utils.keyboard - object for keyboard navigation +* - Dependencies: jQuery +* +* == NICE TO HAVE == +* - date has problems in FF new Date('yyyy-mm-dd') breaks +* - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter +* - overlay should be displayed where more space (on top or on bottom) +* - write and article how to replace certain framework functions +* - format date and time is buggy +* - onComplete should pass widget as context (this) +* - add maxHeight for the w2menu +* - user localization from another lib (make it generic), https://github.com/jquery/globalize#readme +* - hidden and disabled in menus +* - isTime should support seconds +* - TEST On IOS +* +************************************************/ var w2utils = (function ($) { - var tmp = {}; // for some temp variables - var obj = { - settings : { - "locale" : "en-us", - "date_format" : "m/d/yyyy", - "date_display" : "Mon d, yyyy", - "time_format" : "hh:mi pm", - "currency" : "^[\$\€\£\¥]?[-]?[0-9]*[\.]?[0-9]+$", - "currencySymbol": "$", - "float" : "^[-]?[0-9]*[\.]?[0-9]+$", - "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], - "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], - "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], - "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], - "RESTfull" : false, - "phrases" : {} // empty object for english phrases - }, - isInt : isInt, - isFloat : isFloat, - isMoney : isMoney, - isHex : isHex, - isAlphaNumeric : isAlphaNumeric, - isEmail : isEmail, - isDate : isDate, - isTime : isTime, - age : age, - date : date, - size : size, - formatNumber : formatNumber, - formatDate : formatDate, - formatTime : formatTime, - formatDateTime : formatDateTime, - stripTags : stripTags, - encodeTags : encodeTags, - escapeId : escapeId, - base64encode : base64encode, - base64decode : base64decode, - transition : transition, - lock : lock, - unlock : unlock, - lang : lang, - locale : locale, - getSize : getSize, - scrollBarSize : scrollBarSize - } - return obj; - - function isInt (val) { - var re = /^[-]?[0-9]+$/; - return re.test(val); - } - - function isFloat (val) { - var re = new RegExp(w2utils.settings["float"]); - return re.test(val); - } - - function isMoney (val) { - var re = new RegExp(w2utils.settings.currency); - return re.test(val); - } - - function isHex (val) { - var re = /^[a-fA-F0-9]+$/; - return re.test(val); - } - - function isAlphaNumeric (val) { - var re = /^[a-zA-Z0-9_-]+$/; - return re.test(val); - } - - function isEmail (val) { - var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; - return email.test(val); - } - - function isDate (val, format, retDate) { - if (!val) return false; - if (!format) format = w2utils.settings.date_format; - // format date - var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); - var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); - var dt = 'Invalid Date'; - var month, day, year; - if (tmp2 == 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - if (tmp2 == 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - dt = new Date(month + '/' + day + '/' + year); - // do checks - if (typeof month == 'undefined') return false; - if (dt == 'Invalid Date') return false; - if ((dt.getMonth()+1 != month) || (dt.getDate() != day) || (dt.getFullYear() != year)) return false; - if (retDate === true) return dt; else return true; - } - - function isTime (val) { - // Both formats 10:20pm and 22:20 - if (String(val) == 'undefined') return false; - var max; - // -- process american foramt - val = val.toUpperCase(); - if (val.indexOf('PM') >= 0 || val.indexOf('AM') >= 0) max = 12; else max = 23; - val = $.trim(val.replace('AM', '')); - val = $.trim(val.replace('PM', '')); - // --- - var tmp = val.split(':'); - if (tmp.length != 2) { return false; } - if (tmp[0] == '' || parseInt(tmp[0]) < 0 || parseInt(tmp[0]) > max || !this.isInt(tmp[0])) { return false; } - if (tmp[1] == '' || parseInt(tmp[1]) < 0 || parseInt(tmp[1]) > 59 || !this.isInt(tmp[1])) { return false; } - return true; - } - - function age (timeStr) { - if (timeStr == '' || typeof timeStr == 'undefined' || timeStr == null) return ''; - if (w2utils.isInt(timeStr)) timeStr = Number(timeStr); // for unix timestamps - - var d1 = new Date(timeStr); - if (w2utils.isInt(timeStr)) d1 = new Date(Number(timeStr)); // for unix timestamps - var tmp = String(timeStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(timeStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Time') return ''; - - var d2 = new Date(); - var sec = (d2.getTime() - d1.getTime()) / 1000; - var amount = ''; - var type = ''; - - if (sec < 60) { - amount = Math.floor(sec); - type = 'sec'; - if (sec < 0) { amount = 0; type = 'sec' } - } else if (sec < 60*60) { - amount = Math.floor(sec/60); - type = 'min'; - } else if (sec < 24*60*60) { - amount = Math.floor(sec/60/60); - type = 'hour'; - } else if (sec < 30*24*60*60) { - amount = Math.floor(sec/24/60/60); - type = 'day'; - } else if (sec < 12*30*24*60*60) { - amount = Math.floor(sec/30/24/60/60*10)/10; - type = 'month'; - } else if (sec >= 12*30*24*60*60) { - amount = Math.floor(sec/12/30/24/60/60*10)/10; - type = 'year'; - } - return amount + ' ' + type + (amount > 1 ? 's' : ''); - } - - function date (dateStr) { - var months = w2utils.settings.shortmonths; - if (dateStr == '' || typeof dateStr == 'undefined' || dateStr == null) return ''; - if (w2utils.isInt(dateStr)) dateStr = Number(dateStr); // for unix timestamps - - var d1 = new Date(dateStr); - if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Date') return ''; - - var d2 = new Date(); // today - var d3 = new Date(); - d3.setTime(d3.getTime() - 86400000); // yesterday - - var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear(); - var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear(); - var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear(); - - var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var dsp = dd1; - if (dd1 == dd2) dsp = time; - if (dd1 == dd3) dsp = w2utils.lang('Yesterday'); - - return ''+ dsp +''; - } - - function size (sizeStr) { - if (!w2utils.isFloat(sizeStr) || sizeStr == '') return ''; - sizeStr = parseFloat(sizeStr); - if (sizeStr == 0) return 0; - var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB']; - var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) ); - return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i == 0 ? 0 : 1) + ' ' + sizes[i]; - } - - function formatNumber (val) { - var ret = ''; - // check if this is a number - if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) { - ret = String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); - } - return ret; - } - - function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.date_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) dt = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) dt = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (dt == 'Invalid Date') return ''; - - var year = dt.getFullYear(); - var month = dt.getMonth(); - var date = dt.getDate(); - return format.toLowerCase() - .replace('month', w2utils.settings.fullmonths[month]) - .replace('mon', w2utils.settings.shortmonths[month]) - .replace(/yyyy/g, year) - .replace(/yyy/g, year) - .replace(/yy/g, String(year).substr(2)) - .replace(/(^|[^a-z$])y/g, '$1'+year) // only y's that are not preceeded by a letter - .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1)) - .replace(/dd/g, (date < 10 ? '0' : '') + date) - .replace(/(^|[^a-z$])m/g, '$1'+ (month + 1)) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter - } - - - function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.time_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - if (dt == 'Invalid Date') return ''; - - var type = 'am'; - var hour = dt.getHours(); - var h24 = dt.getHours(); - var min = dt.getMinutes(); - var sec = dt.getSeconds(); - if (min < 10) min = '0' + min; - if (sec < 10) sec = '0' + sec; - if (format.indexOf('am') != -1 || format.indexOf('pm') != -1) { - if (hour >= 12) type = 'pm'; - if (hour > 12) hour = hour - 12; - } - return format.toLowerCase() - .replace('am', type) - .replace('pm', type) - .replace('hh', hour) - .replace('h24', h24) - .replace('mm', min) - .replace('mi', min) - .replace('ss', sec) - .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter - } - - function formatDateTime(dateStr, format) { - var fmt; - if (typeof format != 'string') { - var fmt = [this.settings.date_format, this.settings.time_format]; - } else { - var fmt = format.split('|'); - } - return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]); - } - - function stripTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = $.trim(String(html).replace(/(<([^>]+)>)/ig, "")); - break; - case 'object': - for (var a in html) html[a] = this.stripTags(html[a]); - break; - } - return html; - } - - function encodeTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/\|\/? {}\\])/g, '\\$1'); - } - - function base64encode (input) { - var output = ""; - var chr1, chr2, chr3, enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = utf8_encode(input); - - while (i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); + var tmp = {}; // for some temp variables + var obj = { + version : '1.4.1', + settings : { + "locale" : "en-us", + "date_format" : "m/d/yyyy", + "date_display" : "Mon d, yyyy", + "time_format" : "hh:mi pm", + "currencyPrefix" : "$", + "currencySuffix" : "", + "currencyPrecision" : 2, + "groupSymbol" : ",", + "decimalSymbol" : ".", + "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], + "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], + "dataType" : 'HTTP', // can be HTTP, RESTFULL, JSON (case sensative) + "phrases" : {} // empty object for english phrases + }, + isInt : isInt, + isFloat : isFloat, + isMoney : isMoney, + isHex : isHex, + isAlphaNumeric : isAlphaNumeric, + isEmail : isEmail, + isDate : isDate, + isTime : isTime, + age : age, + date : date, + size : size, + formatNumber : formatNumber, + formatDate : formatDate, + formatTime : formatTime, + formatDateTime : formatDateTime, + stripTags : stripTags, + encodeTags : encodeTags, + escapeId : escapeId, + base64encode : base64encode, + base64decode : base64decode, + transition : transition, + lock : lock, + unlock : unlock, + lang : lang, + locale : locale, + getSize : getSize, + scrollBarSize : scrollBarSize, + checkName : checkName, + checkUniqueId : checkUniqueId, + parseRoute : parseRoute, + // some internal variables + isIOS : ((navigator.userAgent.toLowerCase().indexOf('iphone') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipod') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipad') != -1) + ? true : false), + isIE : ((navigator.userAgent.toLowerCase().indexOf('msie') != -1 || + navigator.userAgent.toLowerCase().indexOf('trident') != -1 ) + ? true : false) + }; + return obj; + + function isInt (val) { + var re = /^[-+]?[0-9]+$/; + return re.test(val); } - function utf8_encode (string) { - var string = String(string).replace(/\r\n/g,"\n"); - var utftext = ""; - - for (var n = 0; n < string.length; n++) { - var c = string.charCodeAt(n); - if (c < 128) { - utftext += String.fromCharCode(c); - } - else if((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } - else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - } - return utftext; + function isFloat (val) { + if (typeof val == 'string') val = val.replace(w2utils.settings.decimalSymbol, '.'); + return (typeof val === 'number' || (typeof val === 'string' && val !== '')) && !isNaN(Number(val)); } - return output; - } - - function base64decode (input) { - var output = ""; - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - - while (i < input.length) { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - output = output + String.fromCharCode(chr1); - if (enc3 != 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 != 64) { - output = output + String.fromCharCode(chr3); - } - } - output = utf8_decode(output); - - function utf8_decode (utftext) { - var string = ""; - var i = 0; - var c = 0, c1 = 0, c2 = 0; - - while ( i < utftext.length ) { - c = utftext.charCodeAt(i); - if (c < 128) { - string += String.fromCharCode(c); - i++; - } - else if((c > 191) && (c < 224)) { - c2 = utftext.charCodeAt(i+1); - string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); - i += 2; + function isMoney (val) { + var se = w2utils.settings; + var re = new RegExp('^'+ (se.currencyPrefix ? '\\' + se.currencyPrefix + '?' : '') +'[-+]?[0-9]*[\\'+ w2utils.settings.decimalSymbol +']?[0-9]+'+ (se.currencySuffix ? '\\' + se.currencySuffix + '?' : '') +'$', 'i'); + if (typeof val === 'string') { + val = val.replace(new RegExp(se.groupSymbol, 'g'), ''); } - else { - c2 = utftext.charCodeAt(i+1); - c3 = utftext.charCodeAt(i+2); - string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); - i += 3; - } - } - - return string; + if (typeof val === 'object' || val === '') return false; + return re.test(val); } - return output; - } - - function transition (div_old, div_new, type, callBack) { - var width = $(div_old).width(); - var height = $(div_old).height(); - var time = 0.5; - - if (!div_old || !div_new) { - console.log('ERROR: Cannot do transition when one of the divs is null'); - return; + function isHex (val) { + var re = /^[a-fA-F0-9]+$/; + return re.test(val); } - div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;'; - div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden'); - div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden'); - - switch (type) { - case 'slide-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - }, 1); - break; - - case 'slide-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)'); - }, 1); - break; - - case 'slide-down': - // init divs - div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - }, 1); - break; - - case 'slide-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - }, 1); - break; - - case 'flip-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('-transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)'); - }, 1); - break; - - case 'flip-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)'); - }, 1); - break; - - case 'flip-down': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)'); - }, 1); - break; - - case 'flip-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)'); - }, 1); - break; - - case 'pop-in': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +';'; - }, 1); - break; - - case 'pop-out': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;'; - }, 1); - break; - - default: - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time +'s'); - }, 1); - break; + function isAlphaNumeric (val) { + var re = /^[a-zA-Z0-9_-]+$/; + return re.test(val); } - setTimeout(function () { - if (type == 'slide-down') { - $(div_old).css('z-index', '1019'); - $(div_new).css('z-index', '1020'); - } - if (div_new) { - $(div_new).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - } - if (div_old) { - $(div_old).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - if (div_old.parentNode) $(div_old.parentNode).css({ - '-webkit-perspective': '', - '-moz-perspective': '', - '-ms-perspective': '', - '-o-perspective': '' - }); - } - if (typeof callBack == 'function') callBack(); - }, time * 1000); - - function cross(property, value, none_webkit_value) { - var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR - if (!isWebkit && typeof none_webkit_value != 'undefined') value = none_webkit_value; - return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+ - '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';'; - } - } - - function lock (box, msg, showSpinner) { - if (!msg && msg != 0) msg = ''; - w2utils.unlock(box); - $(box).find('>:first-child').before( - ''+ - '' - ); - setTimeout(function () { - var lock = $(box).find('.w2ui-lock'); - var mess = $(box).find('.w2ui-lock-msg'); - lock.data('old_opacity', lock.css('opacity')).css('opacity', '0').show(); - mess.data('old_opacity', mess.css('opacity')).css('opacity', '0').show(); - setTimeout(function () { - var lock = $(box).find('.w2ui-lock'); - var mess = $(box).find('.w2ui-lock-msg'); - var left = ($(box).width() - w2utils.getSize(mess, 'width')) / 2; - var top = ($(box).height() * 0.9 - w2utils.getSize(mess, 'height')) / 2; - lock.css({ - opacity : lock.data('old_opacity'), - left : '0px', - top : '0px', - width : '100%', - height : '100%' - }); - if (!msg) mess.css({ 'background-color': 'transparent', 'border': '0px' }); - if (showSpinner === true) msg = '' + msg; - mess.html(msg).css({ - opacity : mess.data('old_opacity'), - left : left + 'px', - top : top + 'px' - }); - }, 10); - }, 10); - // hide all tags (do not hide overlays as the form can be in overlay) - $().w2tag(); - } - - function unlock (box) { - $(box).find('.w2ui-lock').remove(); - $(box).find('.w2ui-lock-msg').remove(); - } - - function getSize (el, type) { - var bwidth = { - left: parseInt($(el).css('border-left-width')) || 0, - right: parseInt($(el).css('border-right-width')) || 0, - top: parseInt($(el).css('border-top-width')) || 0, - bottom: parseInt($(el).css('border-bottom-width')) || 0 - } - var mwidth = { - left: parseInt($(el).css('margin-left')) || 0, - right: parseInt($(el).css('margin-right')) || 0, - top: parseInt($(el).css('margin-top')) || 0, - bottom: parseInt($(el).css('margin-bottom')) || 0 - } - var pwidth = { - left: parseInt($(el).css('padding-left')) || 0, - right: parseInt($(el).css('padding-right')) || 0, - top: parseInt($(el).css('padding-top')) || 0, - bottom: parseInt($(el).css('padding-bottom')) || 0 - } - switch (type) { - case 'top': return bwidth.top + mwidth.top + pwidth.top; - case 'bottom': return bwidth.bottom + mwidth.bottom + pwidth.bottom; - case 'left': return bwidth.left + mwidth.left + pwidth.left; - case 'right': return bwidth.right + mwidth.right + pwidth.right; - case 'width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right + parseInt($(el).width()); - case 'height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom + parseInt($(el).height()); - case '+width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right; - case '+height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom; + function isEmail (val) { + var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; + return email.test(val); } - return 0; - } - - function lang (phrase) { - var translation = this.settings.phrases[phrase]; - if (typeof translation == 'undefined') return phrase; else return translation; - } - - function locale (locale) { - if (!locale) locale = 'en-us'; - if (locale.length == 5) locale = 'locale/'+ locale +'.json'; - // load from the file - $.ajax({ - url : locale, - type : "GET", - dataType: "JSON", - async : false, - cache : false, - success : function (data, status, xhr) { - w2utils.settings = $.extend(true, w2utils.settings, data); - }, - error : function (xhr, status, msg) { - console.log('ERROR: Cannot load locale '+ locale); - } - }); - } - - function scrollBarSize () { - if (tmp.scrollBarSize) return tmp.scrollBarSize; - var html = ''+ - ' 1'+ - ''; - $('body').append(html); - tmp.scrollBarSize = 100 - $('#_scrollbar_width > div').width(); - $('#_scrollbar_width').remove(); - if (String(navigator.userAgent).indexOf('MSIE') >= 0) tmp.scrollBarSize = tmp.scrollBarSize / 2; // need this for IE9+ - return tmp.scrollBarSize; - } -})(jQuery); + function isDate (val, format, retDate) { + if (!val) return false; -/*********************************************************** - * Generic Event Object - * --- This object is reused across all other - * --- widgets in w2ui. - * - *********************************************************/ + var dt = 'Invalid Date'; + var month, day, year; -w2utils.event = { + if (format == null) format = w2utils.settings.date_format; - on: function (eventData, handler) { - if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; - eventData = jQuery.extend({ type: null, execute: 'before', target: null, onComplete: null }, eventData); - - if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return; } - if (typeof handler == 'undefined') { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return; } - this.handlers.push({ event: eventData, handler: handler }); - }, - - off: function (eventData, handler) { - if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; - eventData = jQuery.extend({}, { type: null, execute: 'before', target: null, onComplete: null }, eventData); - - if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return; } - if (typeof handler == 'undefined') { handler = null; } - // remove handlers - var newHandlers = []; - for (var h in this.handlers) { - var t = this.handlers[h]; - if ( (t.event.type == eventData.type || eventData.type == '*') - && (t.event.target == eventData.target || eventData.target == null) - && (t.handler == handler || handler == null)) { - // match - } else { - newHandlers.push(t); - } - } - this.handlers = newHandlers; - }, - - trigger: function (eventData) { - var eventData = jQuery.extend({ type: null, phase: 'before', target: null, isStopped: false, isCancelled: false }, eventData, { - preventDefault : function () { this.isCancelled = true; }, - stopPropagation : function () { this.isStopped = true; }, - }); - if (typeof eventData.target == 'undefined') eventData.target = null; - // process events in REVERSE order - for (var h = this.handlers.length-1; h >= 0; h--) { - var item = this.handlers[h]; - if ( (item.event.type == eventData.type || item.event.type == '*') - && (item.event.target == eventData.target || item.event.target == null) - && (item.event.execute == eventData.phase || item.event.execute == '*' || item.event.phase == '*') ) { - eventData = jQuery.extend({}, item.event, eventData); - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(item.handler); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - item.handler.call(this, eventData.target, eventData); // old way for back compatibility + if (typeof val.getUTCFullYear === 'function' && typeof val.getUTCMonth === 'function' && typeof val.getUTCDate === 'function') { + year = val.getUTCFullYear(); + month = val.getUTCMonth(); + day = val.getUTCDate(); + } else if (typeof val.getFullYear === 'function' && typeof val.getMonth === 'function' && typeof val.getDate === 'function') { + year = val.getFullYear(); + month = val.getMonth(); + day = val.getDate(); } else { - item.handler.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true - } - } - // main object events - var funName = 'on' + eventData.type.substr(0,1).toUpperCase() + eventData.type.substr(1); - if (eventData.phase == 'before' && typeof this[funName] == 'function') { - var fun = this[funName]; - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(fun); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - fun.call(this, eventData.target, eventData); // old way for back compatibility - } else { - fun.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true - } - // item object events - if (typeof eventData.object != 'undefined' && eventData.object != null && eventData.phase == 'before' - && typeof eventData.object[funName] == 'function') { - var fun = eventData.object[funName]; - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(fun); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - fun.call(this, eventData.target, eventData); // old way for back compatibility - } else { - fun.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; + val = String(val); + // convert month formats + if (RegExp('mon', 'ig').test(format)) { + format = format.replace(/month/ig, 'm').replace(/mon/ig, 'm').replace(/dd/ig, 'd').replace(/[, ]/ig, '/').replace(/\/\//g, '/').toLowerCase(); + val = val.replace(/[, ]/ig, '/').replace(/\/\//g, '/').toLowerCase(); + for (var m = 0, len = w2utils.settings.fullmonths.length; m < len; m++) { + var t = w2utils.settings.fullmonths[m]; + val = val.replace(RegExp(t, 'ig'), (parseInt(m) + 1)).replace(RegExp(t.substr(0, 3), 'ig'), (parseInt(m) + 1)); + } + } + // format date + var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); + var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); + if (tmp2 === 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } + if (tmp2 === 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } + if (tmp2 === 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } + if (tmp2 === 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } + if (tmp2 === 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } + if (tmp2 === 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } + if (tmp2 === 'mm/dd/yy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'm/d/yy') { month = tmp[0]; day = tmp[1]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'dd/mm/yy') { month = tmp[1]; day = tmp[0]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'd/m/yy') { month = tmp[1]; day = tmp[0]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'yy/dd/mm') { month = tmp[2]; day = tmp[1]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/d/m') { month = tmp[2]; day = tmp[1]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/mm/dd') { month = tmp[1]; day = tmp[2]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/m/d') { month = tmp[1]; day = tmp[2]; year = parseInt(tmp[0]) + 1900; } + } + if (!isInt(year)) return false; + if (!isInt(month)) return false; + if (!isInt(day)) return false; + year = +year; + month = +month; + day = +day; + dt = new Date(year, month - 1, day); + // do checks + if (month == null) return false; + if (dt === 'Invalid Date') return false; + if ((dt.getMonth() + 1 !== month) || (dt.getDate() !== day) || (dt.getFullYear() !== year)) return false; + if (retDate === true) return dt; else return true; } - // execute onComplete - if (eventData.phase == 'after' && eventData.onComplete != null) eventData.onComplete.call(this, eventData); - - return eventData; - } -}; - -/*********************************************************** - * Common Keyboard Handler. Supported in - * - grid - * - sidebar - * - popup - * - *********************************************************/ -w2utils.keyboard = (function (obj) { - // private scope - var w2ui_name = null; - - obj.active = active; - obj.clear = clear; - obj.register = register; - - init(); - return obj; - - function init() { - jQuery(document).on('keydown', keydown); - jQuery(document).on('mousedown', mousedown); - } - - function keydown (event) { - var tag = event.target.tagName; - if (jQuery.inArray(tag, ['INPUT', 'SELECT', 'TEXTAREA']) != -1) return; - if (jQuery(event.target).prop('contenteditable') == 'true') return; - if (!w2ui_name) return; - // pass to appropriate widget - if (w2ui[w2ui_name] && typeof w2ui[w2ui_name].keydown == 'function') { - w2ui[w2ui_name].keydown.call(w2ui[w2ui_name], event); + function isTime (val, retTime) { + // Both formats 10:20pm and 22:20 + if (val == null) return false; + var max, pm; + // -- process american format + val = String(val); + val = val.toUpperCase(); + pm = val.indexOf('PM') >= 0; + var ampm = (pm || val.indexOf('AM') >= 0); + if (ampm) max = 12; else max = 24; + val = val.replace('AM', '').replace('PM', ''); + val = $.trim(val); + // --- + var tmp = val.split(':'); + var h = parseInt(tmp[0] || 0), m = parseInt(tmp[1] || 0); + // accept edge case: 3PM is a good timestamp, but 3 (without AM or PM) is NOT: + if ((!ampm || tmp.length !== 1) && tmp.length !== 2) { return false; } + if (tmp[0] === '' || h < 0 || h > max || !this.isInt(tmp[0]) || tmp[0].length > 2) { return false; } + if (tmp.length === 2 && (tmp[1] === '' || m < 0 || m > 59 || !this.isInt(tmp[1]) || tmp[1].length !== 2)) { return false; } + // check the edge cases: 12:01AM is ok, as is 12:01PM, but 24:01 is NOT ok while 24:00 is (midnight; equivalent to 00:00). + // meanwhile, there is 00:00 which is ok, but 0AM nor 0PM are okay, while 0:01AM and 0:00AM are. + if (!ampm && max === h && m !== 0) { return false; } + if (ampm && tmp.length === 1 && h === 0) { return false; } + + if (retTime === true) { + if (pm) h += 12; + return { + hours: h, + minutes: m + }; + } + return true; } - } - function mousedown (event) { - var tag = event.target.tagName; - var obj = jQuery(event.target).parents('.w2ui-reset'); - if (obj.length > 0) { - w2ui_name = obj.attr('name'); + function age (dateStr) { + if (dateStr === '' || dateStr == null) return ''; + var d1 = new Date(dateStr); + if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps + if (d1 === 'Invalid Date') return ''; + + var d2 = new Date(); + var sec = (d2.getTime() - d1.getTime()) / 1000; + var amount = ''; + var type = ''; + if (sec < 0) { + amount = 'future'; + type = ''; + } else if (sec < 60) { + amount = Math.floor(sec); + type = 'sec'; + if (sec < 0) { amount = 0; type = 'sec'; } + } else if (sec < 60*60) { + amount = Math.floor(sec/60); + type = 'min'; + } else if (sec < 24*60*60) { + amount = Math.floor(sec/60/60); + type = 'hour'; + } else if (sec < 30*24*60*60) { + amount = Math.floor(sec/24/60/60); + type = 'day'; + } else if (sec < 365.25*24*60*60) { + amount = Math.floor(sec/365.25/24/60/60*10)/10; + type = 'month'; + } else if (sec >= 365.25*24*60*60) { + amount = Math.floor(sec/365.25/24/60/60*10)/10; + type = 'year'; + } + return amount + ' ' + type + (amount > 1 ? 's' : ''); } - } - - function active (new_w2ui_name) { - if (typeof new_w2ui_name == 'undefined') return w2ui_name; - w2ui_name = new_w2ui_name; - } - function clear () { - w2ui_name = null; - } + function date (dateStr) { + if (dateStr === '' || dateStr == null) return ''; + var d1 = new Date(dateStr); + if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps + if (d1 === 'Invalid Date') return ''; - function register () { - } - -})({}); + var months = w2utils.settings.shortmonths; + var d2 = new Date(); // today + var d3 = new Date(); + d3.setTime(d3.getTime() - 86400000); // yesterday -/*********************************************************** - * Commonly used plugins - * --- used primarily in grid and form - * - *********************************************************/ + var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear(); + var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear(); + var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear(); -(function ($) { + var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); + var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); + var dsp = dd1; + if (dd1 === dd2) dsp = time; + if (dd1 === dd3) dsp = w2utils.lang('Yesterday'); - $.fn.w2render = function (name) { - if ($(this).length > 0) { - if (typeof name == 'string' && w2ui[name]) w2ui[name].render($(this)[0]); - if (typeof name == 'object') name.render($(this)[0]); - } - } - - $.fn.w2destroy = function (name) { - if (!name && this.length > 0) name = this.attr('name'); - if (typeof name == 'string' && w2ui[name]) w2ui[name].destroy(); - if (typeof name == 'object') name.destroy(); - } - - $.fn.w2marker = function (str) { - if (str == '' || typeof str == 'undefined') { // remove marker - return $(this).each(function (index, el) { - el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark - }); - } else { // add marker - return $(this).each(function (index, el) { - if (typeof str == 'string') str = [str]; - el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark - for (var s in str) { - var tmp = str[s]; - if (typeof tmp != 'string') tmp = String(tmp); - // escape regex special chars - tmp = tmp.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, '&').replace(//g, '<'); - var regex = new RegExp(tmp + '(?!([^<]+)?>)', "gi"); // only outside tags - el.innerHTML = el.innerHTML.replace(regex, function (matched) { // mark new - return '' + matched + ''; - }); - } - }); - } - } - - // -- w2tag - appears on the right side from element, there can be multiple on screen at a time - - $.fn.w2tag = function (text, options) { - if (!$.isPlainObject(options)) options = {}; - if (!$.isPlainObject(options.css)) options.css = {}; - if (typeof options['class'] == 'undefined') options['class'] = ''; - // remove all tags - if ($(this).length == 0) { - $('.w2ui-tag').each(function (index, elem) { - var opt = $(elem).data('options'); - if (typeof opt == 'undefined') opt = {}; - $($(elem).data('taged-el')).removeClass( opt['class'] ); - clearInterval($(elem).data('timer')); - $(elem).remove(); - }); - return; - } - return $(this).each(function (index, el) { - // show or hide tag - var tagOrigID = el.id; - var tagID = w2utils.escapeId(el.id); - if (text == '' || text == null || typeof text == 'undefined') { - $('#w2ui-tag-'+tagID).css('opacity', 0); - setTimeout(function () { - // remmove element - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - }, 300); - } else { - // remove elements - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - // insert - $('body').append(''); - - var timer = setInterval(function () { - // monitor if destroyed - if ($(el).length == 0 || ($(el).offset().left == 0 && $(el).offset().top == 0)) { - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - tmp_hide(); - return; - } - // monitor if moved - if ($('#w2ui-tag-'+tagID).data('position') != ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) { - $('#w2ui-tag-'+tagID).css({ - '-webkit-transition': '.2s', - '-moz-transition': '.2s', - '-ms-transition': '.2s', - '-o-transition': '.2s', - left: ($(el).offset().left + el.offsetWidth) + 'px', - top: $(el).offset().top + 'px' - }).data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top); - } - }, 100); - setTimeout(function () { - if (!$(el).offset()) return; - $('#w2ui-tag-'+tagID).css({ - opacity: '1', - left: ($(el).offset().left + el.offsetWidth) + 'px', - top: $(el).offset().top + 'px' - }).html(' '+ text +' ') - .data('text', text) - .data('taged-el', el) - .data('options', options) - .data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) - .data('timer', timer); - $(el).off('keypress', tmp_hide).on('keypress', tmp_hide).off('change', tmp_hide).on('change', tmp_hide) - .css(options.css).addClass(options['class']); - if (typeof options.onShow == 'function') options.onShow(); - }, 1); - var originalCSS = ''; - if ($(el).length > 0) originalCSS = $(el)[0].style.cssText; - // bind event to hide it - function tmp_hide() { - if ($('#w2ui-tag-'+tagID).length <= 0) return; - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - $(el).off('keypress', tmp_hide).removeClass(options['class']); - if ($(el).length > 0) $(el)[0].style.cssText = originalCSS; - if (typeof options.onHide == 'function') options.onHide(); - } - } - }); - } - - // w2overlay - appears under the element, there can be only one at a time - - $.fn.w2overlay = function (html, options) { - if (!$.isPlainObject(options)) options = {}; - if (!$.isPlainObject(options.css)) options.css = {}; - if (this.length == 0 || html == '' || typeof html == 'undefined') { hide(); return $(this); } - if ($('#w2ui-overlay').length > 0) $(document).click(); - $('body').append(''+ - ' '+ - ''); - - // init - var obj = this; - var div = $('#w2ui-overlay div'); - div.css(options.css).html(html); - if (typeof options['class'] != 'undefined') div.addClass(options['class']); - if (typeof options.top == 'undefined') options.top = 0; - if (typeof options.left == 'undefined') options.left = 0; - if (typeof options.width == 'undefined') options.width = 100; - if (typeof options.height == 'undefined') options.height = 0; - - // pickup bg color of first div - var bc = div.css('background-color'); - var div = $('#w2ui-overlay'); - if (typeof bc != 'undefined' && bc != 'rgba(0, 0, 0, 0)' && bc != 'transparent') div.css('background-color', bc); - - div.css({ - display : 'none', - left : ($(obj).offset().left + options.left) + 'px', - top : ($(obj).offset().top + w2utils.getSize($(obj), 'height') + 3 + options.top) + 'px', - 'min-width' : (options.width ? options.width : 'auto'), - 'min-height' : (options.height ? options.height : 'auto') - }) - .fadeIn('fast') - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }); - - // click anywhere else hides the drop down - function hide () { - var result; - if (typeof options.onHide == 'function') result = options.onHide(); - if (result === false) return; - $('#w2ui-overlay').remove(); - $(document).off('click', hide); + return ''+ dsp +''; } - // need time to display - setTimeout(fixSize, 0); - return $(this); - - function fixSize () { - $(document).on('click', hide); - // if goes over the screen, limit height and width - if ( $('#w2ui-overlay > div').length > 0) { - var h = $('#w2ui-overlay > div').height(); - var w = $('#w2ui-overlay> div').width(); - // $(window).height() - has a problem in FF20 - var max = window.innerHeight - $('#w2ui-overlay > div').offset().top - 7; - if (h > max) $('#w2ui-overlay> div').height(max).width(w + w2utils.scrollBarSize()).css({ 'overflow-y': 'auto' }); - // check width - w = $('#w2ui-overlay> div').width(); - max = window.innerWidth - $('#w2ui-overlay > div').offset().left - 7; - if (w > max) $('#w2ui-overlay> div').width(max).css({ 'overflow-x': 'auto' }); - // onShow event - if (typeof options.onShow == 'function') options.onShow(); - } + function size (sizeStr) { + if (!w2utils.isFloat(sizeStr) || sizeStr === '') return ''; + sizeStr = parseFloat(sizeStr); + if (sizeStr === 0) return 0; + var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB']; + var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) ); + return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i === 0 ? 0 : 1) + ' ' + sizes[i]; } - } - $.fn.w2menu = function (menu, options) { - if (typeof options.select == 'undefined' && typeof options.onSelect == 'function') options.select = options.onSelect; - if (typeof options.select != 'function') { - console.log('ERROR: options.select is required to be a function, not '+ typeof options.select + ' in $().w2menu(menu, options)'); - return $(this); - } - if (!$.isArray(menu)) { - console.log('ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)'); - return $(this); - } - // since only one overlay can exist at a time - $.fn.w2menuHandler = function (event, index) { - options.select(menu[index], event, index); - } - return $(this).w2overlay(getMenuHTML(), options); - - function getMenuHTML () { - var menu_html = ''; - for (var f = 0; f < menu.length; f++) { - var mitem = menu[f]; - if (typeof mitem == 'string') { - var tmp = mitem.split('|'); - // 1 - id, 2 - text, 3 - image, 4 - icon - mitem = { id: tmp[0], text: tmp[0], img: null, icon: null }; - if (tmp[1]) mitem.text = tmp[1]; - if (tmp[2]) mitem.img = tmp[2]; - if (tmp[3]) mitem.icon = tmp[3]; - } else { - if (typeof mitem.text != 'undefined' && typeof mitem.id == 'undefined') mitem.id = mitem.text; - if (typeof mitem.text == 'undefined' && typeof mitem.id != 'undefined') mitem.text = mitem.id; - if (typeof mitem.caption != 'undefined') mitem.text = mitem.caption; - if (typeof mitem.img == 'undefined') mitem.img = null; - if (typeof mitem.icon == 'undefined') mitem.icon = null; + function formatNumber (val, groupSymbol, decimalSymbol) { + var ret = ''; + if (groupSymbol == null) groupSymbol = w2utils.settings.groupSymbol || ','; + if (decimalSymbol == null) decimalSymbol = w2utils.settings.decimalSymbol || '.'; + // check if this is a number + if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) { + tmp = String(val).split('.'); + ret = String(tmp[0]).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + groupSymbol); + if (tmp[1] != null) ret += w2utils.settings.decimalSymbol + tmp[1]; } - var img = ' '; - if (mitem.img) img = ''; - if (mitem.icon) img = ''; - menu_html += - ''+ - img + - ' '+ mitem.text +''+ - ''; - } - menu_html += ""; - return menu_html; + return ret; } - } -})(jQuery); - -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2grid - grid widget - * - $().w2grid - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2toolbar, w2fields, w2alert, w2confirm - * - * == NICE TO HAVE == - * - global search apply types and drop downs - * - editable fields (list) - better inline editing - * - frozen columns - * - column autosize based on largest content - * - save grid state into localStorage and restore - * - easy bubbles in the grid - * - possibly add context menu similar to sidebar's - * - Merged cells - * - More than 2 layers of header groups - * - for search fields one should be able to pass w2field options - * - add enum to advanced search fields - * - be able to attach events in advanced search dialog - * - reorder columns/records - * - hidden searches could not be clearned by the user - * - search-logic -> searchLogic - * - ************************************************************************/ -(function ($) { - var w2grid = function(options) { - - // public properties - this.name = null; - this.box = null; // HTML element that hold this element - this.header = ''; - this.url = ''; - this.columns = []; // { field, caption, size, attr, render, hidden, gridMinWidth, [editable: {type, inTag, outTag, style, items}] } - this.columnGroups = []; // { span: int, caption: 'string', master: true/false } - this.records = []; // { recid: int(requied), field1: 'value1', ... fieldN: 'valueN', style: 'string', editable: true/false, summary: true/false, changed: true/false, changes: object } - this.summary = []; // arry of summary records, same structure as records array - this.searches = []; // { type, caption, field, inTag, outTag, default, items, hidden } - this.searchData = []; - this.sortData = []; - this.postData = {}; - this.toolbar = {}; // if not empty object; then it is toolbar object - - this.show = { - header : false, - toolbar : false, - footer : false, - columnHeaders : true, - lineNumbers : false, - expandColumn : false, - selectColumn : false, - emptyRecords : true, - toolbarReload : true, - toolbarColumns : true, - toolbarSearch : true, - toolbarAdd : false, - toolbarEdit : false, - toolbarDelete : false, - toolbarSave : false, - selectionBorder : true, - recordTitles : true + function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String + var months = w2utils.settings.shortmonths; + var fullMonths = w2utils.settings.fullmonths; + if (!format) format = this.settings.date_format; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + + var dt = new Date(dateStr); + if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps + if (dt === 'Invalid Date') return ''; + + var year = dt.getFullYear(); + var month = dt.getMonth(); + var date = dt.getDate(); + return format.toLowerCase() + .replace('month', w2utils.settings.fullmonths[month]) + .replace('mon', w2utils.settings.shortmonths[month]) + .replace(/yyyy/g, year) + .replace(/yyy/g, year) + .replace(/yy/g, year > 2000 ? 100 + parseInt(String(year).substr(2)) : String(year).substr(2)) + .replace(/(^|[^a-z$])y/g, '$1' + year) // only y's that are not preceeded by a letter + .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1)) + .replace(/dd/g, (date < 10 ? '0' : '') + date) + .replace(/th/g, (date == 1 ? 'st' : 'th')) + .replace(/th/g, (date == 2 ? 'nd' : 'th')) + .replace(/th/g, (date == 3 ? 'rd' : 'th')) + .replace(/(^|[^a-z$])m/g, '$1' + (month + 1)) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter } - this.autoLoad = true; // for infinite scroll - this.fixedBody = true; // if false; then grid grows with data - this.recordHeight = 24; - this.keyboard = true; - this.selectType = 'row'; // can be row|cell - this.multiSearch = true; - this.multiSelect = true; - this.multiSort = true; - this.markSearchResults = true; - - this.total = 0; // server total - this.buffered = 0; // number of records in the records array - this.limit = 100; - this.offset = 0; // how many records to skip (for infinite scroll) when pulling from server - this.style = ''; - this.ranges = []; - - // events - this.onAdd = null; - this.onEdit = null; - this.onRequest = null; // called on any server event - this.onLoad = null; - this.onDelete = null; - this.onDeleted = null - this.onSave = null; - this.onSaved = null; - this.onSelect = null; - this.onUnselect = null; - this.onClick = null; - this.onDblClick = null; - this.onColumnClick = null; - this.onColumnResize = null; - this.onSort = null; - this.onSearch = null; - this.onChange = null; // called when editable record is changed - this.onExpand = null; - this.onCollapse = null; - this.onError = null; - this.onKeydown = null; - this.onToolbar = null; // all events from toolbar - this.onColumnOnOff = null; - this.onCopy = null; - this.onPaste = null; - this.onSelectionExtend = null; - this.onEditField = null; - this.onRender = null; - this.onRefresh = null; - this.onReload = null; - this.onResize = null; - this.onDestroy = null; - - // internal - this.last = { - field : 'all', - caption : w2utils.lang('All Fields'), - logic : 'OR', - search : '', - searchIds : [], - multi : false, - scrollTop : 0, - scrollLeft : 0, - selected : [], - sortData : null, - sortCount : 0, - xhr : null, - range_start : null, - range_end : null, - sel_ind : null, - sel_col : null, - sel_type : null + function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String + var months = w2utils.settings.shortmonths; + var fullMonths = w2utils.settings.fullmonths; + if (!format) format = this.settings.time_format; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + + var dt = new Date(dateStr); + if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps + if (w2utils.isTime(dateStr)) { + var tmp = w2utils.isTime(dateStr, true); + dt = new Date(); + dt.setHours(tmp.hours); + dt.setMinutes(tmp.minutes); + } + if (dt === 'Invalid Date') return ''; + + var type = 'am'; + var hour = dt.getHours(); + var h24 = dt.getHours(); + var min = dt.getMinutes(); + var sec = dt.getSeconds(); + if (min < 10) min = '0' + min; + if (sec < 10) sec = '0' + sec; + if (format.indexOf('am') !== -1 || format.indexOf('pm') !== -1) { + if (hour >= 12) type = 'pm'; + if (hour > 12) hour = hour - 12; + } + return format.toLowerCase() + .replace('am', type) + .replace('pm', type) + .replace('hhh', (hour < 10 ? '0' + hour : hour)) + .replace('hh24', (h24 < 10 ? '0' + h24 : h24)) + .replace('h24', h24) + .replace('hh', hour) + .replace('mm', min) + .replace('mi', min) + .replace('ss', sec) + .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter } - this.isIOS = (navigator.userAgent.toLowerCase().indexOf('iphone') != -1 || - navigator.userAgent.toLowerCase().indexOf('ipod') != -1 || - navigator.userAgent.toLowerCase().indexOf('ipad') != -1) ? true : false; - - $.extend(true, this, w2obj.grid, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2grid = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // remember items - var columns = method.columns; - var columnGroups= method.columnGroups; - var records = method.records; - var searches = method.searches; - var searchData = method.searchData; - var sortData = method.sortData; - var postData = method.postData; - var toolbar = method.toolbar; - // extend items - var object = new w2grid(method); - $.extend(object, { postData: {}, records: [], columns: [], searches: [], toolbar: {}, sortData: [], searchData: [], handlers: [] }); - if (object.onExpand != null) object.show.expandColumn = true; - $.extend(true, object.toolbar, toolbar); - // reassign variables - for (var p in columns) object.columns[p] = $.extend(true, {}, columns[p]); - for (var p in columnGroups) object.columnGroups[p] = $.extend(true, {}, columnGroups[p]); - for (var p in searches) object.searches[p] = $.extend(true, {}, searches[p]); - for (var p in searchData) object.searchData[p] = $.extend(true, {}, searchData[p]); - for (var p in sortData) object.sortData[p] = $.extend(true, {}, sortData[p]); - object.postData = $.extend(true, {}, postData); - - // check if there are records without recid - for (var r in records) { - if (records[r].recid == null || typeof records[r].recid == 'undefined') { - console.log('ERROR: Cannot add records without recid. (obj: '+ object.name +')'); - return; + function formatDateTime(dateStr, format) { + var fmt; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + if (typeof format !== 'string') { + fmt = [this.settings.date_format, this.settings.time_format]; + } else { + fmt = format.split('|'); } - object.records[r] = $.extend(true, {}, records[r]); - } - if (object.records.length > 0) object.buffered = object.records.length; - // add searches - for (var c in object.columns) { - var col = object.columns[c]; - if (typeof col.searchable == 'undefined' || object.getSearch(col.field) != null) continue; - var stype = col.searchable; - var attr = ''; - if (col.searchable === true) { stype = 'text'; attr = 'size="20"'; } - object.addSearch({ field: col.field, caption: col.caption, type: stype, attr: attr }); - } - // init toolbar - object.initToolbar(); - // render if necessary - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2grid'); + return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]); } - } - - // ==================================================== - // -- Implementation of core functionality - - w2grid.prototype = { - // ---- - // properties that need to be in prototype - - msgDelete : w2utils.lang('Are you sure you want to delete selected records?'), - msgNotJSON : w2utils.lang('Returned data is not in valid JSON format.'), - msgRefresh : w2utils.lang('Refreshing...'), - - // for easy button overwrite - buttons: { - 'reload' : { type: 'button', id: 'reload', img: 'icon-reload', hint: w2utils.lang('Reload data in the list') }, - 'columns' : { type: 'drop', id: 'column-on-off', img: 'icon-columns', hint: w2utils.lang('Show/hide columns'), arrow: false, html: '' }, - 'search' : { type: 'html', id: 'search', - html: '' - }, - 'search-go' : { type: 'check', id: 'search-advanced', caption: w2utils.lang('Search...'), hint: w2utils.lang('Open Search Fields') }, - 'add' : { type: 'button', id: 'add', caption: w2utils.lang('Add New'), hint: w2utils.lang('Add new record'), img: 'icon-add' }, - 'edit' : { type: 'button', id: 'edit', caption: w2utils.lang('Edit'), hint: w2utils.lang('Edit selected record'), img: 'icon-edit', disabled: true }, - 'delete' : { type: 'button', id: 'delete', caption: w2utils.lang('Delete'), hint: w2utils.lang('Delete selected records'), img: 'icon-delete', disabled: true }, - 'save' : { type: 'button', id: 'save', caption: w2utils.lang('Save'), hint: w2utils.lang('Save changed records'), img: 'icon-save' } - }, - - add: function (record) { - if (!$.isArray(record)) record = [record]; - var added = 0; - for (var o in record) { - if (record[o].recid == null || typeof record[o].recid == 'undefined') { - console.log('ERROR: Cannot add record without recid. (obj: '+ this.name +')'); - continue; - } - this.records.push(record[o]); - added++; - } - this.buffered = this.records.length; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - this.localSearch(); - } - this.refresh(); // ?? should it be reload? - return added; - }, - find: function (obj, returnIndex) { - if (typeof obj == 'undefined' || obj == null) obj = {}; - var recs = []; - for (var i=0; i]+)>)/ig, "")); + break; + case 'object': + for (var a in html) html[a] = this.stripTags(html[a]); + break; } - if (match && returnIndex !== true) recs.push(this.records[i]); - if (match && returnIndex === true) recs.push(i); - } - return recs; - }, + return html; + } - set: function (recid, record, noRefresh) { // does not delete existing, but overrides on top of it - if (typeof recid == 'object') { - noRefresh = record; - record = recid; - recid = null; - } - // update all records - if (recid == null) { - for (var r in this.records) { - $.extend(true, this.records[r], record); // recid is the whole record - } - if (noRefresh !== true) this.refresh(); - } else { // find record to update - var ind = this.get(recid, true); - if (ind == null) return false; - $.extend(true, this.records[ind], record); - // refresh only that record - if (noRefresh !== true) { - var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); - if (tr.length != 0) { - var line = tr.attr('line'); - // if it is searched, find index in search array - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (this.searchData.length > 0 && !url) for (var s in this.last.searchIds) if (this.last.searchIds[s] == ind) ind = s; - $(tr).replaceWith(this.getRecordHTML(ind, line)); - } + function encodeTags (html) { + if (html === null) return html; + switch (typeof html) { + case 'number': + break; + case 'string': + html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/\|\/? {}\\])/g, '\\$1'); + } - remove: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.records.length-1; r >= 0; r--) { - if (this.records[r].recid == arguments[a]) { this.records.splice(r, 1); removed++; } + function base64encode (input) { + var output = ""; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + input = utf8_encode(input); + + while (i < input.length) { + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); } - } - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.buffered = this.records.length; - this.localSort(); - this.localSearch(); - } - this.refresh(); - return removed; - }, - addColumn: function (before, columns) { - var added = 0; - if (arguments.length == 1) { - columns = before; - before = this.columns.length; - } else { - if (typeof before == 'string') before = this.getColumn(before, true); - if (before === null) before = this.columns.length; - } - if (!$.isArray(columns)) columns = [columns]; - for (var o in columns) { - this.columns.splice(before, 0, columns[o]); - before++; - added++; - } - this.initColumnOnOff(); - this.refresh(); - return added; - }, + function utf8_encode (string) { + var string = String(string).replace(/\r\n/g,"\n"); + var utftext = ""; - removeColumn: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a]) { this.columns.splice(r, 1); removed++; } + for (var n = 0; n < string.length; n++) { + var c = string.charCodeAt(n); + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + } + return utftext; } - } - this.initColumnOnOff(); - this.refresh(); - return removed; - }, - getColumn: function (field, returnIndex) { - for (var i=0; i= 0; r--) { - if (this.columns[r].field == arguments[a]) { - this.columns[r].hidden = !this.columns[r].hidden; - effected++; - } + function base64decode (input) { + var output = ""; + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + enc1 = keyStr.indexOf(input.charAt(i++)); + enc2 = keyStr.indexOf(input.charAt(i++)); + enc3 = keyStr.indexOf(input.charAt(i++)); + enc4 = keyStr.indexOf(input.charAt(i++)); + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + output = output + String.fromCharCode(chr1); + if (enc3 !== 64) { + output = output + String.fromCharCode(chr2); + } + if (enc4 !== 64) { + output = output + String.fromCharCode(chr3); + } } - } - this.refresh(); - return effected; - }, + output = utf8_decode(output); - showColumn: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a] && this.columns[r].hidden !== false) { - this.columns[r].hidden = false; - shown++; - } - } - } - this.refresh(); - return shown; - }, + function utf8_decode (utftext) { + var string = ""; + var i = 0; + var c = 0, c2, c3; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + if (c < 128) { + string += String.fromCharCode(c); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + } - hideColumn: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a] && this.columns[r].hidden !== true) { - this.columns[r].hidden = true; - hidden++; - } + return string; } - } - this.refresh(); - return hidden; - }, - addSearch: function (before, search) { - var added = 0; - if (arguments.length == 1) { - search = before; - before = this.searches.length; - } else { - if (typeof before == 'string') before = this.getSearch(before, true); - if (before === null) before = this.searches.length; - } - if (!$.isArray(search)) search = [search]; - for (var o in search) { - this.searches.splice(before, 0, search[o]); - before++; - added++; - } - this.searchClose(); - return added; - }, + return output; + } - removeSearch: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a]) { this.searches.splice(r, 1); removed++; } - } - } - this.searchClose(); - return removed; - }, + function transition (div_old, div_new, type, callBack) { + var width = $(div_old).width(); + var height = $(div_old).height(); + var time = 0.5; - getSearch: function (field, returnIndex) { - for (var i=0; i= 0; r--) { - if (this.searches[r].field == arguments[a]) { - this.searches[r].hidden = !this.searches[r].hidden; - effected++; - } - } - } - this.searchClose(); - return effected; - }, + div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;'; + div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden'); + div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden'); + + switch (type) { + case 'slide-left': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); + }, 1); + break; - showSearch: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== false) { - this.searches[r].hidden = false; - shown++; - } - } - } - this.searchClose(); - return shown; - }, + case 'slide-right': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)'); + }, 1); + break; - hideSearch: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== true) { - this.searches[r].hidden = true; - hidden++; - } - } - } - this.searchClose(); - return hidden; - }, + case 'slide-down': + // init divs + div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); + }, 1); + break; - getSearchData: function (field) { - for (var s in this.searchData) { - if (this.searchData[s].field == field) return this.searchData[s]; - } - return null; - }, + case 'slide-up': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + }, 1); + break; - localSort: function (silent) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - console.log('ERROR: grid.localSort can only be used on local data source, grid.url should be empty.'); - return; - } - if ($.isEmptyObject(this.sortData)) return; - var time = (new Date()).getTime(); - var obj = this; - this.records.sort(function (a, b) { - var ret = 0; - for (var s in obj.sortData) { - var aa = a[obj.sortData[s].field]; - var bb = b[obj.sortData[s].field]; - if (String(obj.sortData[s].field).indexOf('.') != -1) { - aa = obj.parseField(a, obj.sortData[s].field); - bb = obj.parseField(b, obj.sortData[s].field); - } - if (typeof aa == 'string') aa = $.trim(aa.toLowerCase()); - if (typeof bb == 'string') bb = $.trim(bb.toLowerCase()); - if (aa > bb) ret = (obj.sortData[s].direction == 'asc' ? 1 : -1); - if (aa < bb) ret = (obj.sortData[s].direction == 'asc' ? -1 : 1); - if (typeof aa != 'object' && typeof bb == 'object') ret = -1; - if (typeof bb != 'object' && typeof aa == 'object') ret = 1; - if (ret != 0) break; - } - return ret; - }); - time = (new Date()).getTime() - time; - if (silent !== true) setTimeout(function () { obj.status('Sorting took ' + time/1000 + ' sec'); }, 10); - return time; - }, + case 'flip-left': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)'); + }, 1); + break; - localSearch: function (silent) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - console.log('ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.'); - return; - } - var time = (new Date()).getTime(); - var obj = this; - this.total = this.records.length; - // mark all records as shown - this.last.searchIds = []; - // hide records that did not match - if (this.searchData.length > 0 && !url) { - this.total = 0; - for (var r in this.records) { - var rec = this.records[r]; - var fl = 0; - for (var s in this.searchData) { - var sdata = this.searchData[s]; - var search = this.getSearch(sdata.field); - if (sdata == null) continue; - if (search == null) search = { field: sdata.field, type: sdata.type }; - var val1 = String(obj.parseField(rec, search.field)).toLowerCase(); - if (typeof sdata.value != 'undefined') { - if (!$.isArray(sdata.value)) { - var val2 = String(sdata.value).toLowerCase(); - } else { - var val2 = sdata.value[0]; - var val3 = sdata.value[1]; - } - } - switch (sdata.operator) { - case 'is': - if (rec[search.field] == sdata.value) fl++; // do not hide record - if (search.type == 'date') { - var tmp = new Date(Number(val1)); // create date - val1 = (new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate())).getTime(); // drop time - val2 = Number(val2); - var val3 = Number(val1) + 86400000; // 1 day - if (val2 >= val1 && val2 <= val3) fl++; - } + case 'flip-right': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)'); + }, 1); break; - case 'between': - if (search.type == 'int' && parseInt(rec[search.field]) >= parseInt(val2) && parseInt(rec[search.field]) <= parseInt(val3)) fl++; - if (search.type == 'float' && parseFloat(rec[search.field]) >= parseFloat(val2) && parseFloat(rec[search.field]) <= parseFloat(val3)) fl++; - if (search.type == 'date') { - var tmp = new Date(Number(val3)); // create date - val3 = (new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate())).getTime(); // drop time - var val3 = Number(val3) + 86400000; // 1 day - if (val1 >= val2 && val1 < val3) fl++; - } + + case 'flip-down': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)'); + }, 1); break; - case 'in': - if (sdata.value.indexOf(val1) !== -1) fl++; + + case 'flip-up': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)'); + }, 1); break; - case 'begins with': - if (val1.indexOf(val2) == 0) fl++; // do not hide record + + case 'pop-in': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time+'s') +';'; + }, 1); break; - case 'contains': - if (val1.indexOf(val2) >= 0) fl++; // do not hide record + + case 'pop-out': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;'; + }, 1); break; - case 'ends with': - if (val1.indexOf(val2) == val1.length - val2.length) fl++; // do not hide record + + default: + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time +'s'); + }, 1); break; - } - } - if ((this.last.logic == 'OR' && fl != 0) || (this.last.logic == 'AND' && fl == this.searchData.length)) this.last.searchIds.push(parseInt(r)); } - this.total = this.last.searchIds.length; - } - this.buffered = this.total; - time = (new Date()).getTime() - time; - if (silent !== true) setTimeout(function () { obj.status('Search took ' + time/1000 + ' sec'); }, 10); - return time; - }, - getRangeData: function (range, extra) { - var rec1 = this.get(range[0].recid, true); - var rec2 = this.get(range[1].recid, true); - var col1 = range[0].column; - var col2 = range[1].column; - - var res = []; - if (col1 == col2) { // one row - for (var r = rec1; r <= rec2; r++) { - var record = this.records[r]; - var dt = record[this.columns[col1].field] || null; - if (extra !== true) { - res.push(dt); - } else { - res.push({ data: dt, column: col1, index: r, record: record }); - } - } - } else if (rec1 == rec2) { // one line - var record = this.records[rec1]; - for (var i = col1; i <= col2; i++) { - var dt = record[this.columns[i].field] || null; - if (extra !== true) { - res.push(dt); - } else { - res.push({ data: dt, column: i, index: rec1, record: record }); - } - } - } else { - for (var r = rec1; r <= rec2; r++) { - var record = this.records[r]; - res.push([]); - for (var i = col1; i <= col2; i++) { - var dt = record[this.columns[i].field]; - if (extra !== true) { - res[res.length-1].push(dt); - } else { - res[res.length-1].push({ data: dt, column: i, index: r, record: record }); + setTimeout(function () { + if (type === 'slide-down') { + $(div_old).css('z-index', '1019'); + $(div_new).css('z-index', '1020'); } - } - } - } - return res; - }, - - addRange: function (ranges) { - var added = 0; - if (this.selectType == 'row') return added; - if (!$.isArray(ranges)) ranges = [ranges]; - // if it is selection - for (var r in ranges) { - if (typeof ranges[r] != 'object') ranges[r] = { name: 'selection' }; - if (ranges[r].name == 'selection') { - if (this.show.selectionBorder === false) continue; - var sel = this.getSelection(); - if (sel.length == 0) { - this.removeRange(ranges[r].name); - continue; - } else { - var first = sel[0]; - var last = sel[sel.length-1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - } - } else { // other range - var first = ranges[r].range[0]; - var last = ranges[r].range[1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - } - if (first) { - var rg = { - name: ranges[r].name, - range: [{ recid: first.recid, column: first.column }, { recid: last.recid, column: last.column }], - style: ranges[r].style || '' - }; - // add range - var ind = false; - for (var t in this.ranges) if (this.ranges[t].name == ranges[r].name) { ind = r; break; } - if (ind !== false) { - this.ranges[ind] = rg; - } else { - this.ranges.push(rg); - } - added++ - } - } - this.refreshRanges(); - return added; - }, + if (div_new) { + $(div_new).css({ + 'opacity': '1', + '-webkit-transition': '', + '-moz-transition': '', + '-ms-transition': '', + '-o-transition': '', + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '', + '-webkit-backface-visibility': '', + '-moz-backface-visibility': '', + '-ms-backface-visibility': '', + '-o-backface-visibility': '' + }); + } + if (div_old) { + $(div_old).css({ + 'opacity': '1', + '-webkit-transition': '', + '-moz-transition': '', + '-ms-transition': '', + '-o-transition': '', + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '', + '-webkit-backface-visibility': '', + '-moz-backface-visibility': '', + '-ms-backface-visibility': '', + '-o-backface-visibility': '' + }); + if (div_old.parentNode) $(div_old.parentNode).css({ + '-webkit-perspective': '', + '-moz-perspective': '', + '-ms-perspective': '', + '-o-perspective': '' + }); + } + if (typeof callBack === 'function') callBack(); + }, time * 1000); - removeRange: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var name = arguments[a]; - $('#grid_'+ this.name +'_'+ name).remove(); - for (var r = this.ranges.length-1; r >= 0; r--) { - if (this.ranges[r].name == name) { - this.ranges.splice(r, 1); - removed++; - } + function cross(property, value, none_webkit_value) { + var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR + if (!isWebkit && typeof none_webkit_value !== 'undefined') value = none_webkit_value; + return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+ + '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';'; } - } - return removed; - }, + } - refreshRanges: function () { - var obj = this; - var time = (new Date()).getTime(); - var rec = $('#grid_'+ this.name +'_records'); - for (var r in this.ranges) { - var rg = this.ranges[r]; - var first = rg.range[0]; - var last = rg.range[1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - if ($('#grid_'+ this.name +'_'+ rg.name).length == 0) { - rec.append(''+ - (rg.name == 'selection' ? '' : '')+ - ''); + function lock (box, msg, spinner) { + var options = {}; + if (typeof msg === 'object') { + options = msg; } else { - $('#grid_'+ this.name +'_'+ rg.name).attr('style', rg.style); - } - if (td1.length > 0 && td2.length > 0) { - $('#grid_'+ this.name +'_'+ rg.name).css({ - left : (td1.position().left - 1 + rec.scrollLeft()) + 'px', - top : (td1.position().top - 1 + rec.scrollTop()) + 'px', - width : (td2.position().left - td1.position().left + td2.width() + 3) + 'px', - height : (td2.position().top - td1.position().top + td2.height() + 3) + 'px' - }); - } - } - - // add resizer events - $(this.box).find('#grid_'+ this.name +'_resizer').off('mousedown').on('mousedown', mouseStart); - //$(this.box).find('#grid_'+ this.name +'_resizer').off('selectstart').on('selectstart', function () { return false; }); // fixes chrome cursror bug - - var eventData = { phase: 'before', type: 'selectionExtend', target: obj.name, originalRange: null, newRange: null }; - - function mouseStart (event) { - var sel = obj.getSelection(); - obj.last.move = { - type : 'expand', - x : event.screenX, - y : event.screenY, - divX : 0, - divY : 0, - recid : sel[0].recid, - column : sel[0].column, - originalRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }], - newRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }] - }; - $(document).off('mousemove', mouseMove).on('mousemove', mouseMove); - $(document).off('mouseup', mouseStop).on('mouseup', mouseStop); - } - - function mouseMove (event) { - var mv = obj.last.move; - if (!mv || mv.type != 'expand') return; - mv.divX = (event.screenX - mv.x); - mv.divY = (event.screenY - mv.y); - // find new cell - var recid, column; - var tmp = event.originalEvent.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); - tmp = $(tmp).parents('tr')[0]; - recid = $(tmp).attr('recid'); - // new range - if (mv.newRange[1].recid == recid && mv.newRange[1].column == column) return; - var prevNewRange = $.extend({}, mv.newRange); - mv.newRange = [{ recid: mv.recid, column: mv.column }, { recid: recid, column: column }]; - // event before - eventData = obj.trigger($.extend(eventData, { originalRange: mv.originalRange, newRange : mv.newRange })); - if (eventData.isCancelled === true) { - mv.newRange = prevNewRange; - eventData.newRange = prevNewRange; - return; + options.msg = msg; + options.spinner = spinner; + } + if (!options.msg && options.msg !== 0) options.msg = ''; + w2utils.unlock(box); + $(box).prepend( + ''+ + '' + ); + var $lock = $(box).find('.w2ui-lock'); + var mess = $(box).find('.w2ui-lock-msg'); + if (!options.msg) mess.css({ 'background-color': 'transparent', 'border': '0px' }); + if (options.spinner === true) options.msg = '' + options.msg; + if (options.opacity != null) $lock.css('opacity', options.opacity); + if (typeof $lock.fadeIn == 'function') { + $lock.fadeIn(200); + mess.html(options.msg).fadeIn(200); } else { - // default behavior - obj.removeRange('grid-selection-expand'); - obj.addRange({ - name : 'grid-selection-expand', - range : eventData.newRange, - style : 'background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);' - }); + $lock.show(); + mess.html(options.msg).show(0); } - } - - function mouseStop (event) { - // default behavior - obj.removeRange('grid-selection-expand'); - delete obj.last.move; - $(document).off('mousemove', mouseMove); - $(document).off('mouseup', mouseStop); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - - return (new Date()).getTime() - time; - }, + // hide all tags (do not hide overlays as the form can be in overlay) + $().w2tag(); + } - select: function () { - var selected = 0; - for (var a = 0; a < arguments.length; a++) { - var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; - var record = this.get(recid); - var index = this.get(recid, true); - if (record == null) continue; - if (this.selectType == 'row') { - if (record.selected === true) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid }); - if (eventData.isCancelled === true) continue; - // default action - record.selected = true; - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).addClass('w2ui-selected').data('selected', 'yes'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', true); - selected++; - } else { - var col = arguments[a].column; - if (!w2utils.isInt(col)) { // select all columns - var cols = []; - for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } - return this.select.apply(this, cols); - } - var s = record.selectedColumns; - if ($.isArray(s) && s.indexOf(col) != -1) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, column: col }); - if (eventData.isCancelled === true) continue; - // default action - if (!$.isArray(s)) record.selectedColumns = []; - record.selected = true; - record.selectedColumns.push(col); - record.selectedColumns.sort(function(a, b) { return a-b }); // sort function must be for numerical sort - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').addClass('w2ui-selected'); - selected++; - if (record.selected) { - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).data('selected', 'yes'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', true); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - this.status(); - this.addRange('selection'); - return selected; - }, + function unlock (box) { + $(box).find('.w2ui-lock').remove(); + $(box).find('.w2ui-lock-msg').remove(); + } - unselect: function () { - var unselected = 0; - for (var a = 0; a < arguments.length; a++) { - var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; - var record = this.get(recid); - var index = this.get(record.recid, true); - if (record == null) continue; - if (this.selectType == 'row') { - if (record.selected !== true) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid }); - if (eventData.isCancelled === true) continue; - // default action - record.selected = false - var el = $('#grid_'+this.name +'_rec_'+ w2utils.escapeId(record.recid)); - el.removeClass('w2ui-selected').removeData('selected'); - if (el.length != 0) el[0].style.cssText = 'height: '+ this.recordHeight +'px; ' + el.attr('custom_style'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop("checked", false); - unselected++; - } else { - var col = arguments[a].column; - if (!w2utils.isInt(col)) { // unselect all columns - var cols = []; - for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } - return this.unselect.apply(this, cols); - } - var s = record.selectedColumns; - if (!$.isArray(s) || s.indexOf(col) == -1) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, column: col }); - if (eventData.isCancelled === true) continue; - // default action - s.splice(s.indexOf(col), 1); - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').removeClass('w2ui-selected'); - unselected++; - if (s.length == 0) { - record.selected = false; - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).removeData('selected'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', false); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - // show number of selected - this.status(); - this.addRange('selection'); - return unselected; - }, + function getSize (el, type) { + var $el = $(el); + var bwidth = { + left : parseInt($el.css('border-left-width')) || 0, + right : parseInt($el.css('border-right-width')) || 0, + top : parseInt($el.css('border-top-width')) || 0, + bottom : parseInt($el.css('border-bottom-width')) || 0 + }; + var mwidth = { + left : parseInt($el.css('margin-left')) || 0, + right : parseInt($el.css('margin-right')) || 0, + top : parseInt($el.css('margin-top')) || 0, + bottom : parseInt($el.css('margin-bottom')) || 0 + }; + var pwidth = { + left : parseInt($el.css('padding-left')) || 0, + right : parseInt($el.css('padding-right')) || 0, + top : parseInt($el.css('padding-top')) || 0, + bottom : parseInt($el.css('padding-bottom')) || 0 + }; + switch (type) { + case 'top' : return bwidth.top + mwidth.top + pwidth.top; + case 'bottom' : return bwidth.bottom + mwidth.bottom + pwidth.bottom; + case 'left' : return bwidth.left + mwidth.left + pwidth.left; + case 'right' : return bwidth.right + mwidth.right + pwidth.right; + case 'width' : return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right + parseInt($el.width()); + case 'height' : return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom + parseInt($el.height()); + case '+width' : return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right; + case '+height' : return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom; + } + return 0; + } - selectAll: function () { - if (this.multiSelect === false) return; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, all: true }); - if (eventData.isCancelled === true) return; - // default action - var cols = []; - for (var c in this.columns) cols.push(parseInt(c)); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - if (this.searchData.length == 0) { - // not searched - this.set({ selected: true }); - if (this.selectType == 'row') { - this.set({ selected: true }); - } else { - this.set({ selected: true, selectedColumns: cols.slice() }); // .slice makes copy of the array - } - } else { - // local search applied - for (var i=0; i'+ + ' 1'+ + ''; + $('body').append(html); + tmp.scrollBarSize = 100 - $('#_scrollbar_width > div').width(); + $('#_scrollbar_width').remove(); + if (String(navigator.userAgent).indexOf('MSIE') >= 0) tmp.scrollBarSize = tmp.scrollBarSize / 2; // need this for IE9+ + return tmp.scrollBarSize; + } + + + function checkName (params, component) { // was w2checkNameParam + if (!params || typeof params.name === 'undefined') { + console.log('ERROR: The parameter "name" is required but not supplied in $().'+ component +'().'); + return false; } - } else { // remote data source - if (this.selectType == 'row') { - this.set({ selected: true }); - } else { - this.set({ selected: true, selectedColumns: cols.slice() }); + if (typeof w2ui[params.name] !== 'undefined') { + console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ params.name +').'); + return false; } - this.refresh(); - } - var sel = this.getSelection(); - if (sel.length == 1) this.toolbar.enable('edit'); else this.toolbar.disable('edit'); - if (sel.length >= 1) this.toolbar.enable('delete'); else this.toolbar.disable('delete'); - this.addRange('selection'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - selectNone: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, all: true }); - if (eventData.isCancelled === true) return; - // default action - this.last.selected = []; - for (var i in this.records) { - var rec = this.records[i]; - if (rec.selected === true) { - rec.selected = false; - var tmp = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(rec.recid)); - tmp.removeClass('w2ui-selected').removeData('selected'); - $('#grid_'+ this.name +'_cell_'+ i +'_select_check').prop("checked", false); - if (this.selectType != 'row') { - var cols = rec.selectedColumns; - for (var c in cols) tmp.find(' > td[col='+ cols[c] +']').removeClass('w2ui-selected'); - rec.selectedColumns = []; - } + if (!w2utils.isAlphaNumeric(params.name)) { + console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); + return false; } - } - this.toolbar.disable('edit', 'delete'); - this.removeRange('selection'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + return true; + } - getSelection: function (returnIndex) { - if (this.selectType == 'row') { - var sel = this.find({ selected: true }, true); - var ret = []; - for (var s in sel) { - if (returnIndex === true) { - ret.push(sel[s]); - } else { - ret.push(this.records[sel[s]].recid); - } - } - return ret; - } else { - var sel = this.find({ selected: true }, true); - var ret = []; - for (var s in sel) { - var rec = this.records[sel[s]]; - for (var c in rec.selectedColumns) { - ret.push({ recid: rec.recid, index: parseInt(sel[s]), column: rec.selectedColumns[c] }); - } + function checkUniqueId (id, items, itemsDecription, objName) { // was w2checkUniqueId + if (!$.isArray(items)) items = [items]; + for (var i = 0; i < items.length; i++) { + if (items[i].id === id) { + console.log('ERROR: The parameter "id='+ id +'" is not unique within the current '+ itemsDecription +'. (obj: '+ objName +')'); + return false; + } } - return ret; - } - }, + return true; + } - search: function (field, value) { - var obj = this; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - var searchData = []; - var last_multi = this.last.multi; - var last_logic = this.last.logic; - var last_field = this.last.field; - var last_search = this.last.search; - // 1: search() - advanced search (reads from popup) - if (arguments.length == 0) { - last_search = ''; - // advanced search - for (var s in this.searches) { - var search = this.searches[s]; - var operator = $('#grid_'+ this.name + '_operator_'+s).val(); - var value1 = $('#grid_'+ this.name + '_field_'+s).val(); - var value2 = $('#grid_'+ this.name + '_field2_'+s).val(); - if ((value1 != '' && value1 != null) || (typeof value2 != 'undefined' && value2 != '')) { - var tmp = { - field : search.field, - type : search.type, - operator : operator - } - if (operator == 'between') { - $.extend(tmp, { value: [value1, value2] }); - } else if (operator == 'in') { - $.extend(tmp, { value: value1.split(',') }); + function parseRoute(route) { + var keys = []; + var path = route + .replace(/\/\(/g, '(?:/') + .replace(/\+/g, '__plus__') + .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional) { + keys.push({ name: key, optional: !! optional }); + slash = slash || ''; + return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); + }) + .replace(/([\/.])/g, '\\$1') + .replace(/__plus__/g, '(.+)') + .replace(/\*/g, '(.*)'); + return { + path : new RegExp('^' + path + '$', 'i'), + keys : keys + }; + } +})(jQuery); + +/*********************************************************** +* Generic Event Object +* --- This object is reused across all other +* --- widgets in w2ui. +* +*********************************************************/ + +w2utils.event = { + + on: function (eventData, handler) { + if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; + eventData = jQuery.extend({ type: null, execute: 'before', target: null, onComplete: null }, eventData); + + if (!eventData.type) { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return; } + if (!handler) { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return; } + if (!jQuery.isArray(this.handlers)) this.handlers = []; + this.handlers.push({ event: eventData, handler: handler }); + }, + + off: function (eventData, handler) { + if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; + eventData = jQuery.extend({}, { type: null, execute: 'before', target: null, onComplete: null }, eventData); + + if (!eventData.type) { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return; } + if (!handler) { handler = null; } + // remove handlers + var newHandlers = []; + for (var h = 0, len = this.handlers.length; h < len; h++) { + var t = this.handlers[h]; + if ((t.event.type === eventData.type || eventData.type === '*') && + (t.event.target === eventData.target || eventData.target === null) && + (t.handler === handler || handler === null)) + { + // match } else { - $.extend(tmp, { value: value1 }); - } - // conver date to unix time - try { - if (search.type == 'date' && operator == 'between') { - tmp.value[0] = w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); - tmp.value[1] = w2utils.isDate(value2, w2utils.settings.date_format, true).getTime(); - } - if (search.type == 'date' && operator == 'is') { - tmp.value = w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); - } - } catch (e) { - - } - searchData.push(tmp); - } + newHandlers.push(t); + } } - if (searchData.length > 0 && !url) { - last_multi = true; - last_logic = 'AND'; - } else { - last_multi = true; - last_logic = 'AND'; + this.handlers = newHandlers; + }, + + trigger: function (eventData) { + var eventData = jQuery.extend({ type: null, phase: 'before', target: null }, eventData, { + isStopped: false, isCancelled: false, + preventDefault : function () { this.isCancelled = true; }, + stopPropagation : function () { this.isStopped = true; } + }); + if (eventData.phase === 'before') eventData.onComplete = null; + var args, fun, tmp; + if (eventData.target == null) eventData.target = null; + if (!jQuery.isArray(this.handlers)) this.handlers = []; + // process events in REVERSE order + for (var h = this.handlers.length-1; h >= 0; h--) { + var item = this.handlers[h]; + if ((item.event.type === eventData.type || item.event.type === '*') && + (item.event.target === eventData.target || item.event.target === null) && + (item.event.execute === eventData.phase || item.event.execute === '*' || item.event.phase === '*')) + { + eventData = jQuery.extend({}, item.event, eventData); + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(item.handler); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + item.handler.call(this, eventData.target, eventData); // old way for back compatibility + } else { + item.handler.call(this, eventData); // new way + } + if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true + } } - } - // 2: search(field, value) - regular search - if (typeof field == 'string') { - last_field = field; - last_search = value; - last_multi = false; - last_logic = 'OR'; - // loop through all searches and see if it applies - if (typeof value != 'undefined') { - if (field.toLowerCase() == 'all') { - // if there are search fields loop thru them - if (this.searches.length > 0) { - for (var s in this.searches) { - var search = this.searches[s]; - if (search.type == 'text' || (search.type == 'int' && w2utils.isInt(value)) || (search.type == 'float' && w2utils.isFloat(value)) - || (search.type == 'money' && w2utils.isMoney(value)) || (search.type == 'hex' && w2utils.isHex(value)) - || (search.type == 'date' && w2utils.isDate(value)) || (search.type == 'alphaNumeric' && w2utils.isAlphaNumeric(value)) ) { - var tmp = { - field : search.field, - type : search.type, - operator : (search.type == 'text' ? 'contains' : 'is'), - value : value - }; - searchData.push(tmp); - } - // range in global search box - if (search.type == 'int' && String(value).indexOf('-') != -1) { - var t = String(value).split('-'); - var tmp = { - field : search.field, - type : search.type, - operator : 'between', - value : [t[0], t[1]] - }; - searchData.push(tmp); - } - } + // main object events + var funName = 'on' + eventData.type.substr(0,1).toUpperCase() + eventData.type.substr(1); + if (eventData.phase === 'before' && typeof this[funName] === 'function') { + fun = this[funName]; + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(fun); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + fun.call(this, eventData.target, eventData); // old way for back compatibility } else { - // no search fields, loop thru columns - for (var c in this.columns) { - var tmp = { - field : this.columns[c].field, - type : 'text', - operator : 'contains', - value : value - }; - searchData.push(tmp); - } + fun.call(this, eventData); // new way } - } else { - var search = this.getSearch(field); - if (search == null) search = { field: field, type: 'text' }; - if (search.field == field) this.last.caption = search.caption; - if (value != '') { - var op = 'contains'; - var val = value; - if (w2utils.isInt(value)) { - op = 'is'; - val = value; - } - if (search.type == 'int' && value != '') { - if (String(value).indexOf('-') != -1) { - var tmp = value.split('-'); - if (tmp.length == 2) { - op = 'between'; - val = [parseInt(tmp[0]), parseInt(tmp[1])]; - } - } - if (String(value).indexOf(',') != -1) { - var tmp = value.split(','); - op = 'in'; - val = []; - for (var t in tmp) val.push(tmp[t]); - } - } - var tmp = { - field : search.field, - type : search.type, - operator : op, - value : val - } - searchData.push(tmp); - } - } - } - } - // 3: search([ { field, value, [operator,] [type] }, { field, value, [operator,] [type] } ], logic) - submit whole structure - if ($.isArray(field)) { - var logic = 'AND'; - if (typeof value == 'string') { - logic = value.toUpperCase(); - if (logic != 'OR' && logic != 'AND') logic = 'AND'; - } - last_search = ''; - last_multi = true; - last_logic = logic; - for (var f in field) { - var data = field[f]; - var search = this.getSearch(data.field); - if (search == null) search = { type: 'text', operator: 'contains' }; - // merge current field and search if any - searchData.push($.extend(true, {}, search, data)); + if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true } - } - // event before - var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: searchData, - searchField: (field ? field : 'multi'), searchValue: (value ? value : 'multi') }); - if (eventData.isCancelled === true) return; - // default action - this.searchData = eventData.searchData; - this.last.field = last_field; - this.last.search = last_search; - this.last.multi = last_multi; - this.last.logic = last_logic; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - // -- clear all search field - this.searchClose(); - this.set({ expanded: false }); - // apply search - if (url) { - this.last.xhr_offset = 0; - this.reload(); - } else { - // local search - this.localSearch(); - this.refresh(); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - searchOpen: function () { - if (!this.box) return; - if (this.searches.length == 0) return; - var obj = this; - // show search - $('#tb_'+ this.name +'_toolbar_item_search-advanced').w2overlay( - this.getSearchesHTML(), + // item object events + if (eventData.object != null && eventData.phase === 'before' && + typeof eventData.object[funName] === 'function') { - left: -10, - 'class': 'w2ui-grid-searches', - onShow: function () { - if (obj.last.logic == 'OR') obj.searchData = []; - obj.initSearches(); - $('#w2ui-overlay .w2ui-grid-searches').data('grid-name', obj.name); - var sfields = $('#w2ui-overlay .w2ui-grid-searches *[rel=search]'); - if (sfields.length > 0) sfields[0].focus(); - } + fun = eventData.object[funName]; + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(fun); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + fun.call(this, eventData.target, eventData); // old way for back compatibility + } else { + fun.call(this, eventData); // new way + } + if (eventData.isStopped === true || eventData.stop === true) return eventData; } - ); - }, + // execute onComplete + if (eventData.phase === 'after' && typeof eventData.onComplete === 'function') eventData.onComplete.call(this, eventData); - searchClose: function () { - if (!this.box) return; - if (this.searches.length == 0) return; - if (this.toolbar) this.toolbar.uncheck('search-advanced') - // hide search - if ($('#w2ui-overlay .w2ui-grid-searches').length > 0) $().w2overlay(); - }, + return eventData; + } +}; - searchShowFields: function (el) { - if (typeof el == 'undefined') el = $('#grid_'+ this.name +'_search_all'); - var html = ''; - for (var s = -1; s < this.searches.length; s++) { - var search = this.searches[s]; - if (s == -1) { - if (!this.multiSearch) continue; - search = { - type : 'text', - field : 'all', - caption : w2utils.lang('All Fields') - } - } else { - if (this.searches[s].hidden === true) continue; - } - html += ''+ - ''+ - ''+ search.caption +''+ - ''; - } - html += ""; - $(el).w2overlay(html, { left: -15, top: 7 }); - }, +/*********************************************************** +* Common Keyboard Handler. Supported in +* - grid +* - sidebar +* - popup +* +*********************************************************/ - searchReset: function (noRefresh) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: [] }); - if (eventData.isCancelled === true) return; - // default action - this.searchData = []; - this.last.search = ''; - this.last.logic = 'OR'; - if (this.last.multi) { - if (!this.multiSearch) { - this.last.field = this.searches[0].field; - this.last.caption = this.searches[0].caption; - } else { - this.last.field = 'all'; - this.last.caption = w2utils.lang('All Fields'); - } - } - this.last.multi = false; - this.last.xhr_offset = 0; - // reset scrolling position - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - // -- clear all search field - this.searchClose(); - // apply search - if (!noRefresh) this.reload(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - clear: function (noRefresh) { - this.offset = 0; - this.total = 0; - this.buffered = 0; - this.records = []; - this.summary = []; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.range_start = null; - this.last.range_end = null; - this.last.xhr_offset = 0; - if (!noRefresh) this.refresh(); - }, - - reset: function (noRefresh) { - // reset last remembered state - this.offset = 0; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - this.last.range_start = null; - this.last.range_end = null; - this.last.xhr_offset = 0; - this.searchReset(noRefresh); - // initial sort - if (this.last.sortData != null ) this.sortData = this.last.sortData; - // select none without refresh - this.set({ selected: false, expanded: false }, true); - // refresh - if (!noRefresh) this.refresh(); - }, +w2utils.keyboard = (function (obj) { + // private scope + var w2ui_name = null; - skip: function (offset) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - this.offset = parseInt(offset); - if (this.offset < 0 || !w2utils.isInt(this.offset)) this.offset = 0; - if (this.offset > this.total) this.offset = this.total - this.limit; - // console.log('last', this.last); - this.records = []; - this.buffered = 0; - this.last.xhr_offset = 0; - this.last.pull_more = true; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - $('#grid_'+ this.name +'_records').prop('scrollTop', 0); - this.initColumnOnOff(); - this.reload(); - } else { - console.log('ERROR: grid.skip() can only be called when you have remote data source.'); - } - }, + obj.active = active; + obj.clear = clear; - load: function (url, callBack) { - if (typeof url == 'undefined') { - console.log('ERROR: You need to provide url argument when calling .load() method of "'+ this.name +'" object.'); - return; - } - // default action - this.request('get-records', {}, url, callBack); - }, + init(); + return obj; - reload: function (callBack) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - if (this.last.xhr_offset > 0 && this.last.xhr_offset < this.buffered) this.last.xhr_offset = this.buffered; - this.request('get-records', {}, null, callBack); - } else { - this.localSearch(); - this.refresh(); - if (typeof callBack == 'function') callBack(); - } - }, + function init() { + jQuery(document).on('keydown', keydown); + jQuery(document).on('mousedown', mousedown); + } - request: function (cmd, add_params, url, callBack) { - if (typeof add_params == 'undefined') add_params = {}; - if (typeof url == 'undefined' || url == '' || url == null) url = this.url; - if (url == '' || url == null) return; - // build parameters list - var params = {}; - if (!w2utils.isInt(this.offset)) this.offset = 0; - if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0; - // add list params - params['cmd'] = cmd; - params['name'] = this.name; - params['limit'] = this.limit; - params['offset'] = parseInt(this.offset) + this.last.xhr_offset; - params['selected'] = this.getSelection(); - params['search'] = this.searchData; - params['search-logic'] = this.last.logic; - params['sort'] = (this.sortData.length != 0 ? this.sortData : ''); - // append other params - $.extend(params, this.postData); - $.extend(params, add_params); - // event before - if (cmd == 'get-records') { - var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: url, postData: params }); - if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack(); return false; } - } else { - var eventData = { url: this.url, postData: params }; - } - // call server to get data - var obj = this; - this.lock(this.msgRefresh, true); - if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; - var xhr_type = 'GET'; - var url = (typeof eventData.url != 'object' ? eventData.url : eventData.url.get); - if (params.cmd == 'save-records') { - if (typeof eventData.url == 'object') url = eventData.url.save; - xhr_type = 'PUT'; // so far it is always update - } - if (params.cmd == 'delete-records') { - if (typeof eventData.url == 'object') url = eventData.url.remove; - xhr_type = 'DELETE'; - } - if (!w2utils.settings.RESTfull) xhr_type = 'POST'; - this.last.xhr_cmd = params.cmd; - this.last.xhr_start = (new Date()).getTime(); - this.last.xhr = $.ajax({ - type : xhr_type, - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - complete : function (xhr, status) { - obj.requestComplete(status, cmd, callBack); + function keydown (event) { + var tag = event.target.tagName; + if (jQuery.inArray(tag, ['INPUT', 'SELECT', 'TEXTAREA']) !== -1) return; + if (jQuery(event.target).prop('contenteditable') === 'true') return; + if (!w2ui_name) return; + // pass to appropriate widget + if (w2ui[w2ui_name] && typeof w2ui[w2ui_name].keydown === 'function') { + w2ui[w2ui_name].keydown.call(w2ui[w2ui_name], event); } - }); - if (cmd == 'get-records') { - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, + } - requestComplete: function(status, cmd, callBack) { - var obj = this; - this.unlock(); - setTimeout(function () { obj.status(w2utils.lang('Server Response') + ' ' + ((new Date()).getTime() - obj.last.xhr_start)/1000 +' ' + w2utils.lang('sec')); }, 10); - this.last.pull_more = false; - this.last.pull_refresh = true; - - // event before - var event_name = 'load'; - if (this.last.xhr_cmd == 'save-records') event_name = 'saved'; - if (this.last.xhr_cmd == 'delete-records') event_name = 'deleted'; - var eventData = this.trigger({ phase: 'before', target: this.name, type: event_name, xhr: this.last.xhr, status: status }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // parse server response - var responseText = this.last.xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } - } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : this.msgNotJSON, - responseText : responseText - } - } - if (data['status'] == 'error') { - obj.error(data['message']); - } else { - if (cmd == 'get-records') { - if (this.last.xhr_offset == 0) { - this.records = []; - this.summary = []; - //data.xhr_status=data.status; - delete data.status; - $.extend(true, this, data); - this.buffered = this.records.length; - } else { - var records = data.records; - delete data.records; - //data.xhr_status=data.status; - delete data.status; - $.extend(true, this, data); - for (var r in records) { - this.records.push(records[r]); - } - this.buffered = this.records.length; - } - } - if (cmd == 'delete-records') { - this.reload(); - return; - } - } + function mousedown (event) { + var tag = event.target.tagName; + var obj = jQuery(event.target).parents('.w2ui-reset'); + if (obj.length > 0) { + var name = obj.attr('name'); + if (w2ui[name] && w2ui[name].keyboard) w2ui_name = name; } - } else { - obj.error('AJAX Error. See console for more details.'); - } - // event after - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - this.localSearch(); - } - this.total = parseInt(this.total); - this.trigger($.extend(eventData, { phase: 'after' })); - // do not refresh if loading on infinite scroll - if (this.last.xhr_offset == 0) this.refresh(); else this.scroll(); - // call back - if (typeof callBack == 'function') callBack(); - }, - - error: function (msg) { - var obj = this; - // let the management of the error outside of the grid - var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // need a time out because message might be already up) - setTimeout(function () { w2alert(msg, 'Error'); }, 1); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + } - getChanges: function () { - var changes = []; - var tmp = this.find({ changed: true }); - for (var t in tmp) { - changes.push($.extend(true, { recid: tmp[t].recid }, tmp[t].changes)); - } - return changes; - }, + function active (new_w2ui_name) { + if (typeof new_w2ui_name !== 'undefined') w2ui_name = new_w2ui_name; + return w2ui_name; + } - mergeChanges: function () { - var changed = this.getChanges(); - for (var c in changed) { - var record = this.get(changed[c].recid); - for (var s in changed[c]) { - if (s == 'recid') continue; // do not allow to change recid - try { eval('record.' + s + ' = changed[c][s]'); } catch (e) {} - delete record.changed; - delete record.changes; - } - } - $(this.box).find('.w2ui-editable input').removeClass('changed'); - this.refresh(); - }, + function clear () { + w2ui_name = null; + } - // =================================================== - // -- Action Handlers - - save: function () { - var obj = this; - var changed = this.getChanges(); - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'save', changed: changed }); - if (eventData.isCancelled === true) return false; - var url = (typeof this.url != 'object' ? this.url : this.url.save); - if (url) { - this.request('save-records', { 'changed' : eventData.changed }, null, - function () { // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - ); - } else { - this.mergeChanges(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, +})({}); - editField: function (recid, column, value, event) { - //console.log('edit field', recid, column); - var obj = this; - var index = obj.get(recid, true); - var rec = obj.records[index]; - var col = obj.columns[column]; - var edit = col.editable; - if (!rec || !col || !edit) return; - // event before - var eventData = obj.trigger({ phase: 'before', type: 'editField', target: obj.name, recid: recid, column: column, value: value, - index: index, originalEvent: event }); - if (eventData.isCancelled === true) return; - value = eventData.value; - // default behaviour - this.selectNone(); - this.select({ recid: recid, column: column }); - // create input element - var tr = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(recid)); - var el = tr.find('[col='+ column +'] > div'); - if (edit.type == 'enum') console.log('ERROR: Grid\'s inline editing does not support enum field type.'); - if (edit.type == 'list' || edit.type == 'select') console.log('ERROR: Grid\'s inline editing does not support list/select field type.'); - if (typeof edit.inTag == 'undefined') edit.inTag = ''; - if (typeof edit.outTag == 'undefined') edit.outTag = ''; - if (typeof edit.style == 'undefined') edit.style = ''; - if (typeof edit.items == 'undefined') edit.items = []; - var val = (rec.changed && rec.changes[col.field] ? w2utils.stripTags(rec.changes[col.field]) : w2utils.stripTags(rec[col.field])); - if (val == null || typeof val == 'undefined') val = ''; - if (typeof value != 'undefined' && value != null) val = value; - var addStyle = (typeof col.style != 'undefined' ? col.style + ';' : ''); - if ($.inArray(col.render, ['number', 'int', 'float', 'money', 'percent']) != -1) addStyle += 'text-align: right;'; - el.addClass('w2ui-editable') - .html('' + edit.outTag); - el.find('input') - .w2field(edit.type) - .on('blur', function (event) { - if (obj.parseField(rec, col.field) != this.value) { - // change event - var eventData2 = obj.trigger({ phase: 'before', type: 'change', target: obj.name, input_id: this.id, recid: recid, column: column, - value_new: this.value, value_previous: (rec.changes ? rec.changes[col.field] : obj.parseField(rec, col.field)), - value_original: obj.parseField(rec, col.field) }); - if (eventData2.isCancelled === true) { - // dont save new value - } else { - // default action - rec.changed = true; - rec.changes = rec.changes || {}; - rec.changes[col.field] = eventData2.value_new; - // event after - obj.trigger($.extend(eventData2, { phase: 'after' })); - } - } else { - if (rec.changes) delete rec.changes[col.field]; - if ($.isEmptyObject(rec.changes)) delete rec.changes; - } - // refresh record - $(tr).replaceWith(obj.getRecordHTML(index, tr.attr('line'))); - }) - .on('keydown', function (event) { - var cancel = false; - switch (event.keyCode) { - case 9: // tab - cancel = true; - var next = event.shiftKey ? prevCell(column) : nextCell(column); - if (next != column) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: recid, column: next }); - } else { - obj.editField(recid, next, null, event); - } - }, 1); - } - break; - - case 13: // enter - cancel = true; - var next = event.shiftKey ? prevRow(index) : nextRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 38: // up arrow - cancel = true; - var next = prevRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 40: // down arrow - cancel = true; - var next = nextRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 27: // escape - var old = (rec.changed && rec.changes[col.field]) ? rec.changes[col.field] : obj.parseField(rec, col.field); - this.value = typeof old != 'undefined' ? old : ''; - this.blur(); - setTimeout(function () { obj.select({ recid: recid, column: column }) }, 1); - break; - } - if (cancel) if (event.preventDefault) event.preventDefault(); - // -- functions - function nextCell (check) { - var newCheck = check + 1; - if (obj.columns.length == newCheck) return check; - if (obj.columns[newCheck].hidden) return nextCell(newCheck); - return newCheck; - } - function prevCell (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - if (obj.columns[newCheck].hidden) return prevCell(newCheck); - return newCheck; - } - function nextRow (check) { - var newCheck = check + 1; - if (obj.records.length == newCheck) return check; - return newCheck; - } - function prevRow (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - return newCheck; - } - }); - // unselect - if (typeof value == 'undefined' || value == null) { - el.find('input').focus(); - } else { - el.find('input').val('').focus().val(value); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, +/*********************************************************** +* Commonly used plugins +* --- used primarily in grid and form +* +*********************************************************/ - delete: function (force) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'delete', force: force }); - if (eventData.isCancelled === true) return false; - force = eventData.force; - // default action - var recs = this.getSelection(); - if (recs.length == 0) return; - if (this.msgDelete != '' && !force) { - w2confirm(obj.msgDelete, w2utils.lang('Delete Confirmation'), function (result) { - if (result == 'Yes') w2ui[obj.name].delete(true); - }); - return; - } - // call delete script - var url = (typeof this.url != 'object' ? this.url : this.url.remove); - if (url) { - this.request('delete-records'); - } else { - if (typeof recs[0] != 'object') { - this.remove.apply(this, recs); - } else { - // clear cells - for (var r in recs) { - var fld = this.columns[recs[r].column].field; - var ind = this.get(recs[r].recid, true); - if (ind != null && fld != 'recid') { - this.records[ind][fld] = ''; - if (this.records[ind].changed) this.records[ind].changes[fld] = ''; - } - } - this.refresh(); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, +(function ($) { - click: function (recid, event) { - var time = (new Date()).getTime(); - var column = null; - if (typeof recid == 'object') { - column = recid.column; - recid = recid.recid; - } - if (w2utils.isInt(recid)) recid = parseInt(recid); - if (typeof event == 'undefined') event = {}; - // check for double click - if (time - parseInt(this.last.click_time) < 250 && event.type == 'click') { - this.dblClick(recid, event); - return; - } - this.last.click_time = time; - // column user clicked on - if (column == null && event.target) { - var tmp = event.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'click', recid: recid, column: column, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // if it is subgrid unselect top grid - var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).parents('tr'); - if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var grid = parent.parents('.w2ui-grid').attr('name'); - w2ui[grid].selectNone(); - // all subgrids - parent.parents('.w2ui-grid').find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { - var grid = $(el).attr('name'); - if (w2ui[grid]) w2ui[grid].selectNone(); - }); - } - // unselect all subgrids - $(this.box).find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { - var grid = $(el).attr('name'); - if (w2ui[grid]) w2ui[grid].selectNone(); - }); - // default action - var obj = this; - var sel = this.getSelection(); - $('#grid_'+ this.name +'_check_all').prop("checked", false); - var ind = this.get(recid, true); - var record = this.records[ind]; - var selectColumns = []; - obj.last.sel_ind = ind; - obj.last.sel_col = column; - obj.last.sel_recid = recid; - obj.last.sel_type = 'click'; - // multi select with shif key - if (event.shiftKey && sel.length > 0) { - if (sel[0].recid) { - var start = this.get(sel[0].recid, true); - var end = this.get(recid, true); - if (column > sel[0].column) { - var t1 = sel[0].column; - var t2 = column; - } else { - var t1 = column; - var t2 = sel[0].column; - } - for (var c = t1; c <= t2; c++) selectColumns.push(c); - } else { - var start = this.get(sel[0], true); - var end = this.get(recid, true); - } - var sel_add = [] - if (start > end) { var tmp = start; start = end; end = tmp; } - var url = (typeof this.url != 'object' ? this.url : this.url.get); - for (var i = start; i <= end; i++) { - if (this.searchData.length > 0 && !url && $.inArray(i, this.last.searchIds) == -1) continue; - if (this.selectType == 'row') { - sel_add.push(this.records[i].recid); - } else { - for (var sc in selectColumns) sel_add.push({ recid: this.records[i].recid, column: selectColumns[sc] }); - } - //sel.push(this.records[i].recid); + $.fn.w2render = function (name) { + if ($(this).length > 0) { + if (typeof name === 'string' && w2ui[name]) w2ui[name].render($(this)[0]); + if (typeof name === 'object') name.render($(this)[0]); } - this.select.apply(this, sel_add); - } else { - // clear other if necessary - if (((!event.ctrlKey && !event.shiftKey && !event.metaKey) || !this.multiSelect) && !this.showSelectColumn) { - var flag = record.selected; - if (this.selectType != 'row' && $.inArray(column, record.selectedColumns) == -1) flag = false; - if (sel.length > 300) this.selectNone(); else this.unselect.apply(this, sel); - if (flag === true) { - this.unselect({ recid: recid, column: column }); - //sel = []; - } else { - this.select({ recid: recid, column: column }); - //sel = [{ recid: recid, column: [column] }]; - } - } else { - var flag = record.selected; - if (this.selectType != 'row' && $.inArray(column, record.selectedColumns) == -1) flag = false; - if (flag === true) { - this.unselect({ recid: recid, column: column }); - //sel.splice($.inArray(record.recid, sel), 1); - } else { - this.select({ recid: record.recid, column: column }); - //sel.push(record.recid); - } - setTimeout(function () { if (window.getSelection) window.getSelection().removeAllRanges(); }, 10); - } - } - this.status(); - obj.last.selected = this.getSelection(); - obj.initResize(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }; - columnClick: function (field, event) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'columnClick', target: this.name, field: field, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behaviour - this.sort(field, null, (event && (event.ctrlKey || event.metaKey) ? true : false) ); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + $.fn.w2destroy = function (name) { + if (!name && this.length > 0) name = this.attr('name'); + if (typeof name === 'string' && w2ui[name]) w2ui[name].destroy(); + if (typeof name === 'object') name.destroy(); + }; - keydown: function (event) { - // this method is called from w2utils - var obj = this; - if (obj.keyboard !== true) return; - // trigger event - var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behavior - var sel = obj.getSelection(); - if (sel.length == 0) return; - var records = $('#grid_'+ obj.name +'_records'); - var recid = sel[0]; - var columns = []; - var recid2 = sel[sel.length-1]; - if (typeof recid == 'object') { - recid = sel[0].recid; - columns = []; - var ii = 0; - while (true) { - if (!sel[ii] || sel[ii].recid != recid) break; - columns.push(sel[ii].column); - ii++; + $.fn.w2marker = function (str) { + if (str === '' || str == null) { // remove marker + return $(this).each(function (index, el) { + el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark + }); + } else { // add marker + return $(this).each(function (index, el) { + if (typeof str === 'string') str = [str]; + el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark + for (var s in str) { + var tmp = str[s]; + if (typeof tmp !== 'string') tmp = String(tmp); + // escape regex special chars + tmp = tmp.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, '&').replace(//g, '<'); + var regex = new RegExp(tmp + '(?!([^<]+)?>)', "gi"); // only outside tags + el.innerHTML = el.innerHTML.replace(regex, replaceValue); + } + function replaceValue(matched) { // mark new + return '' + matched + ''; + } + }); + } + }; + + // -- w2tag - appears on the right side from element, there can be multiple on screen at a time + + $.fn.w2tag = function (text, options) { + if (!$.isPlainObject(options)) options = {}; + if (!$.isPlainObject(options.css)) options.css = {}; + if (typeof options['class'] === 'undefined') options['class'] = ''; + // remove all tags + if ($(this).length === 0) { + $('.w2ui-tag').each(function (index, elem) { + var opt = $(elem).data('options'); + if (opt == null) opt = {}; + $($(elem).data('taged-el')).removeClass( opt['class'] ); + clearInterval($(elem).data('timer')); + $(elem).remove(); + }); + return; } - recid2 = sel[sel.length-1].recid; - } - var ind = obj.get(recid, true); - var ind2 = obj.get(recid2, true); - var rec = obj.get(recid); - var recEL = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)); - var cancel = false; - switch (event.keyCode) { - case 8: // backspace - case 46: // delete - obj.delete(); - cancel = true; - event.stopPropagation(); - break; - - case 27: // escape - var sel = obj.getSelection(); - obj.selectNone(); - if (sel.length > 0) { - if (typeof sel[0] == 'object') { - obj.select({ recid: sel[0].recid, column: sel[0].column }); + return $(this).each(function (index, el) { + // show or hide tag + var tagOrigID = el.id; + var tagID = w2utils.escapeId(el.id); + if (text === '' || text == null) { + $('#w2ui-tag-'+tagID).css('opacity', 0); + setTimeout(function () { + // remmove element + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + $('#w2ui-tag-'+tagID).remove(); + }, 300); } else { - obj.select(sel[0]); - } - } - cancel = true; - break; - - case 13: // enter - case 32: // spacebar - if (columns.length == 0) columns.push(0); - obj.editField(recid, columns[0], null, event); - cancel = true; - break; - - case 65: // cmd + A - if (!event.metaKey && !event.ctrlKey) break; - obj.selectAll(); - cancel = true; - break; - - case 70: // cmd + F - if (!event.metaKey && !event.ctrlKey) break; - $('#grid_'+ obj.name + '_search_all').focus(); - cancel = true; - break; - - case 13: // enter - if (this.selectType == 'row') { - if (recEL.length <= 0 || obj.show.expandColumn !== true) break; - obj.toggle(recid, event); - cancel = true; - } else { // same as spacebar - if (columns.length == 0) columns.push(0); - obj.editField(recid, columns[0], null, event); - cancel = true; - } - break; - - case 37: // left - // check if this is subgrid - var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)).parents('tr'); - if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.prev().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].set(recid, { expanded: false }); - w2ui[grid].collapse(recid); - w2ui[grid].click(recid); - cancel = true; - break; - } - if (this.selectType == 'row') { - if (recEL.length <= 0 || rec.expanded !== true ) break; - obj.set(recid, { expanded: false }, true); - obj.collapse(recid, event); - } else { - var prev = prevCell(columns[0]); - if (prev != columns[0]) { - if (event.shiftKey) { - if (tmpUnselect()) return; - var tmp = []; - var newSel = []; - var unSel = []; - if (columns.indexOf(this.last.sel_col) == 0 && columns.length > 1) { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - unSel.push({ recid: sel[i].recid, column: columns[columns.length-1] }); - } - } else { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - newSel.push({ recid: sel[i].recid, column: prev }); - } - } - obj.unselect.apply(obj, unSel); - obj.select.apply(obj, newSel); - } else { - obj.click({ recid: recid, column: prev }, event); - } + // remove elements + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + $('#w2ui-tag-'+tagID).remove(); + // insert + $('body').append( + ''); + + var timer = setInterval(function () { + // monitor if destroyed + if ($(el).length === 0 || ($(el).offset().left === 0 && $(el).offset().top === 0)) { + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + tmp_hide(); + return; + } + // monitor if moved + if ($('#w2ui-tag-'+tagID).data('position') !== ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) { + $('#w2ui-tag-'+tagID).css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s', + left: ($(el).offset().left + el.offsetWidth) + 'px', + top: $(el).offset().top + 'px' + }).data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top); + } + }, 100); + setTimeout(function () { + if (!$(el).offset()) return; + $('#w2ui-tag-'+tagID).css({ + opacity: '1', + left: ($(el).offset().left + el.offsetWidth) + 'px', + top: $(el).offset().top + 'px' + }).html(' '+ text +' ') + .data('text', text) + .data('taged-el', el) + .data('options', options) + .data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) + .data('timer', timer); + $(el).off('keypress', tmp_hide).on('keypress', tmp_hide).off('change', tmp_hide).on('change', tmp_hide) + .css(options.css).addClass(options['class']); + if (typeof options.onShow === 'function') options.onShow(); + }, 1); + var originalCSS = ''; + if ($(el).length > 0) originalCSS = $(el)[0].style.cssText; + // bind event to hide it + function tmp_hide() { + $tag = $('#w2ui-tag-'+tagID); + if ($tag.length <= 0) return; + clearInterval($tag.data('timer')); + $tag.remove(); + $(el).off('keypress', tmp_hide).removeClass(options['class']); + if ($(el).length > 0) $(el)[0].style.cssText = originalCSS; + if (typeof options.onHide === 'function') options.onHide(); + } + } + }); + }; + + // w2overlay - appears under the element, there can be only one at a time + + $.fn.w2overlay = function (html, options) { + var obj = this; + var name = ''; + var defaults = { + name : null, // it not null, then allows multiple concurent overlays + html : '', // html text to display + align : 'none', // can be none, left, right, both + left : 0, // offset left + top : 0, // offset top + tipLeft : 30, // tip offset left + width : 0, // fixed width + height : 0, // fixed height + maxWidth : null, // max width if any + maxHeight : null, // max height if any + style : '', // additional style for main div + 'class' : '', // additional class name for main div + onShow : null, // event on show + onHide : null, // event on hide + openAbove : false, // show abover control + tmp : {} + }; + if (arguments.length == 1) { + if (typeof html == 'object') { + options = html; } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=1; s 1) { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - unSel.push({ recid: sel[i].recid, column: columns[0] }); - } - } else { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - newSel.push({ recid: sel[i].recid, column: next }); - } - } - obj.unselect.apply(obj, unSel); - obj.select.apply(obj, newSel); - } else { - obj.click({ recid: recid, column: next }, event); - } + options = { html: html }; + } + } + if (arguments.length == 2) options.html = html; + if (!$.isPlainObject(options)) options = {}; + options = $.extend({}, defaults, options); + if (options.name) name = '-' + options.name; + // if empty then hide + var tmp_hide; + if (this.length === 0 || options.html === '' || options.html == null) { + if ($('#w2ui-overlay'+ name).length > 0) { + tmp_hide = $('#w2ui-overlay'+ name)[0].hide; + if (typeof tmp_hide === 'function') tmp_hide(); } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=0; s 0 && w2ui[subgrid.attr('name')]) { - obj.selectNone(); - var grid = subgrid.attr('name'); - var recs = w2ui[grid].records; - w2utils.keyboard.active(grid); - w2ui[grid].click(recs[recs.length-1].recid); - cancel = true; - break; - } + $('#w2ui-overlay'+ name).remove(); } - if (event.shiftKey) { // expand selection - if (tmpUnselect()) return; - if (obj.selectType == 'row') { - if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { - obj.unselect(obj.records[ind2].recid); - } else { - obj.select(obj.records[prev].recid); - } - } else { - if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { - prev = ind2; - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); - obj.unselect.apply(obj, tmp); - } else { - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); - obj.select.apply(obj, tmp); - } - } - } else { // move selected record - obj.selectNone(); - obj.click({ recid: obj.records[prev].recid, column: columns[0] }, event); + return $(this); + } + if ($('#w2ui-overlay'+ name).length > 0) { + tmp_hide = $('#w2ui-overlay'+ name)[0].hide; + $(document).off('click', tmp_hide); + if (typeof tmp_hide === 'function') tmp_hide(); + } + $('body').append( + ''+ + ' '+ + ' '+ + '' + ); + // init + var div1 = $('#w2ui-overlay'+ name); + var div2 = div1.find(' > div'); + div2.html(options.html); + // pick bg color of first div + var bc = div2.css('background-color'); + if (bc != null && bc !== 'rgba(0, 0, 0, 0)' && bc !== 'transparent') div1.css('background-color', bc); + + div1.data('element', obj.length > 0 ? obj[0] : null) + .data('options', options) + .data('position', $(obj).offset().left + 'x' + $(obj).offset().top) + .fadeIn('fast').on('mousedown', function (event) { + $('#w2ui-overlay'+ name).data('keepOpen', true); + if (['INPUT', 'TEXTAREA', 'SELECT'].indexOf(event.target.tagName) === -1) event.preventDefault(); + }); + div1[0].hide = hide; + div1[0].resize = resize; + + // need time to display + resize(); + setTimeout(function () { + resize(); + $(document).off('click', hide).on('click', hide); + if (typeof options.onShow === 'function') options.onShow(); + }, 10); + + monitor(); + return $(this); + + // monitor position + function monitor() { + var tmp = $('#w2ui-overlay'+ name); + if (tmp.data('element') !== obj[0]) return; // it if it different overlay + if (tmp.length === 0) return; + var pos = $(obj).offset().left + 'x' + $(obj).offset().top; + if (tmp.data('position') !== pos) { + hide(); + } else { + setTimeout(monitor, 250); } - obj.scrollIntoView(prev); - if (event.preventDefault) event.preventDefault(); - } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=1; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.prev().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].click(recid); - cancel = true; - break; - } - } - break; - - case 40: // down - if (recEL.length <= 0) break; - // jump into subgrid - if (obj.records[ind2].expanded) { - var subgrid = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind2].recid) +'_expanded_row').find('.w2ui-grid'); - if (subgrid.length > 0 && w2ui[subgrid.attr('name')]) { - obj.selectNone(); - var grid = subgrid.attr('name'); - var recs = w2ui[grid].records; - w2utils.keyboard.active(grid); - w2ui[grid].click(recs[0].recid); - cancel = true; - break; - } - } - // move to the next record - var next = nextRow(ind2); - if (next != null) { - if (event.shiftKey) { // expand selection - if (tmpUnselect()) return; - if (obj.selectType == 'row') { - if (this.last.sel_ind < next && this.last.sel_ind != ind) { - obj.unselect(obj.records[ind].recid); - } else { - obj.select(obj.records[next].recid); - } - } else { - if (this.last.sel_ind < next && this.last.sel_ind != ind) { - next = ind; - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); - obj.unselect.apply(obj, tmp); + var result; + if (typeof options.onHide === 'function') result = options.onHide(); + if (result === false) return; + div1.remove(); + $(document).off('click', hide); + clearInterval(div1.data('timer')); + } + + function resize () { + var div1 = $('#w2ui-overlay'+ name); + var div2 = div1.find(' > div'); + // if goes over the screen, limit height and width + if (div1.length > 0) { + div2.height('auto').width('auto'); + // width/height + var overflowX = false; + var overflowY = false; + var h = div2.height(); + var w = div2.width(); + if (options.width && options.width < w) w = options.width; + if (w < 30) w = 30; + // if content of specific height + if (options.tmp.contentHeight) { + h = options.tmp.contentHeight; + div2.height(h); + setTimeout(function () { + if (div2.height() > div2.find('div.menu > table').height()) { + div2.find('div.menu').css('overflow-y', 'hidden'); + } + }, 1); + setTimeout(function () { div2.find('div.menu').css('overflow-y', 'auto'); }, 10); + } + if (options.tmp.contentWidth) { + w = options.tmp.contentWidth; + div2.width(w); + setTimeout(function () { + if (div2.width() > div2.find('div.menu > table').width()) { + div2.find('div.menu').css('overflow-x', 'hidden'); + } + }, 1); + setTimeout(function () { div2.find('div.menu').css('overflow-y', 'auto'); }, 10); + } + // alignment + switch (options.align) { + case 'both': + options.left = 17; + if (options.width === 0) options.width = w2utils.getSize($(obj), 'width'); + break; + case 'left': + options.left = 17; + break; + case 'right': + options.tipLeft = w - 45; + options.left = w2utils.getSize($(obj), 'width') - w + 10; + break; + } + // adjust position + var tmp = (w - 17) / 2; + var boxLeft = options.left; + var boxWidth = options.width; + var tipLeft = options.tipLeft; + if (w === 30 && !boxWidth) boxWidth = 30; else boxWidth = (options.width ? options.width : 'auto'); + if (tmp < 25) { + boxLeft = 25 - tmp; + tipLeft = Math.floor(tmp); + } + // Y coord + div1.css({ + top : (obj.offset().top + w2utils.getSize(obj, 'height') + options.top + 7) + 'px', + left : ((obj.offset().left > 25 ? obj.offset().left : 25) + boxLeft) + 'px', + 'min-width' : boxWidth, + 'min-height': (options.height ? options.height : 'auto') + }); + // $(window).height() - has a problem in FF20 + var maxHeight = window.innerHeight + $(document).scrollTop() - div2.offset().top - 7; + var maxWidth = window.innerWidth + $(document).scrollLeft() - div2.offset().left - 7; + if ((maxHeight > -50 && maxHeight < 210) || options.openAbove === true) { + // show on top + maxHeight = div2.offset().top - $(document).scrollTop() - 7; + if (options.maxHeight && maxHeight > options.maxHeight) maxHeight = options.maxHeight; + if (h > maxHeight) { + overflowY = true; + div2.height(maxHeight).width(w).css({ 'overflow-y': 'auto' }); + h = maxHeight; + } + div1.css('top', ($(obj).offset().top - h - 24 + options.top) + 'px'); + div1.find('>style').html( + '#w2ui-overlay'+ name +':before { display: none; margin-left: '+ parseInt(tipLeft) +'px; }'+ + '#w2ui-overlay'+ name +':after { display: block; margin-left: '+ parseInt(tipLeft) +'px; }' + ); } else { - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); - obj.select.apply(obj, tmp); - } - } - } else { // move selected record - obj.selectNone(); - obj.click({ recid: obj.records[next].recid, column: columns[0] }, event); - } - obj.scrollIntoView(next); - cancel = true; - } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=0; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.next().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].click(recid); - cancel = true; - break; - } - } - break; - - case 86: // v - paste - if (event.ctrlKey || event.metaKey) { - $('body').append(''); - $('#_tmp_copy_data').focus(); - setTimeout(function () { - obj.paste($('#_tmp_copy_data').val()); - $('#_tmp_copy_data').remove(); - }, 50); // need timer to allow paste - } - break; - - case 88: // x - cut - if (event.ctrlKey || event.metaKey) { - setTimeout(function () { obj.delete(true); }, 100); - } - case 67: // c - copy - if (event.ctrlKey || event.metaKey) { - var text = obj.copy(); - $('body').append(''+ text +''); - $('#_tmp_copy_data').focus().select(); - setTimeout(function () { $('#_tmp_copy_data').remove(); }, 50); - } - break; - } - var tmp = [187, 189]; // =- - for (var i=48; i<=90; i++) tmp.push(i); // 0-9,a-z,A-Z - if (tmp.indexOf(event.keyCode) != -1 && !event.ctrlKey && !event.metaKey && !cancel) { - if (columns.length == 0) columns.push(0); - var tmp = String.fromCharCode(event.keyCode); - if (event.keyCode == 187) tmp = '='; - if (event.keyCode == 189) tmp = '-'; - if (!event.shiftKey) tmp = tmp.toLowerCase(); - obj.editField(recid, columns[0], tmp, event); - cancel = true; - } - if (cancel) { // cancel default behaviour - if (event.preventDefault) event.preventDefault(); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - - function nextRow (ind) { - if ((ind + 1 < obj.records.length && obj.last.searchIds.length == 0) // if there are more records - || (obj.last.searchIds.length > 0 && ind < obj.last.searchIds[obj.last.searchIds.length-1])) { - ind++; - if (obj.last.searchIds.length > 0) { - while (true) { - if ($.inArray(ind, obj.last.searchIds) != -1 || ind > obj.records.length) break; - ind++; + // show under + if (options.maxHeight && maxHeight > options.maxHeight) maxHeight = options.maxHeight; + if (h > maxHeight) { + overflowY = true; + div2.height(maxHeight).width(w).css({ 'overflow-y': 'auto' }); + } + div1.find('>style').html( + '#w2ui-overlay'+ name +':before { display: block; margin-left: '+ parseInt(tipLeft) +'px; }'+ + '#w2ui-overlay'+ name +':after { display: none; margin-left: '+ parseInt(tipLeft) +'px; }' + ); + } + // check width + w = div2.width(); + maxWidth = window.innerWidth + $(document).scrollLeft() - div2.offset().left - 7; + if (options.maxWidth && maxWidth > options.maxWidth) maxWidth = options.maxWidth; + if (w > maxWidth && options.align !== 'both') { + options.align = 'right'; + setTimeout(function () { resize(); }, 1); + } + // check scroll bar + if (overflowY && overflowX) div2.width(w + w2utils.scrollBarSize() + 2); } - } - return ind; - } else { - return null; } - } - - function prevRow (ind) { - if ((ind > 0 && obj.last.searchIds.length == 0) // if there are more records - || (obj.last.searchIds.length > 0 && ind > obj.last.searchIds[0])) { - ind--; - if (obj.last.searchIds.length > 0) { - while (true) { - if ($.inArray(ind, obj.last.searchIds) != -1 || ind < 0) break; - ind--; + }; + + $.fn.w2menu = function (menu, options) { + /* + ITEM STRUCTURE + item : { + id : null, + text : '', + style : '', + img : '', + icon : '', + count : '', + hidden : false, + disabled : false + ... } - } - return ind; - } else { - return null; - } - } - - function nextCell (check) { - var newCheck = check + 1; - if (obj.columns.length == newCheck) return check; - if (obj.columns[newCheck].hidden) return findNext(newCheck); - return newCheck; - } - - function prevCell (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - if (obj.columns[newCheck].hidden) return findPrev(newCheck); - return newCheck; - } - - function tmpUnselect () { - if (obj.last.sel_type != 'click') return false; - if (obj.selectType != 'row') { - obj.last.sel_type = 'key'; - if (sel.length > 1) { - for (var s in sel) { - if (sel[s].recid == obj.last.sel_recid && sel[s].column == obj.last.sel_col) { - sel.splice(s, 1); - break; - } + */ + var defaults = { + index : null, // current selected + items : [], + render : null, + msgNoItems : 'No items', + onSelect : null, + tmp : {} + }; + var obj = this; + var name = ''; + if (menu === 'refresh') { + // if not show - call blur + if ($('#w2ui-overlay'+ name).length > 0) { + options = $.extend($.fn.w2menuOptions, options); + var scrTop = $('#w2ui-overlay'+ name +' div.menu').scrollTop(); + $('#w2ui-overlay'+ name +' div.menu').html(getMenuHTML()); + $('#w2ui-overlay'+ name +' div.menu').scrollTop(scrTop); + mresize(); + } else { + $(this).w2menu(options); } - obj.unselect.apply(obj, sel); - return true; - } - return false; } else { - obj.last.sel_type = 'key'; - if (sel.length > 1) { - sel.splice(sel.indexOf(obj.records[obj.last.sel_ind].recid), 1); - obj.unselect.apply(obj, sel); - return true; - } - return false; + if (arguments.length === 1) options = menu; else options.items = menu; + if (typeof options !== 'object') options = {}; + options = $.extend({}, defaults, options); + $.fn.w2menuOptions = options; + if (options.name) name = '-' + options.name; + if (typeof options.select === 'function' && typeof options.onSelect !== 'function') options.onSelect = options.select; + if (typeof options.onRender === 'function' && typeof options.render !== 'function') options.render = options.onRender; + // since only one overlay can exist at a time + $.fn.w2menuHandler = function (event, index) { + if (typeof options.onSelect === 'function') { + // need time so that menu first hides + setTimeout(function () { + options.onSelect({ + index : index, + item : options.items[index], + originalEvent: event + }); + }, 10); + } + // do not uncomment (enum in grid search will not work) + // setTimeout(function () { $(document).click(); }, 50); + }; + var html = ''; + if (options.search) { + html += + ''+ + ' '+ + ' '+ + ''; + options.style += ';background-color: #ECECEC'; + options.index = 0; + for (var i in options.items) options.items[i].hidden = false; + } + html += '' + + getMenuHTML() + + ''; + var ret = $(this).w2overlay(html, options); + setTimeout(function () { + $('#w2ui-overlay'+ name +' #menu-search') + .on('keyup', change) + .on('keydown', function (event) { + // cancel tab key + if (event.keyCode === 9) { event.stopPropagation(); event.preventDefault(); } + }); + if (options.search) { + if (['text', 'password'].indexOf($(obj)[0].type) != -1 || $(obj)[0].tagName == 'texarea') return; + $('#w2ui-overlay'+ name +' #menu-search').focus(); + } + }, 200); + mresize(); + return ret; } - } - }, - - scrollIntoView: function (ind) { - if (typeof ind == 'undefined') { - var sel = this.getSelection(); - if (sel.length == 0) return; - ind = this.get(sel[0], true); - } - var records = $('#grid_'+ this.name +'_records'); - if (records.length == 0) return; - // if all records in view - var len = this.last.searchIds.length; - if (records.height() > this.recordHeight * (len > 0 ? len : this.records.length)) return; - if (len > 0) ind = this.last.searchIds.indexOf(ind); // if seach is applied - // scroll to correct one - var t1 = Math.floor(records[0].scrollTop / this.recordHeight); - var t2 = t1 + Math.floor(records.height() / this.recordHeight); - if (ind == t1) records.animate({ 'scrollTop': records.scrollTop() - records.height() / 1.3 }); - if (ind == t2) records.animate({ 'scrollTop': records.scrollTop() + records.height() / 1.3 }); - if (ind < t1 || ind > t2) records.animate({ 'scrollTop': (ind - 1) * this.recordHeight }); - }, - - dblClick: function (recid, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // find columns - var column = null; - if (typeof recid == 'object') { - column = recid.column; - recid = recid.recid; - } - if (typeof event == 'undefined') event = {}; - // column user clicked on - if (column == null && event.target) { - var tmp = event.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - column = parseInt($(tmp).attr('col')); - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'dblClick', recid: recid, column: column, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - this.selectNone(); - var col = this.columns[column]; - if (col && $.isPlainObject(col.editable)) { - this.editField(recid, column, null, event); - } else { - this.select({ recid: recid, column: column }); - this.last.selected = this.getSelection(); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - toggle: function (recid) { - var rec = this.get(recid); - if (rec.expanded === true) return this.collapse(recid); else return this.expand(recid); - }, - - expand: function (recid) { - var rec = this.get(recid); - var obj = this; - var id = w2utils.escapeId(recid); - if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length > 0) return false; - if (rec.expanded == 'none') return false; - // insert expand row - var tmp = 1 + (this.show.selectColumn ? 1 : 0); - var addClass = ''; // ($('#grid_'+this.name +'_rec_'+ w2utils.escapeId(recid)).hasClass('w2ui-odd') ? 'w2ui-odd' : 'w2ui-even'); - $('#grid_'+ this.name +'_rec_'+ id).after( - ''+ - (this.show.lineNumbers ? '' : '') + - ' '+ - ' '+ - ' '+ - ' '+ - ''); - // event before - var eventData = this.trigger({ phase: 'before', type: 'expand', target: this.name, recid: recid, - box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded', ready: ready }); - if (eventData.isCancelled === true) { - $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').remove(); - return false; - } - // default action - $('#grid_'+ this.name +'_rec_'+ id).attr('expanded', 'yes').addClass('w2ui-expanded'); - $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').show(); - $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html(''); - rec.expanded = true; - // check if height of expaned row > 5 then remove spinner - setTimeout(ready, 300); - function ready() { - var div1 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded'); - var div2 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row .w2ui-expanded1 > div'); - if (div1.height() < 5) return; - div1.css('opacity', 1); - div2.show().css('opacity', 1); - $('#grid_'+ obj.name +'_cell_'+ obj.get(recid, true) +'_expand div').html('-'); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resizeRecords(); - return true; - }, - - collapse: function (recid) { - var rec = this.get(recid); - var obj = this; - var id = w2utils.escapeId(recid); - if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length == 0) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'collapse', target: this.name, recid: recid, - box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded' }); - if (eventData.isCancelled === true) return false; - // default action - $('#grid_'+ this.name +'_rec_'+ id).removeAttr('expanded').removeClass('w2ui-expanded'); - $('#grid_'+ this.name +'_rec_'+ id +'_expanded').css('opacity', 0); - $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html('+'); - setTimeout(function () { - $('#grid_'+ obj.name +'_rec_'+ id +'_expanded').height('0px'); - setTimeout(function () { - $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row').remove(); - delete rec.expanded; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resizeRecords(); - }, 300); - }, 200); - return true; - }, - sort: function (field, direction, multiField) { // if no params - clears sort - // event before - var eventData = this.trigger({ phase: 'before', type: 'sort', target: this.name, field: field, direction: direction, multiField: multiField }); - if (eventData.isCancelled === true) return false; - // check if needed to quit - if (typeof field != 'undefined') { - // default action - var sortIndex = this.sortData.length; - for (var s in this.sortData) { - if (this.sortData[s].field == field) { sortIndex = s; break; } - } - if (typeof direction == 'undefined' || direction == null) { - if (typeof this.sortData[sortIndex] == 'undefined') { - direction = 'asc'; - } else { - switch (String(this.sortData[sortIndex].direction)) { - case 'asc' : direction = 'desc'; break; - case 'desc' : direction = 'asc'; break; - default : direction = 'asc'; break; - } - } + function mresize() { + setTimeout(function () { + // show selected + $('#w2ui-overlay'+ name +' tr.w2ui-selected').removeClass('w2ui-selected'); + var cur = $('#w2ui-overlay'+ name +' tr[index='+ options.index +']'); + var scrTop = $('#w2ui-overlay'+ name +' div.menu').scrollTop(); + cur.addClass('w2ui-selected'); + if (options.tmp) options.tmp.contentHeight = $('#w2ui-overlay'+ name +' table').height() + (options.search ? 50 : 10); + if (options.tmp) options.tmp.contentWidth = $('#w2ui-overlay'+ name +' table').width(); + if ($('#w2ui-overlay'+ name).length > 0) $('#w2ui-overlay'+ name)[0].resize(); + // scroll into view + if (cur.length > 0) { + var top = cur[0].offsetTop - 5; // 5 is margin top + var el = $('#w2ui-overlay'+ name +' div.menu'); + var height = el.height(); + $('#w2ui-overlay'+ name +' div.menu').scrollTop(scrTop); + if (top < scrTop || top + cur.height() > scrTop + height) { + $('#w2ui-overlay'+ name +' div.menu').animate({ 'scrollTop': top - (height - cur.height() * 2) / 2 }, 200, 'linear'); + } + } + }, 1); } - if (this.multiSort === false) { this.sortData = []; sortIndex = 0; } - if (multiField != true) { this.sortData = []; sortIndex = 0; } - // set new sort - if (typeof this.sortData[sortIndex] == 'undefined') this.sortData[sortIndex] = {}; - this.sortData[sortIndex].field = field; - this.sortData[sortIndex].direction = direction; - } else { - this.sortData = []; - } - // if local - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - if (this.searchData.length > 0) this.localSearch(true); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - } else { - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.last.xhr_offset = 0; - this.reload(); - } - }, - copy: function () { - var sel = this.getSelection(); - if (sel.length == 0) return ''; - var text = ''; - if (typeof sel[0] == 'object') { // cell copy - // find min/max column - var minCol = sel[0].column; - var maxCol = sel[0].column; - var recs = []; - for (var s in sel) { - if (sel[s].column < minCol) minCol = sel[s].column; - if (sel[s].column > maxCol) maxCol = sel[s].column; - if (recs.indexOf(sel[s].index) == -1) recs.push(sel[s].index); - } - recs.sort(); - for (var r in recs) { - var ind = recs[r]; - for (var c = minCol; c <= maxCol; c++) { - var col = this.columns[c]; - if (col.hidden === true) continue; - text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; - } - text = text.substr(0, text.length-1); // remove last \t - text += '\n'; - } - } else { // row copy - for (var s in sel) { - var ind = this.get(sel[s], true); - for (var c in this.columns) { - var col = this.columns[c]; - if (col.hidden === true) continue; - text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; - } - text = text.substr(0, text.length-1); // remove last \t - text += '\n'; + function change(event) { + var search = this.value; + var key = event.keyCode; + var cancel = false; + switch (key) { + case 13: // enter + $('#w2ui-overlay'+ name).remove(); + $.fn.w2menuHandler(event, options.index); + break; + case 9: // tab + case 27: // escape + $('#w2ui-overlay'+ name).remove(); + $.fn.w2menuHandler(event, -1); + break; + case 38: // up + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index--; + while (options.index > 0 && options.items[options.index].hidden) options.index--; + if (options.index === 0 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } + if (options.index < 0) options.index = 0; + cancel = true; + break; + case 40: // down + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index++; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (options.index === options.items.length-1 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index--; + } + if (options.index >= options.items.length) options.index = options.items.length - 1; + cancel = true; + break; + } + // filter + if (!cancel) { + var shown = 0; + for (var i in options.items) { + var item = options.items[i]; + var prefix = ''; + var suffix = ''; + if (['is', 'begins with'].indexOf(options.match) !== -1) prefix = '^'; + if (['is', 'ends with'].indexOf(options.match) !== -1) suffix = '$'; + try { + var re = new RegExp(prefix + search + suffix, 'i'); + if (re.test(item.text) || item.text === '...') item.hidden = false; else item.hidden = true; + } catch (e) {} + // do not show selected items + if (obj.type === 'enum' && $.inArray(item.id, ids) !== -1) item.hidden = true; + if (item.hidden !== true) shown++; + } + options.index = 0; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (shown <= 0) options.index = -1; + } + $(obj).w2menu('refresh', options); + mresize(); } - } - text = text.substr(0, text.length - 1); - // before event - var eventData = this.trigger({ phase: 'before', type: 'copy', target: this.name, text: text }); - if (eventData.isCancelled === true) return ''; - text = eventData.text; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return text; - }, - paste: function (text) { - var sel = this.getSelection(); - var ind = this.get(sel[0].recid, true); - var col = sel[0].column; - // before event - var eventData = this.trigger({ phase: 'before', type: 'paste', target: this.name, text: text, index: ind, column: col }); - if (eventData.isCancelled === true) return; - text = eventData.text; - // default action - if (this.selectType == 'row' || sel.length == 0) { - console.log('ERROR: You can paste only if grid.selectType = \'cell\' and when at least one cell selected.'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return; - } - var newSel = []; - var text = text.split('\n'); - for (var t in text) { - var tmp = text[t].split('\t'); - var cnt = 0; - var rec = this.records[ind]; - var cols = []; - for (var dt in tmp) { - if (!this.columns[col + cnt]) continue; - var field = this.columns[col + cnt].field; - rec.changed = true; - rec.changes = rec.changes || {}; - rec.changes[field] = tmp[dt]; - cols.push(col + cnt); - cnt++; + function getMenuHTML () { + if (options.spinner) { + return ''+ + ' '+ + ' '+ w2utils.lang('Loading...') +''+ + ''; + } + var count = 0; + var menu_html = ''; + var img = null, icon = null; + for (var f = 0; f < options.items.length; f++) { + var mitem = options.items[f]; + if (typeof mitem === 'string') { + mitem = { id: mitem, text: mitem }; + } else { + if (mitem.text != null && mitem.id == null) mitem.id = mitem.text; + if (mitem.text == null && mitem.id != null) mitem.text = mitem.id; + if (mitem.caption != null) mitem.text = mitem.caption; + img = mitem.img; + icon = mitem.icon; + if (img == null) img = null; + if (icon == null) icon = null; + } + if (mitem.hidden !== true) { + var imgd = ''; + var txt = mitem.text; + if (typeof options.render === 'function') txt = options.render(mitem, options); + if (img) imgd = ''; + if (icon) imgd = ''; + // render only if non-empty + if (typeof txt !== 'undefined' && txt !== '' && !(/^-+$/.test(txt))) { + var bg = (count % 2 === 0 ? 'w2ui-item-even' : 'w2ui-item-odd'); + if (options.altRows !== true) bg = ''; + var colspan = 1; + if (imgd == '') colspan++; + if (mitem.count == null) colspan++; + menu_html += + ''+ + imgd + + ' '+ txt +''+ + ' '+ (mitem.count != null ? '' + mitem.count + '' : '') + '' + + ''; + count++; + } else { + // horizontal line + menu_html += ''; + } + } + options.items[f] = mitem; + } + if (count === 0) { + menu_html += ''+ options.msgNoItems +''; + } + menu_html += ""; + return menu_html; } - for (var c in cols) newSel.push({ recid: rec.recid, column: cols[c] }); - ind++; - } - this.selectNone(); - this.select.apply(this, newSel); - this.refresh(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }; +})(jQuery); - // ================================================== - // --- Common functions - - resize: function () { - var obj = this; - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // make sure the box is right - if (!this.box || $(this.box).attr('name') != this.name) return; - // determine new width and height - $(this.box).find('> div') - .css('width', $(this.box).width()) - .css('height', $(this.box).height()); - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // resize - obj.resizeBoxes(); - obj.resizeRecords(); - // init editable - // $('#grid_'+ obj.name + '_records .w2ui-editable input').each(function (index, el) { - // var column = obj.columns[$(el).attr('column')]; - // if (column && column.editable) $(el).w2field(column.editable); - // }); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, - refresh: function () { - var obj = this; - var time = (new Date()).getTime(); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (this.total <= 0 && !url && this.searchData.length == 0) { - this.total = this.records.length; - this.buffered = this.total; - } - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - this.toolbar.disable('edit', 'delete'); - if (!this.box) return; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh' }); - if (eventData.isCancelled === true) return false; - // -- header - if (this.show.header) { - $('#grid_'+ this.name +'_header').html(this.header +' ').show(); - } else { - $('#grid_'+ this.name +'_header').hide(); - } - // -- toolbar - if (this.show.toolbar) { - // if select-collumn is checked - no toolbar refresh - if (this.toolbar && this.toolbar.get('column-on-off') && this.toolbar.get('column-on-off').checked) { - // no action - } else { - $('#grid_'+ this.name +'_toolbar').show(); - // refresh toolbar only once - if (typeof this.toolbar == 'object') { - this.toolbar.refresh(); - var tmp = $('#grid_'+ obj.name +'_search_all'); - tmp.val(this.last.search); - } - } - } else { - $('#grid_'+ this.name +'_toolbar').hide(); - } - // -- make sure search is closed - this.searchClose(); - // search placeholder - var searchEl = $('#grid_'+ obj.name +'_search_all'); - if (this.searches.length == 0) { - this.last.field = 'all'; - } - if (!this.multiSearch && this.last.field == 'all' && this.searches.length > 0) { - this.last.field = this.searches[0].field; - this.last.caption = this.searches[0].caption; - } - for (var s in this.searches) { - if (this.searches[s].field == this.last.field) this.last.caption = this.searches[s].caption; - } - if (this.last.multi) { - searchEl.attr('placeholder', '[' + w2utils.lang('Multiple Fields') + ']'); - } else { - searchEl.attr('placeholder', this.last.caption); - } - - // focus search if last searched - if (this._focus_when_refreshed === true) { - clearTimeout(obj._focus_timer); - obj._focus_timer = setTimeout(function () { - if (searchEl.length > 0) { searchEl[0].focus(); } - delete obj._focus_when_refreshed; - delete obj._focus_timer; - }, 600); // need time to render - } - - // -- separate summary - var tmp = this.find({ summary: true }, true); - if (tmp.length > 0) { - for (var t in tmp) this.summary.push(this.records[tmp[t]]); - for (var t=tmp.length-1; t>=0; t--) this.records.splice(tmp[t], 1); - this.total = this.total - tmp.length; - this.buffered = this.buffered - tmp.length; - } - - // -- body - var bodyHTML = ''; - bodyHTML += ''+ - this.getRecordsHTML() + - ''+ - ''+ - ' '+ this.getColumnsHTML() +''+ - ''; // Columns need to be after to be able to overlap - $('#grid_'+ this.name +'_body').html(bodyHTML); - // show summary records - if (this.summary.length > 0) { - $('#grid_'+ this.name +'_summary').html(this.getSummaryHTML()).show(); - } else { - $('#grid_'+ this.name +'_summary').hide(); - } - // -- footer - if (this.show.footer) { - $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()).show(); - } else { - $('#grid_'+ this.name +'_footer').hide(); - } - // select last selected record - if (this.last.selected.length > 0) for (var s in this.last.selected) { - if (this.get(this.last.selected[s]) != null) { - this.select(this.get(this.last.selected[s]).recid); - } - } - // show/hide clear search link - if (this.searchData.length > 0) { - $('#grid_'+ this.name +'_searchClear').show(); - } else { - $('#grid_'+ this.name +'_searchClear').hide(); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - // show number of selected - this.status(); - // collapse all records - var rows = obj.find({ expanded: true }, true); - for (var r in rows) obj.records[rows[r]].expanded = false; - // mark selection - setTimeout(function () { - var str = $.trim($('#grid_'+ obj.name +'_search_all').val()); - if (str != '') $(obj.box).find('.w2ui-grid-data > div').w2marker(str); - }, 50); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - obj.addRange('selection'); - setTimeout(function () { obj.resize(); obj.scroll(); }, 1); // allow to render first - return (new Date()).getTime() - time; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2grid - grid widget +* - $().w2grid - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2toolbar, w2fields, w2alert, w2confirm +* +* == NICE TO HAVE == +* - frozen columns +* - add colspans +* - allow this.total to be unknown (-1) +* - column autosize based on largest content +* - easy bubbles in the grid +* - More than 2 layers of header groups +* - reorder columns/records +* - hidden searches could not be clearned by the user +* - problem with .set() and arrays, array get extended too, but should be replaced +* - move events into prototype +* - add grid.focus() +* - add showExtra, KickIn Infinite scroll when so many records +* - after edit stay on the same record option +* - allow render: function to be filters +* +************************************************************************/ - render: function (box) { - var obj = this; - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-grid') - .html(''); - } - this.box = box; - } - if (!this.box) return; - if (this.last.sortData == null) this.last.sortData = this.sortData; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: box }); - if (eventData.isCancelled === true) return false; - // insert Elements - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-grid') - .html(''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''); - if (this.selectType != 'row') $(this.box).addClass('w2ui-ss'); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // init toolbar - this.initToolbar(); - if (this.toolbar != null) this.toolbar.render($('#grid_'+ this.name +'_toolbar')[0]); - // init footer - $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()); - // refresh - this.refresh(); // show empty grid (need it) - this.reload(); - - // init mouse events for mouse selection - $(this.box).on('mousedown', mouseStart); - $(this.box).on('selectstart', function () { return false; }); // fixes chrome cursror bug - - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // attach to resize event - if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event - this.tmp_resize = function (event) { w2ui[obj.name].resize(); } - $(window).off('resize', this.tmp_resize).on('resize', this.tmp_resize); - } - return (new Date()).getTime() - time; - - function mouseStart (event) { - if (obj.last.move && obj.last.move.type == 'expand') return; - obj.last.move = { - x : event.screenX, - y : event.screenY, - divX : 0, - divY : 0, - recid : $(event.target).parents('tr').attr('recid'), - column : (event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')), - type : 'select', - start : true +(function ($) { + var w2grid = function(options) { + + // public properties + this.name = null; + this.box = null; // HTML element that hold this element + this.header = ''; + this.url = ''; + this.routeData = {}; // data for dynamic routes + this.columns = []; // { field, caption, size, attr, render, hidden, gridMinWidth, editable } + this.columnGroups = []; // { span: int, caption: 'string', master: true/false } + this.records = []; // { recid: int(requied), field1: 'value1', ... fieldN: 'valueN', style: 'string', editable: true/false, summary: true/false, changes: object } + this.summary = []; // arry of summary records, same structure as records array + this.searches = []; // { type, caption, field, inTag, outTag, hidden } + this.searchData = []; + this.sortData = []; + this.postData = {}; + this.toolbar = {}; // if not empty object; then it is toolbar object + + this.show = { + header : false, + toolbar : false, + footer : false, + columnHeaders : true, + lineNumbers : false, + expandColumn : false, + selectColumn : false, + emptyRecords : true, + toolbarReload : true, + toolbarColumns : true, + toolbarSearch : true, + toolbarAdd : false, + toolbarEdit : false, + toolbarDelete : false, + toolbarSave : false, + selectionBorder : true, + recordTitles : true, + skipRecords : true }; - $(document).on('mousemove', mouseMove); - $(document).on('mouseup', mouseStop); - } - - function mouseMove (event) { - if (!obj.last.move || obj.last.move.type != 'select') return; - obj.last.move.divX = (event.screenX - obj.last.move.x); - obj.last.move.divY = (event.screenY - obj.last.move.y); - if (Math.abs(obj.last.move.divX) <= 1 && Math.abs(obj.last.move.divY) <= 1) return; // only if moved more then 1px - if (obj.last.move.start && obj.last.move.recid) { - obj.selectNone(); - obj.last.move.start = false; - } - var newSel= []; - var recid = (event.target.tagName == 'TR' ? $(event.target).attr('recid') : $(event.target).parents('tr').attr('recid')); - if (typeof recid == 'undefined') return; - var ind1 = obj.get(obj.last.move.recid, true); - var ind2 = obj.get(recid, true); - var col1 = parseInt(obj.last.move.column); - var col2 = parseInt(event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')); - if (ind1 > ind2) { var tmp = ind1; ind1 = ind2; ind2 = tmp; } - // check if need to refresh - var tmp = 'ind1:'+ ind1 +',ind2;'+ ind2 +',col1:'+ col1 +',col2:'+ col2; - if (obj.last.move.range == tmp) return; - obj.last.move.range = tmp; - for (var i = ind1; i <= ind2; i++) { - if (obj.last.searchIds.length > 0 && obj.last.searchIds.indexOf(i) == -1) continue; - if (obj.selectType != 'row') { - if (col1 > col2) { var tmp = col1; col1 = col2; col2 = tmp; } - var tmp = []; - for (var c = col1; c <= col2; c++) { - if (obj.columns[c].hidden) continue; - newSel.push({ recid: obj.records[i].recid, column: parseInt(c) }); - } - } else { - newSel.push(obj.records[i].recid); - } - } - if (obj.selectType != 'row') { - var sel = obj.getSelection(); - // add more items - var tmp = []; - for (var ns in newSel) { - var flag = false; - for (var s in sel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; - if (!flag) tmp.push({ recid: newSel[ns].recid, column: newSel[ns].column }); - } - obj.select.apply(obj, tmp); - // remove items - var tmp = []; - for (var s in sel) { - var flag = false; - for (var ns in newSel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; - if (!flag) tmp.push({ recid: sel[s].recid, column: sel[s].column }); - } - obj.unselect.apply(obj, tmp); - } else { - if (obj.multiSelect) { - var sel = obj.getSelection(); - for (var ns in newSel) if (sel.indexOf(newSel[ns]) == -1) obj.select(newSel[ns]); // add more items - for (var s in sel) if (newSel.indexOf(sel[s]) == -1) obj.unselect(sel[s]); // remove items - } - } - } - - function mouseStop (event) { - if (!obj.last.move || obj.last.move.type != 'select') return; - delete obj.last.move; - $(document).off('mousemove', mouseMove); - $(document).off('mouseup', mouseStop); - } - }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); - if (eventData.isCancelled === true) return false; - // remove events - $(window).off('resize', this.tmp_resize); - // clean up - if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); - if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-grid') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - // =========================================== - // --- Internal Functions - - initColumnOnOff: function () { - if (!this.show.toolbarColumns) return; - var obj = this; - var col_html = ''+ - ''; - for (var c in this.columns) { - var col = this.columns[c]; - col_html += ''+ - ''+ - ' '+ - ''+ - ''+ - ' '+ - (this.columns[c].caption == '' ? '- column '+ (c+1) +' -' : this.columns[c].caption) + - ''+ - ''+ - ''; - } - col_html += ''; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - col_html += - ''+ - ' '+ - ' '+ w2utils.lang('Skip') +' '+ w2utils.lang('Records')+ - ' '+ - ''; - } - col_html += ''+ - ' '+ w2utils.lang('Toggle Line Numbers') +''+ - ''+ - ''+ - ' '+ w2utils.lang('Reset Column Size') + ''+ - ''; - col_html += ""; - this.toolbar.get('column-on-off').html = col_html; - }, + this.autoLoad = true; // for infinite scroll + this.fixedBody = true; // if false; then grid grows with data + this.recordHeight = 24; + this.keyboard = true; + this.selectType = 'row'; // can be row|cell + this.multiSearch = true; + this.multiSelect = true; + this.multiSort = true; + this.reorderColumns = false; + this.reorderRows = false; + this.markSearch = true; + + this.total = 0; // server total + this.limit = 100; + this.offset = 0; // how many records to skip (for infinite scroll) when pulling from server + this.style = ''; + this.ranges = []; + this.menu = []; + this.method = null; // if defined, then overwrited ajax method + this.recid = null; + this.parser = null; + + // events + this.onAdd = null; + this.onEdit = null; + this.onRequest = null; // called on any server event + this.onLoad = null; + this.onDelete = null; + this.onDeleted = null; + this.onSubmit = null; + this.onSave = null; + this.onSelect = null; + this.onUnselect = null; + this.onClick = null; + this.onDblClick = null; + this.onContextMenu = null; + this.onMenuClick = null; // when context menu item selected + this.onColumnClick = null; + this.onColumnResize = null; + this.onSort = null; + this.onSearch = null; + this.onChange = null; // called when editable record is changed + this.onRestore = null; // called when editable record is restored + this.onExpand = null; + this.onCollapse = null; + this.onError = null; + this.onKeydown = null; + this.onToolbar = null; // all events from toolbar + this.onColumnOnOff = null; + this.onCopy = null; + this.onPaste = null; + this.onSelectionExtend = null; + this.onEditField = null; + this.onRender = null; + this.onRefresh = null; + this.onReload = null; + this.onResize = null; + this.onDestroy = null; + this.onStateSave = null; + this.onStateRestore = null; + + // internal + this.last = { + field : 'all', + caption : w2utils.lang('All Fields'), + logic : 'OR', + search : '', + searchIds : [], + selection : { + indexes : [], + columns : {} + }, + multi : false, + scrollTop : 0, + scrollLeft : 0, + sortData : null, + sortCount : 0, + xhr : null, + range_start : null, + range_end : null, + sel_ind : null, + sel_col : null, + sel_type : null, + edit_col : null + }; - columnOnOff: function (el, event, field, value) { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'columnOnOff', checkbox: el, field: field, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // regular processing - var obj = this; - // collapse expanded rows - for (var r in this.records) { - if (this.records[r].expanded === true) this.records[r].expanded = false - } - // show/hide - var hide = true; - if (field == 'line-numbers') { - this.show.lineNumbers = !this.show.lineNumbers; - this.refresh(); - } else if (field == 'skip') { - if (!w2utils.isInt(value)) value = 0; - obj.skip(value); - } else if (field == 'resize') { - // restore sizes - for (var c in this.columns) { - if (typeof this.columns[c].sizeOriginal != 'undefined') { - this.columns[c].size = this.columns[c].sizeOriginal; - } - } - this.initResize(); - this.resize(); - } else { - var col = this.getColumn(field); - if (col.hidden) { - $(el).prop('checked', true); - this.showColumn(col.field); + $.extend(true, this, w2obj.grid, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2grid = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2grid')) return; + // remember items + var columns = method.columns; + var columnGroups = method.columnGroups; + var records = method.records; + var searches = method.searches; + var searchData = method.searchData; + var sortData = method.sortData; + var postData = method.postData; + var toolbar = method.toolbar; + // extend items + var object = new w2grid(method); + $.extend(object, { postData: {}, records: [], columns: [], searches: [], toolbar: {}, sortData: [], searchData: [], handlers: [] }); + if (object.onExpand != null) object.show.expandColumn = true; + $.extend(true, object.toolbar, toolbar); + // reassign variables + for (var p in columns) object.columns[p] = $.extend(true, {}, columns[p]); + for (var p in columnGroups) object.columnGroups[p] = $.extend(true, {}, columnGroups[p]); + for (var p in searches) object.searches[p] = $.extend(true, {}, searches[p]); + for (var p in searchData) object.searchData[p] = $.extend(true, {}, searchData[p]); + for (var p in sortData) object.sortData[p] = $.extend(true, {}, sortData[p]); + object.postData = $.extend(true, {}, postData); + + // check if there are records without recid + for (var r in records) { + if (records[r].recid == null || typeof records[r].recid == 'undefined') { + console.log('ERROR: Cannot add records without recid. (obj: '+ object.name +')'); + return; + } + object.records[r] = $.extend(true, {}, records[r]); + } + // add searches + for (var c in object.columns) { + var col = object.columns[c]; + if (typeof col.searchable == 'undefined' || object.getSearch(col.field) != null) continue; + var stype = col.searchable; + var attr = ''; + if (col.searchable === true) { stype = 'text'; attr = 'size="20"'; } + object.addSearch({ field: col.field, caption: col.caption, type: stype, attr: attr }); + } + // init toolbar + object.initToolbar(); + // render if necessary + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - $(el).prop('checked', false); - this.hideColumn(col.field); + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2grid'); } - hide = false; - } - this.initColumnOnOff(); - if (hide) { - setTimeout(function () { - $().w2overlay(); - obj.toolbar.uncheck('column-on-off'); - }, 100); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - initToolbar: function () { - // -- if toolbar is true - if (typeof this.toolbar['render'] == 'undefined') { - var tmp_items = this.toolbar.items; - this.toolbar.items = []; - this.toolbar = $().w2toolbar($.extend(true, {}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - - // ============================================= - // ------ Toolbar Generic buttons + } - if (this.show.toolbarReload) { - this.toolbar.items.push($.extend(true, {}, this.buttons['reload'])); - } - if (this.show.toolbarColumns) { - this.toolbar.items.push($.extend(true, {}, this.buttons['columns'])); - this.initColumnOnOff(); - } - if (this.show.toolbarReload || this.show.toolbarColumn) { - this.toolbar.items.push({ type: 'break', id: 'break0' }); - } - if (this.show.toolbarSearch) { - var html = - ''+ - ''+ - ' '+ this.buttons['search'].html +''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''+ - ''; - this.toolbar.items.push({ type: 'html', id: 'search', html: html }); - if (this.multiSearch && this.searches.length > 0) { - this.toolbar.items.push($.extend(true, {}, this.buttons['search-go'])); - } - } - if (this.show.toolbarSearch && (this.show.toolbarAdd || this.show.toolbarEdit || this.show.toolbarDelete || this.show.toolbarSave)) { - this.toolbar.items.push({ type: 'break', id: 'break1' }); - } - if (this.show.toolbarAdd) { - this.toolbar.items.push($.extend(true, {}, this.buttons['add'])); - } - if (this.show.toolbarEdit) { - this.toolbar.items.push($.extend(true, {}, this.buttons['edit'])); - } - if (this.show.toolbarDelete) { - this.toolbar.items.push($.extend(true, {}, this.buttons['delete'])); - } - if (this.show.toolbarSave) { - if (this.show.toolbarAdd || this.show.toolbarDelete || this.show.toolbarEdit) { - this.toolbar.items.push({ type: 'break', id: 'break2' }); - } - this.toolbar.items.push($.extend(true, {}, this.buttons['save'])); - } - // add original buttons - for (var i in tmp_items) this.toolbar.items.push(tmp_items[i]); - - // ============================================= - // ------ Toolbar onClick processing - - var obj = this; - this.toolbar.on('click', function (event) { - var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); - if (eventData.isCancelled === true) return false; - var id = event.target; - switch (id) { - case 'reload': - var eventData2 = obj.trigger({ phase: 'before', type: 'reload', target: obj.name }); - if (eventData2.isCancelled === true) return false; - var url = (typeof obj.url != 'object' ? obj.url : obj.url.get); - if (url) { - obj.clear(true); - } else { - obj.last.scrollTop = 0; - obj.last.scrollLeft = 0; - obj.last.range_start= null; - obj.last.range_end = null; - } - obj.reload(); - obj.trigger($.extend(eventData2, { phase: 'after' })); - break; - case 'column-on-off': - for (var c in obj.columns) { - if (obj.columns[c].hidden) { - $("#grid_"+ obj.name +"_column_"+ c + "_check").prop("checked", false); + // ==================================================== + // -- Implementation of core functionality + + w2grid.prototype = { + // ---- + // properties that need to be in prototype + + msgDelete : 'Are you sure you want to delete selected records?', + msgNotJSON : 'Returned data is not in valid JSON format.', + msgAJAXerror : 'AJAX error. See console for more details.', + msgRefresh : 'Refreshing...', + + // for easy button overwrite + buttons: { + 'reload' : { type: 'button', id: 'w2ui-reload', icon: 'w2ui-icon-reload', hint: 'Reload data in the list' }, + 'columns' : { type: 'drop', id: 'w2ui-column-on-off', icon: 'w2ui-icon-columns', hint: 'Show/hide columns', arrow: false, html: '' }, + 'search' : { type: 'html', id: 'w2ui-search', + html: '' + }, + 'search-go': { type: 'check', id: 'w2ui-search-advanced', caption: 'Search...', hint: 'Open Search Fields' }, + 'add' : { type: 'button', id: 'w2ui-add', caption: 'Add New', hint: 'Add new record', icon: 'w2ui-icon-plus' }, + 'edit' : { type: 'button', id: 'w2ui-edit', caption: 'Edit', hint: 'Edit selected record', icon: 'w2ui-icon-pencil', disabled: true }, + 'delete' : { type: 'button', id: 'w2ui-delete', caption: 'Delete', hint: 'Delete selected records', icon: 'w2ui-icon-cross', disabled: true }, + 'save' : { type: 'button', id: 'w2ui-save', caption: 'Save', hint: 'Save changed records', icon: 'w2ui-icon-check' } + }, + + add: function (record) { + if (!$.isArray(record)) record = [record]; + var added = 0; + for (var o in record) { + if (!this.recid && typeof record[o].recid == 'undefined') record[o].recid = record[o][this.recid]; + if (record[o].recid == null || typeof record[o].recid == 'undefined') { + console.log('ERROR: Cannot add record without recid. (obj: '+ this.name +')'); + continue; + } + this.records.push(record[o]); + added++; + } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.total = this.records.length; + this.localSort(); + this.localSearch(); + } + this.refresh(); // ?? should it be reload? + return added; + }, + + find: function (obj, returnIndex) { + if (typeof obj == 'undefined' || obj == null) obj = {}; + var recs = []; + var hasDots = false; + // check if property is nested - needed for speed + for (var o in obj) if (String(o).indexOf('.') != -1) hasDots = true; + // look for an item + for (var i = 0; i < this.records.length; i++) { + var match = true; + for (var o in obj) { + var val = this.records[i][o]; + if (hasDots && String(o).indexOf('.') != -1) val = this.parseField(this.records[i], o); + if (obj[o] != val) match = false; + } + if (match && returnIndex !== true) recs.push(this.records[i].recid); + if (match && returnIndex === true) recs.push(i); + } + return recs; + }, + + set: function (recid, record, noRefresh) { // does not delete existing, but overrides on top of it + if (typeof recid == 'object') { + noRefresh = record; + record = recid; + recid = null; + } + // update all records + if (recid == null) { + for (var r in this.records) { + $.extend(true, this.records[r], record); // recid is the whole record + } + if (noRefresh !== true) this.refresh(); + } else { // find record to update + var ind = this.get(recid, true); + if (ind == null) return false; + var isSummary = (this.records[ind] && this.records[ind].recid == recid ? false : true); + if (isSummary) { + $.extend(true, this.summary[ind], record); } else { - $("#grid_"+ obj.name +"_column_"+ c + "_check").prop('checked', true); - } - } - obj.initResize(); - obj.resize(); - break; - case 'search-advanced': - var tb = this; - var it = this.get(id); - if (it.checked) { - obj.searchClose(); - setTimeout(function () { tb.uncheck(id); }, 1); - } else { - obj.searchOpen(); - event.originalEvent.stopPropagation(); - function tmp_close() { tb.uncheck(id); $(document).off('click', 'body', tmp_close); } - $(document).on('click', 'body', tmp_close); - } - break; - case 'add': - // events - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'add', recid: null }); - obj.trigger($.extend(eventData, { phase: 'after' })); - break; - case 'edit': - var sel = obj.getSelection(); - var recid = null; - if (sel.length == 1) recid = sel[0]; - // events - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'edit', recid: recid }); - obj.trigger($.extend(eventData, { phase: 'after' })); - break; - case 'delete': - obj.delete(); - break; - case 'save': - obj.save(); - break; - } - // no default action - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - } - return; - }, - - initSearches: function () { - var obj = this; - // init searches - for (var s in this.searches) { - var search = this.searches[s]; - var sdata = this.getSearchData(search.field); - // init types - switch (String(search.type).toLowerCase()) { - case 'alphaNumeric': - case 'text': - $('#grid_'+ this.name +'_operator_'+s).val('begins with'); - break; - - case 'int': - case 'float': - case 'hex': - case 'money': - case 'date': - $('#grid_'+ this.name +'_field_'+s).w2field('clear').w2field(search.type); - $('#grid_'+ this.name +'_field2_'+s).w2field('clear').w2field(search.type); - break; - - case 'list': - // build options - var options = '--'; - for (var i in search.items) { - if ($.isPlainObject(search.items[i])) { - var val = search.items[i].id; - var txt = search.items[i].text; - if (typeof val == 'undefined' && typeof search.items[i].value != 'undefined') val = search.items[i].value; - if (typeof txt == 'undefined' && typeof search.items[i].caption != 'undefined') txt = search.items[i].caption; - if (val == null) val = ''; - options += ''+ txt +''; - } else { - options += ''+ search.items[i] +''; - } - } - $('#grid_'+ this.name +'_field_'+s).html(options); - break; - } - if (sdata != null) { - $('#grid_'+ this.name +'_operator_'+ s).val(sdata.operator).trigger('change'); - if (!$.isArray(sdata.value)) { - if (typeof sdata.value != 'udefined') $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); - } else { - if (sdata.operator == 'in') { - $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); - } else { - $('#grid_'+ this.name +'_field_'+ s).val(sdata.value[0]).trigger('change'); - $('#grid_'+ this.name +'_field2_'+ s).val(sdata.value[1]).trigger('change'); + $.extend(true, this.records[ind], record); + } + if (noRefresh !== true) this.refreshRow(recid); // refresh only that record } - } - } - } - // add on change event - $('#w2ui-overlay .w2ui-grid-searches *[rel=search]').on('keypress', function (evnt) { - if (evnt.keyCode == 13) { obj.search(); } - }); - }, - - initResize: function () { - var obj = this; - //if (obj.resizing === true) return; - $(this.box).find('.w2ui-resizer') - .off('click') - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); - }) - .off('mousedown') - .on('mousedown', function (event) { - if (!event) event = window.event; - if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } - obj.resizing = true; - obj.last.tmp = { - x : event.screenX, - y : event.screenY, - gx : event.screenX, - gy : event.screenY, - col : parseInt($(this).attr('name')) - }; - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); - // fix sizes - for (var c in obj.columns) { - if (typeof obj.columns[c].sizeOriginal == 'undefined') obj.columns[c].sizeOriginal = obj.columns[c].size; - obj.columns[c].size = obj.columns[c].sizeCalculated; - } - var eventData = { phase: 'before', type: 'columnResize', target: obj.name, column: obj.last.tmp.col, field: obj.columns[obj.last.tmp.col].field }; - eventData = obj.trigger($.extend(eventData, { resizeBy: 0, originalEvent: event })); - // set move event - var mouseMove = function (event) { - if (obj.resizing != true) return; - if (!event) event = window.event; - // event before - eventData = obj.trigger($.extend(eventData, { resizeBy: (event.screenX - obj.last.tmp.gx), originalEvent: event })); - if (eventData.isCancelled === true) { eventData.isCancelled = false; return; } - // default action - obj.last.tmp.x = (event.screenX - obj.last.tmp.x); - obj.last.tmp.y = (event.screenY - obj.last.tmp.y); - obj.columns[obj.last.tmp.col].size = (parseInt(obj.columns[obj.last.tmp.col].size) + obj.last.tmp.x) + 'px'; - obj.resizeRecords(); - // reset - obj.last.tmp.x = event.screenX; - obj.last.tmp.y = event.screenY; - } - var mouseUp = function (event) { - delete obj.resizing; - $(document).off('mousemove', 'body'); - $(document).off('mouseup', 'body'); - obj.resizeRecords(); - // event before - obj.trigger($.extend(eventData, { phase: 'after', originalEvent: event })); - } - $(document).on('mousemove', 'body', mouseMove); - $(document).on('mouseup', 'body', mouseUp); - }) - .each(function (index, el) { - var td = $(el).parent(); - $(el).css({ - "height" : '25px', - "margin-left" : (td.width() - 3) + 'px' - }) - }); - }, - - resizeBoxes: function () { - // elements - var main = $(this.box).find('> div'); - var header = $('#grid_'+ this.name +'_header'); - var toolbar = $('#grid_'+ this.name +'_toolbar'); - var summary = $('#grid_'+ this.name +'_summary'); - var footer = $('#grid_'+ this.name +'_footer'); - var body = $('#grid_'+ this.name +'_body'); - var columns = $('#grid_'+ this.name +'_columns'); - var records = $('#grid_'+ this.name +'_records'); - - if (this.show.header) { - header.css({ - top: '0px', - left: '0px', - right: '0px' - }); - } + return true; + }, - if (this.show.toolbar) { - toolbar.css({ - top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - } - if (this.show.footer) { - footer.css({ - bottom: '0px', - left: '0px', - right: '0px' - }); - } - if (this.summary.length > 0) { - summary.css({ - bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - } - body.css({ - top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) + (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) ) + 'px', - bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) + (this.summary.length > 0 ? w2utils.getSize(summary, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - }, + get: function (recid, returnIndex) { + // search records + for (var i = 0; i < this.records.length; i++) { + if (this.records[i].recid == recid) { + if (returnIndex === true) return i; else return this.records[i]; + } + } + // search summary + for (var i = 0; i < this.summary.length; i++) { + if (this.summary[i].recid == recid) { + if (returnIndex === true) return i; else return this.summary[i]; + } + } + return null; + }, - resizeRecords: function () { - var obj = this; - // remove empty records - $(this.box).find('.w2ui-empty-record').remove(); - // -- Calculate Column size in PX - var box = $(this.box); - var grid = $(this.box).find('> div'); - var header = $('#grid_'+ this.name +'_header'); - var toolbar = $('#grid_'+ this.name +'_toolbar'); - var summary = $('#grid_'+ this.name +'_summary'); - var footer = $('#grid_'+ this.name +'_footer'); - var body = $('#grid_'+ this.name +'_body'); - var columns = $('#grid_'+ this.name +'_columns'); - var records = $('#grid_'+ this.name +'_records'); - - // body might be expanded by data - if (!this.fixedBody) { - // allow it to render records, then resize - setTimeout(function () { - var calculatedHeight = w2utils.getSize(columns, 'height') - + w2utils.getSize($('#grid_'+ obj.name +'_records table'), 'height'); - obj.height = calculatedHeight - + w2utils.getSize(grid, '+height') - + (obj.show.header ? w2utils.getSize(header, 'height') : 0) - + (obj.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) - + (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) - + (obj.show.footer ? w2utils.getSize(footer, 'height') : 0); - grid.css('height', obj.height); - body.css('height', calculatedHeight); - box.css('height', w2utils.getSize(grid, 'height') + w2utils.getSize(box, '+height')); - }, 1); - } else { - // fixed body height - var calculatedHeight = grid.height() - - (this.show.header ? w2utils.getSize(header, 'height') : 0) - - (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) - - (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) - - (this.show.footer ? w2utils.getSize(footer, 'height') : 0); - body.css('height', calculatedHeight); - } - - // check overflow - var bodyOverflowX = false; - var bodyOverflowY = false; - if (body.width() < $(records).find('>table').width()) bodyOverflowX = true; - if (body.height() - columns.height() < $(records).find('>table').height() + (bodyOverflowX ? w2utils.scrollBarSize() : 0)) bodyOverflowY = true; - if (!this.fixedBody) { bodyOverflowY = false; bodyOverflowX = false; } - if (bodyOverflowX || bodyOverflowY) { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); - records.css({ - top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', - "-webkit-overflow-scrolling": "touch", - "overflow-x": (bodyOverflowX ? 'auto' : 'hidden'), - "overflow-y": (bodyOverflowY ? 'auto' : 'hidden') }); - } else { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').hide(); - records.css({ - top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', - overflow: 'hidden' - }); - if (records.length > 0) { this.last.scrollTop = 0; this.last.scrollLeft = 0; } // if no scrollbars, always show top - } - if (this.show.emptyRecords && !bodyOverflowY) { - var max = Math.floor(records.height() / this.recordHeight) + 1; - if (this.fixedBody) { - for (var di = this.buffered; di <= max; di++) { - var html = ''; - html += ''; - if (this.show.lineNumbers) html += ''; - if (this.show.selectColumn) html += ''; - if (this.show.expandColumn) html += ''; - var j = 0; - while (true && this.columns.length > 0) { - var col = this.columns[j]; - if (col.hidden) { j++; if (typeof this.columns[j] == 'undefined') break; else continue; } - html += ''; - j++; - if (typeof this.columns[j] == 'undefined') break; - } - html += ''; - html += ''; - $('#grid_'+ this.name +'_records > table').append(html); - } - } - } - if (body.length > 0) { - var width_max = parseInt(body.width()) - - (bodyOverflowY ? w2utils.scrollBarSize() : 0) - - (this.show.lineNumbers ? 34 : 0) - - (this.show.selectColumn ? 26 : 0) - - (this.show.expandColumn ? 26 : 0); - var width_box = width_max; - var percent = 0; - // gridMinWidth processiong - var restart = false; - for (var i=0; i width_box && col.hidden !== true) { - col.hidden = true; - restart = true; - } - if (col.gridMinWidth < width_box && col.hidden === true) { - col.hidden = false; - restart = true; - } - } - } - if (restart === true) { - this.refresh(); - return; - } - // assign PX column s - for (var i=0; i 0) { - for (var i=0; i= 0; r--) { + if (this.records[r].recid == arguments[a]) { this.records.splice(r, 1); removed++; } + } + } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + this.localSearch(); + } + this.refresh(); + return removed; + }, + + addColumn: function (before, columns) { + var added = 0; + if (arguments.length == 1) { + columns = before; + before = this.columns.length; } else { - // make it 1px smaller, so margin of error can be calculated correctly - this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.size) / 100) - 1 + 'px'; + if (typeof before == 'string') before = this.getColumn(before, true); + if (before === null) before = this.columns.length; } - } - } - } - // fix margin of error that is due percentage calculations - var width_cols = 0; - for (var i=0; i parseInt(col.max)) col.sizeCalculated = col.max + 'px'; - width_cols += parseInt(col.sizeCalculated); - } - var width_diff = parseInt(width_box) - parseInt(width_cols); - if (width_diff > 0 && percent > 0) { - var i = 0; - while (true) { - var col = this.columns[i]; - if (typeof col == 'undefined') { i = 0; continue; } - if (col.hidden || col.sizeType == 'px') { i++; continue; } - col.sizeCalculated = (parseInt(col.sizeCalculated) + 1) + 'px'; - width_diff--; - if (width_diff == 0) break; - i++; - } - } else if (width_diff > 0) { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); - } - // resize columns - columns.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-head-last')) { - $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - // if there are column groups - hide first row (needed for sizing) - if (columns.find('> table > tbody > tr').length == 3) { - columns.find('> table > tbody > tr:nth-child(1) td').html('').css({ - 'height' : '0px', - 'border' : '0px', - 'padding' : '0px', - 'margin' : '0px' - }); - } - // resize records - records.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-grid-data-last')) { - $(el).css('width', (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - // resize summary - summary.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-grid-data-last')) { - $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - this.initResize(); - this.refreshRanges(); - // apply last scroll if any - if (this.last.scrollTop != '' && records.length > 0) { - columns.prop('scrollLeft', this.last.scrollLeft); - records.prop('scrollTop', this.last.scrollTop); - records.prop('scrollLeft', this.last.scrollLeft); - } - }, + if (!$.isArray(columns)) columns = [columns]; + for (var o in columns) { + this.columns.splice(before, 0, columns[o]); + before++; + added++; + } + this.refresh(); + return added; + }, + + removeColumn: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + if (this.columns[r].field == arguments[a]) { this.columns.splice(r, 1); removed++; } + } + } + this.refresh(); + return removed; + }, + + getColumn: function (field, returnIndex) { + for (var i = 0; i < this.columns.length; i++) { + if (this.columns[i].field == field) { + if (returnIndex === true) return i; else return this.columns[i]; + } + } + return null; + }, + + toggleColumn: function () { + var effected = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.field == arguments[a]) { + col.hidden = !col.hidden; + effected++; + } + } + } + this.refresh(); + return effected; + }, + + showColumn: function () { + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.gridMinWidth) delete col.gridMinWidth; + if (col.field == arguments[a] && col.hidden !== false) { + col.hidden = false; + shown++; + } + } + } + this.refresh(); + return shown; + }, + + hideColumn: function () { + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.field == arguments[a] && col.hidden !== true) { + col.hidden = true; + hidden++; + } + } + } + this.refresh(); + return hidden; + }, + + addSearch: function (before, search) { + var added = 0; + if (arguments.length == 1) { + search = before; + before = this.searches.length; + } else { + if (typeof before == 'string') before = this.getSearch(before, true); + if (before === null) before = this.searches.length; + } + if (!$.isArray(search)) search = [search]; + for (var o in search) { + this.searches.splice(before, 0, search[o]); + before++; + added++; + } + this.searchClose(); + return added; + }, + + removeSearch: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a]) { this.searches.splice(r, 1); removed++; } + } + } + this.searchClose(); + return removed; + }, + + getSearch: function (field, returnIndex) { + for (var i = 0; i < this.searches.length; i++) { + if (this.searches[i].field == field) { + if (returnIndex === true) return i; else return this.searches[i]; + } + } + return null; + }, + + toggleSearch: function () { + var effected = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a]) { + this.searches[r].hidden = !this.searches[r].hidden; + effected++; + } + } + } + this.searchClose(); + return effected; + }, + + showSearch: function () { + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== false) { + this.searches[r].hidden = false; + shown++; + } + } + } + this.searchClose(); + return shown; + }, + + hideSearch: function () { + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== true) { + this.searches[r].hidden = true; + hidden++; + } + } + } + this.searchClose(); + return hidden; + }, + + getSearchData: function (field) { + for (var s in this.searchData) { + if (this.searchData[s].field == field) return this.searchData[s]; + } + return null; + }, + + localSort: function (silent) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + console.log('ERROR: grid.localSort can only be used on local data source, grid.url should be empty.'); + return; + } + if ($.isEmptyObject(this.sortData)) return; + var time = (new Date()).getTime(); + var obj = this; + // process date fields + obj.prepareData(); + // process sortData + for (var s in this.sortData) { + var column = this.getColumn(this.sortData[s].field); + if (!column) return; + if (typeof column.render == 'string') { + if (['date', 'age'].indexOf(column.render.split(':')[0]) != -1) { + this.sortData[s]['field_'] = column.field + '_'; + } + if (['time'].indexOf(column.render.split(':')[0]) != -1) { + this.sortData[s]['field_'] = column.field + '_'; + } + } + } + // process sort + this.records.sort(function (a, b) { + var ret = 0; + for (var s in obj.sortData) { + var fld = obj.sortData[s].field; + if (obj.sortData[s].field_) fld = obj.sortData[s].field_; + var aa = a[fld]; + var bb = b[fld]; + if (String(fld).indexOf('.') != -1) { + aa = obj.parseField(a, fld); + bb = obj.parseField(b, fld); + } + if (typeof aa == 'string') aa = $.trim(aa.toLowerCase()); + if (typeof bb == 'string') bb = $.trim(bb.toLowerCase()); + if (aa > bb) ret = (obj.sortData[s].direction == 'asc' ? 1 : -1); + if (aa < bb) ret = (obj.sortData[s].direction == 'asc' ? -1 : 1); + if (typeof aa != 'object' && typeof bb == 'object') ret = -1; + if (typeof bb != 'object' && typeof aa == 'object') ret = 1; + if (aa == null && bb != null) ret = 1; // all nuls and undefined on bottom + if (aa != null && bb == null) ret = -1; + if (ret != 0) break; + } + return ret; + }); + time = (new Date()).getTime() - time; + if (silent !== true) setTimeout(function () { obj.status(w2utils.lang('Sorting took') + ' ' + time/1000 + ' ' + w2utils.lang('sec')); }, 10); + return time; + }, + + localSearch: function (silent) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + console.log('ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.'); + return; + } + var time = (new Date()).getTime(); + var obj = this; + this.total = this.records.length; + // mark all records as shown + this.last.searchIds = []; + // prepare date/time fields + this.prepareData(); + // hide records that did not match + if (this.searchData.length > 0 && !url) { + this.total = 0; + for (var r in this.records) { + var rec = this.records[r]; + var fl = 0; + for (var s in this.searchData) { + var sdata = this.searchData[s]; + var search = this.getSearch(sdata.field); + if (sdata == null) continue; + if (search == null) search = { field: sdata.field, type: sdata.type }; + var val1 = String(obj.parseField(rec, search.field)).toLowerCase(); + if (typeof sdata.value != 'undefined') { + if (!$.isArray(sdata.value)) { + var val2 = String(sdata.value).toLowerCase(); + } else { + var val2 = sdata.value[0]; + var val3 = sdata.value[1]; + } + } + switch (sdata.operator) { + case 'is': + if (rec[search.field] == sdata.value) fl++; // do not hide record + if (search.type == 'date') { + var val1 = w2utils.formatDate(rec[search.field + '_'], 'yyyy-mm-dd'); + var val2 = w2utils.formatDate(val2, 'yyyy-mm-dd'); + if (val1 == val2) fl++; + } + if (search.type == 'time') { + var val1 = w2utils.formatTime(rec[search.field + '_'], 'h24:mi'); + var val2 = w2utils.formatTime(val2, 'h24:mi'); + if (val1 == val2) fl++; + } + break; + case 'between': + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1) { + if (parseFloat(rec[search.field]) >= parseFloat(val2) && parseFloat(rec[search.field]) <= parseFloat(val3)) fl++; + } + if (search.type == 'date') { + var val1 = rec[search.field + '_']; + var val2 = w2utils.isDate(val2, w2utils.settings.date_format, true); + var val3 = w2utils.isDate(val3, w2utils.settings.date_format, true); + if (val3 != null) val3 = new Date(val3.getTime() + 86400000); // 1 day + if (val1 >= val2 && val1 < val3) fl++; + } + if (search.type == 'time') { + var val1 = rec[search.field + '_']; + var val2 = w2utils.isTime(val2, true); + var val3 = w2utils.isTime(val3, true); + val2 = (new Date()).setHours(val2.hours, val2.minutes, val2.seconds ? val2.seconds : 0, 0); + val3 = (new Date()).setHours(val3.hours, val3.minutes, val3.seconds ? val3.seconds : 0, 0); + if (val1 >= val2 && val1 < val3) fl++; + } + break; + case 'in': + var tmp = sdata.value; + if (sdata.svalue) tmp = sdata.svalue; + if (tmp.indexOf(val1) !== -1) fl++; + break; + case 'not in': + var tmp = sdata.value; + if (sdata.svalue) tmp = sdata.svalue; + if (tmp.indexOf(val1) == -1) fl++; + break; + case 'begins': + case 'begins with': // need for back compatib. + if (val1.indexOf(val2) == 0) fl++; // do not hide record + break; + case 'contains': + if (val1.indexOf(val2) >= 0) fl++; // do not hide record + break; + case 'ends': + case 'ends with': // need for back compatib. + if (val1.indexOf(val2) == val1.length - val2.length) fl++; // do not hide record + break; + } + } + if ((this.last.logic == 'OR' && fl != 0) || (this.last.logic == 'AND' && fl == this.searchData.length)) this.last.searchIds.push(parseInt(r)); + } + this.total = this.last.searchIds.length; + } + time = (new Date()).getTime() - time; + if (silent !== true) setTimeout(function () { obj.status(w2utils.lang('Search took') + ' ' + time/1000 + ' ' + w2utils.lang('sec')); }, 10); + return time; + }, + + getRangeData: function (range, extra) { + var rec1 = this.get(range[0].recid, true); + var rec2 = this.get(range[1].recid, true); + var col1 = range[0].column; + var col2 = range[1].column; + + var res = []; + if (col1 == col2) { // one row + for (var r = rec1; r <= rec2; r++) { + var record = this.records[r]; + var dt = record[this.columns[col1].field] || null; + if (extra !== true) { + res.push(dt); + } else { + res.push({ data: dt, column: col1, index: r, record: record }); + } + } + } else if (rec1 == rec2) { // one line + var record = this.records[rec1]; + for (var i = col1; i <= col2; i++) { + var dt = record[this.columns[i].field] || null; + if (extra !== true) { + res.push(dt); + } else { + res.push({ data: dt, column: i, index: rec1, record: record }); + } + } + } else { + for (var r = rec1; r <= rec2; r++) { + var record = this.records[r]; + res.push([]); + for (var i = col1; i <= col2; i++) { + var dt = record[this.columns[i].field]; + if (extra !== true) { + res[res.length-1].push(dt); + } else { + res[res.length-1].push({ data: dt, column: i, index: r, record: record }); + } + } + } + } + return res; + }, + + addRange: function (ranges) { + var added = 0; + if (this.selectType == 'row') return added; + if (!$.isArray(ranges)) ranges = [ranges]; + // if it is selection + for (var r in ranges) { + if (typeof ranges[r] != 'object') ranges[r] = { name: 'selection' }; + if (ranges[r].name == 'selection') { + if (this.show.selectionBorder === false) continue; + var sel = this.getSelection(); + if (sel.length == 0) { + this.removeRange(ranges[r].name); + continue; + } else { + var first = sel[0]; + var last = sel[sel.length-1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + } + } else { // other range + var first = ranges[r].range[0]; + var last = ranges[r].range[1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + } + if (first) { + var rg = { + name: ranges[r].name, + range: [{ recid: first.recid, column: first.column }, { recid: last.recid, column: last.column }], + style: ranges[r].style || '' + }; + // add range + var ind = false; + for (var t in this.ranges) if (this.ranges[t].name == ranges[r].name) { ind = r; break; } + if (ind !== false) { + this.ranges[ind] = rg; + } else { + this.ranges.push(rg); + } + added++ + } + } + this.refreshRanges(); + return added; + }, + + removeRange: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var name = arguments[a]; + $('#grid_'+ this.name +'_'+ name).remove(); + for (var r = this.ranges.length-1; r >= 0; r--) { + if (this.ranges[r].name == name) { + this.ranges.splice(r, 1); + removed++; + } + } + } + return removed; + }, + + refreshRanges: function () { + var obj = this; + var time = (new Date()).getTime(); + var rec = $('#grid_'+ this.name +'_records'); + for (var r in this.ranges) { + var rg = this.ranges[r]; + var first = rg.range[0]; + var last = rg.range[1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + if ($('#grid_'+ this.name +'_'+ rg.name).length == 0) { + rec.append(''+ + (rg.name == 'selection' ? '' : '')+ + ''); + } else { + $('#grid_'+ this.name +'_'+ rg.name).attr('style', rg.style); + } + if (td1.length > 0 && td2.length > 0) { + $('#grid_'+ this.name +'_'+ rg.name).css({ + left : (td1.position().left - 1 + rec.scrollLeft()) + 'px', + top : (td1.position().top - 1 + rec.scrollTop()) + 'px', + width : (td2.position().left - td1.position().left + td2.width() + 3) + 'px', + height : (td2.position().top - td1.position().top + td2.height() + 3) + 'px' + }); + } + } + + // add resizer events + $(this.box).find('#grid_'+ this.name +'_resizer').off('mousedown').on('mousedown', mouseStart); + //$(this.box).find('#grid_'+ this.name +'_resizer').off('selectstart').on('selectstart', function () { return false; }); // fixes chrome cursror bug + + var eventData = { phase: 'before', type: 'selectionExtend', target: obj.name, originalRange: null, newRange: null }; + + function mouseStart (event) { + var sel = obj.getSelection(); + obj.last.move = { + type : 'expand', + x : event.screenX, + y : event.screenY, + divX : 0, + divY : 0, + recid : sel[0].recid, + column : sel[0].column, + originalRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }], + newRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }] + }; + $(document).off('mousemove', mouseMove).on('mousemove', mouseMove); + $(document).off('mouseup', mouseStop).on('mouseup', mouseStop); + } + + function mouseMove (event) { + var mv = obj.last.move; + if (!mv || mv.type != 'expand') return; + mv.divX = (event.screenX - mv.x); + mv.divY = (event.screenY - mv.y); + // find new cell + var recid, column; + var tmp = event.originalEvent.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); + tmp = $(tmp).parents('tr')[0]; + recid = $(tmp).attr('recid'); + // new range + if (mv.newRange[1].recid == recid && mv.newRange[1].column == column) return; + var prevNewRange = $.extend({}, mv.newRange); + mv.newRange = [{ recid: mv.recid, column: mv.column }, { recid: recid, column: column }]; + // event before + eventData = obj.trigger($.extend(eventData, { originalRange: mv.originalRange, newRange : mv.newRange })); + if (eventData.isCancelled === true) { + mv.newRange = prevNewRange; + eventData.newRange = prevNewRange; + return; + } else { + // default behavior + obj.removeRange('grid-selection-expand'); + obj.addRange({ + name : 'grid-selection-expand', + range : eventData.newRange, + style : 'background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);' + }); + } + } + + function mouseStop (event) { + // default behavior + obj.removeRange('grid-selection-expand'); + delete obj.last.move; + $(document).off('mousemove', mouseMove); + $(document).off('mouseup', mouseStop); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + + return (new Date()).getTime() - time; + }, + + select: function () { + var selected = 0; + var sel = this.last.selection; + if (!this.multiSelect) this.selectNone(); + for (var a = 0; a < arguments.length; a++) { + var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; + var record = this.get(recid); + if (record == null) continue; + var index = this.get(recid, true); + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (this.selectType == 'row') { + if (sel.indexes.indexOf(index) >= 0) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, index: index }); + if (eventData.isCancelled === true) continue; + // default action + sel.indexes.push(index); + sel.indexes.sort(function(a, b) { return a-b }); + recEl.addClass('w2ui-selected').data('selected', 'yes'); + recEl.find('.w2ui-grid-select-check').prop("checked", true); + selected++; + } else { + var col = arguments[a].column; + if (!w2utils.isInt(col)) { // select all columns + var cols = []; + for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } + if (!this.multiSelect) cols = cols.splice(0, 1); + return this.select.apply(this, cols); + } + var s = sel.columns[index] || []; + if ($.isArray(s) && s.indexOf(col) != -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, index: index, column: col }); + if (eventData.isCancelled === true) continue; + // default action + if (sel.indexes.indexOf(index) == -1) { + sel.indexes.push(index); + sel.indexes.sort(function(a, b) { return a-b }); + } + s.push(col); + s.sort(function(a, b) { return a-b }); // sort function must be for numerical sort + recEl.find(' > td[col='+ col +']').addClass('w2ui-selected'); + selected++; + recEl.data('selected', 'yes'); + recEl.find('.w2ui-grid-select-check').prop("checked", true); + // save back to selection object + sel.columns[index] = s; + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + // all selected? + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + this.status(); + this.addRange('selection'); + return selected; + }, + + unselect: function () { + var unselected = 0; + var sel = this.last.selection; + for (var a = 0; a < arguments.length; a++) { + var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; + var record = this.get(recid); + if (record == null) continue; + var index = this.get(record.recid, true); + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (this.selectType == 'row') { + if (sel.indexes.indexOf(index) == -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, index: index }); + if (eventData.isCancelled === true) continue; + // default action + sel.indexes.splice(sel.indexes.indexOf(index), 1); + recEl.removeClass('w2ui-selected').removeData('selected'); + if (recEl.length != 0) recEl[0].style.cssText = 'height: '+ this.recordHeight +'px; ' + recEl.attr('custom_style'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + unselected++; + } else { + var col = arguments[a].column; + if (!w2utils.isInt(col)) { // unselect all columns + var cols = []; + for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } + return this.unselect.apply(this, cols); + } + var s = sel.columns[index]; + if (!$.isArray(s) || s.indexOf(col) == -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, column: col }); + if (eventData.isCancelled === true) continue; + // default action + s.splice(s.indexOf(col), 1); + $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').removeClass('w2ui-selected'); + unselected++; + if (s.length == 0) { + delete sel.columns[index]; + sel.indexes.splice(sel.indexes.indexOf(index), 1); + recEl.removeData('selected'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + // all selected? + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + // show number of selected + this.status(); + this.addRange('selection'); + return unselected; + }, + + selectAll: function () { + if (this.multiSelect === false) return; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, all: true }); + if (eventData.isCancelled === true) return; + // default action + var url = (typeof this.url != 'object' ? this.url : this.url.get); + var sel = this.last.selection; + var cols = []; + for (var c in this.columns) cols.push(parseInt(c)); + // if local data source and searched + sel.indexes = []; + if (!url && this.searchData.length !== 0) { + // local search applied + for (var i = 0; i < this.last.searchIds.length; i++) { + sel.indexes.push(this.last.searchIds[i]); + if (this.selectType != 'row') sel.columns[this.last.searchIds[i]] = cols.slice(); // .slice makes copy of the array + } + } else { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + for (var i = 0; i < buffered; i++) { + sel.indexes.push(i); + if (this.selectType != 'row') sel.columns[i] = cols.slice(); // .slice makes copy of the array + } + } + this.refresh(); + // enable/disable toolbar buttons + var sel = this.getSelection(); + if (sel.length == 1) this.toolbar.enable('w2ui-edit'); else this.toolbar.disable('w2ui-edit'); + if (sel.length >= 1) this.toolbar.enable('w2ui-delete'); else this.toolbar.disable('w2ui-delete'); + this.addRange('selection'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + selectNone: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, all: true }); + if (eventData.isCancelled === true) return; + // default action + var sel = this.last.selection; + for (var s in sel.indexes) { + var index = sel.indexes[s]; + var rec = this.records[index]; + var recid = rec ? rec.recid : null; + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + recEl.removeClass('w2ui-selected').removeData('selected'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + // for not rows + if (this.selectType != 'row') { + var cols = sel.columns[index]; + for (var c in cols) recEl.find(' > td[col='+ cols[c] +']').removeClass('w2ui-selected'); + } + } + sel.indexes = []; + sel.columns = {}; + this.toolbar.disable('w2ui-edit', 'w2ui-delete'); + this.removeRange('selection'); + $('#grid_'+ this.name +'_check_all').prop('checked', false); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + getSelection: function (returnIndex) { + var ret = []; + var sel = this.last.selection; + if (this.selectType == 'row') { + for (var s in sel.indexes) { + if (!this.records[sel.indexes[s]]) continue; + if (returnIndex === true) ret.push(sel.indexes[s]); else ret.push(this.records[sel.indexes[s]].recid); + } + return ret; + } else { + for (var s in sel.indexes) { + var cols = sel.columns[sel.indexes[s]]; + if (!this.records[sel.indexes[s]]) continue; + for (var c in cols) { + ret.push({ recid: this.records[sel.indexes[s]].recid, index: parseInt(sel.indexes[s]), column: cols[c] }); + } + } + return ret; + } + }, + + search: function (field, value) { + var obj = this; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + var searchData = []; + var last_multi = this.last.multi; + var last_logic = this.last.logic; + var last_field = this.last.field; + var last_search = this.last.search; + // 1: search() - advanced search (reads from popup) + if (arguments.length == 0) { + last_search = ''; + // advanced search + for (var s in this.searches) { + var search = this.searches[s]; + var operator = $('#grid_'+ this.name + '_operator_'+s).val(); + var field1 = $('#grid_'+ this.name + '_field_'+s); + var field2 = $('#grid_'+ this.name + '_field2_'+s); + var value1 = field1.val(); + var value2 = field2.val(); + var svalue = null; + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1) { + var fld1 = field1.data('w2field'); + var fld2 = field2.data('w2field'); + if (fld1) value1 = fld1.clean(value1); + if (fld2) value2 = fld2.clean(value2); + } + if (['list', 'enum'].indexOf(search.type) != -1) { + value1 = field1.data('selected') || {}; + if ($.isArray(value1)) { + svalue = []; + for (var v in value1) { + svalue.push(w2utils.isFloat(value1[v].id) ? parseFloat(value1[v].id) : String(value1[v].id).toLowerCase()); + delete value1[v].hidden; + } + } else { + value1 = value1.id || ''; + } + } + if ((value1 != '' && value1 != null) || (typeof value2 != 'undefined' && value2 != '')) { + var tmp = { + field : search.field, + type : search.type, + operator : operator + } + if (operator == 'between') { + $.extend(tmp, { value: [value1, value2] }); + } else if (operator == 'in' && typeof value1 == 'string') { + $.extend(tmp, { value: value1.split(',') }); + } else if (operator == 'not in' && typeof value1 == 'string') { + $.extend(tmp, { value: value1.split(',') }); + } else { + $.extend(tmp, { value: value1 }); + } + if (svalue) $.extend(tmp, { svalue: svalue }); + // conver date to unix time + try { + if (search.type == 'date' && operator == 'between') { + tmp.value[0] = value1; // w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); + tmp.value[1] = value2; // w2utils.isDate(value2, w2utils.settings.date_format, true).getTime(); + } + if (search.type == 'date' && operator == 'is') { + tmp.value = value1; // w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); + } + } catch (e) { + + } + searchData.push(tmp); + } + } + if (searchData.length > 0 && !url) { + last_multi = true; + last_logic = 'AND'; + } else { + last_multi = true; + last_logic = 'AND'; + } + } + // 2: search(field, value) - regular search + if (typeof field == 'string') { + last_field = field; + last_search = value; + last_multi = false; + last_logic = 'OR'; + // loop through all searches and see if it applies + if (typeof value != 'undefined') { + if (field.toLowerCase() == 'all') { + // if there are search fields loop thru them + if (this.searches.length > 0) { + for (var s in this.searches) { + var search = this.searches[s]; + if (search.type == 'text' || (search.type == 'alphanumeric' && w2utils.isAlphaNumeric(value)) + || (search.type == 'int' && w2utils.isInt(value)) || (search.type == 'float' && w2utils.isFloat(value)) + || (search.type == 'percent' && w2utils.isFloat(value)) || (search.type == 'hex' && w2utils.isHex(value)) + || (search.type == 'currency' && w2utils.isMoney(value)) || (search.type == 'money' && w2utils.isMoney(value)) + || (search.type == 'date' && w2utils.isDate(value)) ) { + var tmp = { + field : search.field, + type : search.type, + operator : (search.type == 'text' ? 'contains' : 'is'), + value : value + }; + searchData.push(tmp); + } + // range in global search box + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1 && String(value).indexOf('-') != -1) { + var t = String(value).split('-'); + var tmp = { + field : search.field, + type : search.type, + operator : 'between', + value : [t[0], t[1]] + }; + searchData.push(tmp); + } + } + } else { + // no search fields, loop thru columns + for (var c in this.columns) { + var tmp = { + field : this.columns[c].field, + type : 'text', + operator : 'contains', + value : value + }; + searchData.push(tmp); + } + } + } else { + var el = $('#grid_'+ this.name +'_search_all'); + var search = this.getSearch(field); + if (search == null) search = { field: field, type: 'text' }; + if (search.field == field) this.last.caption = search.caption; + if (search.type == 'list') { + var tmp = el.data('selected'); + if (tmp && !$.isEmptyObject(tmp)) value = tmp.id; + } + if (value != '') { + var op = 'contains'; + var val = value; + if (['date', 'time', 'list'].indexOf(search.type) != -1) op = 'is'; + if (search.type == 'int' && value != '') { + op = 'is'; + if (String(value).indexOf('-') != -1) { + var tmp = value.split('-'); + if (tmp.length == 2) { + op = 'between'; + val = [parseInt(tmp[0]), parseInt(tmp[1])]; + } + } + if (String(value).indexOf(',') != -1) { + var tmp = value.split(','); + op = 'in'; + val = []; + for (var t in tmp) val.push(tmp[t]); + } + } + var tmp = { + field : search.field, + type : search.type, + operator : op, + value : val + } + searchData.push(tmp); + } + } + } + } + // 3: search([ { field, value, [operator,] [type] }, { field, value, [operator,] [type] } ], logic) - submit whole structure + if ($.isArray(field)) { + var logic = 'AND'; + if (typeof value == 'string') { + logic = value.toUpperCase(); + if (logic != 'OR' && logic != 'AND') logic = 'AND'; + } + last_search = ''; + last_multi = true; + last_logic = logic; + for (var f in field) { + var data = field[f]; + var search = this.getSearch(data.field); + if (search == null) search = { type: 'text', operator: 'contains' }; + // merge current field and search if any + searchData.push($.extend(true, {}, search, data)); + } + } + // event before + var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: searchData, + searchField: (field ? field : 'multi'), searchValue: (value ? value : 'multi') }); + if (eventData.isCancelled === true) return; + // default action + this.searchData = eventData.searchData; + this.last.field = last_field; + this.last.search = last_search; + this.last.multi = last_multi; + this.last.logic = last_logic; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + // -- clear all search field + this.searchClose(); + this.set({ expanded: false }, true); + // apply search + if (url) { + this.last.xhr_offset = 0; + this.reload(); + } else { + // local search + this.localSearch(); + this.refresh(); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + searchOpen: function () { + if (!this.box) return; + if (this.searches.length == 0) return; + var obj = this; + // show search + $('#tb_'+ this.name +'_toolbar_item_w2ui-search-advanced').w2overlay( + this.getSearchesHTML(), { + name : 'searches-'+ this.name, + left : -10, + 'class' : 'w2ui-grid-searches', + onShow : function () { + if (obj.last.logic == 'OR') obj.searchData = []; + obj.initSearches(); + $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches').data('grid-name', obj.name); + var sfields = $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches *[rel=search]'); + if (sfields.length > 0) sfields[0].focus(); + } + } + ); + }, + + searchClose: function () { + if (!this.box) return; + if (this.searches.length == 0) return; + if (this.toolbar) this.toolbar.uncheck('w2ui-search-advanced') + // hide search + if ($('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches').length > 0) { + $().w2overlay('', { name: 'searches-'+ this.name }); + } + }, + + searchShowFields: function () { + var el = $('#grid_'+ this.name +'_search_all'); + var html = ''; + for (var s = -1; s < this.searches.length; s++) { + var search = this.searches[s]; + if (s == -1) { + if (!this.multiSearch) continue; + search = { field: 'all', caption: w2utils.lang('All Fields') }; + } else { + if (this.searches[s].hidden === true) continue; + } + html += ''+ + ' '+ + ' '+ search.caption +''+ + ''; + } + html += ""; + // need timer otherwise does nto show with list type + setTimeout(function () { + $(el).w2overlay(html, { left: -10 }); + }, 1); + }, + + initAllField: function (field, value) { + var el = $('#grid_'+ this.name +'_search_all'); + var search = this.getSearch(field); + if (field == 'all') { + search = { field: 'all', caption: w2utils.lang('All Fields') }; + el.w2field('clear'); + el.change().focus(); + } else { + var st = search.type; + if (['enum', 'select'].indexOf(st) != -1) st = 'list'; + el.w2field(st, $.extend({}, search.options, { suffix: '', autoFormat: false, selected: value })); + if (['list', 'enum'].indexOf(search.type) != -1) { + this.last.search = ''; + this.last.item = ''; + el.val(''); + } + // set focus + setTimeout(function () { + el.focus(); /* do not do el.change() as it will refresh grid and pull from server */ + }, 1); + } + // update field + if (this.last.search != '') { + this.search(search.field, this.last.search); + } else { + this.last.field = search.field; + this.last.caption = search.caption; + } + el.attr('placeholder', search.caption); + $().w2overlay(); + }, + + searchReset: function (noRefresh) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: [] }); + if (eventData.isCancelled === true) return; + // default action + this.searchData = []; + this.last.search = ''; + this.last.logic = 'OR'; + // --- do not reset to All Fields (I think) + // if (this.last.multi) { + // if (!this.multiSearch) { + // this.last.field = this.searches[0].field; + // this.last.caption = this.searches[0].caption; + // } else { + // this.last.field = 'all'; + // this.last.caption = w2utils.lang('All Fields'); + // } + // } + this.last.multi = false; + this.last.xhr_offset = 0; + // reset scrolling position + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + // -- clear all search field + this.searchClose(); + $('#grid_'+ this.name +'_search_all').val(''); + // apply search + if (!noRefresh) this.reload(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + clear: function (noRefresh) { + // this.offset = 0; // clear should not reset offset + // this.total = 0; // clear should not reset total + this.records = []; + this.summary = []; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.range_start = null; + this.last.range_end = null; + // this.last.xhr_offset = 0; // clear should not reset offset + if (!noRefresh) this.refresh(); + }, + + reset: function (noRefresh) { + // reset last remembered state + this.offset = 0; + this.total = 0; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + this.last.range_start = null; + this.last.range_end = null; + this.last.xhr_offset = 0; + this.searchReset(noRefresh); + // initial sort + if (this.last.sortData != null ) this.sortData = this.last.sortData; + // select none without refresh + this.set({ expanded: false }, true); + // refresh + if (!noRefresh) this.refresh(); + }, + + skip: function (offset) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + this.offset = parseInt(offset); + if (this.offset > this.total) this.offset = this.total - this.limit; + if (this.offset < 0 || !w2utils.isInt(this.offset)) this.offset = 0; + this.records = []; + this.last.xhr_offset = 0; + this.last.pull_more = true; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + $('#grid_'+ this.name +'_records').prop('scrollTop', 0); + this.reload(); + } else { + console.log('ERROR: grid.skip() can only be called when you have remote data source.'); + } + }, + + load: function (url, callBack) { + if (typeof url == 'undefined') { + console.log('ERROR: You need to provide url argument when calling .load() method of "'+ this.name +'" object.'); + return; + } + // default action + this.request('get-records', {}, url, callBack); + }, + + reload: function (callBack) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + this.clear(true); + this.request('get-records', {}, null, callBack); + } else { + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.range_start = null; + this.last.range_end = null; + this.localSearch(); + this.refresh(); + if (typeof callBack == 'function') callBack({ status: 'success' }); + } + }, + + request: function (cmd, add_params, url, callBack) { + if (typeof add_params == 'undefined') add_params = {}; + if (typeof url == 'undefined' || url == '' || url == null) url = this.url; + if (url == '' || url == null) return; + // build parameters list + var params = {}; + if (!w2utils.isInt(this.offset)) this.offset = 0; + if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0; + // add list params + params['cmd'] = cmd; + params['selected'] = this.getSelection(); + params['limit'] = this.limit; + params['offset'] = parseInt(this.offset) + this.last.xhr_offset; + params['search'] = this.searchData; + params['searchLogic'] = this.last.logic; + params['sort'] = this.sortData; + if (this.searchData.length == 0) { + delete params['search']; + delete params['searchLogic']; + } + if (this.sortData.length == 0) { + delete params['sort']; + } + // append other params + $.extend(params, this.postData); + $.extend(params, add_params); + // event before + if (cmd == 'get-records') { + var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: url, postData: params }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + } else { + var eventData = { url: url, postData: params }; + } + // call server to get data + var obj = this; + if (this.last.xhr_offset == 0) { + this.lock(this.msgRefresh, true); + } else { + var more = $('#grid_'+ this.name +'_rec_more'); + if (this.autoLoad === true) { + more.show().find('td').html(''); + } else { + more.find('td').html(''+ w2utils.lang('Load') + ' ' + obj.limit + ' ' + w2utils.lang('More') + '...'); + } + } + if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; + // URL + var url = (typeof eventData.url != 'object' ? eventData.url : eventData.url.get); + if (params.cmd == 'save-records' && typeof eventData.url == 'object') url = eventData.url.save; + if (params.cmd == 'delete-records' && typeof eventData.url == 'object') url = eventData.url.remove; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + // ajax ptions + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text' // expected data type from server + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = (typeof ajaxOptions.data == 'object' ? String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']') : ajaxOptions.data); + } + if (w2utils.settings.dataType == 'RESTFULL') { + ajaxOptions.type = 'GET'; + if (params.cmd == 'save-records') ajaxOptions.type = 'PUT'; // so far it is always update + if (params.cmd == 'delete-records') ajaxOptions.type = 'DELETE'; + ajaxOptions.data = (typeof ajaxOptions.data == 'object' ? String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']') : ajaxOptions.data); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + if (this.method) ajaxOptions.type = this.method; + + this.last.xhr_cmd = params.cmd; + this.last.xhr_start = (new Date()).getTime(); + this.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.requestComplete(status, cmd, callBack); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', total: 5, records: [{ recid: 1, field: 'value' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + obj.requestComplete('error', cmd, callBack); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + if (cmd == 'get-records') { + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, + + requestComplete: function(status, cmd, callBack) { + var obj = this; + this.unlock(); + setTimeout(function () { obj.status(w2utils.lang('Server Response') + ' ' + ((new Date()).getTime() - obj.last.xhr_start)/1000 +' ' + w2utils.lang('sec')); }, 10); + this.last.pull_more = false; + this.last.pull_refresh = true; + + // event before + var event_name = 'load'; + if (this.last.xhr_cmd == 'save-records') event_name = 'save'; + if (this.last.xhr_cmd == 'delete-records') event_name = 'deleted'; + var eventData = this.trigger({ phase: 'before', target: this.name, type: event_name, xhr: this.last.xhr, status: status }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + // parse server response + var data; + var responseText = this.last.xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + if (typeof obj.parser == 'function') { + data = obj.parser(responseText); + if (typeof data != 'object') { + console.log('ERROR: Your parser did not return proper object'); + } + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + } + // convert recids + if (obj.recid) { + for (var r in data.records) { + data.records[r]['recid'] = data.records[r][obj.recid]; + } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : this.msgNotJSON, + responseText : responseText + }; + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + if (cmd == 'get-records') { + if (this.last.xhr_offset == 0) { + this.records = []; + this.summary = []; + //data.xhr_status=data.status; + delete data.status; + $.extend(true, this, data); + } else { + var records = data.records; + delete data.records; + //data.xhr_status=data.status; + delete data.status; + $.extend(true, this, data); + for (var r in records) { + this.records.push(records[r]); + } + } + } + if (cmd == 'delete-records') { + // reset() also triggers reload + this.reset(); // unselect old selections + return; + } + } + } + } else { + data = { + status : 'error', + message : this.msgAJAXerror, + responseText : responseText + }; + obj.error(this.msgAJAXerror); + } + // event after + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + this.localSearch(); + } + this.total = parseInt(this.total); + this.trigger($.extend(eventData, { phase: 'after' })); + // do not refresh if loading on infinite scroll + if (this.last.xhr_offset == 0) this.refresh(); else this.scroll(); + // call back + if (typeof callBack == 'function') callBack(data); + }, + + error: function (msg) { + var obj = this; + // let the management of the error outside of the grid + var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + w2alert(msg, 'Error'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + getChanges: function () { + var changes = []; + for (var r in this.records) { + var rec = this.records[r]; + if (typeof rec['changes'] != 'undefined') { + changes.push($.extend(true, { recid: rec.recid }, rec.changes)); + } + } + return changes; + }, + + mergeChanges: function () { + var changes = this.getChanges(); + for (var c in changes) { + var record = this.get(changes[c].recid); + for (var s in changes[c]) { + if (s == 'recid') continue; // do not allow to change recid + try { eval('record.' + s + ' = changes[c][s]'); } catch (e) {} + delete record.changes; + } + } + this.refresh(); + }, + + // =================================================== + // -- Action Handlers + + save: function () { + var obj = this; + var changes = this.getChanges(); + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'submit', changes: changes }); + if (eventData.isCancelled === true) return; + var url = (typeof this.url != 'object' ? this.url : this.url.save); + if (url) { + this.request('save-records', { 'changes' : eventData.changes }, null, + function (data) { + if (data.status !== 'error') { + // only merge changes, if save was successful + obj.mergeChanges(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + ); + } else { + this.mergeChanges(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, + + editField: function (recid, column, value, event) { + var obj = this; + var index = obj.get(recid, true); + var rec = obj.records[index]; + var col = obj.columns[column]; + var edit = col ? col.editable : null; + if (!rec || !col || !edit || rec.editable === false) return; + if (['enum', 'file'].indexOf(edit.type) != -1) { + console.log('ERROR: input types "enum" and "file" are not supported in inline editing.'); + return; + } + // event before + var eventData = obj.trigger({ phase: 'before', type: 'editField', target: obj.name, recid: recid, column: column, value: value, + index: index, originalEvent: event }); + if (eventData.isCancelled === true) return; + value = eventData.value; + // default behaviour + this.selectNone(); + this.select({ recid: recid, column: column }); + this.last.edit_col = column; + if (['checkbox', 'check'].indexOf(edit.type) != -1) return; + // create input element + var tr = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(recid)); + var el = tr.find('[col='+ column +'] > div'); + if (typeof edit.inTag == 'undefined') edit.inTag = ''; + if (typeof edit.outTag == 'undefined') edit.outTag = ''; + if (typeof edit.style == 'undefined') edit.style = ''; + if (typeof edit.items == 'undefined') edit.items = []; + var val = (rec.changes && typeof rec.changes[col.field] != 'undefined' ? w2utils.stripTags(rec.changes[col.field]) : w2utils.stripTags(rec[col.field])); + if (val == null || typeof val == 'undefined') val = ''; + if (typeof value != 'undefined' && value != null) val = value; + var addStyle = (typeof col.style != 'undefined' ? col.style + ';' : ''); + if (typeof col.render == 'string' && ['number', 'int', 'float', 'money', 'percent'].indexOf(col.render.split(':')[0]) != -1) { + addStyle += 'text-align: right;'; + } + // mormalize items + if (edit.items.length > 0 && !$.isPlainObject(edit.items[0])) { + edit.items = w2obj.field.prototype.normMenu(edit.items); + } + if (edit.type == 'select') { + var html = ''; + for (var i in edit.items) { + html += ''+ edit.items[i].text +''; + } + el.addClass('w2ui-editable') + .html(''+ html +'' + edit.outTag); + el.find('select').focus() + .on('change', function (event) { + delete obj.last.move; + }) + .on('blur', function (event) { + obj.editChange.call(obj, this, index, column, event); + }); + } else { + el.addClass('w2ui-editable') + .html('' + edit.outTag); + if (value == null) el.find('input').val(val != 'object' ? val : ''); + // init w2field + var input = el.find('input').get(0); + $(input).w2field(edit.type, $.extend(edit, { selected: val })) + // add blur listener + setTimeout(function () { + var tmp = input; + if (edit.type == 'list') { + tmp = $($(input).data('w2field').helpers.focus).find('input'); + if (val != 'object' && val != '') tmp.val(val).css({ opacity: 1 }).prev().css({ opacity: 1 }); + } + $(tmp).on('blur', function (event) { + obj.editChange.call(obj, input, index, column, event); + }); + }, 10); + if (value != null) $(input).val(val != 'object' ? val : ''); + } + setTimeout(function () { + el.find('input, select') + .on('click', function (event) { + event.stopPropagation(); + }) + .on('keydown', function (event) { + var cancel = false; + switch (event.keyCode) { + case 9: // tab + cancel = true; + var next_rec = recid; + var next_col = event.shiftKey ? obj.prevCell(column, true) : obj.nextCell(column, true); + // next or prev row + if (next_col == null) { + var tmp = event.shiftKey ? obj.prevRow(index) : obj.nextRow(index); + if (tmp != null && tmp != index) { + next_rec = obj.records[tmp].recid; + // find first editable row + for (var c in obj.columns) { + var tmp = obj.columns[c].editable; + if (typeof tmp != 'undefined' && ['checkbox', 'check'].indexOf(tmp.type) == -1) { + next_col = parseInt(c); + if (!event.shiftKey) break; + } + } + } + + } + if (next_rec === false) next_rec = recid; + if (next_col == null) next_col = column; + // init new or same record + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: next_rec, column: next_col }); + } else { + obj.editField(next_rec, next_col, null, event); + } + }, 1); + break; + + case 13: // enter + this.blur(); + var next = event.shiftKey ? obj.prevRow(index) : obj.nextRow(index); + if (next != null && next != index) { + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 100); + } + break; + + case 38: // up arrow + if (!event.shiftKey) break; + cancel = true; + var next = obj.prevRow(index); + if (next != index) { + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 1); + } + break; + + case 40: // down arrow + if (!event.shiftKey) break; + cancel = true; + var next = obj.nextRow(index); + if (next != null && next != index) { + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 1); + } + break; + + case 27: // escape + var old = obj.parseField(rec, col.field); + if (rec.changes && typeof rec.changes[col.field] != 'undefined') old = rec.changes[col.field]; + this.value = typeof old != 'undefined' ? old : ''; + this.blur(); + setTimeout(function () { obj.select({ recid: recid, column: column }) }, 1); + break; + } + if (cancel) if (event.preventDefault) event.preventDefault(); + }); + // focus and select + var tmp = el.find('input').focus(); + if (value != null) { + // set cursor to the end + tmp[0].setSelectionRange(tmp.val().length, tmp.val().length); + } else { + tmp.select(); + } + + }, 1); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + editChange: function (el, index, column, event) { + // all other fields + var summary = index < 0; + index = index < 0 ? -index - 1 : index; + var records = summary ? this.summary : this.records; + var rec = records[index]; + var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(rec.recid)); + var col = this.columns[column]; + var new_val = el.value; + var old_val = this.parseField(rec, col.field); + var tmp = $(el).data('w2field'); + if (tmp) { + new_val = tmp.clean(new_val); + if (tmp.type == 'list' && new_val != '') new_val = $(el).data('selected'); + } + if (el.type == 'checkbox') new_val = el.checked; + // change/restore event + var eventData = { + phase: 'before', type: 'change', target: this.name, input_id: el.id, recid: rec.recid, index: index, column: column, + value_new: new_val, value_previous: (rec.changes && rec.changes.hasOwnProperty(col.field) ? rec.changes[col.field]: old_val), value_original: old_val + }; + while (true) { + new_val = eventData.value_new; + if (( typeof old_val == 'undefined' || old_val === null ? '' : String(old_val)) !== String(new_val)) { + // change event + eventData = this.trigger($.extend(eventData, { type: 'change', phase: 'before' })); + if (eventData.isCancelled !== true) { + if (new_val !== eventData.value_new) { + // re-evaluate the type of change to be made + continue; + } + // default action + rec.changes = rec.changes || {}; + rec.changes[col.field] = eventData.value_new; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + // restore event + eventData = this.trigger($.extend(eventData, { type: 'restore', phase: 'before' })); + if (eventData.isCancelled !== true) { + if (new_val !== eventData.value_new) { + // re-evaluate the type of change to be made + continue; + } + // default action + if (rec.changes) delete rec.changes[col.field]; + if ($.isEmptyObject(rec.changes)) delete rec.changes; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + } + break; + } + // refresh cell + var cell = this.getCellHTML(index, column, summary); + if (!summary) { + if (rec.changes && typeof rec.changes[col.field] != 'undefined') { + $(tr).find('[col='+ column +']').addClass('w2ui-changed').html(cell); + } else { + $(tr).find('[col='+ column +']').removeClass('w2ui-changed').html(cell); + } + } + }, + + "delete": function (force) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'delete', force: force }); + if (eventData.isCancelled === true) return; + force = eventData.force; + // default action + var recs = this.getSelection(); + if (recs.length == 0) return; + if (this.msgDelete != '' && !force) { + w2confirm({ + title : w2utils.lang('Delete Confirmation'), + msg : obj.msgDelete, + btn_yes : { "class": 'btn-red' }, + callBack: function (result) { + if (result == 'Yes') w2ui[obj.name].delete(true); + } + }); + return; + } + // call delete script + var url = (typeof this.url != 'object' ? this.url : this.url.remove); + if (url) { + this.request('delete-records'); + } else { + this.selectNone(); + if (typeof recs[0] != 'object') { + this.remove.apply(this, recs); + } else { + // clear cells + for (var r in recs) { + var fld = this.columns[recs[r].column].field; + var ind = this.get(recs[r].recid, true); + if (ind != null && fld != 'recid') { + this.records[ind][fld] = ''; + if (this.records[ind].changes) delete this.records[ind].changes[fld]; + } + } + this.refresh(); + } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + click: function (recid, event) { + var time = (new Date()).getTime(); + var column = null; + if (this.last.cancelClick == true || (event && event.altKey)) return; + if (typeof recid == 'object') { + column = recid.column; + recid = recid.recid; + } + if (typeof event == 'undefined') event = {}; + // check for double click + if (time - parseInt(this.last.click_time) < 350 && event.type == 'click') { + this.dblClick(recid, event); + return; + } + this.last.click_time = time; + // column user clicked on + if (column == null && event.target) { + var tmp = event.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'click', recid: recid, column: column, originalEvent: event }); + if (eventData.isCancelled === true) return; + // if it is subgrid unselect top grid + var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).parents('tr'); + if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var grid = parent.parents('.w2ui-grid').attr('name'); + w2ui[grid].selectNone(); + // all subgrids + parent.parents('.w2ui-grid').find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { + var grid = $(el).attr('name'); + if (w2ui[grid]) w2ui[grid].selectNone(); + }); + } + // unselect all subgrids + $(this.box).find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { + var grid = $(el).attr('name'); + if (w2ui[grid]) w2ui[grid].selectNone(); + }); + // default action + var obj = this; + var sel = this.getSelection(); + $('#grid_'+ this.name +'_check_all').prop("checked", false); + var ind = this.get(recid, true); + var record = this.records[ind]; + var selectColumns = []; + obj.last.sel_ind = ind; + obj.last.sel_col = column; + obj.last.sel_recid = recid; + obj.last.sel_type = 'click'; + // multi select with shif key + if (event.shiftKey && sel.length > 0 && obj.multiSelect) { + if (sel[0].recid) { + var start = this.get(sel[0].recid, true); + var end = this.get(recid, true); + if (column > sel[0].column) { + var t1 = sel[0].column; + var t2 = column; + } else { + var t1 = column; + var t2 = sel[0].column; + } + for (var c = t1; c <= t2; c++) selectColumns.push(c); + } else { + var start = this.get(sel[0], true); + var end = this.get(recid, true); + } + var sel_add = [] + if (start > end) { var tmp = start; start = end; end = tmp; } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + for (var i = start; i <= end; i++) { + if (this.searchData.length > 0 && !url && $.inArray(i, this.last.searchIds) == -1) continue; + if (this.selectType == 'row') { + sel_add.push(this.records[i].recid); + } else { + for (var sc in selectColumns) sel_add.push({ recid: this.records[i].recid, column: selectColumns[sc] }); + } + //sel.push(this.records[i].recid); + } + this.select.apply(this, sel_add); + } else { + var last = this.last.selection; + var flag = (last.indexes.indexOf(ind) != -1 ? true : false); + // clear other if necessary + if (((!event.ctrlKey && !event.shiftKey && !event.metaKey) || !this.multiSelect) && !this.showSelectColumn) { + if (this.selectType != 'row' && $.inArray(column, last.columns[ind]) == -1) flag = false; + if (sel.length > 300) this.selectNone(); else this.unselect.apply(this, sel); + if (flag === true) { + this.unselect({ recid: recid, column: column }); + } else { + this.select({ recid: recid, column: column }); + } + } else { + if (this.selectType != 'row' && $.inArray(column, last.columns[ind]) == -1) flag = false; + if (flag === true) { + this.unselect({ recid: recid, column: column }); + } else { + this.select({ recid: recid, column: column }); + } + } + } + this.status(); + obj.initResize(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - getSearchesHTML: function () { - var html = ''; - var showBtn = false; - for (var i = 0; i < this.searches.length; i++) { - var s = this.searches[i]; - if (s.hidden) continue; - var btn = ''; - if (showBtn == false) { - btn = ''; - showBtn = true; - } - if (typeof s.inTag == 'undefined') s.inTag = ''; - if (typeof s.outTag == 'undefined') s.outTag = ''; - if (typeof s.type == 'undefined') s.type = 'text'; - if (s.type == 'text') { - var operator = ''+ - ' '+ w2utils.lang('is') +''+ - ' '+ w2utils.lang('begins with') +''+ - ' '+ w2utils.lang('contains') +''+ - ' '+ w2utils.lang('ends with') +''+ - ''; - } - if (s.type == 'int' || s.type == 'float' || s.type == 'date') { - var operator = ''+ - ' '+ w2utils.lang('is') +''+ - (s.type == 'date' ? '' : ''+ w2utils.lang('in') +'')+ - ' '+ w2utils.lang('between') +''+ - ''; - } - if (s.type == 'list') { - var operator = 'is '; - } - html += ''+ - ' '+ btn +'' + - ' '+ s.caption +'' + - ' '+ operator +''+ - ' '; - - switch (s.type) { - case 'alphaNumeric': - case 'text': - html += ''; - break; - - case 'int': - case 'float': - case 'hex': - case 'money': - case 'date': - html += ''+ - ''+ - ' - '+ - ''; - break; - - case 'list': - html += ''; - break; + columnClick: function (field, event) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'columnClick', target: this.name, field: field, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behaviour + var column = this.getColumn(field); + if (column.sortable) this.sort(field, null, (event && (event.ctrlKey || event.metaKey) ? true : false) ); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - } - html += s.outTag + - ' ' + - ''; - } - html += ''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''; - return html; - }, + keydown: function (event) { + // this method is called from w2utils + var obj = this; + if (obj.keyboard !== true) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behavior + var empty = false; + var records = $('#grid_'+ obj.name +'_records'); + var sel = obj.getSelection(); + if (sel.length == 0) empty = true; + var recid = sel[0] || null; + var columns = []; + var recid2 = sel[sel.length-1]; + if (typeof recid == 'object' && recid != null) { + recid = sel[0].recid; + columns = []; + var ii = 0; + while (true) { + if (!sel[ii] || sel[ii].recid != recid) break; + columns.push(sel[ii].column); + ii++; + } + recid2 = sel[sel.length-1].recid; + } + var ind = obj.get(recid, true); + var ind2 = obj.get(recid2, true); + var rec = obj.get(recid); + var recEL = $('#grid_'+ obj.name +'_rec_'+ (ind !== null ? w2utils.escapeId(obj.records[ind].recid) : 'none')); + var cancel = false; + var key = event.keyCode; + var shiftKey= event.shiftKey; + if (key == 9) { // tab key + if (event.shiftKey) key = 37; else key = 39; // replace with arrows + shiftKey = false; + cancel = true; + } + switch (key) { + case 8: // backspace + case 46: // delete + if (this.show.toolbarDelete) obj["delete"](); + cancel = true; + event.stopPropagation(); + break; - getColumnsHTML: function () { - var obj = this; - var html = ''; - if (this.show.columnHeaders) { - if (this.columnGroups.length > 0) { - html = getColumns(true) + getGroups() + getColumns(false); - } else { - html = getColumns(true); - } - } - return html; - - function getGroups () { - var html = ''; - // add empty group at the end - if (obj.columnGroups[obj.columnGroups.length-1].caption != '') obj.columnGroups.push({ caption: '' }); - - if (obj.show.lineNumbers) { - html += ''+ - ' '+ - ''; - } - if (obj.show.selectColumn) { - html += ''+ - ' '+ - ''; - } - if (obj.show.expandColumn) { - html += ''+ - ' '+ - ''; - } - var ii = 0; - for (var i=0; i'; - } - html += ''+ - resizer + - ' '+ - (col.caption == '' ? ' ' : col.caption) + - ' '+ - ''; - } else { - html += ''+ - ' '+ - (colg.caption == '' ? ' ' : colg.caption) + - ' '+ - ''; - } - ii += colg.span; - } - html += ''; - return html; - } - - function getColumns (master) { - var html = ''; - if (obj.show.lineNumbers) { - html += ''+ - ' #'+ - ''; - } - if (obj.show.selectColumn) { - html += ''+ - ' '+ - ' '+ - ' '+ - ''; - } - if (obj.show.expandColumn) { - html += ''+ - ' '+ - ''; - } - var ii = 0; - var id = 0; - for (var i=0; i'; - } - html += ''+ - resizer + - ' '+ - (col.caption == '' ? ' ' : col.caption) + - ' '+ - ''; - } - } - html += ' '; - html += ''; - return html; - } - }, + case 27: // escape + obj.selectNone(); + if (sel.length > 0 && typeof sel[0] == 'object') { + obj.select({ recid: sel[0].recid, column: sel[0].column }); + } + cancel = true; + break; + + case 65: // cmd + A + if (!event.metaKey && !event.ctrlKey) break; + obj.selectAll(); + cancel = true; + break; + + case 70: // cmd + F + if (!event.metaKey && !event.ctrlKey) break; + $('#grid_'+ obj.name + '_search_all').focus(); + cancel = true; + break; + + case 13: // enter + // if expandable columns - expand it + if (this.selectType == 'row' && obj.show.expandColumn === true) { + if (recEL.length <= 0) break; + obj.toggle(recid, event); + cancel = true; + } else { // or enter edit + for (var c in this.columns) { + if (this.columns[c].editable) { + columns.push(parseInt(c)); + break; + } + } + // edit last column that was edited + if (this.selectType == 'row' && this.last.edit_col) columns = [this.last.edit_col]; + if (columns.length > 0) { + obj.editField(recid, columns[0], null, event); + cancel = true; + } + } + break; + + case 37: // left + if (empty) break; + // check if this is subgrid + var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)).parents('tr'); + if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.prev().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].set(recid, { expanded: false }); + w2ui[grid].collapse(recid); + w2ui[grid].click(recid); + cancel = true; + break; + } + if (this.selectType == 'row') { + if (recEL.length <= 0 || rec.expanded !== true ) break; + obj.set(recid, { expanded: false }, true); + obj.collapse(recid, event); + } else { + var prev = obj.prevCell(columns[0]); + if (prev != null) { + if (shiftKey && obj.multiSelect) { + if (tmpUnselect()) return; + var tmp = []; + var newSel = []; + var unSel = []; + if (columns.indexOf(this.last.sel_col) == 0 && columns.length > 1) { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + unSel.push({ recid: sel[i].recid, column: columns[columns.length-1] }); + } + } else { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + newSel.push({ recid: sel[i].recid, column: prev }); + } + } + obj.unselect.apply(obj, unSel); + obj.select.apply(obj, newSel); + } else { + event.shiftKey = false; + obj.click({ recid: recid, column: prev }, event); + } + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=1; s 1) { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + unSel.push({ recid: sel[i].recid, column: columns[0] }); + } + } else { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + newSel.push({ recid: sel[i].recid, column: next }); + } + } + obj.unselect.apply(obj, unSel); + obj.select.apply(obj, newSel); + } else { + obj.click({ recid: recid, column: next }, event); + } + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=0; s 0 && w2ui[subgrid.attr('name')]) { + obj.selectNone(); + var grid = subgrid.attr('name'); + var recs = w2ui[grid].records; + w2utils.keyboard.active(grid); + w2ui[grid].click(recs[recs.length-1].recid); + cancel = true; + break; + } + } + if (shiftKey && obj.multiSelect) { // expand selection + if (tmpUnselect()) return; + if (obj.selectType == 'row') { + if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { + obj.unselect(obj.records[ind2].recid); + } else { + obj.select(obj.records[prev].recid); + } + } else { + if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { + prev = ind2; + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); + obj.unselect.apply(obj, tmp); + } else { + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); + obj.select.apply(obj, tmp); + } + } + } else { // move selected record + obj.selectNone(); + obj.click({ recid: obj.records[prev].recid, column: columns[0] }, event); + } + obj.scrollIntoView(prev); + if (event.preventDefault) event.preventDefault(); + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=1; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.prev().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].click(recid); + cancel = true; + break; + } + } + break; + + case 40: // down + if (empty) selectTopRecord(); + if (recEL.length <= 0) break; + // jump into subgrid + if (obj.records[ind2].expanded) { + var subgrid = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind2].recid) +'_expanded_row').find('.w2ui-grid'); + if (subgrid.length > 0 && w2ui[subgrid.attr('name')]) { + obj.selectNone(); + var grid = subgrid.attr('name'); + var recs = w2ui[grid].records; + w2utils.keyboard.active(grid); + w2ui[grid].click(recs[0].recid); + cancel = true; + break; + } + } + // move to the next record + var next = obj.nextRow(ind2); + if (next != null) { + if (shiftKey && obj.multiSelect) { // expand selection + if (tmpUnselect()) return; + if (obj.selectType == 'row') { + if (this.last.sel_ind < next && this.last.sel_ind != ind) { + obj.unselect(obj.records[ind].recid); + } else { + obj.select(obj.records[next].recid); + } + } else { + if (this.last.sel_ind < next && this.last.sel_ind != ind) { + next = ind; + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); + obj.unselect.apply(obj, tmp); + } else { + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); + obj.select.apply(obj, tmp); + } + } + } else { // move selected record + obj.selectNone(); + obj.click({ recid: obj.records[next].recid, column: columns[0] }, event); + } + obj.scrollIntoView(next); + cancel = true; + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=0; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.next().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].click(recid); + cancel = true; + break; + } + } + break; + + // copy & paste + + case 17: // ctrl key + case 91: // cmd key + if (empty) break; + var text = obj.copy(); + $('body').append(''+ text +''); + $('#_tmp_copy_data').focus().select(); + // remove _tmp_copy_data textarea + $(document).on('keyup', tmp_key_down); + function tmp_key_down() { + $('#_tmp_copy_data').remove(); + $(document).off('keyup', tmp_key_down); + } + break; + + case 88: // x - cut + if (empty) break; + if (event.ctrlKey || event.metaKey) { + setTimeout(function () { obj["delete"](true); }, 100); + } + break; + } + var tmp = [187, 189, 32]; // =-spacebar + for (var i=48; i<=90; i++) tmp.push(i); // 0-9,a-z,A-Z + if (tmp.indexOf(key) != -1 && !event.ctrlKey && !event.metaKey && !cancel) { + if (columns.length == 0) columns.push(0); + var tmp = String.fromCharCode(key); + if (key == 187) tmp = '='; + if (key == 189) tmp = '-'; + if (!shiftKey) tmp = tmp.toLowerCase(); + obj.editField(recid, columns[0], tmp, event); + cancel = true; + } + if (cancel) { // cancel default behaviour + if (event.preventDefault) event.preventDefault(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + + function selectTopRecord() { + var ind = Math.floor((records[0].scrollTop + (records.height() / 2.1)) / obj.recordHeight); + if (!obj.records[ind]) ind = 0; + obj.select({ recid: obj.records[ind].recid, column: 0}); + } + + function tmpUnselect () { + if (obj.last.sel_type != 'click') return false; + if (obj.selectType != 'row') { + obj.last.sel_type = 'key'; + if (sel.length > 1) { + for (var s in sel) { + if (sel[s].recid == obj.last.sel_recid && sel[s].column == obj.last.sel_col) { + sel.splice(s, 1); + break; + } + } + obj.unselect.apply(obj, sel); + return true; + } + return false; + } else { + obj.last.sel_type = 'key'; + if (sel.length > 1) { + sel.splice(sel.indexOf(obj.records[obj.last.sel_ind].recid), 1); + obj.unselect.apply(obj, sel); + return true; + } + return false; + } + } + }, + + scrollIntoView: function (ind) { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + if (typeof ind == 'undefined') { + var sel = this.getSelection(); + if (sel.length == 0) return; + ind = this.get(sel[0], true); + } + var records = $('#grid_'+ this.name +'_records'); + if (buffered == 0) return; + // if all records in view + var len = this.last.searchIds.length; + if (records.height() > this.recordHeight * (len > 0 ? len : buffered)) return; + if (len > 0) ind = this.last.searchIds.indexOf(ind); // if seach is applied + // scroll to correct one + var t1 = Math.floor(records[0].scrollTop / this.recordHeight); + var t2 = t1 + Math.floor(records.height() / this.recordHeight); + if (ind == t1) records.animate({ 'scrollTop': records.scrollTop() - records.height() / 1.3 }, 250, 'linear'); + if (ind == t2) records.animate({ 'scrollTop': records.scrollTop() + records.height() / 1.3 }, 250, 'linear'); + if (ind < t1 || ind > t2) records.animate({ 'scrollTop': (ind - 1) * this.recordHeight }); + }, + + dblClick: function (recid, event) { + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // find columns + var column = null; + if (typeof recid == 'object') { + column = recid.column; + recid = recid.recid; + } + if (typeof event == 'undefined') event = {}; + // column user clicked on + if (column == null && event.target) { + var tmp = event.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + column = parseInt($(tmp).attr('col')); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'dblClick', recid: recid, column: column, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + this.selectNone(); + var col = this.columns[column]; + if (col && $.isPlainObject(col.editable)) { + this.editField(recid, column, null, event); + } else { + this.select({ recid: recid, column: column }); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + contextMenu: function (recid, event) { + var obj = this; + if (obj.last.userSelect == 'text') return; + if (typeof event == 'undefined') event = { offsetX: 0, offsetY: 0, target: $('#grid_'+ obj.name +'_rec_'+ recid)[0] }; + if (typeof event.offsetX === 'undefined') { + event.offsetX = event.layerX - event.target.offsetLeft; + event.offsetY = event.layerY - event.target.offsetTop; + } + if (w2utils.isFloat(recid)) recid = parseFloat(recid); + if (this.getSelection().indexOf(recid) == -1) obj.click(recid); + // need timeout to allow click to finish first + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: obj.name, originalEvent: event, recid: recid }); + if (eventData.isCancelled === true) return; + // default action + if (obj.menu.length > 0) { + $(obj.box).find(event.target) + .w2menu(obj.menu, { + left : event.offsetX, + onSelect: function (event) { + obj.menuClick(recid, parseInt(event.index), event.originalEvent); + } + } + ); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 150); // need timer 150 for FF + // cancel event + if (event.preventDefault) event.preventDefault(); + }, + + menuClick: function (recid, index, event) { + var obj = this; + // event before + var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: obj.name, originalEvent: event, + recid: recid, menuIndex: index, menuItem: obj.menu[index] }); + if (eventData.isCancelled === true) return; + // default action + // -- empty + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + toggle: function (recid) { + var rec = this.get(recid); + if (rec.expanded === true) return this.collapse(recid); else return this.expand(recid); + }, + + expand: function (recid) { + var rec = this.get(recid); + var obj = this; + var id = w2utils.escapeId(recid); + if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length > 0) return false; + if (rec.expanded == 'none') return false; + // insert expand row + var tmp = 1 + (this.show.selectColumn ? 1 : 0); + var addClass = ''; // ($('#grid_'+this.name +'_rec_'+ w2utils.escapeId(recid)).hasClass('w2ui-odd') ? 'w2ui-odd' : 'w2ui-even'); + $('#grid_'+ this.name +'_rec_'+ id).after( + ''+ + (this.show.lineNumbers ? '' : '') + + ' '+ + ' '+ + ' '+ + ' '+ + ''); + // event before + var eventData = this.trigger({ phase: 'before', type: 'expand', target: this.name, recid: recid, + box_id: 'grid_'+ this.name +'_rec_'+ recid +'_expanded', ready: ready }); + if (eventData.isCancelled === true) { + $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').remove(); + return; + } + // default action + $('#grid_'+ this.name +'_rec_'+ id).attr('expanded', 'yes').addClass('w2ui-expanded'); + $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').show(); + $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html(''); + rec.expanded = true; + // check if height of expanded row > 5 then remove spinner + setTimeout(ready, 300); + function ready() { + var div1 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded'); + var div2 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row .w2ui-expanded1 > div'); + if (div1.height() < 5) return; + div1.css('opacity', 1); + div2.show().css('opacity', 1); + $('#grid_'+ obj.name +'_cell_'+ obj.get(recid, true) +'_expand div').html('-'); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.resizeRecords(); + return true; + }, + + collapse: function (recid) { + var rec = this.get(recid); + var obj = this; + var id = w2utils.escapeId(recid); + if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length == 0) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'collapse', target: this.name, recid: recid, + box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded' }); + if (eventData.isCancelled === true) return; + // default action + $('#grid_'+ this.name +'_rec_'+ id).removeAttr('expanded').removeClass('w2ui-expanded'); + $('#grid_'+ this.name +'_rec_'+ id +'_expanded').css('opacity', 0); + $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html('+'); + setTimeout(function () { + $('#grid_'+ obj.name +'_rec_'+ id +'_expanded').height('0px'); + setTimeout(function () { + $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row').remove(); + delete rec.expanded; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resizeRecords(); + }, 300); + }, 200); + return true; + }, + + sort: function (field, direction, multiField) { // if no params - clears sort + // event before + var eventData = this.trigger({ phase: 'before', type: 'sort', target: this.name, field: field, direction: direction, multiField: multiField }); + if (eventData.isCancelled === true) return; + // check if needed to quit + if (typeof field != 'undefined') { + // default action + var sortIndex = this.sortData.length; + for (var s in this.sortData) { + if (this.sortData[s].field == field) { sortIndex = s; break; } + } + if (typeof direction == 'undefined' || direction == null) { + if (typeof this.sortData[sortIndex] == 'undefined') { + direction = 'asc'; + } else { + switch (String(this.sortData[sortIndex].direction)) { + case 'asc' : direction = 'desc'; break; + case 'desc' : direction = 'asc'; break; + default : direction = 'asc'; break; + } + } + } + if (this.multiSort === false) { this.sortData = []; sortIndex = 0; } + if (multiField != true) { this.sortData = []; sortIndex = 0; } + // set new sort + if (typeof this.sortData[sortIndex] == 'undefined') this.sortData[sortIndex] = {}; + this.sortData[sortIndex].field = field; + this.sortData[sortIndex].direction = direction; + } else { + this.sortData = []; + } + this.selectNone(); + // if local + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + if (this.searchData.length > 0) this.localSearch(true); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + } else { + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.last.xhr_offset = 0; + this.reload(); + } + }, + + copy: function () { + var sel = this.getSelection(); + if (sel.length == 0) return ''; + var text = ''; + if (typeof sel[0] == 'object') { // cell copy + // find min/max column + var minCol = sel[0].column; + var maxCol = sel[0].column; + var recs = []; + for (var s in sel) { + if (sel[s].column < minCol) minCol = sel[s].column; + if (sel[s].column > maxCol) maxCol = sel[s].column; + if (recs.indexOf(sel[s].index) == -1) recs.push(sel[s].index); + } + recs.sort(); + for (var r in recs) { + var ind = recs[r]; + for (var c = minCol; c <= maxCol; c++) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + } + } else { // row copy + // copy headers + for (var c in this.columns) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += '"' + w2utils.stripTags(col.caption ? col.caption : col.field) + '"\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + // copy selected text + for (var s in sel) { + var ind = this.get(sel[s], true); + for (var c in this.columns) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += '"' + w2utils.stripTags(this.getCellHTML(ind, c)) + '"\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + } + } + text = text.substr(0, text.length - 1); + // before event + var eventData = this.trigger({ phase: 'before', type: 'copy', target: this.name, text: text }); + if (eventData.isCancelled === true) return ''; + text = eventData.text; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return text; + }, + + paste: function (text) { + var sel = this.getSelection(); + var ind = this.get(sel[0].recid, true); + var col = sel[0].column; + // before event + var eventData = this.trigger({ phase: 'before', type: 'paste', target: this.name, text: text, index: ind, column: col }); + if (eventData.isCancelled === true) return; + text = eventData.text; + // default action + if (this.selectType == 'row' || sel.length == 0) { + console.log('ERROR: You can paste only if grid.selectType = \'cell\' and when at least one cell selected.'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return; + } + var newSel = []; + var text = text.split('\n'); + for (var t in text) { + var tmp = text[t].split('\t'); + var cnt = 0; + var rec = this.records[ind]; + var cols = []; + for (var dt in tmp) { + if (!this.columns[col + cnt]) continue; + var field = this.columns[col + cnt].field; + rec.changes = rec.changes || {}; + rec.changes[field] = tmp[dt]; + cols.push(col + cnt); + cnt++; + } + for (var c in cols) newSel.push({ recid: rec.recid, column: cols[c] }); + ind++; + } + this.selectNone(); + this.select.apply(this, newSel); + this.refresh(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // ================================================== + // --- Common functions + + resize: function () { + var obj = this; + var time = (new Date()).getTime(); + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // make sure the box is right + if (!this.box || $(this.box).attr('name') != this.name) return; + // determine new width and height + $(this.box).find('> div') + .css('width', $(this.box).width()) + .css('height', $(this.box).height()); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; + // resize + obj.resizeBoxes(); + obj.resizeRecords(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, + + refreshCell: function (recid, field) { + var index = this.get(recid, true); + var isSummary = (this.records[index] && this.records[index].recid == recid ? false : true); + var col_ind = this.getColumn(field, true); + var rec = (isSummary ? this.summary[index] : this.records[index]); + var col = this.columns[col_ind]; + var cell = $('#grid_'+ this.name + '_rec_'+ recid +' [col='+ col_ind +']'); + // set cell html and changed flag + cell.html(this.getCellHTML(index, col_ind, isSummary)); + if (rec.changes && typeof rec.changes[col.field] != 'undefined') { + cell.addClass('w2ui-changed'); + } else { + cell.removeClass('w2ui-changed'); + } + }, + + refreshRow: function (recid) { + var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (tr.length != 0) { + var ind = this.get(recid, true); + var line = tr.attr('line'); + var isSummary = (this.records[ind] && this.records[ind].recid == recid ? false : true); + // if it is searched, find index in search array + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (this.searchData.length > 0 && !url) for (var s in this.last.searchIds) if (this.last.searchIds[s] == ind) ind = s; + $(tr).replaceWith(this.getRecordHTML(ind, line, isSummary)); + if (isSummary) this.resize(); + } + }, + + refresh: function () { + var obj = this; + var time = (new Date()).getTime(); + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (this.total <= 0 && !url && this.searchData.length == 0) { + this.total = this.records.length; + } + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + this.toolbar.disable('w2ui-edit', 'w2ui-delete'); + if (!this.box) return; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh' }); + if (eventData.isCancelled === true) return; + // -- header + if (this.show.header) { + $('#grid_'+ this.name +'_header').html(this.header +' ').show(); + } else { + $('#grid_'+ this.name +'_header').hide(); + } + // -- toolbar + if (this.show.toolbar) { + // if select-collumn is checked - no toolbar refresh + if (this.toolbar && this.toolbar.get('w2ui-column-on-off') && this.toolbar.get('w2ui-column-on-off').checked) { + // no action + } else { + $('#grid_'+ this.name +'_toolbar').show(); + // refresh toolbar all but search field + if (typeof this.toolbar == 'object') { + var tmp = this.toolbar.items; + for (var t in tmp) { + if (tmp[t].id == 'w2ui-search' || tmp[t].type == 'break') continue; + this.toolbar.refresh(tmp[t].id); + } + } + } + } else { + $('#grid_'+ this.name +'_toolbar').hide(); + } + // -- make sure search is closed + this.searchClose(); + // search placeholder + var el = $('#grid_'+ obj.name +'_search_all'); + if (!this.multiSearch && this.last.field == 'all' && this.searches.length > 0) { + this.last.field = this.searches[0].field; + this.last.caption = this.searches[0].caption; + } + for (var s in this.searches) { + if (this.searches[s].field == this.last.field) this.last.caption = this.searches[s].caption; + } + if (this.last.multi) { + el.attr('placeholder', '[' + w2utils.lang('Multiple Fields') + ']'); + } else { + el.attr('placeholder', this.last.caption); + } + if (el.val() != this.last.search) { + var val = this.last.search; + var tmp = el.data('w2field'); + if (tmp) val = tmp.format(val); + el.val(val); + } + + // -- separate summary + var tmp = this.find({ summary: true }, true); + if (tmp.length > 0) { + for (var t in tmp) this.summary.push(this.records[tmp[t]]); + for (var t=tmp.length-1; t>=0; t--) this.records.splice(tmp[t], 1); + this.total = this.total - tmp.length; + } + + // -- body + var bodyHTML = ''; + bodyHTML += ''+ + this.getRecordsHTML() + + ''+ + ''+ + ' '+ this.getColumnsHTML() +''+ + ''; // Columns need to be after to be able to overlap + $('#grid_'+ this.name +'_body').html(bodyHTML); + // show summary records + if (this.summary.length > 0) { + $('#grid_'+ this.name +'_summary').html(this.getSummaryHTML()).show(); + } else { + $('#grid_'+ this.name +'_summary').hide(); + } + // -- footer + if (this.show.footer) { + $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()).show(); + } else { + $('#grid_'+ this.name +'_footer').hide(); + } + // show/hide clear search link + if (this.searchData.length > 0) { + $('#grid_'+ this.name +'_searchClear').show(); + } else { + $('#grid_'+ this.name +'_searchClear').hide(); + } + // all selected? + var sel = this.last.selection; + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + // show number of selected + this.status(); + // collapse all records + var rows = obj.find({ expanded: true }, true); + for (var r in rows) obj.records[rows[r]].expanded = false; + // mark selection + setTimeout(function () { + var str = $.trim($('#grid_'+ obj.name +'_search_all').val()); + if (str != '') $(obj.box).find('.w2ui-grid-data > div').w2marker(str); + }, 50); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + obj.addRange('selection'); + setTimeout(function () { obj.resize(); obj.scroll(); }, 1); // allow to render first + + if ( obj.reorderColumns && !obj.last.columnDrag ) { + obj.last.columnDrag = obj.initColumnDrag(); + } else if ( !obj.reorderColumns && obj.last.columnDrag ) { + obj.last.columnDrag.remove(); + } + + return (new Date()).getTime() - time; + }, + + render: function (box) { + var obj = this; + var time = (new Date()).getTime(); + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof box != 'undefined' && box != null) { + if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-grid') + .html(''); + } + this.box = box; + } + if (!this.box) return; + if (this.last.sortData == null) this.last.sortData = this.sortData; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: box }); + if (eventData.isCancelled === true) return; + // insert Elements + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-grid') + .html(''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''); + if (this.selectType != 'row') $(this.box).addClass('w2ui-ss'); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // init toolbar + this.initToolbar(); + if (this.toolbar != null) this.toolbar.render($('#grid_'+ this.name +'_toolbar')[0]); + // reinit search_all + if (this.last.field && this.last.field != 'all') { + var sd = this.searchData; + this.initAllField(this.last.field, (sd.length == 1 ? sd[0].value : null)); + } + // init footer + $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()); + // refresh + if (!this.last.state) this.last.state = this.stateSave(true); // initial default state + this.stateRestore(); + if (this.url) this.refresh(); // show empty grid (need it) - should it be only for remote data source + this.reload(); + + // init mouse events for mouse selection + $(this.box).on('mousedown', mouseStart); + $(this.box).on('selectstart', function () { return false; }); // fixes chrome cursor bug + + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // attach to resize event + if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event + this.tmp_resize = function (event) { w2ui[obj.name].resize(); } + $(window).off('resize', this.tmp_resize).on('resize', this.tmp_resize); + } + return (new Date()).getTime() - time; + + function mouseStart (event) { + if (event.which != 1) return; // if not left mouse button + // restore css user-select + if (obj.last.userSelect == 'text') { + delete obj.last.userSelect; + $(obj.box).find('.w2ui-grid-body') + .css('user-select', 'none') + .css('-webkit-user-select', 'none') + .css('-moz-user-select', 'none') + .css('-ms-user-select', 'none'); + $(this.box).on('selectstart', function () { return false; }); + } + // regular record select + if ($(event.target).parents().hasClass('w2ui-head') || $(event.target).hasClass('w2ui-head')) return; + if (obj.last.move && obj.last.move.type == 'expand') return; + // if altKey - alow text selection + if (event.altKey) { + $(obj.box).off('selectstart'); + $(obj.box).find('.w2ui-grid-body') + .css('user-select', 'text') + .css('-webkit-user-select', 'text') + .css('-moz-user-select', 'text') + .css('-ms-user-select', 'text'); + obj.selectNone(); + obj.last.move = { type: 'text-select' }; + obj.last.userSelect = 'text'; + } else { + if (!obj.multiSelect) return; + obj.last.move = { + x : event.screenX, + y : event.screenY, + divX : 0, + divY : 0, + recid : $(event.target).parents('tr').attr('recid'), + column : (event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')), + type : 'select', + ghost : false, + start : true + }; + } + $(document).on('mousemove', mouseMove); + $(document).on('mouseup', mouseStop); + } + + function mouseMove (event) { + var mv = obj.last.move; + if (!mv || mv.type != 'select') return; + mv.divX = (event.screenX - mv.x); + mv.divY = (event.screenY - mv.y); + if (Math.abs(mv.divX) <= 1 && Math.abs(mv.divY) <= 1) return; // only if moved more then 1px + obj.last.cancelClick = true; + if (obj.reorderRows == true) { + if (!mv.ghost) { + var row = $('#grid_'+ obj.name + '_rec_'+ mv.recid); + var tmp = row.parents('table').find('tr:first-child').clone(); + mv.offsetY = event.offsetY; + mv.from = mv.recid; + mv.pos = row.position(); + mv.ghost = $(row).clone(true); + mv.ghost.removeAttr('id'); + row.find('td:first-child').replaceWith(''); + var recs = $(obj.box).find('.w2ui-grid-records'); + recs.append(''); + $('#grid_'+ obj.name + '_ghost').append(tmp).append(mv.ghost); + } + var recid = $(event.target).parents('tr').attr('recid'); + if (recid != mv.from) { + var row1 = $('#grid_'+ obj.name + '_rec_'+ mv.recid); + var row2 = $('#grid_'+ obj.name + '_rec_'+ recid); + if (event.screenY - mv.lastY < 0) row1.after(row2); else row2.after(row1); + mv.lastY = event.screenY; + mv.to = recid; + } + var ghost = $('#grid_'+ obj.name + '_ghost'); + var recs = $(obj.box).find('.w2ui-grid-records'); + ghost.css({ + top : mv.pos.top + mv.divY + recs.scrollTop(), // + mv.offsetY - obj.recordHeight / 2, + left : mv.pos.left + }); + return; + } + if (mv.start && mv.recid) { + obj.selectNone(); + mv.start = false; + } + var newSel= []; + var recid = (event.target.tagName == 'TR' ? $(event.target).attr('recid') : $(event.target).parents('tr').attr('recid')); + if (typeof recid == 'undefined') return; + var ind1 = obj.get(mv.recid, true); + // |:wolfmanx:| this happens when selection is started on summary row + if (ind1 === null) return; + var ind2 = obj.get(recid, true); + // this happens when selection is extended into summary row (a good place to implement scrolling) + if (ind2 === null) return; + var col1 = parseInt(mv.column); + var col2 = parseInt(event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')); + if (ind1 > ind2) { var tmp = ind1; ind1 = ind2; ind2 = tmp; } + // check if need to refresh + var tmp = 'ind1:'+ ind1 +',ind2;'+ ind2 +',col1:'+ col1 +',col2:'+ col2; + if (mv.range == tmp) return; + mv.range = tmp; + for (var i = ind1; i <= ind2; i++) { + if (obj.last.searchIds.length > 0 && obj.last.searchIds.indexOf(i) == -1) continue; + if (obj.selectType != 'row') { + if (col1 > col2) { var tmp = col1; col1 = col2; col2 = tmp; } + var tmp = []; + for (var c = col1; c <= col2; c++) { + if (obj.columns[c].hidden) continue; + newSel.push({ recid: obj.records[i].recid, column: parseInt(c) }); + } + } else { + newSel.push(obj.records[i].recid); + } + } + if (obj.selectType != 'row') { + var sel = obj.getSelection(); + // add more items + var tmp = []; + for (var ns in newSel) { + var flag = false; + for (var s in sel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; + if (!flag) tmp.push({ recid: newSel[ns].recid, column: newSel[ns].column }); + } + obj.select.apply(obj, tmp); + // remove items + var tmp = []; + for (var s in sel) { + var flag = false; + for (var ns in newSel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; + if (!flag) tmp.push({ recid: sel[s].recid, column: sel[s].column }); + } + obj.unselect.apply(obj, tmp); + } else { + if (obj.multiSelect) { + var sel = obj.getSelection(); + for (var ns in newSel) if (sel.indexOf(newSel[ns]) == -1) obj.select(newSel[ns]); // add more items + for (var s in sel) if (newSel.indexOf(sel[s]) == -1) obj.unselect(sel[s]); // remove items + } + } + } + + function mouseStop (event) { + var mv = obj.last.move; + setTimeout(function () { delete obj.last.cancelClick; }, 1); + if ($(event.target).parents().hasClass('.w2ui-head') || $(event.target).hasClass('.w2ui-head')) return; + if (mv && mv.type == 'select') { + if (obj.reorderRows == true) { + var ind1 = obj.get(mv.from, true); + var tmp = obj.records[ind1]; + obj.records.splice(ind1, 1); + var ind2 = obj.get(mv.to, true); + if (ind1 > ind2) obj.records.splice(ind2, 0, tmp); else obj.records.splice(ind2+1, 0, tmp); + $('#grid_'+ obj.name + '_ghost').remove(); + obj.refresh(); + } + } + delete obj.last.move; + $(document).off('mousemove', mouseMove); + $(document).off('mouseup', mouseStop); + } + }, + + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); + if (eventData.isCancelled === true) return; + // remove events + $(window).off('resize', this.tmp_resize); + // clean up + if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); + if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-grid') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // =========================================== + // --- Internal Functions + + initColumnOnOff: function () { + if (!this.show.toolbarColumns) return; + var obj = this; + var col_html = ''+ + ''+ + ''+ + ' '+ + ''+ + ''+ + ' '+ w2utils.lang('Line #') +''+ + ''; + for (var c in this.columns) { + var col = this.columns[c]; + var tmp = this.columns[c].caption; + if (col.hideable === false) continue; + if (!tmp && this.columns[c].hint) tmp = this.columns[c].hint; + if (!tmp) tmp = '- column '+ (parseInt(c) + 1) +' -'; + col_html += ''+ + ''+ + ' '+ + ''+ + ''+ + ' '+ tmp + ''+ + ''+ + ''; + } + col_html += ''; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && obj.show.skipRecords) { + col_html += + ''+ + ' '+ w2utils.lang('Skip') + + ' '+ w2utils.lang('Records')+ + ' '+ + ''; + } + col_html += ''+ + ' '+ w2utils.lang('Save Grid State') + ''+ + ''+ + ''+ + ' '+ w2utils.lang('Restore Default State') + ''+ + ''; + col_html += ""; + this.toolbar.get('w2ui-column-on-off').html = col_html; + }, + + /** + * + * @param box, grid object + * @returns {{remove: Function}} contains a closure around all events to ensure they are removed from the dom + */ + initColumnDrag: function ( box ) { + //throw error if using column groups + if ( this.columnGroups && this.columnGroups.length ) throw 'Draggable columns are not currently supported with column groups.'; + + var obj = this, + _dragData = {}; + _dragData.lastInt = null; + _dragData.pressed = false; + _dragData.timeout = null;_dragData.columnHead = null; + + //attach orginal event listener + $(obj.box).on('mousedown', dragColStart); + $(obj.box).on('mouseup', catchMouseup); + + function catchMouseup(){ + _dragData.pressed = false; + clearTimeout( _dragData.timeout ); + } + /** + * + * @param event, mousedown + * @returns {boolean} false, preventsDefault + */ + function dragColStart ( event ) { + if ( _dragData.timeout ) clearTimeout( _dragData.timeout ); + var self = this; + _dragData.pressed = true; + + _dragData.timeout = setTimeout(function(){ + if ( !_dragData.pressed ) return; + + var eventData, + columns, + selectedCol, + origColumn, + origColumnNumber, + invalidPreColumns = [ 'w2ui-col-number', 'w2ui-col-expand', 'w2ui-col-select' ], + invalidPostColumns = [ 'w2ui-head-last' ], + invalidColumns = invalidPreColumns.concat( invalidPostColumns ), + preColumnsSelector = '.w2ui-col-number, .w2ui-col-expand, .w2ui-col-select', + preColHeadersSelector = '.w2ui-head.w2ui-col-number, .w2ui-head.w2ui-col-expand, .w2ui-head.w2ui-col-select'; + + // do nothing if it is not a header + if ( !$( event.originalEvent.target ).parents().hasClass( 'w2ui-head' ) ) return; + + // do nothing if it is an invalid column + for ( var i = 0, l = invalidColumns.length; i < l; i++ ){ + if ( $( event.originalEvent.target ).parents().hasClass( invalidColumns[ i ] ) ) return; + } + + _dragData.numberPreColumnsPresent = $( obj.box ).find( preColHeadersSelector ).length; + + //start event for drag start + _dragData.columnHead = origColumn = $( event.originalEvent.target ).parents( '.w2ui-head' ); + origColumnNumber = parseInt( origColumn.attr( 'col' ), 10); + eventData = obj.trigger({ type: 'columnDragStart', phase: 'before', originalEvent: event, origColumnNumber: origColumnNumber, target: origColumn[0] }); + if ( eventData.isCancelled === true ) return false; + + columns = _dragData.columns = $( obj.box ).find( '.w2ui-head:not(.w2ui-head-last)' ); + + //add events + $( document ).on( 'mouseup', dragColEnd ); + $( document ).on( 'mousemove', dragColOver ); + + _dragData.originalPos = parseInt( $( event.originalEvent.target ).parent( '.w2ui-head' ).attr( 'col' ), 10 ); + //_dragData.columns.css({ overflow: 'visible' }).children( 'div' ).css({ overflow: 'visible' }); + + //configure and style ghost image + _dragData.ghost = $( self ).clone( true ); + + //hide other elements on ghost except the grid body + $( _dragData.ghost ).find( '[col]:not([col="' + _dragData.originalPos + '"]), .w2ui-toolbar, .w2ui-grid-header' ).remove(); + $( _dragData.ghost ).find( preColumnsSelector ).remove(); + $( _dragData.ghost ).find( '.w2ui-grid-body' ).css({ top: 0 }); + + selectedCol = $( _dragData.ghost ).find( '[col="' + _dragData.originalPos + '"]' ); + $( document.body ).append( _dragData.ghost ); + + $( _dragData.ghost ).css({ + width: 0, + height: 0, + margin: 0, + position: 'fixed', + zIndex: 999999, + opacity: 0 + }).addClass( '.w2ui-grid-ghost' ).animate({ + width: selectedCol.width(), + height: $(obj.box).find('.w2ui-grid-body:first').height(), + left : event.pageX, + top : event.pageY, + opacity: .8 + }, 0 ); + + //establish current offsets + _dragData.offsets = []; + for ( var i = 0, l = columns.length; i < l; i++ ) { + _dragData.offsets.push( $( columns[ i ] ).offset().left ); + } + + //conclude event + obj.trigger( $.extend( eventData, { phase: 'after' } ) ); + }, 150 );//end timeout wrapper + } + + function dragColOver ( event ) { + if ( !_dragData.pressed ) return; + + var cursorX = event.originalEvent.pageX, + cursorY = event.originalEvent.pageY, + offsets = _dragData.offsets, + lastWidth = $( '.w2ui-head:not(.w2ui-head-last)' ).width(); + + _dragData.targetInt = Math.max(_dragData.numberPreColumnsPresent,targetIntersection( cursorX, offsets, lastWidth )); + + markIntersection( _dragData.targetInt ); + trackGhost( cursorX, cursorY ); + } + + function dragColEnd ( event ) { + _dragData.pressed = false; + + var eventData, + target, + selected, + columnConfig, + targetColumn, + ghosts = $( '.w2ui-grid-ghost' ); + + //start event for drag start + eventData = obj.trigger({ type: 'columnDragEnd', phase: 'before', originalEvent: event, target: _dragData.columnHead[0] }); + if ( eventData.isCancelled === true ) return false; + + selected = obj.columns[ _dragData.originalPos ]; + columnConfig = obj.columns; + targetColumn = $( _dragData.columns[ Math.min(_dragData.lastInt, _dragData.columns.length - 1) ] ); + target = (_dragData.lastInt < _dragData.columns.length) ? parseInt(targetColumn.attr('col')) : columnConfig.length; + + if ( target !== _dragData.originalPos + 1 && target !== _dragData.originalPos && targetColumn && targetColumn.length ) { + $( _dragData.ghost ).animate({ + top: $( obj.box ).offset().top, + left: targetColumn.offset().left, + width: 0, + height: 0, + opacity:.2 + }, 300, function(){ + $( this ).remove(); + ghosts.remove(); + }); + + columnConfig.splice( target, 0, $.extend( {}, selected ) ); + columnConfig.splice( columnConfig.indexOf( selected ), 1); + + } else { + $( _dragData.ghost ).remove(); + ghosts.remove(); + } + + //_dragData.columns.css({ overflow: '' }).children( 'div' ).css({ overflow: '' }); + + $( document ).off( 'mouseup', dragColEnd ); + $( document ).off( 'mousemove', dragColOver ); + if ( _dragData.marker ) _dragData.marker.remove(); + _dragData = {}; + + obj.refresh(); + + //conclude event + obj.trigger( $.extend( eventData, { phase: 'after', targetColumnNumber: target - 1 } ) ); + } + + function markIntersection( intersection ){ + if ( !_dragData.marker && !_dragData.markerLeft ) { + _dragData.marker = $('' + + '' + + '' + + ''); + _dragData.markerLeft = $('' + + '' + + '' + + ''); + } + + if ( !_dragData.lastInt || _dragData.lastInt !== intersection ){ + _dragData.lastInt = intersection; + _dragData.marker.remove(); + _dragData.markerLeft.remove(); + $('.w2ui-head').removeClass('w2ui-col-intersection'); + + //if the current intersection is greater than the number of columns add the marker to the end of the last column only + if ( intersection >= _dragData.columns.length ) { + $( _dragData.columns[ _dragData.columns.length - 1 ] ).children( 'div:last' ).append( _dragData.marker.addClass( 'right' ).removeClass( 'left' ) ); + $( _dragData.columns[ _dragData.columns.length - 1 ] ).addClass('w2ui-col-intersection'); + } else if ( intersection <= _dragData.numberPreColumnsPresent ) { + //if the current intersection is on the column numbers place marker on first available column only + $( _dragData.columns[ _dragData.numberPreColumnsPresent ] ).prepend( _dragData.marker.addClass( 'left' ).removeClass( 'right' ) ).css({ position: 'relative' }); + $( _dragData.columns[ _dragData.numberPreColumnsPresent ] ).prev().addClass('w2ui-col-intersection'); + } else { + //otherwise prepend the marker to the targeted column and append it to the previous column + $( _dragData.columns[intersection] ).children( 'div:last' ).prepend( _dragData.marker.addClass( 'left' ).removeClass( 'right' ) ); + $( _dragData.columns[intersection] ).prev().children( 'div:last' ).append( _dragData.markerLeft.addClass( 'right' ).removeClass( 'left' ) ).css({ position: 'relative' }); + $( _dragData.columns[intersection - 1] ).addClass('w2ui-col-intersection'); + } + } + } - getRecordsHTML: function () { - // larget number works better with chrome, smaller with FF. - if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300; - var records = $('#grid_'+ this.name +'_records'); - var limit = Math.floor(records.height() / this.recordHeight) + this.show_extra + 1; - if (!this.fixedBody) limit = this.buffered; - // always need first record for resizing purposes - var html = '' + this.getRecordHTML(-1, 0); - // first empty row with height - html += ''+ - ' '+ - ''; - for (var i = 0; i < limit; i++) { - html += this.getRecordHTML(i, i+1); - } - html += ''+ - ' '+ - ''+ - ''+ - ' '+ - ''+ - ''; - this.last.range_start = 0; - this.last.range_end = limit; - return html; - }, + function targetIntersection( cursorX, offsets, lastWidth ){ + if ( cursorX <= offsets[0] ) { + return 0; + } else if ( cursorX >= offsets[offsets.length - 1] + lastWidth ) { + return offsets.length; + } else { + for ( var i = 0, l = offsets.length; i < l; i++ ) { + var thisOffset = offsets[ i ]; + var nextOffset = offsets[ i + 1 ] || offsets[ i ] + lastWidth; + var midpoint = ( nextOffset - offsets[ i ]) / 2 + offsets[ i ]; + + if ( cursorX > thisOffset && cursorX <= midpoint ) { + return i; + } else if ( cursorX > midpoint && cursorX <= nextOffset ) { + return i + 1; + } + } + return intersection; + } + } - getSummaryHTML: function () { - if (this.summary.length == 0) return; - var html = ''; - for (var i = 0; i < this.summary.length; i++) { - html += this.getRecordHTML(i, i+1, true); - } - html += ''; - return html; - }, + function trackGhost( cursorX, cursorY ){ + $( _dragData.ghost ).css({ + left: cursorX - 10, + top: cursorY - 10 + }); + } - scroll: function (event) { - var time = (new Date()).getTime(); - var obj = this; - var records = $('#grid_'+ this.name +'_records'); - if (this.records.length == 0 || records.length == 0 || records.height() == 0) return; - if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300; - // need this to enable scrolling when this.limit < then a screen can fit - if (records.height() < this.buffered * this.recordHeight && records.css('overflow-y') == 'hidden') { - if (this.total > 0) this.refresh(); - return; - } - // update footer - var t1 = Math.floor(records[0].scrollTop / this.recordHeight + 1); - var t2 = Math.floor(records[0].scrollTop / this.recordHeight + 1) + Math.round(records.height() / this.recordHeight); - if (t1 > this.buffered) t1 = this.buffered; - if (t2 > this.buffered) t2 = this.buffered; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - $('#grid_'+ this.name + '_footer .w2ui-footer-right').html(w2utils.formatNumber(this.offset + t1) + '-' + w2utils.formatNumber(this.offset + t2) + ' ' + w2utils.lang('of') + ' ' + w2utils.formatNumber(this.total) + - (url ? ' ('+ w2utils.lang('buffered') + ' '+ w2utils.formatNumber(this.buffered) + (this.offset > 0 ? ', skip ' + w2utils.formatNumber(this.offset) : '') + ')' : '') - ); - // only for local data source, else no extra records loaded - if (!url && (!this.fixedBody || this.total <= 300)) return; - // regular processing - var start = Math.floor(records[0].scrollTop / this.recordHeight) - this.show_extra; - var end = start + Math.floor(records.height() / this.recordHeight) + this.show_extra * 2 + 1; - // var div = start - this.last.range_start; - if (start < 1) start = 1; - if (end > this.total) end = this.total; - var tr1 = records.find('#grid_'+ this.name +'_rec_top'); - var tr2 = records.find('#grid_'+ this.name +'_rec_bottom'); - // if row is expanded - if (String(tr1.next().prop('id')).indexOf('_expanded_row') != -1) tr1.next().remove(); - if (String(tr2.prev().prop('id')).indexOf('_expanded_row') != -1) tr2.prev().remove(); - var first = parseInt(tr1.next().attr('line')); - var last = parseInt(tr2.prev().attr('line')); - //$('#log').html('buffer: '+ this.buffered +' start-end: ' + start + '-'+ end + ' ===> first-last: ' + first + '-' + last); - if (first < start || first == 1 || this.last.pull_refresh) { // scroll down - //console.log('end', end, 'last', last, 'show_extre', this.show_extra, this.last.pull_refresh); - if (end <= last + this.show_extra - 2 && end != this.total) return; - this.last.pull_refresh = false; - // remove from top - while (true) { - var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); - if (tmp.attr('line') == 'bottom') break; - if (parseInt(tmp.attr('line')) < start) tmp.remove(); else break; - } - // add at bottom - var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); - var rec_start = tmp.attr('line'); - if (rec_start == 'top') rec_start = start; - for (var i = parseInt(rec_start) + 1; i <= end; i++) { - if (!this.records[i-1]) continue; - if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; - tr2.before(this.getRecordHTML(i-1, i)); - } - markSearch(); - setTimeout(function() { obj.refreshRanges(); }, 0); - } else { // scroll up - if (start >= first - this.show_extra + 2 && start > 1) return; - // remove from bottom - while (true) { - var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); - if (tmp.attr('line') == 'top') break; - if (parseInt(tmp.attr('line')) > end) tmp.remove(); else break; - } - // add at top - var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); - var rec_start = tmp.attr('line'); - if (rec_start == 'bottom') rec_start = end; - for (var i = parseInt(rec_start) - 1; i >= start; i--) { - if (!this.records[i-1]) continue; - if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; - tr1.after(this.getRecordHTML(i-1, i)); - } - markSearch(); - setTimeout(function() { obj.refreshRanges(); }, 0); - } - // first/last row size - var h1 = (start - 1) * obj.recordHeight; - var h2 = (this.buffered - end) * obj.recordHeight; - if (h2 < 0) h2 = 0; - tr1.css('height', h1 + 'px'); - tr2.css('height', h2 + 'px'); - obj.last.range_start = start; - obj.last.range_end = end; - // load more if needed - var s = Math.floor(records[0].scrollTop / this.recordHeight); - var e = s + Math.floor(records.height() / this.recordHeight); - if (e + 10 > this.buffered && this.last.pull_more !== true && this.buffered < this.total - this.offset) { - if (this.autoLoad === true) { - this.last.pull_more = true; - this.last.xhr_offset += this.limit; - this.request('get-records'); - } else { - var more = $('#grid_'+ this.name +'_rec_more'); - if (more.css('display') == 'none') { - more.show() - .on('click', function () { - $(this).find('td').html(''); - obj.last.pull_more = true; - obj.last.xhr_offset += obj.limit; - obj.request('get-records'); - }); - } - if (more.find('td').text().indexOf('Load') == -1) { - more.find('td').html('Load '+ obj.limit + ' More...'); - } - } - } - // check for grid end - if (this.buffered >= this.total - this.offset) $('#grid_'+ this.name +'_rec_more').hide(); - return; - - function markSearch() { - // mark search - if(obj.markSearchResults === false) return; - clearTimeout(obj.last.marker_timer); - obj.last.marker_timer = setTimeout(function () { - // mark all search strings - var str = []; - for (var s in obj.searchData) { - var tmp = obj.searchData[s]; - if ($.inArray(tmp.value, str) == -1) str.push(tmp.value); - } - if (str.length > 0) $(obj.box).find('.w2ui-grid-data > div').w2marker(str); - }, 50); - } - }, + //return an object to remove drag if it has ever been enabled + return { + remove: function(){ + $( obj.box ).off( 'mousedown', dragColStart ); + $( obj.box ).off( 'mouseup', catchMouseup ); + $( obj.box ).find( '.w2ui-head' ).removeAttr( 'draggable' ); + obj.last.columnDrag = false; + } + } + }, - getRecordHTML: function (ind, lineNum, summary) { - var rec_html = ''; - // first record needs for resize purposes - if (ind == -1) { - rec_html += ''; - if (this.show.lineNumbers) rec_html += ''; - if (this.show.selectColumn) rec_html += ''; - if (this.show.expandColumn) rec_html += ''; - for (var i in this.columns) { - if (this.columns[i].hidden) continue; - rec_html += ''; - } - rec_html += ''; - rec_html += ''; - return rec_html; - } - // regular record - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (summary !== true) { - if (this.searchData.length > 0 && !url) { - if (ind >= this.last.searchIds.length) return ''; - ind = this.last.searchIds[ind]; - record = this.records[ind]; - } else { - if (ind >= this.records.length) return ''; - record = this.records[ind]; - } - } else { - if (ind >= this.summary.length) return ''; - record = this.summary[ind]; - } - if (!record) return ''; - var id = w2utils.escapeId(record.recid); - var isRowSelected = false; - if (record.selected && this.selectType == 'row') isRowSelected = true; - // render TR - rec_html += ''; - if (this.show.lineNumbers) { - rec_html += ''+ - (summary !== true ? ''+ lineNum +'' : '') + - ''; - } - if (this.show.selectColumn) { - rec_html += - ''+ - (summary !== true ? - ' '+ - ' '+ - ' ' - : - '' ) + - ''; - } - if (this.show.expandColumn) { - var tmp_img = ''; - if (record.expanded === true) tmp_img = '-'; else tmp_img = '+'; - if (record.expanded == 'none') tmp_img = ''; - if (record.expanded == 'spinner') tmp_img = ''; - rec_html += - ''+ - (summary !== true ? - ' '+ - ' '+ tmp_img +' ' - : - '' ) + - ''; - } - var col_ind = 0; - while (true) { - var col = this.columns[col_ind]; - if (col.hidden) { col_ind++; if (typeof this.columns[col_ind] == 'undefined') break; else continue; } - var isChanged = record.changed && record.changes[col.field]; - var rec_cell = this.getCellHTML(ind, col_ind, summary); - var addStyle = ''; - if (typeof col.render == 'string') { - var tmp = col.render.toLowerCase().split(':'); - if ($.inArray(tmp[0], ['number', 'int', 'float', 'money', 'percent']) != -1) addStyle = 'text-align: right'; - if ($.inArray(tmp[0], ['date']) != -1) addStyle = 'text-align: right'; - } - var isCellSelected = false; - if (record.selected && $.inArray(col_ind, record.selectedColumns) != -1) isCellSelected = true; - rec_html += ''+ - rec_cell + - ''; - col_ind++; - if (typeof this.columns[col_ind] == 'undefined') break; - } - rec_html += ''; - rec_html += ''; - // if row is expanded (buggy) - // if (record.expanded === true && $('#grid_'+ this.name +'_rec_'+ record.recid +'_expanded_row').length == 0) { - // var tmp = 1 + (this.show.selectColumn ? 1 : 0); - // rec_html += - // ''+ - // (this.show.lineNumbers ? '' : '') + - // ' '+ - // ' '+ - // ' '+ - // ' '+ - // ''; - // } - return rec_html; - }, + columnOnOff: function (el, event, field) { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'columnOnOff', checkbox: el, field: field, originalEvent: event }); + if (eventData.isCancelled === true) return; + // regular processing + var obj = this; + // collapse expanded rows + for (var r in this.records) { + if (this.records[r].expanded === true) this.records[r].expanded = false + } + // show/hide + var hide = true; + if (field == 'line-numbers') { + this.show.lineNumbers = !this.show.lineNumbers; + this.refresh(); + } else { + var col = this.getColumn(field); + if (col.hidden) { + $(el).prop('checked', true); + this.showColumn(col.field); + } else { + $(el).prop('checked', false); + this.hideColumn(col.field); + } + hide = false; + } + if (hide) { + setTimeout(function () { + $().w2overlay('', { name: 'searches-'+ this.name }); + obj.toolbar.uncheck('column-on-off'); + }, 100); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - getCellHTML: function (ind, col_ind, summary) { - var col = this.columns[col_ind]; - var record = (summary !== true ? this.records[ind] : this.summary[ind]); - var data = this.parseField(record, col.field); - var isChanged = record.changed && typeof record.changes[col.field] != 'undefined'; - if (isChanged) data = record.changes[col.field]; - // various renderers - if (data == null || typeof data == 'undefined') data = ''; - if (typeof col.render != 'undefined') { - if (typeof col.render == 'function') { - data = col.render.call(this, record, ind, col_ind); - if (data.length >= 4 && data.substr(0, 4) != ''; - } - if (typeof col.render == 'object') data = '' + col.render[data] + ''; - if (typeof col.render == 'string') { - var tmp = col.render.toLowerCase().split(':'); - var prefix = ''; - var suffix = ''; - if ($.inArray(tmp[0], ['number', 'int', 'float', 'money', 'percent']) != -1) { - if (typeof tmp[1] == 'undefined' || !w2utils.isInt(tmp[1])) tmp[1] = 0; - if (tmp[1] > 20) tmp[1] = 20; - if (tmp[1] < 0) tmp[1] = 0; - if (tmp[0] == 'money') { tmp[1] = 2; prefix = w2utils.settings.currencySymbol; } - if (tmp[0] == 'percent') { suffix = '%'; if (tmp[1] !== '0') tmp[1] = 1; } - if (tmp[0] == 'int') { tmp[1] = 0; } - // format - data = '' + prefix + w2utils.formatNumber(Number(data).toFixed(tmp[1])) + suffix + ''; - } - if (tmp[0] == 'date') { - if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.date_display; - data = '' + prefix + w2utils.formatDate(data, tmp[1]) + suffix + ''; - } - if (tmp[0] == 'age') { - data = '' + prefix + w2utils.age(data) + suffix + ''; - } - } - } else { - if (!this.show.recordTitles) { - var data = ''+ data +''; - } else { - // title overwrite - var title = String(data).replace(/"/g, "''"); - if (typeof col.title != 'undefined') { - if (typeof col.title == 'function') title = col.title.call(this, record, ind, col_ind); - if (typeof col.title == 'string') title = col.title; - } - var data = ''+ data +''; - } - } - if (data == null || typeof data == 'undefined') data = ''; - return data; - }, + initToolbar: function () { + // -- if toolbar is true + if (typeof this.toolbar['render'] == 'undefined') { + var tmp_items = this.toolbar.items; + this.toolbar.items = []; + this.toolbar = $().w2toolbar($.extend(true, {}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - getFooterHTML: function () { - return ''+ - ' '+ - ' '+ - ' '+ - ''; - }, + // ============================================= + // ------ Toolbar Generic buttons - status: function (msg) { - if (typeof msg != 'undefined') { - $('#grid_'+ this.name +'_footer').find('.w2ui-footer-left').html(msg); - } else { - // show number of selected - var msgLeft = ''; - var sel = this.getSelection(); - if (sel.length > 0) { - msgLeft = String(sel.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' ' + w2utils.lang('selected'); - var tmp = sel[0]; - if (typeof tmp == 'object') tmp = tmp.recid + ', '+ w2utils.lang('Column') +': '+ tmp.column; - if (sel.length == 1) msgLeft = w2utils.lang('Record ID') + ': '+ tmp + ' '; - } - $('#grid_'+ this.name +'_footer .w2ui-footer-left').html(msgLeft); - // toolbar - if (sel.length == 1) this.toolbar.enable('edit'); else this.toolbar.disable('edit'); - if (sel.length >= 1) this.toolbar.enable('delete'); else this.toolbar.disable('delete'); - } - }, + if (this.show.toolbarReload) { + this.toolbar.items.push($.extend(true, {}, this.buttons['reload'])); + } + if (this.show.toolbarColumns) { + this.toolbar.items.push($.extend(true, {}, this.buttons['columns'])); + } + if (this.show.toolbarReload || this.show.toolbarColumn) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break0' }); + } + if (this.show.toolbarSearch) { + var html = + ''+ + ''+ + ' '+ this.buttons['search'].html +''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''+ + ''; + this.toolbar.items.push({ type: 'html', id: 'w2ui-search', html: html }); + if (this.multiSearch && this.searches.length > 0) { + this.toolbar.items.push($.extend(true, {}, this.buttons['search-go'])); + } + } + if (this.show.toolbarSearch && (this.show.toolbarAdd || this.show.toolbarEdit || this.show.toolbarDelete || this.show.toolbarSave)) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break1' }); + } + if (this.show.toolbarAdd) { + this.toolbar.items.push($.extend(true, {}, this.buttons['add'])); + } + if (this.show.toolbarEdit) { + this.toolbar.items.push($.extend(true, {}, this.buttons['edit'])); + } + if (this.show.toolbarDelete) { + this.toolbar.items.push($.extend(true, {}, this.buttons['delete'])); + } + if (this.show.toolbarSave) { + if (this.show.toolbarAdd || this.show.toolbarDelete || this.show.toolbarEdit) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break2' }); + } + this.toolbar.items.push($.extend(true, {}, this.buttons['save'])); + } + // add original buttons + for (var i in tmp_items) this.toolbar.items.push(tmp_items[i]); - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - setTimeout(function () { w2utils.lock(box, msg, showSpinner); }, 10); - }, + // ============================================= + // ------ Toolbar onClick processing - unlock: function () { - var box = this.box; - setTimeout(function () { w2utils.unlock(box); }, 25); // needed timer so if server fast, it will not flash - }, + var obj = this; + this.toolbar.on('click', function (event) { + var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); + if (eventData.isCancelled === true) return; + var id = event.target; + switch (id) { + case 'w2ui-reload': + var eventData2 = obj.trigger({ phase: 'before', type: 'reload', target: obj.name }); + if (eventData2.isCancelled === true) return false; + obj.reload(); + obj.trigger($.extend(eventData2, { phase: 'after' })); + break; + case 'w2ui-column-on-off': + obj.initColumnOnOff(); + obj.initResize(); + obj.resize(); + break; + case 'w2ui-search-advanced': + var tb = this; + var it = this.get(id); + if (it.checked) { + obj.searchClose(); + setTimeout(function () { tb.uncheck(id); }, 1); + } else { + obj.searchOpen(); + event.originalEvent.stopPropagation(); + function tmp_close() { + if ($('#w2ui-overlay-searches-'+ obj.name).data('keepOpen') === true) return; + tb.uncheck(id); + $(document).off('click', 'body', tmp_close); + } + $(document).on('click', 'body', tmp_close); + } + break; + case 'w2ui-add': + // events + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'add', recid: null }); + obj.trigger($.extend(eventData, { phase: 'after' })); + break; + case 'w2ui-edit': + var sel = obj.getSelection(); + var recid = null; + if (sel.length == 1) recid = sel[0]; + // events + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'edit', recid: recid }); + obj.trigger($.extend(eventData, { phase: 'after' })); + break; + case 'w2ui-delete': + obj["delete"](); + break; + case 'w2ui-save': + obj.save(); + break; + } + // no default action + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + } + return; + }, - parseField: function (obj, field) { - var val = ''; - try { // need this to make sure no error in fields - val = obj; - var tmp = String(field).split('.'); - for (var i in tmp) { - val = val[tmp[i]]; - } - } catch (event) { - val = ''; - } - return val; - } - } + initResize: function () { + var obj = this; + //if (obj.resizing === true) return; + $(this.box).find('.w2ui-resizer') + .off('click') + .on('click', function (event) { + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + if (event.preventDefault) event.preventDefault(); + }) + .off('mousedown') + .on('mousedown', function (event) { + if (!event) event = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + obj.resizing = true; + obj.last.tmp = { + x : event.screenX, + y : event.screenY, + gx : event.screenX, + gy : event.screenY, + col : parseInt($(this).attr('name')) + }; + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + if (event.preventDefault) event.preventDefault(); + // fix sizes + for (var c in obj.columns) { + if (typeof obj.columns[c].sizeOriginal == 'undefined') obj.columns[c].sizeOriginal = obj.columns[c].size; + obj.columns[c].size = obj.columns[c].sizeCalculated; + } + var eventData = { phase: 'before', type: 'columnResize', target: obj.name, column: obj.last.tmp.col, field: obj.columns[obj.last.tmp.col].field }; + eventData = obj.trigger($.extend(eventData, { resizeBy: 0, originalEvent: event })); + // set move event + var mouseMove = function (event) { + if (obj.resizing != true) return; + if (!event) event = window.event; + // event before + eventData = obj.trigger($.extend(eventData, { resizeBy: (event.screenX - obj.last.tmp.gx), originalEvent: event })); + if (eventData.isCancelled === true) { eventData.isCancelled = false; return; } + // default action + obj.last.tmp.x = (event.screenX - obj.last.tmp.x); + obj.last.tmp.y = (event.screenY - obj.last.tmp.y); + obj.columns[obj.last.tmp.col].size = (parseInt(obj.columns[obj.last.tmp.col].size) + obj.last.tmp.x) + 'px'; + obj.resizeRecords(); + // reset + obj.last.tmp.x = event.screenX; + obj.last.tmp.y = event.screenY; + } + var mouseUp = function (event) { + delete obj.resizing; + $(document).off('mousemove', 'body'); + $(document).off('mouseup', 'body'); + obj.resizeRecords(); + // event before + obj.trigger($.extend(eventData, { phase: 'after', originalEvent: event })); + } + $(document).on('mousemove', 'body', mouseMove); + $(document).on('mouseup', 'body', mouseUp); + }) + .each(function (index, el) { + var td = $(el).parent(); + $(el).css({ + "height" : '25px', + "margin-left" : (td.width() - 3) + 'px' + }) + }); + }, + + resizeBoxes: function () { + // elements + var main = $(this.box).find('> div'); + var header = $('#grid_'+ this.name +'_header'); + var toolbar = $('#grid_'+ this.name +'_toolbar'); + var summary = $('#grid_'+ this.name +'_summary'); + var footer = $('#grid_'+ this.name +'_footer'); + var body = $('#grid_'+ this.name +'_body'); + var columns = $('#grid_'+ this.name +'_columns'); + var records = $('#grid_'+ this.name +'_records'); + + if (this.show.header) { + header.css({ + top: '0px', + left: '0px', + right: '0px' + }); + } - $.extend(w2grid.prototype, w2utils.event); - w2obj.grid = w2grid; -})(jQuery); + if (this.show.toolbar) { + toolbar.css({ + top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + } + if (this.show.footer) { + footer.css({ + bottom: '0px', + left: '0px', + right: '0px' + }); + } + if (this.summary.length > 0) { + summary.css({ + bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + } + body.css({ + top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) + (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) ) + 'px', + bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) + (this.summary.length > 0 ? w2utils.getSize(summary, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + }, -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2layout - layout widget - * - $().w2layout - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2toolbar, w2tabs - * - * == NICE TO HAVE == - * - onResize for the panel - * - problem with layout.html (see in 1.3) - * - add panel title - * - ************************************************************************/ + resizeRecords: function () { + var obj = this; + // remove empty records + $(this.box).find('.w2ui-empty-record').remove(); + // -- Calculate Column size in PX + var box = $(this.box); + var grid = $(this.box).find('> div'); + var header = $('#grid_'+ this.name +'_header'); + var toolbar = $('#grid_'+ this.name +'_toolbar'); + var summary = $('#grid_'+ this.name +'_summary'); + var footer = $('#grid_'+ this.name +'_footer'); + var body = $('#grid_'+ this.name +'_body'); + var columns = $('#grid_'+ this.name +'_columns'); + var records = $('#grid_'+ this.name +'_records'); + + // body might be expanded by data + if (!this.fixedBody) { + // allow it to render records, then resize + var calculatedHeight = w2utils.getSize(columns, 'height') + + w2utils.getSize($('#grid_'+ obj.name +'_records table'), 'height'); + obj.height = calculatedHeight + + w2utils.getSize(grid, '+height') + + (obj.show.header ? w2utils.getSize(header, 'height') : 0) + + (obj.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) + + (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) + + (obj.show.footer ? w2utils.getSize(footer, 'height') : 0); + grid.css('height', obj.height); + body.css('height', calculatedHeight); + box.css('height', w2utils.getSize(grid, 'height') + w2utils.getSize(box, '+height')); + } else { + // fixed body height + var calculatedHeight = grid.height() + - (this.show.header ? w2utils.getSize(header, 'height') : 0) + - (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) + - (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) + - (this.show.footer ? w2utils.getSize(footer, 'height') : 0); + body.css('height', calculatedHeight); + } -(function ($) { - var w2layout = function (options) { - this.box = null // DOM Element that holds the element - this.name = null; // unique name for w2ui - this.panels = []; - this.tmp = {}; - - this.padding = 1; // panel padding - this.resizer = 4; // resizer width or height - this.style = ''; - - this.onShow = null; - this.onHide = null; - this.onResizing = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null - - $.extend(true, this, w2obj.layout, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2layout = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - var panels = method.panels; - var object = new w2layout(method); - $.extend(object, { handlers: [], panels: [] }); - // add defined panels panels - for (var p in panels) { - object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, panels[p]); - if ($.isPlainObject(object.panels[p].tabs) || $.isArray(object.panels[p].tabs)) initTabs(object, panels[p].type); - if ($.isPlainObject(object.panels[p].toolbar) || $.isArray(object.panels[p].toolbar)) initToolbar(object, panels[p].type); - } - // add all other panels - for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) { - if (object.get(p) != null) continue; - object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, { type: p, hidden: true, size: 50 }); - } - - if ($(this).length > 0) { - object.render($(this)[0]); - } - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2layout' ); - } + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + // check overflow + var bodyOverflowX = false; + var bodyOverflowY = false; + if (body.width() < $(records).find('>table').width()) bodyOverflowX = true; + if (body.height() - columns.height() < $(records).find('>table').height() + (bodyOverflowX ? w2utils.scrollBarSize() : 0)) bodyOverflowY = true; + if (!this.fixedBody) { bodyOverflowY = false; bodyOverflowX = false; } + if (bodyOverflowX || bodyOverflowY) { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); + records.css({ + top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', + "-webkit-overflow-scrolling": "touch", + "overflow-x": (bodyOverflowX ? 'auto' : 'hidden'), + "overflow-y": (bodyOverflowY ? 'auto' : 'hidden') }); + } else { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').hide(); + records.css({ + top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', + overflow: 'hidden' + }); + if (records.length > 0) { this.last.scrollTop = 0; this.last.scrollLeft = 0; } // if no scrollbars, always show top + } + if (this.show.emptyRecords && !bodyOverflowY) { + var max = Math.floor(records.height() / this.recordHeight) + 1; + if (this.fixedBody) { + for (var di = buffered; di <= max; di++) { + var html = ''; + html += ''; + if (this.show.lineNumbers) html += ''; + if (this.show.selectColumn) html += ''; + if (this.show.expandColumn) html += ''; + var j = 0; + while (true && this.columns.length > 0) { + var col = this.columns[j]; + if (col.hidden) { j++; if (typeof this.columns[j] == 'undefined') break; else continue; } + html += ''; + j++; + if (typeof this.columns[j] == 'undefined') break; + } + html += ''; + html += ''; + $('#grid_'+ this.name +'_records > table').append(html); + } + } + } + if (body.length > 0) { + var width_max = parseInt(body.width()) + - (bodyOverflowY ? w2utils.scrollBarSize() : 0) + - (this.show.lineNumbers ? 34 : 0) + - (this.show.selectColumn ? 26 : 0) + - (this.show.expandColumn ? 26 : 0); + var width_box = width_max; + var percent = 0; + // gridMinWidth processiong + var restart = false; + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.gridMinWidth > 0) { + if (col.gridMinWidth > width_box && col.hidden !== true) { + col.hidden = true; + restart = true; + } + if (col.gridMinWidth < width_box && col.hidden === true) { + col.hidden = false; + restart = true; + } + } + } + if (restart === true) { + this.refresh(); + return; + } + // assign PX column s + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (String(col.size).substr(String(col.size).length-2).toLowerCase() == 'px') { + width_max -= parseFloat(col.size); + this.columns[i].sizeCalculated = col.size; + this.columns[i].sizeType = 'px'; + } else { + percent += parseFloat(col.size); + this.columns[i].sizeType = '%'; + delete col.sizeCorrected; + } + } + // if sum != 100% -- reassign proportionally + if (percent != 100 && percent > 0) { + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (col.sizeType == '%') { + col.sizeCorrected = Math.round(parseFloat(col.size) * 100 * 100 / percent) / 100 + '%'; + } + } + } + // calculate % columns + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (col.sizeType == '%') { + if (typeof this.columns[i].sizeCorrected != 'undefined') { + // make it 1px smaller, so margin of error can be calculated correctly + this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.sizeCorrected) / 100) - 1 + 'px'; + } else { + // make it 1px smaller, so margin of error can be calculated correctly + this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.size) / 100) - 1 + 'px'; + } + } + } + } + // fix margin of error that is due percentage calculations + var width_cols = 0; + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (typeof col.min == 'undefined') col.min = 20; + if (parseInt(col.sizeCalculated) < parseInt(col.min)) col.sizeCalculated = col.min + 'px'; + if (parseInt(col.sizeCalculated) > parseInt(col.max)) col.sizeCalculated = col.max + 'px'; + width_cols += parseInt(col.sizeCalculated); + } + var width_diff = parseInt(width_box) - parseInt(width_cols); + if (width_diff > 0 && percent > 0) { + var i = 0; + while (true) { + var col = this.columns[i]; + if (typeof col == 'undefined') { i = 0; continue; } + if (col.hidden || col.sizeType == 'px') { i++; continue; } + col.sizeCalculated = (parseInt(col.sizeCalculated) + 1) + 'px'; + width_diff--; + if (width_diff == 0) break; + i++; + } + } else if (width_diff > 0) { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); + } + // resize columns + columns.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-head-last')) { + $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + // if there are column groups - hide first row (needed for sizing) + if (columns.find('> table > tbody > tr').length == 3) { + columns.find('> table > tbody > tr:nth-child(1) td').html('').css({ + 'height' : '0px', + 'border' : '0px', + 'padding': '0px', + 'margin' : '0px' + }); + } + // resize records + records.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-grid-data-last')) { + $(el).css('width', (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + // resize summary + summary.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-grid-data-last')) { + $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + this.initResize(); + this.refreshRanges(); + // apply last scroll if any + if ((this.last.scrollTop || this.last.scrollLeft) && records.length > 0) { + columns.prop('scrollLeft', this.last.scrollLeft); + records.prop('scrollTop', this.last.scrollTop); + records.prop('scrollLeft', this.last.scrollLeft); + } + }, + + getSearchesHTML: function () { + var html = ''; + var showBtn = false; + for (var i = 0; i < this.searches.length; i++) { + var s = this.searches[i]; + s.type = String(s.type).toLowerCase(); + if (s.hidden) continue; + var btn = ''; + if (showBtn == false) { + btn = 'X'+ + ' '+ w2utils.lang('is') +''+ + ' '+ w2utils.lang('begins') +''+ + ' '+ w2utils.lang('contains') +''+ + ' '+ w2utils.lang('ends') +''+ + ''; + } + if (['int', 'float', 'money', 'currency', 'percent', 'date', 'time'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('is') +''+ + (['int'].indexOf(s.type) != -1 ? ''+ w2utils.lang('in') +'' : '') + + (['int'].indexOf(s.type) != -1 ? ''+ w2utils.lang('not in') +'' : '') + + ''+ w2utils.lang('between') +''+ + ''; + } + if (['select', 'list', 'hex'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('is') +''+ + ''; + } + if (['enum'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('in') +''+ + ' '+ w2utils.lang('not in') +''+ + ''; + } + html += ''+ + ' '+ btn +'' + + ' '+ s.caption +'' + + ' '+ operator +''+ + ' '; + + switch (s.type) { + case 'text': + case 'alphanumeric': + case 'hex': + case 'list': + case 'combo': + case 'enum': + html += ''; + break; + + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'date': + case 'time': + html += ''+ + ''+ + ' - '+ + ''; + break; + + case 'select': + html += ''; + break; - function initTabs(object, panel, tabs) { - var pan = object.get(panel); - if (pan != null && typeof tabs == 'undefined') tabs = pan.tabs; - if (pan == null || tabs == null) return false; - // instanciate tabs - if ($.isArray(tabs)) tabs = { tabs: tabs }; - $().w2destroy(object.name + '_' + panel + '_tabs'); // destroy if existed - pan.tabs = $().w2tabs($.extend({}, tabs, { owner: object, name: object.name + '_' + panel + '_tabs' })); - pan.show.tabs = true; - return true; - } + } + html += s.outTag + + ' ' + + ''; + } + html += ''+ + ' '+ + ' '+ + ' '+ w2utils.lang('Reset') + ''+ + ' '+ w2utils.lang('Search') + ''+ + ' '+ + ' '+ + ''; + return html; + }, + + initOperator: function (el, search_ind) { + var obj = this; + var search = obj.searches[search_ind]; + var range = $('#grid_'+ obj.name + '_range_'+ search_ind); + var fld1 = $('#grid_'+ obj.name +'_field_'+ search_ind); + var fld2 = fld1.parent().find('span input'); + if ($(el).val() == 'in' || $(el).val() == 'not in') { fld1.w2field('clear'); } else { fld1.w2field(search.type); } + if ($(el).val() == 'between') { range.show(); fld2.w2field(search.type); } else { range.hide(); } + }, + + initSearches: function () { + var obj = this; + // init searches + for (var s in this.searches) { + var search = this.searches[s]; + var sdata = this.getSearchData(search.field); + search.type = String(search.type).toLowerCase(); + if (typeof search.options != 'object') search.options = {}; + // init types + switch (search.type) { + case 'text': + case 'alphanumeric': + $('#grid_'+ this.name +'_operator_'+s).val('begins'); + if (['alphanumeric', 'hex'].indexOf(search.type) != -1) { + $('#grid_'+ this.name +'_field_' + s).w2field(search.type, search.options); + } + break; + + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'date': + case 'time': + if (sdata && sdata.type == 'int' && ['in', 'not in'].indexOf(sdata.operator) != -1) break; + $('#grid_'+ this.name +'_field_'+s).w2field(search.type, search.options); + $('#grid_'+ this.name +'_field2_'+s).w2field(search.type, search.options); + setTimeout(function () { // convert to date if it is number + $('#grid_'+ obj.name +'_field_'+s).keydown(); + $('#grid_'+ obj.name +'_field2_'+s).keydown(); + }, 1); + break; + + case 'hex': + break; + + case 'list': + case 'combo': + case 'enum': + var options = search.options; + if (search.type == 'list') options.selected = {}; + if (search.type == 'enum') options.selected = []; + if (sdata) options.selected = sdata.value; + $('#grid_'+ this.name +'_field_'+s).w2field(search.type, options); + if (search.type == 'combo') { + $('#grid_'+ this.name +'_operator_'+s).val('begins'); + } + break; + + case 'select': + // build options + var options = '--'; + for (var i in search.options.items) { + var si = search.options.items[i]; + if ($.isPlainObject(search.options.items[i])) { + var val = si.id; + var txt = si.text; + if (typeof val == 'undefined' && typeof si.value != 'undefined') val = si.value; + if (typeof txt == 'undefined' && typeof si.caption != 'undefined') txt = si.caption; + if (val == null) val = ''; + options += ''+ txt +''; + } else { + options += ''+ si +''; + } + } + $('#grid_'+ this.name +'_field_'+s).html(options); + break; + } + if (sdata != null) { + if (sdata.type == 'int' && ['in', 'not in'].indexOf(sdata.operator) != -1) { + $('#grid_'+ this.name +'_field_'+ s).w2field('clear').val(sdata.value); + } + $('#grid_'+ this.name +'_operator_'+ s).val(sdata.operator).trigger('change'); + if (!$.isArray(sdata.value)) { + if (typeof sdata.value != 'udefined') $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); + } else { + if (['in', 'not in'].indexOf(sdata.operator) != -1) { + $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); + } else { + $('#grid_'+ this.name +'_field_'+ s).val(sdata.value[0]).trigger('change'); + $('#grid_'+ this.name +'_field2_'+ s).val(sdata.value[1]).trigger('change'); + } + } + } + } + // add on change event + $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches *[rel=search]').on('keypress', function (evnt) { + if (evnt.keyCode == 13) { + obj.search(); + $().w2overlay(); + } + }); + }, + + getColumnsHTML: function () { + var obj = this; + var html = ''; + if (this.show.columnHeaders) { + if (this.columnGroups.length > 0) { + html = getColumns(true) + getGroups() + getColumns(false); + } else { + html = getColumns(true); + } + } + return html; - function initToolbar(object, panel, toolbar) { - var pan = object.get(panel); - if (pan != null && typeof toolbar == 'undefined') toolbar = pan.toolbar; - if (pan == null || toolbar == null) return false; - // instanciate toolbar - if ($.isArray(toolbar)) toolbar = { items: toolbar }; - $().w2destroy(object.name + '_' + panel + '_toolbar'); // destroy if existed - pan.toolbar = $().w2toolbar($.extend({}, toolbar, { owner: object, name: object.name + '_' + panel + '_toolbar' })); - pan.show.toolbar = true; - return true; - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2layout.prototype = { - // default setting for a panel - panel: { - type : null, // left, right, top, bottom - size : 100, // width or height depending on panel name - minSize : 20, - hidden : false, - resizable : false, - overflow : 'auto', - style : '', - content : '', // can be String or Object with .render(box) method - tabs : null, - toolbar : null, - width : null, // read only - height : null, // read only - show : { - toolbar : false, - tabs : false - }, - onRefresh : null, - onShow : null, - onHide : null - }, + function getGroups () { + var html = ''; + // add empty group at the end + if (obj.columnGroups[obj.columnGroups.length-1].caption != '') obj.columnGroups.push({ caption: '' }); - // alias for content - html: function (panel, data, transition) { - return this.content(panel, data, transition); - }, + if (obj.show.lineNumbers) { + html += ''+ + ' '+ + ''; + } + if (obj.show.selectColumn) { + html += ''+ + ' '+ + ''; + } + if (obj.show.expandColumn) { + html += ''+ + ' '+ + ''; + } + var ii = 0; + for (var i=0; i'; + } + html += ''+ + resizer + + ' '+ + ' '+ + (!col.caption ? ' ' : col.caption) + + ' '+ + ''; + } else { + html += ''+ + ' '+ + (!colg.caption ? ' ' : colg.caption) + + ' '+ + ''; + } + ii += colg.span; + } + html += ''; + return html; + } - content: function (panel, data, transition) { - var obj = this; - var p = this.get(panel); - if (panel == 'css') { - $('#layout_'+ obj.name +'_panel_css').html(''); - return true; - } - if (p == null) return false; - if ($('#layout_'+ this.name + '_panel2_'+ p.type).length > 0) return false; - $('#layout_'+ this.name + '_panel_'+ p.type).scrollTop(0); - if (data == null || typeof data == 'undefined') { - return p.content; - } else { - if (data instanceof jQuery) { - console.log('ERROR: You can not pass jQuery object to w2layout.content() method'); - return false; - } - // remove foreign classes and styles - var tmp = $('#'+ 'layout_'+ this.name + '_panel_'+ panel + ' > .w2ui-panel-content'); - var panelTop = $(tmp).position().top; - tmp.attr('class', 'w2ui-panel-content'); - if (tmp.length > 0 && typeof p.style != 'undefined') tmp[0].style.cssText = p.style; - if (p.content == '') { - p.content = data; - if (!p.hidden) this.refresh(panel); - } else { - p.content = data; - if (!p.hidden) { - if (transition != null && transition != '' && typeof transition != 'undefined') { - // apply transition - var nm = 'layout_'+ this.name + '_panel_'+ p.type; - var div1 = $('#'+ nm + ' > .w2ui-panel-content'); - div1.after(''); - var div2 = $('#'+ nm + ' > .w2ui-panel-content.new-panel'); - div1.css('top', panelTop); - div2.css('top', panelTop); - if (typeof data == 'object') { - data.box = div2[0]; // do not do .render(box); - data.render(); - } else { - div2.html(data); - } - w2utils.transition(div1[0], div2[0], transition, function () { - div1.remove(); - div2.removeClass('new-panel'); - div2.css('overflow', p.overflow); - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - }); + function getColumns (master) { + var html = '', + reorderCols = (obj.reorderColumns && (!obj.columnGroups || !obj.columnGroups.length)) ? ' w2ui-reorder-cols-head ' : ''; + if (obj.show.lineNumbers) { + html += ''+ + ' #'+ + ''; + } + if (obj.show.selectColumn) { + html += ''+ + ' '+ + ' '+ + ' '+ + ''; + } + if (obj.show.expandColumn) { + html += ''+ + ' '+ + ''; + } + var ii = 0; + var id = 0; + for (var i=0; i'; + } + html += ''+ + resizer + + ' '+ + ' '+ + (!col.caption ? ' ' : col.caption) + + ' '+ + ''; + } + } + html += ' '; + html += ''; + return html; + } + }, + + getRecordsHTML: function () { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + // larget number works better with chrome, smaller with FF. + if (buffered > 300) this.show_extra = 30; else this.show_extra = 300; + var records = $('#grid_'+ this.name +'_records'); + var limit = Math.floor(records.height() / this.recordHeight) + this.show_extra + 1; + if (!this.fixedBody || limit > buffered) limit = buffered; + // always need first record for resizing purposes + var html = '' + this.getRecordHTML(-1, 0); + // first empty row with height + html += ''+ + ' '+ + ''; + for (var i = 0; i < limit; i++) { + html += this.getRecordHTML(i, i+1); + } + html += ''+ + ' '+ + ''+ + ''+ + ' '+ + ''+ + ''; + this.last.range_start = 0; + this.last.range_end = limit; + return html; + }, + + getSummaryHTML: function () { + if (this.summary.length == 0) return; + var html = ''; + for (var i = 0; i < this.summary.length; i++) { + html += this.getRecordHTML(i, i+1, true); + } + html += ''; + return html; + }, + + scroll: function (event) { + var time = (new Date()).getTime(); + var obj = this; + var records = $('#grid_'+ this.name +'_records'); + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + if (buffered == 0 || records.length == 0 || records.height() == 0) return; + if (buffered > 300) this.show_extra = 30; else this.show_extra = 300; + // need this to enable scrolling when this.limit < then a screen can fit + if (records.height() < buffered * this.recordHeight && records.css('overflow-y') == 'hidden') { + if (this.total > 0) this.refresh(); + return; + } + // update footer + var t1 = Math.round(records[0].scrollTop / this.recordHeight + 1); + var t2 = t1 + (Math.round(records.height() / this.recordHeight) - 1); + if (t1 > buffered) t1 = buffered; + if (t2 > buffered) t2 = buffered; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + $('#grid_'+ this.name + '_footer .w2ui-footer-right').html(w2utils.formatNumber(this.offset + t1) + '-' + w2utils.formatNumber(this.offset + t2) + ' ' + w2utils.lang('of') + ' ' + w2utils.formatNumber(this.total) + + (url ? ' ('+ w2utils.lang('buffered') + ' '+ w2utils.formatNumber(buffered) + (this.offset > 0 ? ', skip ' + w2utils.formatNumber(this.offset) : '') + ')' : '') + ); + // only for local data source, else no extra records loaded + if (!url && (!this.fixedBody || this.total <= 300)) return; + // regular processing + var start = Math.floor(records[0].scrollTop / this.recordHeight) - this.show_extra; + var end = start + Math.floor(records.height() / this.recordHeight) + this.show_extra * 2 + 1; + // var div = start - this.last.range_start; + if (start < 1) start = 1; + if (end > this.total) end = this.total; + var tr1 = records.find('#grid_'+ this.name +'_rec_top'); + var tr2 = records.find('#grid_'+ this.name +'_rec_bottom'); + // if row is expanded + if (String(tr1.next().prop('id')).indexOf('_expanded_row') != -1) tr1.next().remove(); + if (this.total > end && String(tr2.prev().prop('id')).indexOf('_expanded_row') != -1) tr2.prev().remove(); + var first = parseInt(tr1.next().attr('line')); + var last = parseInt(tr2.prev().attr('line')); + //$('#log').html('buffer: '+ this.buffered +' start-end: ' + start + '-'+ end + ' ===> first-last: ' + first + '-' + last); + if (first < start || first == 1 || this.last.pull_refresh) { // scroll down + // console.log('end', end, 'last', last, 'show_extre', this.show_extra, this.last.pull_refresh); + if (end <= last + this.show_extra - 2 && end != this.total) return; + this.last.pull_refresh = false; + // remove from top + while (true) { + var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); + if (tmp.attr('line') == 'bottom') break; + if (parseInt(tmp.attr('line')) < start) tmp.remove(); else break; + } + // add at bottom + var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); + var rec_start = tmp.attr('line'); + if (rec_start == 'top') rec_start = start; + for (var i = parseInt(rec_start) + 1; i <= end; i++) { + if (!this.records[i-1]) continue; + if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; + tr2.before(this.getRecordHTML(i-1, i)); + } + markSearch(); + setTimeout(function() { obj.refreshRanges(); }, 0); + } else { // scroll up + if (start >= first - this.show_extra + 2 && start > 1) return; + // remove from bottom + while (true) { + var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); + if (tmp.attr('line') == 'top') break; + if (parseInt(tmp.attr('line')) > end) tmp.remove(); else break; + } + // add at top + var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); + var rec_start = tmp.attr('line'); + if (rec_start == 'bottom') rec_start = end; + for (var i = parseInt(rec_start) - 1; i >= start; i--) { + if (!this.records[i-1]) continue; + if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; + tr1.after(this.getRecordHTML(i-1, i)); + } + markSearch(); + setTimeout(function() { obj.refreshRanges(); }, 0); + } + // first/last row size + var h1 = (start - 1) * obj.recordHeight; + var h2 = (buffered - end) * obj.recordHeight; + if (h2 < 0) h2 = 0; + tr1.css('height', h1 + 'px'); + tr2.css('height', h2 + 'px'); + obj.last.range_start = start; + obj.last.range_end = end; + // load more if needed + var s = Math.floor(records[0].scrollTop / this.recordHeight); + var e = s + Math.floor(records.height() / this.recordHeight); + if (e + 10 > buffered && this.last.pull_more !== true && buffered < this.total - this.offset) { + if (this.autoLoad === true) { + this.last.pull_more = true; + this.last.xhr_offset += this.limit; + this.request('get-records'); + } else { + var more = $('#grid_'+ this.name +'_rec_more'); + if (more.css('display') == 'none') { + more.show() + .on('click', function () { + obj.last.pull_more = true; + obj.last.xhr_offset += obj.limit; + obj.request('get-records'); + // show spinner the last + $(this).find('td').html(''); + }); + } + if (more.find('td').text().indexOf('Load') == -1) { + more.find('td').html(''+ w2utils.lang('Load') + ' ' + obj.limit + ' ' + w2utils.lang('More') + '...'); + } + } + } + // check for grid end + if (buffered >= this.total - this.offset) $('#grid_'+ this.name +'_rec_more').hide(); + return; + + function markSearch() { + // mark search + if(obj.markSearch === false) return; + clearTimeout(obj.last.marker_timer); + obj.last.marker_timer = setTimeout(function () { + // mark all search strings + var str = []; + for (var s in obj.searchData) { + var tmp = obj.searchData[s]; + if ($.inArray(tmp.value, str) == -1) str.push(tmp.value); + } + if (str.length > 0) $(obj.box).find('.w2ui-grid-data > div').w2marker(str); + }, 50); + } + }, + + getRecordHTML: function (ind, lineNum, summary) { + var rec_html = ''; + var sel = this.last.selection; + var record; + // first record needs for resize purposes + if (ind == -1) { + rec_html += ''; + if (this.show.lineNumbers) rec_html += ''; + if (this.show.selectColumn) rec_html += ''; + if (this.show.expandColumn) rec_html += ''; + for (var i in this.columns) { + if (this.columns[i].hidden) continue; + rec_html += ''; + } + rec_html += ''; + rec_html += ''; + return rec_html; + } + // regular record + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (summary !== true) { + if (this.searchData.length > 0 && !url) { + if (ind >= this.last.searchIds.length) return ''; + ind = this.last.searchIds[ind]; + record = this.records[ind]; + } else { + if (ind >= this.records.length) return ''; + record = this.records[ind]; + } } else { - if (!p.hidden) this.refresh(panel); + if (ind >= this.summary.length) return ''; + record = this.summary[ind]; } - } - } - } - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - return true; - }, + if (!record) return ''; + var id = w2utils.escapeId(record.recid); + var isRowSelected = false; + if (sel.indexes.indexOf(ind) != -1) isRowSelected = true; + // render TR + rec_html += ''; + if (this.show.lineNumbers) { + rec_html += ''+ + (summary !== true ? ''+ lineNum +'' : '') + + ''; + } + if (this.show.selectColumn) { + rec_html += + ''+ + (summary !== true ? + ' '+ + ' '+ + ' ' + : + '' ) + + ''; + } + if (this.show.expandColumn) { + var tmp_img = ''; + if (record.expanded === true) tmp_img = '-'; else tmp_img = '+'; + if (record.expanded == 'none') tmp_img = ''; + if (record.expanded == 'spinner') tmp_img = ''; + rec_html += + ''+ + (summary !== true ? + ' '+ + ' '+ tmp_img +' ' + : + '' ) + + ''; + } + var col_ind = 0; + while (true) { + var col = this.columns[col_ind]; + if (col.hidden) { col_ind++; if (typeof this.columns[col_ind] == 'undefined') break; else continue; } + var isChanged = !summary && record.changes && typeof record.changes[col.field] != 'undefined'; + var rec_cell = this.getCellHTML(ind, col_ind, summary); + var addStyle = ''; + if (typeof col.render == 'string') { + var tmp = col.render.toLowerCase().split(':'); + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(tmp[0]) != -1) addStyle += 'text-align: right;'; + } + if (typeof record.style == 'object' && typeof record.style[col_ind] == 'string') { + addStyle += record.style[col_ind] + ';'; + } + var isCellSelected = false; + if (isRowSelected && $.inArray(col_ind, sel.columns[ind]) != -1) isCellSelected = true; + rec_html += ''+ + rec_cell + + ''; + col_ind++; + if (typeof this.columns[col_ind] == 'undefined') break; + } + rec_html += ''; + rec_html += ''; + return rec_html; + }, + + getCellHTML: function (ind, col_ind, summary) { + var col = this.columns[col_ind]; + var record = (summary !== true ? this.records[ind] : this.summary[ind]); + var data = this.getCellValue(ind, col_ind, summary); + var edit = col.editable; + // various renderers + if (typeof col.render != 'undefined') { + if (typeof col.render == 'function') { + data = $.trim(col.render.call(this, record, ind, col_ind)); + if (data.length < 4 || data.substr(0, 4).toLowerCase() != ''; + } + if (typeof col.render == 'object') data = '' + (col.render[data] || '') + ''; + if (typeof col.render == 'string') { + var tmp = col.render.toLowerCase().split(':'); + var prefix = ''; + var suffix = ''; + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(tmp[0]) != -1) { + if (typeof tmp[1] == 'undefined' || !w2utils.isInt(tmp[1])) tmp[1] = 0; + if (tmp[1] > 20) tmp[1] = 20; + if (tmp[1] < 0) tmp[1] = 0; + if (['money', 'currency'].indexOf(tmp[0]) != -1) { tmp[1] = w2utils.settings.currencyPrecision; prefix = w2utils.settings.currencyPrefix; suffix = w2utils.settings.currencySuffix } + if (tmp[0] == 'percent') { suffix = '%'; if (tmp[1] !== '0') tmp[1] = 1; } + if (tmp[0] == 'int') { tmp[1] = 0; } + // format + data = '' + (data !== '' ? prefix + w2utils.formatNumber(Number(data).toFixed(tmp[1])) + suffix : '') + ''; + } + if (tmp[0] == 'time') { + if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.time_format; + data = '' + prefix + w2utils.formatTime(data, tmp[1] == 'h12' ? 'hh:mi pm': 'h24:min') + suffix + ''; + } + if (tmp[0] == 'date') { + if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.date_display; + data = '' + prefix + w2utils.formatDate(data, tmp[1]) + suffix + ''; + } + if (tmp[0] == 'age') { + data = '' + prefix + w2utils.age(data) + suffix + ''; + } + if (tmp[0] == 'toggle') { + data = '' + prefix + (data ? 'Yes' : '') + suffix + ''; + } + } + } else { + // if editable checkbox + var addStyle = ''; + if (edit && ['checkbox', 'check'].indexOf(edit.type) != -1) { + var changeInd = summary ? -(ind + 1) : ind; + addStyle = 'text-align: center'; + data = ''; + } + if (!this.show.recordTitles) { + var data = ''+ data +''; + } else { + // title overwrite + var title = String(data).replace(/"/g, "''"); + if (typeof col.title != 'undefined') { + if (typeof col.title == 'function') title = col.title.call(this, record, ind, col_ind); + if (typeof col.title == 'string') title = col.title; + } + var data = ''+ data +''; + } + } + if (data == null || typeof data == 'undefined') data = ''; + return data; + }, + + getCellValue: function (ind, col_ind, summary) { + var col = this.columns[col_ind]; + var record = (summary !== true ? this.records[ind] : this.summary[ind]); + var data = this.parseField(record, col.field); + if (record.changes && typeof record.changes[col.field] != 'undefined') data = record.changes[col.field]; + if (data == null || typeof data == 'undefined') data = ''; + return data; + }, + + getFooterHTML: function () { + return ''+ + ' '+ + ' '+ + ' '+ + ''; + }, - load: function (panel, url, transition, onLoad) { - var obj = this; - if (panel == 'css') { - $.get(url, function (data, status, xhr) { - obj.content(panel, xhr.responseText); - if (onLoad) onLoad(); - }); - return true; - } - if (this.get(panel) != null) { - $.get(url, function (data, status, xhr) { - obj.content(panel, xhr.responseText, transition); - if (onLoad) onLoad(); - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - }); - return true; - } - return false; - }, + status: function (msg) { + if (typeof msg != 'undefined') { + $('#grid_'+ this.name +'_footer').find('.w2ui-footer-left').html(msg); + } else { + // show number of selected + var msgLeft = ''; + var sel = this.getSelection(); + if (sel.length > 0) { + msgLeft = String(sel.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' ' + w2utils.lang('selected'); + var tmp = sel[0]; + if (typeof tmp == 'object') tmp = tmp.recid + ', '+ w2utils.lang('Column') +': '+ tmp.column; + if (sel.length == 1) msgLeft = w2utils.lang('Record ID') + ': '+ tmp + ' '; + } + $('#grid_'+ this.name +'_footer .w2ui-footer-left').html(msgLeft); + // toolbar + if (sel.length == 1) this.toolbar.enable('w2ui-edit'); else this.toolbar.disable('w2ui-edit'); + if (sel.length >= 1) this.toolbar.enable('w2ui-delete'); else this.toolbar.disable('w2ui-delete'); + } + }, + + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + setTimeout(function () { w2utils.lock.apply(window, args); }, 10); + }, + + unlock: function () { + var box = this.box; + setTimeout(function () { w2utils.unlock(box); }, 25); // needed timer so if server fast, it will not flash + }, + + stateSave: function (returnOnly) { + if (!localStorage) return null; + var state = { + columns : [], + show : $.extend({}, this.show), + last : { + search : this.last.search, + multi : this.last.multi, + logic : this.last.logic, + caption : this.last.caption, + field : this.last.field, + scrollTop : this.last.scrollTop, + scrollLeft : this.last.scrollLeft + }, + sortData : [], + searchData : [] + }; + for (var i in this.columns) { + var col = this.columns[i]; + state.columns.push({ + field : col.field, + hidden : col.hidden, + size : col.size, + sizeCalculated : col.sizeCalculated, + sizeOriginal : col.sizeOriginal, + sizeType : col.sizeType + }); + } + for (var i in this.sortData) state.sortData.push($.extend({}, this.sortData[i])); + for (var i in this.searchData) state.searchData.push($.extend({}, this.searchData[i])); + // save into local storage + if (returnOnly !== true) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'stateSave', target: this.name, state: state }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + try { + var savedState = $.parseJSON(localStorage.w2ui || '{}'); + if (!savedState) savedState = {}; + if (!savedState.states) savedState.states = {}; + savedState.states[this.name] = state; + localStorage.w2ui = JSON.stringify(savedState); + } catch (e) { + delete localStorage.w2ui; + return null; + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + return state; + }, - sizeTo: function (panel, size) { - var obj = this; - var pan = obj.get(panel); - if (pan == null) return false; - // resize - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.35s', - '-moz-transition' : '.35s', - '-ms-transition' : '.35s', - '-o-transition' : '.35s' - }); - setTimeout(function () { - obj.set(panel, { size: size }); - }, 1); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.resize(); - }, 500); - return true; - }, + stateRestore: function (newState) { + var obj = this; + if (!newState) { + // read it from local storage + try { + if (!localStorage) return false; + var tmp = $.parseJSON(localStorage.w2ui || '{}'); + if (!tmp) tmp = {}; + if (!tmp.states) tmp.states = {}; + newState = tmp.states[this.name]; + } catch (e) { + delete localStorage.w2ui; + return null; + } + } + // event before + var eventData = this.trigger({ phase: 'before', type: 'stateRestore', target: this.name, state: newState }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + // default behavior + if ($.isPlainObject(newState)) { + $.extend(this.show, newState.show); + $.extend(this.last, newState.last); + var sTop = this.last.scrollTop; + var sLeft = this.last.scrollLeft; + for (var c in newState.columns) { + var tmp = newState.columns[c]; + var col = this.getColumn(tmp.field); + if (col) $.extend(col, tmp); + } + this.sortData.splice(0, this.sortData.length); + for (var c in newState.sortData) this.sortData.push(newState.sortData[c]); + this.searchData.splice(0, this.searchData.length); + for (var c in newState.searchData) this.searchData.push(newState.searchData[c]); + // apply sort and search + setTimeout(function () { + // needs timeout as records need to be populated + if (obj.sortData.length > 0) obj.localSort(); + if (obj.searchData.length > 0) obj.localSearch(); + obj.last.scrollTop = sTop; + obj.last.scrollLeft = sLeft; + obj.refresh(); + }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return true; + }, + + stateReset: function () { + this.stateRestore(this.last.state); + // remove from local storage + if (localStorage) { + try { + var tmp = $.parseJSON(localStorage.w2ui || '{}'); + if (tmp.states && tmp.states[this.name]) { + delete tmp.states[this.name]; + } + localStorage.w2ui = JSON.stringify(tmp); + } catch (e) { + delete localStorage.w2ui; + return null; + } + } + }, + + parseField: function (obj, field) { + var val = ''; + try { // need this to make sure no error in fields + val = obj; + var tmp = String(field).split('.'); + for (var i in tmp) { + val = val[tmp[i]]; + } + } catch (event) { + val = ''; + } + return val; + }, + + prepareData: function () { + // loops thru records and prepares date and time objects + for (var r in this.records) { + var rec = this.records[r]; + for (var c in this.columns) { + var column = this.columns[c]; + if (rec[column.field] == null || typeof column.render != 'string') continue; + // number + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(column.render.split(':')[0]) != -1) { + if (typeof rec[column.field] != 'number') rec[column.field] = parseFloat(rec[column.field]); + } + // date + if (['date', 'age'].indexOf(column.render.split(':')[0]) != -1) { + if (!rec[column.field + '_']) { + var dt = rec[column.field]; + if (w2utils.isInt(dt)) dt = parseInt(dt); + rec[column.field + '_'] = new Date(dt); + } + } + // time + if (['time'].indexOf(column.render) != -1) { + if (w2utils.isTime(rec[column.field])) { // if string + var tmp = w2utils.isTime(rec[column.field], true); + var dt = new Date(); + dt.setHours(tmp.hours, tmp.minutes, (tmp.seconds ? tmp.seconds : 0), 0); // sets hours, min, sec, mills + if (!rec[column.field + '_']) rec[column.field + '_'] = dt; + } else { // if date object + var tmp = rec[column.field]; + if (w2utils.isInt(tmp)) tmp = parseInt(tmp); + var tmp = (tmp != null ? new Date(tmp) : new Date()); + var dt = new Date(); + dt.setHours(tmp.getHours(), tmp.getMinutes(), tmp.getSeconds(), 0); // sets hours, min, sec, mills + if (!rec[column.field + '_']) rec[column.field + '_'] = dt; + } + } + } + } + }, + + nextCell: function (col_ind, editable) { + var check = col_ind + 1; + if (this.columns.length == check) return null; + if (editable === true) { + var edit = this.columns[check].editable; + if (this.columns[check].hidden || typeof edit == 'undefined' + || (edit && ['checkbox', 'check'].indexOf(edit.type) != -1)) return this.nextCell(check, editable); + } + return check; + }, + + prevCell: function (col_ind, editable) { + var check = col_ind - 1; + if (check < 0) return null; + if (editable === true) { + var edit = this.columns[check].editable; + if (this.columns[check].hidden || typeof edit == 'undefined' + || (edit && ['checkbox', 'check'].indexOf(edit.type) != -1)) return this.prevCell(check, editable); + } + return check; + }, + + nextRow: function (ind) { + if ((ind + 1 < this.records.length && this.last.searchIds.length == 0) // if there are more records + || (this.last.searchIds.length > 0 && ind < this.last.searchIds[this.last.searchIds.length-1])) { + ind++; + if (this.last.searchIds.length > 0) { + while (true) { + if ($.inArray(ind, this.last.searchIds) != -1 || ind > this.records.length) break; + ind++; + } + } + return ind; + } else { + return null; + } + }, + + prevRow: function (ind) { + if ((ind > 0 && this.last.searchIds.length == 0) // if there are more records + || (this.last.searchIds.length > 0 && ind > this.last.searchIds[0])) { + ind--; + if (this.last.searchIds.length > 0) { + while (true) { + if ($.inArray(ind, this.last.searchIds) != -1 || ind < 0) break; + ind--; + } + } + return ind; + } else { + return null; + } + } + }; - show: function (panel, immediate) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', type: 'show', target: panel, object: this.get(panel), immediate: immediate }); - if (eventData.isCancelled === true) return false; - - var p = obj.get(panel); - if (p == null) return false; - p.hidden = false; - if (immediate === true) { - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '1' }); - if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show(); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - } else { - if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show(); - // resize - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.2s', - '-moz-transition' : '.2s', - '-ms-transition' : '.2s', - '-o-transition' : '.2s' - }); - setTimeout(function () { obj.resize(); }, 1); - // show - setTimeout(function() { - $('#layout_'+ obj.name +'_panel_'+ panel).css({ 'opacity': '1' }); - }, 250); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - }, 500); - } - return true; - }, + $.extend(w2grid.prototype, w2utils.event); + w2obj.grid = w2grid; +})(jQuery); - hide: function (panel, immediate) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', type: 'hide', target: panel, object: this.get(panel), immediate: immediate }); - if (eventData.isCancelled === true) return false; - - var p = obj.get(panel); - if (p == null) return false; - p.hidden = true; - if (immediate === true) { - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - $('#layout_'+ obj.name +'_resizer_'+panel).hide(); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - } else { - $('#layout_'+ obj.name +'_resizer_'+panel).hide(); - // hide - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.2s', - '-moz-transition' : '.2s', - '-ms-transition' : '.2s', - '-o-transition' : '.2s' - }); - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - setTimeout(function () { obj.resize(); }, 1); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - }, 500); - } - return true; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2layout - layout widget +* - $().w2layout - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2toolbar, w2tabs +* +* == NICE TO HAVE == +* - onResize for the panel +* - add more panel title positions (left=rotated, right=rotated, bottom) +* - bug: resizer is visible (and onHover) when panel is hidden. +* - bug: when you assign content before previous transition completed. +* +************************************************************************/ - toggle: function (panel, immediate) { - var p = this.get(panel); - if (p == null) return false; - if (p.hidden) return this.show(panel, immediate); else return this.hide(panel, immediate); - }, +(function ($) { + var w2layout = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.panels = []; + this.tmp = {}; + + this.padding = 1; // panel padding + this.resizer = 4; // resizer width or height + this.style = ''; + + this.onShow = null; + this.onHide = null; + this.onResizing = null; + this.onResizerClick = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.layout, options); + }; + + /* @const */ var w2layout_panels = ['top', 'left', 'main', 'preview', 'right', 'bottom']; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2layout = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2layout')) return; + var panels = method.panels || []; + var object = new w2layout(method); + $.extend(object, { handlers: [], panels: [] }); + // add defined panels + for (var p = 0, len = panels.length; p < len; p++) { + object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, panels[p]); + if ($.isPlainObject(object.panels[p].tabs) || $.isArray(object.panels[p].tabs)) initTabs(object, panels[p].type); + if ($.isPlainObject(object.panels[p].toolbar) || $.isArray(object.panels[p].toolbar)) initToolbar(object, panels[p].type); + } + // add all other panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + if (object.get(p1) !== null) continue; + object.panels.push($.extend(true, {}, w2layout.prototype.panel, { type: p1, hidden: (p1 !== 'main'), size: 50 })); + } + if ($(this).length > 0) { + object.render($(this)[0]); + } + w2ui[object.name] = object; + return object; - set: function (panel, options) { - var obj = this.get(panel, true); - if (obj == null) return false; - $.extend(this.panels[obj], options); - this.refresh(panel); - this.resize(); // resize is needed when panel size is changed - return true; - }, + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; + } else { + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2layout' ); + } + + function initTabs(object, panel, tabs) { + var pan = object.get(panel); + if (pan !== null && typeof tabs == 'undefined') tabs = pan.tabs; + if (pan === null || tabs === null) return false; + // instanciate tabs + if ($.isArray(tabs)) tabs = { tabs: tabs }; + $().w2destroy(object.name + '_' + panel + '_tabs'); // destroy if existed + pan.tabs = $().w2tabs($.extend({}, tabs, { owner: object, name: object.name + '_' + panel + '_tabs' })); + pan.show.tabs = true; + return true; + } - get: function (panel, returnIndex) { - var obj = null; - for (var p in this.panels) { - if (this.panels[p].type == panel) { - if (returnIndex === true) return p; else return this.panels[p]; + function initToolbar(object, panel, toolbar) { + var pan = object.get(panel); + if (pan !== null && typeof toolbar == 'undefined') toolbar = pan.toolbar; + if (pan === null || toolbar === null) return false; + // instanciate toolbar + if ($.isArray(toolbar)) toolbar = { items: toolbar }; + $().w2destroy(object.name + '_' + panel + '_toolbar'); // destroy if existed + pan.toolbar = $().w2toolbar($.extend({}, toolbar, { owner: object, name: object.name + '_' + panel + '_toolbar' })); + pan.show.toolbar = true; + return true; } - } - return null; - }, + }; + + // ==================================================== + // -- Implementation of core functionality + + w2layout.prototype = { + // default setting for a panel + panel: { + type : null, // left, right, top, bottom + title : '', + size : 100, // width or height depending on panel name + minSize : 20, + maxSize : false, + hidden : false, + resizable : false, + overflow : 'auto', + style : '', + content : '', // can be String or Object with .render(box) method + tabs : null, + toolbar : null, + width : null, // read only + height : null, // read only + show : { + toolbar : false, + tabs : false + }, + onRefresh : null, + onShow : null, + onHide : null + }, + + // alias for content + html: function (panel, data, transition) { + return this.content(panel, data, transition); + }, + + content: function (panel, data, transition) { + var obj = this; + var p = this.get(panel); + // if it is CSS panel + if (panel == 'css') { + $('#layout_'+ obj.name +'_panel_css').html(''); + return true; + } + if (p === null) return false; + if (typeof data == 'undefined' || data === null) { + return p.content; + } else { + if (data instanceof jQuery) { + console.log('ERROR: You can not pass jQuery object to w2layout.content() method'); + return false; + } + var pname = '#layout_'+ this.name + '_panel_'+ p.type; + var current = $(pname + '> .w2ui-panel-content'); + var panelTop = 0; + if (current.length > 0) { + $(pname).scrollTop(0); + panelTop = $(current).position().top; + } + if (p.content === '') { + p.content = data; + this.refresh(panel); + } else { + p.content = data; + if (!p.hidden) { + if (transition !== null && transition !== '' && typeof transition != 'undefined') { + // apply transition + var div1 = $(pname + '> .w2ui-panel-content'); + div1.after(''); + var div2 = $(pname + '> .w2ui-panel-content.new-panel'); + div1.css('top', panelTop); + div2.css('top', panelTop); + if (typeof data == 'object') { + data.box = div2[0]; // do not do .render(box); + data.render(); + } else { + div2.html(data); + } + w2utils.transition(div1[0], div2[0], transition, function () { + div1.remove(); + div2.removeClass('new-panel'); + div2.css('overflow', p.overflow); + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + }); + } + } + this.refresh(panel); + } + } + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + return true; + }, - el: function (panel) { - var el = $('#layout_'+ this.name +'_panel_'+ panel +' .w2ui-panel-content'); - if (el.length != 1) return null; - return el[0]; - }, + load: function (panel, url, transition, onLoad) { + var obj = this; + if (panel == 'css') { + $.get(url, function (data, status, xhr) { // should always be $.get as it is template + obj.content(panel, xhr.responseText); + if (onLoad) onLoad(); + }); + return true; + } + if (this.get(panel) !== null) { + $.get(url, function (data, status, xhr) { // should always be $.get as it is template + obj.content(panel, xhr.responseText, transition); + if (onLoad) onLoad(); + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + }); + return true; + } + return false; + }, - hideToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.toolbar = false; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').hide(); - this.resize(); - }, + sizeTo: function (panel, size) { + var obj = this; + var pan = obj.get(panel); + if (pan === null) return false; + // resize + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + setTimeout(function () { + obj.set(panel, { size: size }); + }, 1); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.resize(); + }, 500); + return true; + }, - showToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.toolbar = true; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').show(); - this.resize(); - }, + show: function (panel, immediate) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', type: 'show', target: panel, object: this.get(panel), immediate: immediate }); + if (eventData.isCancelled === true) return; + + var p = obj.get(panel); + if (p === null) return false; + p.hidden = false; + if (immediate === true) { + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '1' }); + if (p.resizable) $('#layout_'+ obj.name +'_resizer_'+panel).show(); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + } else { + if (p.resizable) $('#layout_'+ obj.name +'_resizer_'+panel).show(); + // resize + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + setTimeout(function () { obj.resize(); }, 1); + // show + setTimeout(function() { + $('#layout_'+ obj.name +'_panel_'+ panel).css({ 'opacity': '1' }); + }, 250); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + }, 500); + } + return true; + }, - toggleToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - if (pan.show.toolbar) this.hideToolbar(panel); else this.showToolbar(panel); - }, + hide: function (panel, immediate) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', type: 'hide', target: panel, object: this.get(panel), immediate: immediate }); + if (eventData.isCancelled === true) return; + + var p = obj.get(panel); + if (p === null) return false; + p.hidden = true; + if (immediate === true) { + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + $('#layout_'+ obj.name +'_resizer_'+panel).hide(); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + } else { + $('#layout_'+ obj.name +'_resizer_'+panel).hide(); + // hide + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + setTimeout(function () { obj.resize(); }, 1); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + }, 500); + } + return true; + }, + + toggle: function (panel, immediate) { + var p = this.get(panel); + if (p === null) return false; + if (p.hidden) return this.show(panel, immediate); else return this.hide(panel, immediate); + }, + + set: function (panel, options) { + var obj = this.get(panel, true); + if (obj === null) return false; + $.extend(this.panels[obj], options); + if (typeof options['content'] != 'undefined') this.refresh(panel); // refresh only when content changed + this.resize(); // resize is needed when panel size is changed + return true; + }, - hideTabs: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.tabs = false; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-tabs').hide(); - this.resize(); - }, + get: function (panel, returnIndex) { + for (var p in this.panels) { + if (this.panels[p].type == panel) { + if (returnIndex === true) return p; else return this.panels[p]; + } + } + return null; + }, + + el: function (panel) { + var el = $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-content'); + if (el.length != 1) return null; + return el[0]; + }, + + hideToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.toolbar = false; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-toolbar').hide(); + this.resize(); + }, + + showToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.toolbar = true; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-toolbar').show(); + this.resize(); + }, + + toggleToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + if (pan.show.toolbar) this.hideToolbar(panel); else this.showToolbar(panel); + }, + + hideTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.tabs = false; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-tabs').hide(); + this.resize(); + }, + + showTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.tabs = true; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-tabs').show(); + this.resize(); + }, + + toggleTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + if (pan.show.tabs) this.hideTabs(panel); else this.showTabs(panel); + }, + + render: function (box) { + var obj = this; + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + var time = (new Date()).getTime(); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'render', target: obj.name, box: box }); + if (eventData.isCancelled === true) return; + + if (typeof box != 'undefined' && box !== null) { + if ($(obj.box).find('#layout_'+ obj.name +'_panel_main').length > 0) { + $(obj.box) + .removeAttr('name') + .removeClass('w2ui-layout') + .html(''); + } + obj.box = box; + } + if (!obj.box) return false; + $(obj.box) + .attr('name', obj.name) + .addClass('w2ui-layout') + .html(''); + if ($(obj.box).length > 0) $(obj.box)[0].style.cssText += obj.style; + // create all panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + var pan = obj.get(p1); + var html = ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ''+ + ''; + $(obj.box).find(' > div').append(html); + // tabs are rendered in refresh() + } + $(obj.box).find(' > div') + .append(' .w2ui-panel-tabs').show(); - this.resize(); - }, + function resizeStart(type, evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + $(document).off('mousemove', obj.tmp.events.mouseMove).on('mousemove', obj.tmp.events.mouseMove); + $(document).off('mouseup', obj.tmp.events.mouseUp).on('mouseup', obj.tmp.events.mouseUp); + obj.tmp.resize = { + type : type, + x : evnt.screenX, + y : evnt.screenY, + diff_x : 0, + diff_y : 0, + value : 0 + }; + // lock all panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + obj.lock(p1, { opacity: 0 }); + } + if (type == 'left' || type == 'right') { + obj.tmp.resize.value = parseInt($('#layout_'+ obj.name +'_resizer_'+ type)[0].style.left); + } + if (type == 'top' || type == 'preview' || type == 'bottom') { + obj.tmp.resize.value = parseInt($('#layout_'+ obj.name +'_resizer_'+ type)[0].style.top); + } + } - toggleTabs: function (panel) { - var pan = this.get(panel); - if (!pan) return; - if (pan.show.tabs) this.hideTabs(panel); else this.showTabs(panel); - }, + function resizeStop(evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + $(document).off('mousemove', obj.tmp.events.mouseMove); + $(document).off('mouseup', obj.tmp.events.mouseUp); + if (typeof obj.tmp.resize == 'undefined') return; + // unlock all panels + for (var p1 in w2layout_panels) { + obj.unlock(w2layout_panels[p1]); + } + // set new size + if (obj.tmp.diff_x !== 0 || obj.tmp.resize.diff_y !== 0) { // only recalculate if changed + var ptop = obj.get('top'); + var pbottom = obj.get('bottom'); + var panel = obj.get(obj.tmp.resize.type); + var height = parseInt($(obj.box).height()); + var width = parseInt($(obj.box).width()); + var str = String(panel.size); + var ns, nd; + switch (obj.tmp.resize.type) { + case 'top': + ns = parseInt(panel.sizeCalculated) + obj.tmp.resize.diff_y; + nd = 0; + break; + case 'bottom': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_y; + nd = 0; + break; + case 'preview': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_y; + nd = (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) + + (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); + break; + case 'left': + ns = parseInt(panel.sizeCalculated) + obj.tmp.resize.diff_x; + nd = 0; + break; + case 'right': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_x; + nd = 0; + break; + } + // set size + if (str.substr(str.length-1) == '%') { + panel.size = Math.floor(ns * 100 / + (panel.type == 'left' || panel.type == 'right' ? width : height - nd) * 100) / 100 + '%'; + } else { + panel.size = ns; + } + obj.resize(); + } + $('#layout_'+ obj.name + '_resizer_'+ obj.tmp.resize.type).removeClass('active'); + delete obj.tmp.resize; + } - render: function (box) { - var obj = this; - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var time = (new Date()).getTime(); - // event before - var eventData = obj.trigger({ phase: 'before', type: 'render', target: obj.name, box: box }); - if (eventData.isCancelled === true) return false; - - if (typeof box != 'undefined' && box != null) { - if ($(obj.box).find('#layout_'+ obj.name +'_panel_main').length > 0) { - $(obj.box) - .removeAttr('name') - .removeClass('w2ui-layout') - .html(''); - } - obj.box = box; - } - if (!obj.box) return false; - $(obj.box) - .attr('name', obj.name) - .addClass('w2ui-layout') - .html(''); - if ($(obj.box).length > 0) $(obj.box)[0].style.cssText += obj.style; - // create all panels - var tmp = ['top', 'left', 'main', 'preview', 'right', 'bottom']; - for (var t in tmp) { - var pan = obj.get(tmp[t]); - var html = ''+ - ' '+ - ' '+ - ' '+ - ''+ - ''; - $(obj.box).find(' > div').append(html); - // tabs are rendered in refresh() - } - $(obj.box).find(' > div') - .append(' drag - if (obj.tmp.resizing == 'left' && (obj.get('left').minSize - obj.tmp.resize.div_x > obj.get('left').width)) { - obj.tmp.resize.div_x = obj.get('left').minSize - obj.get('left').width; - } - if (obj.tmp.resize.type == 'left' && (obj.get('main').minSize + obj.tmp.resize.div_x > obj.get('main').width)) { - obj.tmp.resize.div_x = obj.get('main').width - obj.get('main').minSize; - } - // right panel -> drag - if (obj.tmp.resize.type == 'right' && (obj.get('right').minSize + obj.tmp.resize.div_x > obj.get('right').width)) { - obj.tmp.resize.div_x = obj.get('right').width - obj.get('right').minSize; - } - if (obj.tmp.resize.type == 'right' && (obj.get('main').minSize - obj.tmp.resize.div_x > obj.get('main').width)) { - obj.tmp.resize.div_x = obj.get('main').minSize - obj.get('main').width; - } - // top panel -> drag - if (obj.tmp.resize.type == 'top' && (obj.get('top').minSize - obj.tmp.resize.div_y > obj.get('top').height)) { - obj.tmp.resize.div_y = obj.get('top').minSize - obj.get('top').height; - } - if (obj.tmp.resize.type == 'top' && (obj.get('main').minSize + obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').height - obj.get('main').minSize; - } - // bottom panel -> drag - if (obj.tmp.resize.type == 'bottom' && (obj.get('bottom').minSize + obj.tmp.resize.div_y > obj.get('bottom').height)) { - obj.tmp.resize.div_y = obj.get('bottom').height - obj.get('bottom').minSize; - } - if (obj.tmp.resize.type == 'bottom' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height; - } - // preview panel -> drag - if (obj.tmp.resize.type == 'preview' && (obj.get('preview').minSize + obj.tmp.resize.div_y > obj.get('preview').height)) { - obj.tmp.resize.div_y = obj.get('preview').height - obj.get('preview').minSize; - } - if (obj.tmp.resize.type == 'preview' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height; - } - switch(obj.tmp.resize.type) { - case 'top': - case 'preview': - case 'bottom': - obj.tmp.resize.div_x = 0; - if (p.length > 0) p[0].style.top = (obj.tmp.resize.value + obj.tmp.resize.div_y) + 'px'; - break; - case 'left': - case 'right': - obj.tmp.resize.div_y = 0; - if (p.length > 0) p[0].style.left = (obj.tmp.resize.value + obj.tmp.resize.div_x) + 'px'; - break; - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - }, + function resizeMove(evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (typeof obj.tmp.resize == 'undefined') return; + var panel = obj.get(obj.tmp.resize.type); + // event before + var tmp = obj.tmp.resize; + var eventData = obj.trigger({ phase: 'before', type: 'resizing', target: obj.name, object: panel, originalEvent: evnt, + panel: tmp ? tmp.type : 'all', diff_x: tmp ? tmp.diff_x : 0, diff_y: tmp ? tmp.diff_y : 0 }); + if (eventData.isCancelled === true) return; + + var p = $('#layout_'+ obj.name + '_resizer_'+ tmp.type); + var resize_x = (evnt.screenX - tmp.x); + var resize_y = (evnt.screenY - tmp.y); + var mainPanel = obj.get('main'); + + if (!p.hasClass('active')) p.addClass('active'); + + switch (tmp.type) { + case 'left': + if (panel.minSize - resize_x > panel.width) { + resize_x = panel.minSize - panel.width; + } + if (panel.maxSize && (panel.width + resize_x > panel.maxSize)) { + resize_x = panel.maxSize - panel.width; + } + if (mainPanel.minSize + resize_x > mainPanel.width) { + resize_x = mainPanel.width - mainPanel.minSize; + } + break; + + case 'right': + if (panel.minSize + resize_x > panel.width) { + resize_x = panel.width - panel.minSize; + } + if (panel.maxSize && (panel.width - resize_x > panel.maxSize)) { + resize_x = panel.width - panel.maxSize; + } + if (mainPanel.minSize - resize_x > mainPanel.width) { + resize_x = mainPanel.minSize - mainPanel.width; + } + break; + + case 'top': + if (panel.minSize - resize_y > panel.height) { + resize_y = panel.minSize - panel.height; + } + if (panel.maxSize && (panel.height + resize_y > panel.maxSize)) { + resize_y = panel.maxSize - panel.height; + } + if (mainPanel.minSize + resize_y > mainPanel.height) { + resize_y = mainPanel.height - mainPanel.minSize; + } + break; + + case 'preview': + case 'bottom': + if (panel.minSize + resize_y > panel.height) { + resize_y = panel.height - panel.minSize; + } + if (panel.maxSize && (panel.height - resize_y > panel.maxSize)) { + resize_y = panel.height - panel.maxSize; + } + if (mainPanel.minSize - resize_y > mainPanel.height) { + resize_y = mainPanel.minSize - mainPanel.height; + } + break; + } + tmp.diff_x = resize_x; + tmp.diff_y = resize_y; + + switch (tmp.type) { + case 'top': + case 'preview': + case 'bottom': + tmp.diff_x = 0; + if (p.length > 0) p[0].style.top = (tmp.value + tmp.diff_y) + 'px'; + break; + + case 'left': + case 'right': + tmp.diff_y = 0; + if (p.length > 0) p[0].style.left = (tmp.value + tmp.diff_x) + 'px'; + break; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + }, - refresh: function (panel) { - var obj = this; - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (typeof panel == 'undefined') panel = null; - var time = (new Date()).getTime(); - // event before - var eventData = obj.trigger({ phase: 'before', type: 'refresh', target: (typeof panel != 'undefined' ? panel : obj.name), object: obj.get(panel) }); - if (eventData.isCancelled === true) return; - - // obj.unlock(panel); - if (panel != null && typeof panel != 'undefined') { - var p = obj.get(panel); - if (p == null) return; - // apply properties to the panel - var el = $('#layout_'+ obj.name +'_panel_'+ panel).css({ display: p.hidden ? 'none' : 'block' }); - el = el.find('.w2ui-panel-content'); - if (el.length > 0) el.css('overflow', p.overflow)[0].style.cssText += ';' + p.style; - if (p.resizable === true) { - $('#layout_'+ this.name +'_resizer_'+ panel).show(); - } else { - $('#layout_'+ this.name +'_resizer_'+ panel).hide(); - } - // insert content - if (typeof p.content == 'object' && p.content.render) { - p.content.box = $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content')[0]; - p.content.render(); // do not do .render(box); - } else { - $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content').html(p.content); - } - // if there are tabs and/or toolbar - render it - var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-tabs'); - if (p.show.tabs) { - if (tmp.find('[name='+ p.tabs.name +']').length == 0 && p.tabs != null) tmp.w2render(p.tabs); else p.tabs.refresh(); - } else { - tmp.html('').removeClass('w2ui-tabs').hide(); - } - var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-toolbar'); - if (p.show.toolbar) { - if (tmp.find('[name='+ p.toolbar.name +']').length == 0 && p.toolbar != null) tmp.w2render(p.toolbar); else p.toolbar.refresh(); - } else { - tmp.html('').removeClass('w2ui-toolbar').hide(); - } - } else { - if ($('#layout_' +obj.name +'_panel_main').length <= 0) { - obj.render(); - return; - } - obj.resize(); - // refresh all of them - for (var p in this.panels) { obj.refresh(this.panels[p].type); } - } - obj.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + refresh: function (panel) { + var obj = this; + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof panel == 'undefined') panel = null; + var time = (new Date()).getTime(); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'refresh', target: (typeof panel != 'undefined' ? panel : obj.name), object: obj.get(panel) }); + if (eventData.isCancelled === true) return; + // obj.unlock(panel); + if (typeof panel == 'string') { + var p = obj.get(panel); + if (p === null) return; + var pname = '#layout_'+ obj.name + '_panel_'+ p.type; + var rname = '#layout_'+ obj.name +'_resizer_'+ p.type; + // apply properties to the panel + $(pname).css({ display: p.hidden ? 'none' : 'block' }); + if (p.resizable) $(rname).show(); else $(rname).hide(); + // insert content + if (typeof p.content == 'object' && typeof p.content.render === 'function') { + p.content.box = $(pname +'> .w2ui-panel-content')[0]; + setTimeout(function () { + // need to remove unnecessary classes + if ($(pname +'> .w2ui-panel-content').length > 0) { + $(pname +'> .w2ui-panel-content') + .removeClass() + .addClass('w2ui-panel-content') + .css('overflow', p.overflow)[0].style.cssText += ';' + p.style; + } + p.content.render(); // do not do .render(box); + }, 1); + } else { + // need to remove unnecessary classes + if ($(pname +'> .w2ui-panel-content').length > 0) { + $(pname +'> .w2ui-panel-content') + .removeClass() + .addClass('w2ui-panel-content') + .html(p.content) + .css('overflow', p.overflow)[0].style.cssText += ';' + p.style; + } + } + // if there are tabs and/or toolbar - render it + var tmp = $(obj.box).find(pname +'> .w2ui-panel-tabs'); + if (p.show.tabs) { + if (tmp.find('[name='+ p.tabs.name +']').length === 0 && p.tabs !== null) tmp.w2render(p.tabs); else p.tabs.refresh(); + } else { + tmp.html('').removeClass('w2ui-tabs').hide(); + } + tmp = $(obj.box).find(pname +'> .w2ui-panel-toolbar'); + if (p.show.toolbar) { + if (tmp.find('[name='+ p.toolbar.name +']').length === 0 && p.toolbar !== null) tmp.w2render(p.toolbar); else p.toolbar.refresh(); + } else { + tmp.html('').removeClass('w2ui-toolbar').hide(); + } + // show title + tmp = $(obj.box).find(pname +'> .w2ui-panel-title'); + if (p.title) { + tmp.html(p.title).show(); + } else { + tmp.html('').hide(); + } + } else { + if ($('#layout_'+ obj.name +'_panel_main').length == 0) { + obj.render(); + return; + } + obj.resize(); + // refresh all of them + for (var p1 in this.panels) { obj.refresh(this.panels[p1].type); } + } + obj.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - resize: function () { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (!this.box) return false; - var time = (new Date()).getTime(); - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name, panel: this.tmp.resizing }); - if (eventData.isCancelled === true) return false; - if (this.padding < 0) this.padding = 0; - - // layout itself - var width = parseInt($(this.box).width()); - var height = parseInt($(this.box).height()); - $(this.box).find(' > div').css({ - width : width + 'px', - height : height + 'px' - }); - var obj = this; - // panels - var pmain = this.get('main'); - var pprev = this.get('preview'); - var pleft = this.get('left'); - var pright = this.get('right'); - var ptop = this.get('top'); - var pbottom = this.get('bottom'); - var smain = true; // main always on - var sprev = (pprev != null && pprev.hidden != true ? true : false); - var sleft = (pleft != null && pleft.hidden != true ? true : false); - var sright = (pright != null && pright.hidden != true ? true : false); - var stop = (ptop != null && ptop.hidden != true ? true : false); - var sbottom = (pbottom != null && pbottom.hidden != true ? true : false); - // calculate % - for (var p in { 'top':'', 'left':'', 'right':'', 'bottom':'', 'preview':'' }) { - var tmp = this.get(p); - var str = String(tmp.size); - if (tmp && str.substr(str.length-1) == '%') { - var tmph = height; - if (tmp.type == 'preview') { - tmph = tmph - - (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) - - (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); - } - tmp.sizeCalculated = parseInt((tmp.type == 'left' || tmp.type == 'right' ? width : tmph) * parseFloat(tmp.size) / 100); - } else { - tmp.sizeCalculated = parseInt(tmp.size); - } - if (tmp.sizeCalculated < parseInt(tmp.minSize)) tmp.sizeCalculated = parseInt(tmp.minSize); - } - // top if any - if (ptop != null && ptop.hidden != true) { - var l = 0; - var t = 0; - var w = width; - var h = ptop.sizeCalculated; - $('#layout_'+ this.name +'_panel_top').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - ptop.width = w; - ptop.height = h; - // resizer - if (ptop.resizable) { - t = ptop.sizeCalculated - (this.padding == 0 ? this.resizer : 0); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_top').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('top', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_top').hide(); - } - // left if any - if (pleft != null && pleft.hidden != true) { - var l = 0; - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = pleft.sizeCalculated; - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0); - var e = $('#layout_'+ this.name +'_panel_left'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_left').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pleft.width = w; - pleft.height = h; - // resizer - if (pleft.resizable) { - l = pleft.sizeCalculated - (this.padding == 0 ? this.resizer : 0); - w = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_left').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ew-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('left', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_left').hide(); - $('#layout_'+ this.name +'_resizer_left').hide(); - } - // right if any - if (pright != null && pright.hidden != true) { - var l = width - pright.sizeCalculated; - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = pright.sizeCalculated; - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0); - $('#layout_'+ this.name +'_panel_right').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pright.width = w; - pright.height = h; - // resizer - if (pright.resizable) { - l = l - this.padding; - w = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_right').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ew-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('right', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_right').hide(); - } - // bottom if any - if (pbottom != null && pbottom.hidden != true) { - var l = 0; - var t = height - pbottom.sizeCalculated; - var w = width; - var h = pbottom.sizeCalculated; - $('#layout_'+ this.name +'_panel_bottom').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pbottom.width = w; - pbottom.height = h; - // resizer - if (pbottom.resizable) { - t = t - (this.padding == 0 ? 0 : this.padding); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_bottom').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('bottom', event); - return false; + resize: function () { + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (!this.box) return false; + var time = (new Date()).getTime(); + // event before + var tmp = this.tmp.resize; + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name, + panel: tmp ? tmp.type : 'all', diff_x: tmp ? tmp.diff_x : 0, diff_y: tmp ? tmp.diff_y : 0 }); + if (eventData.isCancelled === true) return; + if (this.padding < 0) this.padding = 0; + + // layout itself + var width = parseInt($(this.box).width()); + var height = parseInt($(this.box).height()); + $(this.box).find(' > div').css({ + width : width + 'px', + height : height + 'px' }); - } - } else { - $('#layout_'+ this.name +'_panel_bottom').hide(); - } - // main - always there - var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - - (sright ? pright.sizeCalculated + this.padding: 0); - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - - (sprev ? pprev.sizeCalculated + this.padding : 0); - var e = $('#layout_'+ this.name +'_panel_main'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_main').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }); - pmain.width = w; - pmain.height = h; - - // preview if any - if (pprev != null && pprev.hidden != true) { - var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); - var t = height - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - pprev.sizeCalculated; - var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - - (sright ? pright.sizeCalculated + this.padding : 0); - var h = pprev.sizeCalculated; - var e = $('#layout_'+ this.name +'_panel_preview'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_preview').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pprev.width = w; - pprev.height = h; - // resizer - if (pprev.resizable) { - t = t - (this.padding == 0 ? 0 : this.padding); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_preview').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('preview', event); - return false; + var obj = this; + // panels + var pmain = this.get('main'); + var pprev = this.get('preview'); + var pleft = this.get('left'); + var pright = this.get('right'); + var ptop = this.get('top'); + var pbottom = this.get('bottom'); + var smain = true; // main always on + var sprev = (pprev !== null && pprev.hidden !== true ? true : false); + var sleft = (pleft !== null && pleft.hidden !== true ? true : false); + var sright = (pright !== null && pright.hidden !== true ? true : false); + var stop = (ptop !== null && ptop.hidden !== true ? true : false); + var sbottom = (pbottom !== null && pbottom.hidden !== true ? true : false); + var l, t, w, h, e; + // calculate % + for (var p in w2layout_panels) { + p = w2layout_panels[p]; + if (p === 'main') continue; + var tmp = this.get(p); + if (!tmp) continue; + var str = String(tmp.size || 0); + if (str.substr(str.length-1) == '%') { + var tmph = height; + if (tmp.type == 'preview') { + tmph = tmph - + (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) - + (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); + } + tmp.sizeCalculated = parseInt((tmp.type == 'left' || tmp.type == 'right' ? width : tmph) * parseFloat(tmp.size) / 100); + } else { + tmp.sizeCalculated = parseInt(tmp.size); + } + tmp.sizeCalculated = Math.max(tmp.sizeCalculated, parseInt(tmp.minSize)); + } + // top if any + if (ptop !== null && ptop.hidden !== true) { + l = 0; + t = 0; + w = width; + h = ptop.sizeCalculated; + $('#layout_'+ this.name +'_panel_top').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + ptop.width = w; + ptop.height = h; + // resizer + if (ptop.resizable) { + t = ptop.sizeCalculated - (this.padding === 0 ? this.resizer : 0); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_top').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'top', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('top', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_top').hide(); + } + // left if any + if (pleft !== null && pleft.hidden !== true) { + l = 0; + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = pleft.sizeCalculated; + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0); + e = $('#layout_'+ this.name +'_panel_left'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pleft.width = w; + pleft.height = h; + // resizer + if (pleft.resizable) { + l = pleft.sizeCalculated - (this.padding === 0 ? this.resizer : 0); + w = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_left').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ew-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'left', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('left', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_left').hide(); + $('#layout_'+ this.name +'_resizer_left').hide(); + } + // right if any + if (pright !== null && pright.hidden !== true) { + l = width - pright.sizeCalculated; + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = pright.sizeCalculated; + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0); + $('#layout_'+ this.name +'_panel_right').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pright.width = w; + pright.height = h; + // resizer + if (pright.resizable) { + l = l - this.padding; + w = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_right').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ew-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'right', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('right', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_right').hide(); + } + // bottom if any + if (pbottom !== null && pbottom.hidden !== true) { + l = 0; + t = height - pbottom.sizeCalculated; + w = width; + h = pbottom.sizeCalculated; + $('#layout_'+ this.name +'_panel_bottom').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pbottom.width = w; + pbottom.height = h; + // resizer + if (pbottom.resizable) { + t = t - (this.padding === 0 ? 0 : this.padding); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_bottom').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'bottom', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('bottom', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_bottom').hide(); + } + // main - always there + l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - + (sright ? pright.sizeCalculated + this.padding: 0); + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0) - + (sprev ? pprev.sizeCalculated + this.padding : 0); + e = $('#layout_'+ this.name +'_panel_main'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' }); - } - } else { - $('#layout_'+ this.name +'_panel_preview').hide(); - } - - // display tabs and toolbar if needed - for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) { - var pan = this.get(p); - var tmp = '#layout_'+ this.name +'_panel_'+ p +' > .w2ui-panel-'; - var height = 0; - if (pan.show.tabs) { - if (pan.tabs != null && w2ui[this.name +'_'+ p +'_tabs']) w2ui[this.name +'_'+ p +'_tabs'].resize(); - height += w2utils.getSize($(tmp + 'tabs').css({ display: 'block' }), 'height'); - } - if (pan.show.toolbar) { - if (pan.toolbar != null && w2ui[this.name +'_'+ p +'_toolbar']) w2ui[this.name +'_'+ p +'_toolbar'].resize(); - height += w2utils.getSize($(tmp + 'toolbar').css({ top: height + 'px', display: 'block' }), 'height'); - } - $(tmp + 'content').css({ display: 'block' }).css({ top: height + 'px' }); - } - // send resize to all objects - var obj = this; - clearTimeout(this._resize_timer); - this._resize_timer = setTimeout(function () { - for (var e in w2ui) { - if (typeof w2ui[e].resize == 'function') { - // sent to all none-layouts - if (w2ui[e].panels == 'undefined') w2ui[e].resize(); - // only send to nested layouts - var parent = $(w2ui[e].box).parents('.w2ui-layout'); - if (parent.length > 0 && parent.attr('name') == obj.name) w2ui[e].resize(); - } - } - }, 100); - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + pmain.width = w; + pmain.height = h; + + // preview if any + if (pprev !== null && pprev.hidden !== true) { + l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); + t = height - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - pprev.sizeCalculated; + w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - + (sright ? pright.sizeCalculated + this.padding : 0); + h = pprev.sizeCalculated; + e = $('#layout_'+ this.name +'_panel_preview'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pprev.width = w; + pprev.height = h; + // resizer + if (pprev.resizable) { + t = t - (this.padding === 0 ? 0 : this.padding); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_preview').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'preview', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('preview', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_preview').hide(); + } - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - if (typeof w2ui[this.name] == 'undefined') return false; - // clean up - if ($(this.box).find('#layout_'+ this.name +'_panel_main').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-layout') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - - if (this.tmp.events && this.tmp.events.resize) $(window).off('resize', this.tmp.events.resize); - if (this.tmp.events && this.tmp.events.mousemove) $(document).off('mousemove', this.tmp.events.mousemove); - if (this.tmp.events && this.tmp.events.mouseup) $(document).off('mouseup', this.tmp.events.mouseup); - - return true; - }, + // display tabs and toolbar if needed + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + var pan = this.get(p1); + var tmp2 = '#layout_'+ this.name +'_panel_'+ p1 +' > .w2ui-panel-'; + var tabHeight = 0; + if (pan) { + if (pan.title) { + tabHeight += w2utils.getSize($(tmp2 + 'title').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + if (pan.show.tabs) { + if (pan.tabs !== null && w2ui[this.name +'_'+ p1 +'_tabs']) w2ui[this.name +'_'+ p1 +'_tabs'].resize(); + tabHeight += w2utils.getSize($(tmp2 + 'tabs').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + if (pan.show.toolbar) { + if (pan.toolbar !== null && w2ui[this.name +'_'+ p1 +'_toolbar']) w2ui[this.name +'_'+ p1 +'_toolbar'].resize(); + tabHeight += w2utils.getSize($(tmp2 + 'toolbar').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + } + $(tmp2 + 'content').css({ display: 'block' }).css({ top: tabHeight + 'px' }); + } + // send resize to all objects + clearTimeout(this._resize_timer); + this._resize_timer = setTimeout(function () { + for (var e in w2ui) { + if (typeof w2ui[e].resize == 'function') { + // sent to all none-layouts + if (w2ui[e].panels == 'undefined') w2ui[e].resize(); + // only send to nested layouts + var parent = $(w2ui[e].box).parents('.w2ui-layout'); + if (parent.length > 0 && parent.attr('name') == obj.name) w2ui[e].resize(); + } + } + }, 100); + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - lock: function (panel, msg, showSpinner) { - if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) { - console.log('ERROR: First parameter needs to be the a valid panel name.'); - return; - } - var nm = '#layout_'+ this.name + '_panel_' + panel; - w2utils.lock(nm, msg, showSpinner); - }, + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + if (typeof w2ui[this.name] == 'undefined') return false; + // clean up + if ($(this.box).find('#layout_'+ this.name +'_panel_main').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-layout') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + if (this.tmp.events && this.tmp.events.resize) $(window).off('resize', this.tmp.events.resize); + return true; + }, - unlock: function (panel) { - if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) { - console.log('ERROR: First parameter needs to be the a valid panel name.'); - return; - } - var nm = '#layout_'+ this.name + '_panel_' + panel; - w2utils.unlock(nm); - } - } + lock: function (panel, msg, showSpinner) { + if (w2layout_panels.indexOf(panel) == -1) { + console.log('ERROR: First parameter needs to be the a valid panel name.'); + return; + } + var args = Array.prototype.slice.call(arguments, 0); + args[0] = '#layout_'+ this.name + '_panel_' + panel; + w2utils.lock.apply(window, args); + }, + + unlock: function (panel) { + if (w2layout_panels.indexOf(panel) == -1) { + console.log('ERROR: First parameter needs to be the a valid panel name.'); + return; + } + var nm = '#layout_'+ this.name + '_panel_' + panel; + w2utils.unlock(nm); + } + }; - $.extend(w2layout.prototype, w2utils.event); - w2obj.layout = w2layout; + $.extend(w2layout.prototype, w2utils.event); + w2obj.layout = w2layout; })(jQuery); /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2popup - popup widget - * - $().w2popup - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - when maximized, align the slide down message - * - bug: after transfer to another content, message does not work - * - transition should include title, body and buttons, not just body - * - add lock method() to lock popup content - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2popup - popup widget +* - $().w2popup - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - transition should include title, body and buttons, not just body +* +************************************************************************/ var w2popup = {}; (function ($) { - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2popup = function(method, options) { - if (typeof method == 'undefined') { - options = {}; - method = 'open'; - } - if ($.isPlainObject(method)) { - options = method; - method = 'open'; - } - method = method.toLowerCase(); - if (method == 'load' && typeof options == 'string') options = { url: options }; - if (method == 'open' && typeof options.url != 'undefined') method = 'load'; - if (typeof options == 'undefined') options = {}; - // load options from markup - var dlgOptions = {}; - if ($(this).length > 0 ) { - if ($(this).find('div[rel=title], div[rel=body], div[rel=buttons]').length > 0) { - if ($(this).find('div[rel=title]').length > 0) { - dlgOptions['title'] = $(this).find('div[rel=title]').html(); - } - if ($(this).find('div[rel=body]').length > 0) { - dlgOptions['body'] = $(this).find('div[rel=body]').html(); - dlgOptions['style'] = $(this).find('div[rel=body]')[0].style.cssText; - } - if ($(this).find('div[rel=buttons]').length > 0) { - dlgOptions['buttons'] = $(this).find('div[rel=buttons]').html(); - } - } else { - dlgOptions['title'] = ' '; - dlgOptions['body'] = $(this).html(); - } - if (parseInt($(this).css('width')) != 0) dlgOptions['width'] = parseInt($(this).css('width')); - if (parseInt($(this).css('height')) != 0) dlgOptions['height'] = parseInt($(this).css('height')); - } - // show popup - return w2popup[method]($.extend({}, dlgOptions, options)); - }; - - // ==================================================== - // -- Implementation of core functionality (SINGELTON) - - w2popup = { - defaults: { - title : '', - body : '', - buttons : '', - style : '', - color : '#000', - opacity : 0.4, - speed : 0.3, - modal : false, - maximized : false, - keyboard : true, // will close popup on esc if not modal - width : 500, - height : 300, - showClose : true, - showMax : false, - transition : null - }, - handlers : [], - onOpen : null, - onClose : null, - onMax : null, - onMin : null, - onKeydown : null, - - open: function (options) { - var obj = this; - // get old options and merge them - var old_options = $('#w2ui-popup').data('options'); - var options = $.extend({}, this.defaults, { body : '' }, old_options, options); - // if new - reset event handlers - if ($('#w2ui-popup').length == 0) { - w2popup.handlers = []; - w2popup.onMax = null; - w2popup.onMin = null; - w2popup.onOpen = null; - w2popup.onClose = null; - w2popup.onKeydown = null; - } - if (options.onOpen) w2popup.onOpen = options.onOpen; - if (options.onClose) w2popup.onClose = options.onClose; - if (options.onMax) w2popup.onMax = options.onMax; - if (options.onMin) w2popup.onMin = options.onMin; - if (options.onKeydown) w2popup.onKeydown = options.onKeydown; - - if (window.innerHeight == undefined) { - var width = document.documentElement.offsetWidth; - var height = document.documentElement.offsetHeight; - if (w2utils.engine == 'IE7') { width += 21; height += 4; } - } else { - var width = window.innerWidth; - var height = window.innerHeight; - } - if (parseInt(width) - 10 < parseInt(options.width)) options.width = parseInt(width) - 10; - if (parseInt(height) - 10 < parseInt(options.height)) options.height = parseInt(height) - 10; - var top = ((parseInt(height) - parseInt(options.height)) / 2) * 0.6; - var left = (parseInt(width) - parseInt(options.width)) / 2; - // check if message is already displayed - if ($('#w2ui-popup').length == 0) { - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: false }); - if (eventData.isCancelled === true) return; - // output message - w2popup.lockScreen(options); - var msg = ''; - if (options.title != '') { - msg +=''+ - (options.showClose ? 'Close' : '')+ - (options.showMax ? 'Max' : '') + - options.title + - ''; - } - msg += ''; - msg += ''+ options.body +''; - msg += ''; - msg += ''; - msg += ''; - msg += ''; - if (options.buttons != '') { - msg += ''+ options.buttons +''; - } - msg += ''; - $('body').append(msg); - // allow element to render - setTimeout(function () { - $('#w2ui-popup .w2ui-box2').hide(); - $('#w2ui-popup').css({ - '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform', - '-webkit-transform': 'scale(1)', - '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform', - '-moz-transform': 'scale(1)', - '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform', - '-ms-transform': 'scale(1)', - '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform', - '-o-transform': 'scale(1)', - 'opacity': '1' - }); - }, 1); - // clean transform - setTimeout(function () { - $('#w2ui-popup').css({ - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '' - }); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, options.speed * 1000); - } else { - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: true }); - if (eventData.isCancelled === true) return; - // check if size changed - if (typeof old_options == 'undefined' || old_options['width'] != options['width'] || old_options['height'] != options['height']) { - $('#w2ui-panel').remove(); - w2popup.resize(options.width, options.height); - } - // show new items - var body = $('#w2ui-popup .w2ui-box2 > .w2ui-msg-body').html(options.body); - if (body.length > 0) body[0].style.cssText = options.style; - $('#w2ui-popup .w2ui-msg-buttons').html(options.buttons); - $('#w2ui-popup .w2ui-msg-title').html( - (options.showClose ? 'Close' : '')+ - (options.showMax ? 'Max' : '') + - options.title); - // transition - var div_old = $('#w2ui-popup .w2ui-box1')[0]; - var div_new = $('#w2ui-popup .w2ui-box2')[0]; - w2utils.transition(div_old, div_new, options.transition); - div_new.className = 'w2ui-box1'; - div_old.className = 'w2ui-box2'; - $(div_new).addClass('w2ui-current-box'); - // remove max state - $('#w2ui-popup').data('prev-size', null); - // call event onChange - setTimeout(function () { - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - } - // save new options - options._last_w2ui_name = w2utils.keyboard.active(); - w2utils.keyboard.active(null); - $('#w2ui-popup').data('options', options); - // keyboard events - if (options.keyboard) $(document).on('keydown', this.keydown); - - // initialize move - var tmp = { resizing: false }; - $('#w2ui-popup .w2ui-msg-title') - .on('mousedown', function (event) { mvStart(event); }) - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - $('#w2ui-popup .w2ui-msg-body') - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - $('#w2ui-lock') - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - - // handlers - function mvStart(event) { - if (!event) event = window.event; - if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } - tmp.resizing = true; - tmp.tmp_x = event.screenX; - tmp.tmp_y = event.screenY; - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); else return false; - } - - function mvMove(evnt) { - if (tmp.resizing != true) return; - if (!evnt) evnt = window.event; - tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x); - tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y); - $('#w2ui-popup').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-ms-transition': 'none', - '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-o-transition': 'none', - '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)' - }); - $('#w2ui-panel').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-ms-transition': 'none', - '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px', - '-o-transition': 'none', - '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)' - }); - } - - function mvStop(evnt) { - if (tmp.resizing != true) return; - if (!evnt) evnt = window.event; - tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x); - tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y); - $('#w2ui-popup').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d(0px, 0px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate(0px, 0px)', - '-ms-transition': 'none', - '-ms-transform': 'translate(0px, 0px)', - '-o-transition': 'none', - '-o-transform': 'translate(0px, 0px)', - 'left': (parseInt($('#w2ui-popup').css('left')) + parseInt(tmp.tmp_div_x)) + 'px', - 'top': (parseInt($('#w2ui-popup').css('top')) + parseInt(tmp.tmp_div_y)) + 'px' - }); - $('#w2ui-panel').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d(0px, 0px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate(0px, 0px)', - '-ms-transition': 'none', - '-ms-transform': 'translate(0px, 0px)', - '-o-transition': 'none', - '-o-transform': 'translate(0px, 0px)', - 'left': (parseInt($('#w2ui-panel').css('left')) + parseInt(tmp.tmp_div_x)) + 'px', - 'top': (parseInt($('#w2ui-panel').css('top')) + parseInt(tmp.tmp_div_y)) + 'px' - }); - tmp.resizing = false; - } - return this; - }, - - keydown: function (event) { - var options = $('#w2ui-popup').data('options'); - if (!options.keyboard) return; - // trigger event - var eventData = w2popup.trigger({ phase: 'before', type: 'keydown', target: 'popup', options: options, object: w2popup, originalEvent: event }); - if (eventData.isCancelled === true) return; - // default behavior - switch (event.keyCode) { - case 27: - event.preventDefault(); - if ($('#w2ui-popup .w2ui-popup-message').length > 0) w2popup.message(); else w2popup.close(); - break; - } - // event after - w2popup.trigger($.extend(eventData, { phase: 'after'})); - }, - - close: function (options) { - var obj = this; - var options = $.extend({}, $('#w2ui-popup').data('options'), options); - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'close', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - $('#w2ui-popup, #w2ui-panel').css({ - '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform', - '-webkit-transform': 'scale(0.9)', - '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform', - '-moz-transform': 'scale(0.9)', - '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform', - '-ms-transform': 'scale(0.9)', - '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform', - '-o-transform': 'scale(0.9)', - 'opacity': '0' - }); - w2popup.unlockScreen(); - setTimeout(function () { - $('#w2ui-popup').remove(); - $('#w2ui-panel').remove(); - // event after - obj.trigger($.extend(eventData, { phase: 'after'})); - }, options.speed * 1000); - // restore active - w2utils.keyboard.active(options._last_w2ui_name); - // remove keyboard events - if (options.keyboard) $(document).off('keydown', this.keydown); - }, - - toggle: function () { - var options = $('#w2ui-popup').data('options'); - if (options.maximized === true) w2popup.min(); else w2popup.max(); - }, - - max: function () { - var obj = this; - var options = $('#w2ui-popup').data('options'); - if (options.maximized === true) return; - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'max', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - options.maximized = true; - options.prevSize = $('#w2ui-popup').css('width')+':'+$('#w2ui-popup').css('height'); - $('#w2ui-popup').data('options', options); - // do resize - w2popup.resize(10000, 10000, function () { - obj.trigger($.extend(eventData, { phase: 'after'})); - }); - }, - - min: function () { - var obj = this; - var options = $('#w2ui-popup').data('options'); - if (options.maximized !== true) return; - var size = options.prevSize.split(':'); - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'min', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - options.maximized = false; - options.prevSize = null; - $('#w2ui-popup').data('options', options); - // do resize - w2popup.resize(size[0], size[1], function () { - obj.trigger($.extend(eventData, { phase: 'after'})); - }); - }, - - get: function () { - return $('#w2ui-popup').data('options'); - }, - - set: function (options) { - w2popup.open(options); - }, - - clear: function() { - $('#w2ui-popup .w2ui-msg-title').html(''); - $('#w2ui-popup .w2ui-msg-body').html(''); - $('#w2ui-popup .w2ui-msg-buttons').html(''); - }, - - reset: function () { - w2popup.open(w2popup.defaults); - }, + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2popup = function(method, options) { + if (typeof method === 'undefined') { + options = {}; + method = 'open'; + } + if ($.isPlainObject(method)) { + options = method; + method = 'open'; + } + method = method.toLowerCase(); + if (method === 'load' && typeof options === 'string') { + options = $.extend({ url: options }, arguments.length > 2 ? arguments[2] : {}); + } + if (method === 'open' && options.url != null) method = 'load'; + options = options || {}; + // load options from markup + var dlgOptions = {}; + if ($(this).length > 0) { + if ($(this).find('div[rel=title], div[rel=body], div[rel=buttons]').length > 0) { + if ($(this).find('div[rel=title]').length > 0) { + dlgOptions['title'] = $(this).find('div[rel=title]').html(); + } + if ($(this).find('div[rel=body]').length > 0) { + dlgOptions['body'] = $(this).find('div[rel=body]').html(); + dlgOptions['style'] = $(this).find('div[rel=body]')[0].style.cssText; + } + if ($(this).find('div[rel=buttons]').length > 0) { + dlgOptions['buttons'] = $(this).find('div[rel=buttons]').html(); + } + } else { + dlgOptions['title'] = ' '; + dlgOptions['body'] = $(this).html(); + } + if (parseInt($(this).css('width')) != 0) dlgOptions['width'] = parseInt($(this).css('width')); + if (parseInt($(this).css('height')) != 0) dlgOptions['height'] = parseInt($(this).css('height')); + } + // show popup + return w2popup[method]($.extend({}, dlgOptions, options)); + }; + + // ==================================================== + // -- Implementation of core functionality (SINGELTON) + + w2popup = { + defaults: { + title : '', + body : '', + buttons : '', + style : '', + color : '#000', + opacity : 0.4, + speed : 0.3, + modal : false, + maximized : false, + keyboard : true, // will close popup on esc if not modal + width : 500, + height : 300, + showClose : true, + showMax : false, + transition: null + }, + status : 'closed', // string that describes current status + handlers : [], + onOpen : null, + onClose : null, + onMax : null, + onMin : null, + onToggle : null, + onKeydown : null, + + open: function (options) { + var obj = this; + if (w2popup.status == 'closing') { + setTimeout(function () { obj.open.call(obj, options); }, 100); + return; + } + // get old options and merge them + var old_options = $('#w2ui-popup').data('options'); + var options = $.extend({}, this.defaults, old_options, { title: '', body : '', buttons: '' }, options, { maximized: false }); + // need timer because popup might not be open + setTimeout(function () { $('#w2ui-popup').data('options', options); }, 100); + // if new - reset event handlers + if ($('#w2ui-popup').length == 0) { + w2popup.handlers = []; + w2popup.onMax = null; + w2popup.onMin = null; + w2popup.onToggle = null; + w2popup.onOpen = null; + w2popup.onClose = null; + w2popup.onKeydown = null; + } + if (options.onOpen) w2popup.onOpen = options.onOpen; + if (options.onClose) w2popup.onClose = options.onClose; + if (options.onMax) w2popup.onMax = options.onMax; + if (options.onMin) w2popup.onMin = options.onMin; + if (options.onToggle) w2popup.onToggle = options.onToggle; + if (options.onKeydown) w2popup.onKeydown = options.onKeydown; + + if (window.innerHeight == undefined) { + var width = document.documentElement.offsetWidth; + var height = document.documentElement.offsetHeight; + if (w2utils.engine === 'IE7') { width += 21; height += 4; } + } else { + var width = window.innerWidth; + var height = window.innerHeight; + } + if (parseInt(width) - 10 < parseInt(options.width)) options.width = parseInt(width) - 10; + if (parseInt(height) - 10 < parseInt(options.height)) options.height = parseInt(height) - 10; + var top = parseInt(((parseInt(height) - parseInt(options.height)) / 2) * 0.6); + var left = parseInt((parseInt(width) - parseInt(options.width)) / 2); + // check if message is already displayed + if ($('#w2ui-popup').length == 0) { + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: false }); + if (eventData.isCancelled === true) return; + w2popup.status = 'opening'; + // output message + w2popup.lockScreen(options); + var btn = ''; + if (options.showClose) { + btn += 'Close'; + } + if (options.showMax) { + btn += 'Max'; + } + var msg=''+ + ' ' + btn + options.title + ''+ + ' '+ + ' ' + options.body + ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' ' + options.buttons + ''+ + ''; + $('body').append(msg); + // allow element to render + setTimeout(function () { + $('#w2ui-popup .w2ui-box2').hide(); + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's opacity, ' + options.speed + 's -webkit-transform', + '-webkit-transform': 'scale(1)', + '-moz-transition': options.speed + 's opacity, ' + options.speed + 's -moz-transform', + '-moz-transform': 'scale(1)', + '-ms-transition': options.speed + 's opacity, ' + options.speed + 's -ms-transform', + '-ms-transform': 'scale(1)', + '-o-transition': options.speed + 's opacity, ' + options.speed + 's -o-transform', + '-o-transform': 'scale(1)', + 'opacity': '1' + }); + }, 1); + // clean transform + setTimeout(function () { + $('#w2ui-popup').css({ + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '' + }); + // event after + w2popup.status = 'open'; + setTimeout(function () { + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 100); + }, options.speed * 1000); + } else { + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: true }); + if (eventData.isCancelled === true) return; + // check if size changed + w2popup.status = 'opening'; + if (typeof old_options == 'undefined' || old_options['width'] != options['width'] || old_options['height'] != options['height']) { + w2popup.resize(options.width, options.height); + } + if (typeof old_options != 'undefined') { + options.prevSize = options.width + ':' + options.height; + options.maximized = old_options.maximized; + } + // show new items + var body = $('#w2ui-popup .w2ui-box2 > .w2ui-msg-body').html(options.body); + if (body.length > 0) body[0].style.cssText = options.style; + if (options.buttons != '') { + $('#w2ui-popup .w2ui-msg-buttons').show().html(options.buttons); + $('#w2ui-popup .w2ui-msg-body').removeClass('w2ui-msg-no-buttons'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('bottom', ''); + } else { + $('#w2ui-popup .w2ui-msg-buttons').hide().html(''); + $('#w2ui-popup .w2ui-msg-body').addClass('w2ui-msg-no-buttons'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('bottom', '0px'); + } + if (options.title != '') { + $('#w2ui-popup .w2ui-msg-title').show().html( + (options.showClose ? 'Close' : '') + + (options.showMax ? 'Max' : '') + + options.title); + $('#w2ui-popup .w2ui-msg-body').removeClass('w2ui-msg-no-title'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('top', ''); + } else { + $('#w2ui-popup .w2ui-msg-title').hide().html(''); + $('#w2ui-popup .w2ui-msg-body').addClass('w2ui-msg-no-title'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('top', '0px'); + } + // transition + var div_old = $('#w2ui-popup .w2ui-box1')[0]; + var div_new = $('#w2ui-popup .w2ui-box2')[0]; + w2utils.transition(div_old, div_new, options.transition); + div_new.className = 'w2ui-box1'; + div_old.className = 'w2ui-box2'; + $(div_new).addClass('w2ui-current-box'); + // remove max state + $('#w2ui-popup').data('prev-size', null); + // call event onChange + setTimeout(function () { + w2popup.status = 'open'; + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 100); + } + // save new options + options._last_w2ui_name = w2utils.keyboard.active(); + w2utils.keyboard.active(null); + // keyboard events + if (options.keyboard) $(document).on('keydown', this.keydown); - load: function (options) { - if (String(options.url) == 'undefined') { - console.log('ERROR: The url parameter is empty.'); - return; - } - var tmp = String(options.url).split('#'); - var url = tmp[0]; - var selector = tmp[1]; - if (String(options) == 'undefined') options = {}; - // load url - var html = $('#w2ui-popup').data(url); - if (typeof html != 'undefined' && html != null) { - popup(html, selector); - } else { - $.get(url, function (data, status, obj) { - popup(obj.responseText, selector); - $('#w2ui-popup').data(url, obj.responseText); // remember for possible future purposes - }); - } - function popup(html, selector) { - delete options.url; - $('body').append(''+ html +''); - if (typeof selector != 'undefined' && $('#w2ui-tmp #'+selector).length > 0) { - $('#w2ui-tmp #'+ selector).w2popup(options); - } else { - $('#w2ui-tmp > div').w2popup(options); - } - // link styles - if ($('#w2ui-tmp > style').length > 0) { - var style = $('').append($('#w2ui-tmp > style').clone()).html(); - if ($('#w2ui-popup #div-style').length == 0) { - $('#w2ui-ppopup').append(''); - } - $('#w2ui-popup #div-style').html(style); - } - $('#w2ui-tmp').remove(); - } - }, + // initialize move + var tmp = { + resizing : false, + mvMove : mvMove, + mvStop : mvStop + }; + $('#w2ui-popup .w2ui-msg-title').on('mousedown', function (event) { mvStart(event); }) + + // handlers + function mvStart(evnt) { + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + w2popup.status = 'moving'; + tmp.resizing = true; + tmp.x = evnt.screenX; + tmp.y = evnt.screenY; + tmp.pos_x = $('#w2ui-popup').position().left; + tmp.pos_y = $('#w2ui-popup').position().top; + w2popup.lock({ opacity: 0 }); + $(document).on('mousemove', tmp.mvMove); + $(document).on('mouseup', tmp.mvStop); + if (evnt.stopPropagation) evnt.stopPropagation(); else evnt.cancelBubble = true; + if (evnt.preventDefault) evnt.preventDefault(); else return false; + } - message: function (options) { - $().w2tag(); // hide all tags - if (!options) options = { width: 200, height: 100 }; - if (parseInt(options.width) < 10) options.width = 10; - if (parseInt(options.height) < 10) options.height = 10; - if (typeof options.hideOnClick == 'undefined') options.hideOnClick = false; - - var head = $('#w2ui-popup .w2ui-msg-title'); - if ($('#w2ui-popup .w2ui-popup-message').length == 0) { - var pwidth = parseInt($('#w2ui-popup').width()); - $('#w2ui-popup .w2ui-box1') - .before(''+ - ''); - $('#w2ui-popup .w2ui-popup-message').data('options', options); - } else { - if (typeof options.width == 'undefined') options.width = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'width'); - if (typeof options.height == 'undefined') options.height = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'height'); - } - var display = $('#w2ui-popup .w2ui-popup-message').css('display'); - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-moz-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-ms-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-o-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)') - }); - if (display == 'none') { - $('#w2ui-popup .w2ui-popup-message').show().html(options.html); - setTimeout(function() { - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transition': '0s', '-moz-transition': '0s', '-ms-transition': '0s', '-o-transition': '0s', - 'z-Index': 1500 - }); // has to be on top of lock - w2popup.lock(); - if (typeof options.onOpen == 'function') options.onOpen(); - }, 300); - } else { - $('#w2ui-popup .w2ui-popup-message').css('z-Index', 250); - var options = $('#w2ui-popup .w2ui-popup-message').data('options'); - $('#w2ui-popup .w2ui-popup-message').remove(); - w2popup.unlock(); - if (typeof options.onClose == 'function') options.onClose(); - } - // timer needs to animation - setTimeout(function () { - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-moz-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-ms-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-o-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)') - }); - }, 1); - }, + function mvMove(evnt) { + if (tmp.resizing != true) return; + if (!evnt) evnt = window.event; + tmp.div_x = evnt.screenX - tmp.x; + tmp.div_y = evnt.screenY - tmp.y; + $('#w2ui-popup').css({ + '-webkit-transition': 'none', + '-webkit-transform': 'translate3d('+ tmp.div_x +'px, '+ tmp.div_y +'px, 0px)', + '-moz-transition': 'none', + '-moz-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)', + '-ms-transition': 'none', + '-ms-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)', + '-o-transition': 'none', + '-o-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)' + }); + } - lock: function (msg, showSpinner) { - w2utils.lock($('#w2ui-popup'), msg, showSpinner); - }, + function mvStop(evnt) { + if (tmp.resizing != true) return; + if (!evnt) evnt = window.event; + w2popup.status = 'open'; + tmp.div_x = (evnt.screenX - tmp.x); + tmp.div_y = (evnt.screenY - tmp.y); + $('#w2ui-popup').css({ + 'left': (tmp.pos_x + tmp.div_x) + 'px', + 'top': (tmp.pos_y + tmp.div_y) + 'px', + '-webkit-transition': 'none', + '-webkit-transform': 'translate3d(0px, 0px, 0px)', + '-moz-transition': 'none', + '-moz-transform': 'translate(0px, 0px)', + '-ms-transition': 'none', + '-ms-transform': 'translate(0px, 0px)', + '-o-transition': 'none', + '-o-transform': 'translate(0px, 0px)' + }); + tmp.resizing = false; + $(document).off('mousemove', tmp.mvMove); + $(document).off('mouseup', tmp.mvStop); + w2popup.unlock(); + } + return this; + }, + + keydown: function (event) { + var options = $('#w2ui-popup').data('options'); + if (!options.keyboard) return; + // trigger event + var eventData = w2popup.trigger({ phase: 'before', type: 'keydown', target: 'popup', options: options, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behavior + switch (event.keyCode) { + case 27: + event.preventDefault(); + if ($('#w2ui-popup .w2ui-popup-message').length > 0) w2popup.message(); else w2popup.close(); + break; + } + // event after + w2popup.trigger($.extend(eventData, { phase: 'after'})); + }, - unlock: function () { - w2utils.unlock($('#w2ui-popup')); - }, + close: function (options) { + var obj = this; + var options = $.extend({}, $('#w2ui-popup').data('options'), options); + if ($('#w2ui-popup').length == 0) return; + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'close', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'closing'; + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's opacity, ' + options.speed + 's -webkit-transform', + '-webkit-transform': 'scale(0.9)', + '-moz-transition': options.speed + 's opacity, ' + options.speed + 's -moz-transform', + '-moz-transform': 'scale(0.9)', + '-ms-transition': options.speed + 's opacity, ' + options.speed + 's -ms-transform', + '-ms-transform': 'scale(0.9)', + '-o-transition': options.speed + 's opacity, ' + options.speed + 's -o-transform', + '-o-transform': 'scale(0.9)', + 'opacity': '0' + }); + w2popup.unlockScreen(options); + setTimeout(function () { + $('#w2ui-popup').remove(); + w2popup.status = 'closed'; + // event after + obj.trigger($.extend(eventData, { phase: 'after'})); + }, options.speed * 1000); + // restore active + w2utils.keyboard.active(options._last_w2ui_name); + // remove keyboard events + if (options.keyboard) $(document).off('keydown', this.keydown); + }, + + toggle: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'toggle', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // defatul action + if (options.maximized === true) w2popup.min(); else w2popup.max(); + // event after + setTimeout(function () { + obj.trigger($.extend(eventData, { phase: 'after'})); + }, (options.speed * 1000) + 50); + }, - // --- INTERNAL FUNCTIONS - - lockScreen: function (options) { - if ($('#w2ui-lock').length > 0) return false; - if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); - if (typeof options == 'undefined') options = {}; - options = $.extend({}, w2popup.defaults, options); - // show element - $('body').append(''); - // lock screen - setTimeout(function () { - $('#w2ui-lock').css({ - '-webkit-transition': options.speed +'s opacity', - '-moz-transition': options.speed +'s opacity', - '-ms-transition': options.speed +'s opacity', - '-o-transition': options.speed +'s opacity', - 'opacity': options.opacity - }); - }, 1); - // add events - if (options.modal == true) { - $('#w2ui-lock').on('mousedown', function () { - $('#w2ui-lock').css({ - '-webkit-transition': '.1s', - '-moz-transition': '.1s', - '-ms-transition': '.1s', - '-o-transition': '.1s', - 'opacity': '0.6' - }); - if (window.getSelection) window.getSelection().removeAllRanges(); - }); - $('#w2ui-lock').on('mouseup', function () { - setTimeout(function () { - $('#w2ui-lock').css({ - '-webkit-transition': '.1s', - '-moz-transition': '.1s', - '-ms-transition': '.1s', - '-o-transition': '.1s', - 'opacity': options.opacity + max: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + if (options.maximized === true) return; + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'max', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'resizing'; + options.prevSize = $('#w2ui-popup').css('width') + ':' + $('#w2ui-popup').css('height'); + // do resize + w2popup.resize(10000, 10000, function () { + w2popup.status = 'open'; + options.maximized = true; + obj.trigger($.extend(eventData, { phase: 'after'})); }); - }, 100); - if (window.getSelection) window.getSelection().removeAllRanges(); - }); - } else { - $('#w2ui-lock').on('mouseup', function () { w2popup.close(); }); - } - return true; - }, + }, - unlockScreen: function () { - if ($('#w2ui-lock').length == 0) return false; - var options = $.extend({}, $('#w2ui-popup').data('options'), options); - $('#w2ui-lock').css({ - '-webkit-transition': options.speed +'s opacity', - '-moz-transition': options.speed +'s opacity', - '-ms-transition': options.speed +'s opacity', - '-o-transition': options.speed +'s opacity', - 'opacity': 0 - }); - setTimeout(function () { - $('#w2ui-lock').remove(); - }, options.speed * 1000); - return true; - }, + min: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + if (options.maximized !== true) return; + var size = options.prevSize.split(':'); + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'min', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'resizing'; + // do resize + w2popup.resize(size[0], size[1], function () { + w2popup.status = 'open'; + options.maximized = false; + options.prevSize = null; + obj.trigger($.extend(eventData, { phase: 'after'})); + }); + }, + + get: function () { + return $('#w2ui-popup').data('options'); + }, + + set: function (options) { + w2popup.open(options); + }, + + clear: function() { + $('#w2ui-popup .w2ui-msg-title').html(''); + $('#w2ui-popup .w2ui-msg-body').html(''); + $('#w2ui-popup .w2ui-msg-buttons').html(''); + }, + + reset: function () { + w2popup.open(w2popup.defaults); + }, + + load: function (options) { + w2popup.status = 'loading'; + if (String(options.url) == 'undefined') { + console.log('ERROR: The url parameter is empty.'); + return; + } + var tmp = String(options.url).split('#'); + var url = tmp[0]; + var selector = tmp[1]; + if (String(options) == 'undefined') options = {}; + // load url + var html = $('#w2ui-popup').data(url); + if (typeof html != 'undefined' && html != null) { + popup(html, selector); + } else { + $.get(url, function (data, status, obj) { // should always be $.get as it is template + popup(obj.responseText, selector); + $('#w2ui-popup').data(url, obj.responseText); // remember for possible future purposes + }); + } + function popup(html, selector) { + delete options.url; + $('body').append('' + html + ''); + if (typeof selector != 'undefined' && $('#w2ui-tmp #'+selector).length > 0) { + $('#w2ui-tmp #' + selector).w2popup(options); + } else { + $('#w2ui-tmp > div').w2popup(options); + } + // link styles + if ($('#w2ui-tmp > style').length > 0) { + var style = $('').append($('#w2ui-tmp > style').clone()).html(); + if ($('#w2ui-popup #div-style').length == 0) { + $('#w2ui-popup').append(''); + } + $('#w2ui-popup #div-style').html(style); + } + $('#w2ui-tmp').remove(); + } + }, + + message: function (options) { + $().w2tag(); // hide all tags + if (!options) options = { width: 200, height: 100 }; + if (parseInt(options.width) < 10) options.width = 10; + if (parseInt(options.height) < 10) options.height = 10; + if (typeof options.hideOnClick == 'undefined') options.hideOnClick = false; + var poptions = $('#w2ui-popup').data('options') || {}; + if (typeof options.width == 'undefined' || options.width > poptions.width - 10) options.width = poptions.width - 10; + if (typeof options.height == 'undefined' || options.height > poptions.height - 40) options.height = poptions.height - 40; // title is 30px or so + + var head = $('#w2ui-popup .w2ui-msg-title'); + var pwidth = parseInt($('#w2ui-popup').width()); + var msgCount = $('#w2ui-popup .w2ui-popup-message').length; + // remove message + if ($.trim(options.html) == '') { + $('#w2ui-popup #w2ui-message'+ (msgCount-1)).css('z-Index', 250); + var options = $('#w2ui-popup #w2ui-message'+ (msgCount-1)).data('options') || {}; + $('#w2ui-popup #w2ui-message'+ (msgCount-1)).remove(); + if (typeof options.onClose == 'function') options.onClose(); + if (msgCount == 1) { + w2popup.unlock(); + } else { + $('#w2ui-popup #w2ui-message'+ (msgCount-2)).show(); + } + } else { + // hide previous messages + $('#w2ui-popup .w2ui-popup-message').hide(); + // add message + $('#w2ui-popup .w2ui-box1') + .before('' + + ''); + $('#w2ui-popup #w2ui-message'+ msgCount).data('options', options); + var display = $('#w2ui-popup #w2ui-message'+ msgCount).css('display'); + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-moz-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-ms-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-o-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)') + }); + if (display == 'none') { + $('#w2ui-popup #w2ui-message'+ msgCount).show().html(options.html); + // timer needs to animation + setTimeout(function () { + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-moz-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-ms-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-o-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)') + }); + }, 1); + // timer for lock + setTimeout(function() { + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transition': '0s', '-moz-transition': '0s', '-ms-transition': '0s', '-o-transition': '0s', + 'z-Index': 1500 + }); // has to be on top of lock + if (msgCount == 0) w2popup.lock(); + if (typeof options.onOpen == 'function') options.onOpen(); + }, 300); + } + } + }, + + lock: function (msg, showSpinner) { + var args = Array.prototype.slice.call(arguments, 0); + args.unshift($('#w2ui-popup')); + w2utils.lock.apply(window, args); + }, + + unlock: function () { + w2utils.unlock($('#w2ui-popup')); + }, + + // --- INTERNAL FUNCTIONS + + lockScreen: function (options) { + if ($('#w2ui-lock').length > 0) return false; + if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); + if (typeof options == 'undefined') options = {}; + options = $.extend({}, w2popup.defaults, options); + // show element + $('body').append(''); + // lock screen + setTimeout(function () { + $('#w2ui-lock').css({ + '-webkit-transition': options.speed + 's opacity', + '-moz-transition': options.speed + 's opacity', + '-ms-transition': options.speed + 's opacity', + '-o-transition': options.speed + 's opacity', + 'opacity': options.opacity + }); + }, 1); + // add events + if (options.modal == true) { + $('#w2ui-lock').on('mousedown', function () { + $('#w2ui-lock').css({ + '-webkit-transition': '.1s', + '-moz-transition': '.1s', + '-ms-transition': '.1s', + '-o-transition': '.1s', + 'opacity': '0.6' + }); + // if (window.getSelection) window.getSelection().removeAllRanges(); + }); + $('#w2ui-lock').on('mouseup', function () { + setTimeout(function () { + $('#w2ui-lock').css({ + '-webkit-transition': '.1s', + '-moz-transition': '.1s', + '-ms-transition': '.1s', + '-o-transition': '.1s', + 'opacity': options.opacity + }); + }, 100); + // if (window.getSelection) window.getSelection().removeAllRanges(); + }); + } else { + $('#w2ui-lock').on('mouseup', function () { w2popup.close(); }); + } + return true; + }, - resize: function (width, height, callBack) { - var options = $('#w2ui-popup').data('options'); - // calculate new position - if (parseInt($(window).width()) - 10 < parseInt(width)) width = parseInt($(window).width()) - 10; - if (parseInt($(window).height()) - 10 < parseInt(height)) height = parseInt($(window).height()) - 10; - var top = ((parseInt($(window).height()) - parseInt(height)) / 2) * 0.8; - var left = (parseInt($(window).width()) - parseInt(width)) / 2; - // resize there - $('#w2ui-popup').css({ - '-webkit-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-moz-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-ms-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-o-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - 'top': top, - 'left': left, - 'width': width, - 'height': height - }); - if (typeof callBack == 'function') { - setTimeout(function () { - callBack(); - }, options.speed * 1000); - } + unlockScreen: function (options) { + if ($('#w2ui-lock').length == 0) return false; + if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); + if (typeof options == 'undefined') options = {}; + options = $.extend({}, w2popup.defaults, options); + $('#w2ui-lock').css({ + '-webkit-transition': options.speed + 's opacity', + '-moz-transition': options.speed + 's opacity', + '-ms-transition': options.speed + 's opacity', + '-o-transition': options.speed + 's opacity', + 'opacity': 0 + }); + setTimeout(function () { + $('#w2ui-lock').remove(); + }, options.speed * 1000); + return true; + }, + + resize: function (width, height, callBack) { + var options = $('#w2ui-popup').data('options'); + // calculate new position + if (parseInt($(window).width()) - 10 < parseInt(width)) width = parseInt($(window).width()) - 10; + if (parseInt($(window).height()) - 10 < parseInt(height)) height = parseInt($(window).height()) - 10; + var top = ((parseInt($(window).height()) - parseInt(height)) / 2) * 0.8; + var left = (parseInt($(window).width()) - parseInt(width)) / 2; + // resize there + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-moz-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-ms-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-o-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + 'top': top, + 'left': left, + 'width': width, + 'height': height + }); + setTimeout(function () { + options.width = width; + options.height = height; + if (typeof callBack == 'function') callBack(); + }, (options.speed * 1000) + 50); // give extra 50 ms + } } - } - // merge in event handling - $.extend(w2popup, w2utils.event); + // merge in event handling + $.extend(w2popup, w2utils.event); })(jQuery); @@ -6940,4212 +8480,5213 @@ var w2popup = {}; // --- Common dialogs var w2alert = function (msg, title, callBack) { - if (typeof title == 'undefined') title = w2utils.lang('Notification'); - if (jQuery('#w2ui-popup').length > 0) { - w2popup.message({ - width : 400, - height : 150, - html : ''+ - ' '+ msg +''+ - ''+ - ''+ - ' '+ - '', - onClose : function () { - if (typeof callBack == 'function') callBack(); - } - }); - } else { - w2popup.open({ - width : 450, - height : 200, - showMax : false, - title : title, - body : '' + msg +'', - buttons : '', - onClose : function () { - if (typeof callBack == 'function') callBack(); - } - }); - } -}; - -var w2confirm = function (msg, title, callBack) { - if (typeof callBack == 'undefined' || typeof title == 'function') { - callBack = title; - title = w2utils.lang('Confirmation'); - } - if (typeof title == 'undefined') { - title = w2utils.lang('Confirmation'); - } - if (jQuery('#w2ui-popup').length > 0) { - w2popup.message({ - width : 400, - height : 150, - html : ''+ - ' '+ msg +''+ - ''+ - ''+ - ' '+ - ' '+ - '', - onOpen: function () { - jQuery('#w2ui-popup .w2ui-popup-message .w2ui-popup-button').on('click', function (event) { - w2popup.message(); - if (typeof callBack == 'function') callBack(event.target.id); + if (title == null) title = w2utils.lang('Notification'); + if (jQuery('#w2ui-popup').length > 0 && w2popup.status != 'closing') { + w2popup.message({ + width : 400, + height : 170, + html : '' + + ' ' + msg + '' + + '' + + '' + + ' ' + w2utils.lang('Ok') + '' + + '', + onClose : function () { + if (typeof callBack == 'function') callBack(); + } }); - }, - onKeydown: function (event) { - switch (event.originalEvent.keyCode) { - case 13: // enter - if (typeof callBack == 'function') callBack('Yes'); - w2popup.message(); - break - case 27: // esc - if (typeof callBack == 'function') callBack('No'); - w2popup.message(); - break - } - } - }); - } else { - w2popup.open({ - width : 450, - height : 200, - title : title, - modal : true, - showClose : false, - body : '' + msg +'', - buttons : ''+ - '', - onOpen: function (event) { - event.onComplete = function () { - jQuery('#w2ui-popup .w2ui-popup-button').on('click', function (event) { - w2popup.close(); - if (typeof callBack == 'function') callBack(event.target.id); - }); - } - }, - onKeydown: function (event) { - switch (event.originalEvent.keyCode) { - case 13: // enter - if (typeof callBack == 'function') callBack('Yes'); - w2popup.close(); - break - case 27: // esc - if (typeof callBack == 'function') callBack('No'); - w2popup.close(); - break - } - } - }); - } -}; - -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2tabs - tabs widget - * - $().w2tabs - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - tabs might not work in chromium apps, need bind() - * - on overflow display << >> - * - individual tab onClick (possibly other events) are not working - * - ************************************************************************/ - -(function ($) { - var w2tabs = function (options) { - this.box = null; // DOM Element that holds the element - this.name = null; // unique name for w2ui - this.active = null; - this.tabs = []; - this.right = ''; - this.style = ''; - this.onClick = null; - this.onClose = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - - $.extend(true, this, w2obj.tabs, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2tabs = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2tabs().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // extend tabs - var tabs = method.tabs; - var object = new w2tabs(method); - $.extend(object, { tabs: [], handlers: [] }); - for (var i in tabs) { object.tabs[i] = $.extend({}, w2tabs.prototype.tab, tabs[i]); } - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2tabs' ); + w2popup.open({ + width : 450, + height : 220, + showMax : false, + showClose : false, + title : title, + body : '' + msg + '', + buttons : '' + w2utils.lang('Ok') + '', + onClose : function () { + if (typeof callBack == 'function') callBack(); + } + }); } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2tabs.prototype = { - tab : { - id : null, // commnad to be sent to all event handlers - text : '', - hidden : false, - disabled : false, - closable : false, - hint : '', - onClick : null, - onRefresh : null, - onClose : null - }, - - add: function (tab) { - return this.insert(null, tab); - }, +}; - insert: function (id, tab) { - if (!$.isArray(tab)) tab = [tab]; - // assume it is array - for (var r in tab) { - // checks - if (String(tab[r].id) == 'undefined') { - console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+ this.name +')'); - return; - } - var unique = true; - for (var i in this.tabs) { if (this.tabs[i].id == tab[r].id) { unique = false; break; } } - if (!unique) { - console.log('ERROR: The parameter "id='+ tab[r].id +'" is not unique within the current tabs. (obj: '+ this.name +')'); - return; - } - if (!w2utils.isAlphaNumeric(tab[r].id)) { - console.log('ERROR: The parameter "id='+ tab[r].id +'" must be alpha-numeric + "-_". (obj: '+ this.name +')'); - return; - } - // add tab - var tab = $.extend({}, tab, tab[r]); - if (id == null || typeof id == 'undefined') { - this.tabs.push(tab); +var w2confirm = function (msg, title, callBack) { + var options = {}; + var defaults = { + msg : '', + title : w2utils.lang('Confirmation'), + width : (jQuery('#w2ui-popup').length > 0 ? 400 : 450), + height : (jQuery('#w2ui-popup').length > 0 ? 170 : 220), + yes_text : 'Yes', + yes_class : '', + yes_style : '', + yes_callBack: null, + no_text : 'No', + no_class : '', + no_style : '', + no_callBack : null, + callBack : null + }; + if (arguments.length == 1 && typeof msg == 'object') { + jQuery.extend(options, defaults, msg); + } else { + if (typeof title == 'function') { + jQuery.extend(options, defaults, { + msg : msg, + callBack: title + }) } else { - var middle = this.get(id, true); - this.tabs = this.tabs.slice(0, middle).concat([tab], this.tabs.slice(middle)); + jQuery.extend(options, defaults, { + msg : msg, + title : title, + callBack: callBack + }) } - this.refresh(tab[r].id); - } - }, - - remove: function (id) { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab) return false; - removed++; - // remove from array - this.tabs.splice(this.get(tab.id, true), 1); - // remove from screen - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).remove(); - } - return removed; - }, + } + if (jQuery('#w2ui-popup').length > 0 && w2popup.status != 'closing') { + if (options.width > w2popup.get().width) options.width = w2popup.get().width; + if (options.height > (w2popup.get().height - 50)) options.height = w2popup.get().height - 50; + w2popup.message({ + width : options.width, + height : options.height, + html : '' + + ' ' + options.msg + '' + + '' + + '' + + ' ' + w2utils.lang(options.yes_text) + '' + + ' ' + w2utils.lang(options.no_text) + '' + + '', + onOpen: function () { + jQuery('#w2ui-popup .w2ui-popup-message .btn').on('click', function (event) { + w2popup.message(); + if (typeof options.callBack == 'function') options.callBack(event.target.id); + if (event.target.id == 'Yes' && typeof options.yes_callBack == 'function') options.yes_callBack(); + if (event.target.id == 'No' && typeof options.no_callBack == 'function') options.no_callBack(); + }); + }, + onKeydown: function (event) { + switch (event.originalEvent.keyCode) { + case 13: // enter + if (typeof options.callBack == 'function') options.callBack('Yes'); + if (typeof options.yes_callBack == 'function') options.yes_callBack(); + w2popup.message(); + break + case 27: // esc + if (typeof options.callBack == 'function') options.callBack('No'); + if (typeof options.no_callBack == 'function') options.no_callBack(); + w2popup.message(); + break + } + } + }); - select: function (id) { - if (this.get(id) == null || this.active == id) return false; - this.active = id; - this.refresh(); - return true; - }, + } else { - set: function (id, tab) { - var index = this.get(id, true); - if (index == null) return false; - $.extend(this.tabs[index], tab); - this.refresh(id); - return true; - }, + if (!w2utils.isInt(options.height)) options.height = options.height + 50; + w2popup.open({ + width : options.width, + height : options.height, + title : options.title, + modal : true, + showClose : false, + body : '' + options.msg + '', + buttons : ''+ w2utils.lang(options.yes_text) +''+ + ''+ w2utils.lang(options.no_text) +'', + onOpen: function (event) { + event.onComplete = function () { + jQuery('#w2ui-popup .w2ui-popup-btn').on('click', function (event) { + w2popup.close(); + if (typeof options.callBack == 'function') options.callBack(event.target.id); + if (event.target.id == 'Yes' && typeof options.yes_callBack == 'function') options.yes_callBack(); + if (event.target.id == 'No' && typeof options.no_callBack == 'function') options.no_callBack(); + }); + } + }, + onKeydown: function (event) { + switch (event.originalEvent.keyCode) { + case 13: // enter + if (typeof options.callBack == 'function') options.callBack('Yes'); + if (typeof options.yes_callBack == 'function') options.yes_callBack(); + w2popup.close(); + break + case 27: // esc + if (typeof options.callBack == 'function') options.callBack('No'); + if (typeof options.no_callBack == 'function') options.no_callBack(); + w2popup.close(); + break + } + } + }); + } - get: function (id, returnIndex) { - if (arguments.length == 0) { - var all = []; - for (var i = 0; i < this.tabs.length; i++) if (this.tabs[i].id != null) all.push(this.tabs[i].id); - return all; - } - for (var i in this.tabs) { - if (this.tabs[i].id == id) { - if (returnIndex === true) return i; else return this.tabs[i]; + return { + yes: function (fun) { + options.yes_callBack = fun; + return this; + }, + no: function (fun) { + options.no_callBack = fun; + return this; } - } - return null; - }, - - show: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.hidden === false) continue; - tab.hidden = false; - this.refresh(tab.id); - shown++; - } - return shown; - }, - - hide: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.hidden === true) continue; - tab.hidden = true; - this.refresh(tab.id); - hidden++; - } - return hidden; - }, - - enable: function (id) { - var enabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.disabled === false) continue; - tab.disabled = false; - this.refresh(tab.id); - enabled++; - } - return enabled; - }, - - disable: function (id) { - var disabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.disabled === true) continue; - tab.disabled = true; - this.refresh(tab.id); - disabled++; - } - return disabled; - }, + }; +}; +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2tabs - tabs widget +* - $().w2tabs - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - on overflow display << >> +* +************************************************************************/ - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (String(id) == 'undefined') { - // refresh all - for (var i in this.tabs) this.refresh(this.tabs[i].id); - } - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), object: this.get(id) }); - if (eventData.isCancelled === true) return false; - // create or refresh only one item - var tab = this.get(id); - if (tab == null) return; - if (typeof tab.caption != 'undefined') tab.text = tab.caption; - - var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); - var tabHTML = (tab.closable ? '' : '') + - ' ' + tab.text + ''; - if (jq_el.length == 0) { - // does not exist - create it - var addStyle = ''; - if (tab.hidden) { addStyle += 'display: none;'; } - if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } - html = ''+ tabHTML + ''; - if (this.get(id, true) != this.tabs.length-1 && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).length > 0) { - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).before(html); +(function ($) { + var w2tabs = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.active = null; + this.tabs = []; + this.routeData = {}; // data for dynamic routes + this.right = ''; + this.style = ''; + this.onClick = null; + this.onClose = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(this, { handlers: [] }); + $.extend(true, this, w2obj.tabs, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2tabs = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2tabs')) return; + // extend tabs + var tabs = method.tabs || []; + var object = new w2tabs(method); + for (var i = 0; i < tabs.length; i++) { + object.tabs[i] = $.extend({}, w2tabs.prototype.tab, tabs[i]); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - $(this.box).find('#tabs_'+ this.name +'_right').before(html); - } - } else { - // refresh - jq_el.html(tabHTML); - if (tab.hidden) { jq_el.css('display', 'none'); } - else { jq_el.css('display', ''); } - if (tab.disabled) { jq_el.css({ 'opacity': '0.2', '-moz-opacity': '0.2', '-webkit-opacity': '0.2', '-o-opacity': '0.2', 'filter': 'alpha(opacity=20)' }); } - else { jq_el.css({ 'opacity': '1', '-moz-opacity': '1', '-webkit-opacity': '1', '-o-opacity': '1', 'filter': 'alpha(opacity=100)' }); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2tabs' ); + return undefined; + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2tabs.prototype = { + tab : { + id : null, // command to be sent to all event handlers + text : '', + route : null, + hidden : false, + disabled : false, + closable : false, + hint : '', + onClick : null, + onRefresh : null, + onClose : null + }, + + add: function (tab) { + return this.insert(null, tab); + }, + + insert: function (id, tab) { + if (!$.isArray(tab)) tab = [tab]; + // assume it is array + for (var i = 0; i < tab.length; i++) { + // checks + if (typeof tab[i].id === 'undefined') { + console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+ this.name +')'); + return; + } + if (!w2utils.checkUniqueId(tab[i].id, this.tabs, 'tabs', this.name)) return; + // add tab + var newTab = $.extend({}, w2tabs.prototype.tab, tab[i]); + if (id === null || typeof id === 'undefined') { + this.tabs.push(newTab); + } else { + var middle = this.get(id, true); + this.tabs = this.tabs.slice(0, middle).concat([newTab], this.tabs.slice(middle)); + } + this.refresh(tab[i].id); + } + }, + + remove: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab) return false; + removed++; + // remove from array + this.tabs.splice(this.get(tab.id, true), 1); + // remove from screen + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).remove(); + } + return removed; + }, - render: function (box) { - var time = (new Date()).getTime(); - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - // default action - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (String(box) != 'undefined' && box != null) { - if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-tabs') - .html(''); - } - this.box = box; - } - if (!this.box) return; - // render all buttons - var html = ''+ - ' '+ this.right +''+ - ''; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-tabs') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - return (new Date()).getTime() - time; - }, + select: function (id) { + if (this.active == id || this.get(id) === null) return false; + this.active = id; + this.refresh(); + return true; + }, - resize: function () { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // empty function - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + set: function (id, tab) { + var index = this.get(id, true); + if (index === null) return false; + $.extend(this.tabs[index], tab); + this.refresh(id); + return true; + }, + + get: function (id, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var i1 = 0; i1 < this.tabs.length; i1++) { + if (this.tabs[i1].id != null) { + all.push(this.tabs[i1].id); + } + } + return all; + } else { + for (var i2 = 0; i2 < this.tabs.length; i2++) { + if (this.tabs[i2].id == id) { // need to be == since id can be numeric + return (returnIndex === true ? i2 : this.tabs[i2]); + } + } + } + return null; + }, + + show: function () { + var obj = this; + var shown = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.hidden === false) continue; + shown++; + tab.hidden = false; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return shown; + }, + + hide: function () { + var obj = this; + var hidden= 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.hidden === true) continue; + hidden++; + tab.hidden = true; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return hidden; + }, + + enable: function () { + var obj = this; + var enabled = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.disabled === false) continue; + enabled++; + tab.disabled = false; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return enabled; + }, + + disable: function () { + var obj = this; + var disabled = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.disabled === true) continue; + disabled++; + tab.disabled = true; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return disabled; + }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-tabs') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id !== 'undefined' ? id : this.name), object: this.get(id) }); + if (eventData.isCancelled === true) return; + if (typeof id === 'undefined') { + // refresh all + for (var i = 0; i < this.tabs.length; i++) this.refresh(this.tabs[i].id); + } else { + // create or refresh only one item + var tab = this.get(id); + if (tab === null) return false; + if (typeof tab.caption !== 'undefined') tab.text = tab.caption; + + var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); + var tabHTML = (tab.closable ? '' : '') + + ' ' + tab.text + ''; + if (jq_el.length === 0) { + // does not exist - create it + var addStyle = ''; + if (tab.hidden) { addStyle += 'display: none;'; } + if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } + var html = ''+ tabHTML + ''; + if (this.get(id, true) !== this.tabs.length-1 && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).length > 0) { + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).before(html); + } else { + $(this.box).find('#tabs_'+ this.name +'_right').before(html); + } + } else { + // refresh + jq_el.html(tabHTML); + if (tab.hidden) { jq_el.css('display', 'none'); } + else { jq_el.css('display', ''); } + if (tab.disabled) { jq_el.css({ 'opacity': '0.2', '-moz-opacity': '0.2', '-webkit-opacity': '0.2', '-o-opacity': '0.2', 'filter': 'alpha(opacity=20)' }); } + else { jq_el.css({ 'opacity': '1', '-moz-opacity': '1', '-webkit-opacity': '1', '-o-opacity': '1', 'filter': 'alpha(opacity=100)' }); } + } + } + // right html + $('#tabs_'+ this.name +'_right').html(this.right); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - // =================================================== - // -- Internal Event Handlers - - click: function (id, event) { - var tab = this.get(id); - if (tab == null || tab.disabled) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: id, object: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.active) +' .w2ui-tab').removeClass('active'); - this.active = tab.id; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(id); - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + // default action + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof box !== 'undefined' && box !== null) { + if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-tabs') + .html(''); + } + this.box = box; + } + if (!this.box) return false; + // render all buttons + var html = ''+ + ' '+ this.right +''+ + ''; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-tabs') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + return (new Date()).getTime() - time; + }, - animateClose: function(id, event) { - var tab = this.get(id); - if (tab == null || tab.disabled) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'close', target: id, object: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - var obj = this; - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).css({ - '-webkit-transition': '.2s', - '-moz-transition': '2s', - '-ms-transition': '.2s', - '-o-transition': '.2s', - opacity: '0' }); - setTimeout(function () { - var width = $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).width(); - $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)) - .html('') - setTimeout(function () { - $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).find(':first-child').css({ 'width': '0px' }); - }, 50); - }, 200); - setTimeout(function () { - obj.remove(id); - }, 450); - // event before - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - }, + resize: function () { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; - animateInsert: function(id, tab) { - if (this.get(id) == null) return; - if (!$.isPlainObject(tab)) return; - // check for unique - var unique = true; - for (var i in this.tabs) { if (this.tabs[i].id == tab.id) { unique = false; break; } } - if (!unique) { - console.log('ERROR: The parameter "id='+ tab.id +'" is not unique within the current tabs. (obj: '+ this.name +')'); - return; - } - // insert simple div - var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); - if (jq_el.length != 0) return; // already exists - // measure width - if (typeof tab.caption != 'undefined') tab.text = tab.caption; - var tmp = ''+ - ''+ - ''+ - (tab.closable ? '' : '') + - ' '+ tab.text +''+ - ''+ - ''; - $('body').append(tmp); - // create dummy element - tabHTML = ' '; - var addStyle = ''; - if (tab.hidden) { addStyle += 'display: none;'; } - if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } - html = ''+ tabHTML +''; - if (this.get(id, true) != this.tabs.length && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).length > 0) { - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).before(html); - } else { - $(this.box).find('#tabs_'+ this.name +'_right').before(html); - } - // -- move - var obj = this; - setTimeout(function () { - var width = $('#_tmp_simple_tab').width(); - $('#_tmp_tabs').remove(); - $('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id) +' > div').css('width', width+'px'); - }, 1); - setTimeout(function () { - // insert for real - obj.insert(id, tab); - }, 200); - } - } + // intentionaly blank - $.extend(w2tabs.prototype, w2utils.event); - w2obj.tabs = w2tabs; -})(jQuery); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2toolbar - toolbar widget - * - $().w2toolbar - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - on overflow display << >> - * - ************************************************************************/ + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-tabs') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, -(function ($) { - var w2toolbar = function (options) { - this.box = null, // DOM Element that holds the element - this.name = null, // unique name for w2ui - this.items = [], - this.right = '', // HTML text on the right of toolbar - this.onClick = null, - this.onRender = null, - this.onRefresh = null, - this.onResize = null, - this.onDestroy = null - - $.extend(true, this, w2obj.toolbar, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2toolbar = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2toolbar().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - var items = method.items; - // extend items - var object = new w2toolbar(method); - $.extend(object, { items: [], handlers: [] }); - - for (var i in items) { object.items[i] = $.extend({}, w2toolbar.prototype.item, items[i]); } - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2toolbar' ); - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2toolbar.prototype = { - item: { - id : null, // commnad to be sent to all event handlers - type : 'button', // button, check, radio, drop, menu, break, html, spacer - text : '', - html : '', - img : null, - icon : null, - hidden : false, - disabled: false, - checked : false, // used for radio buttons - arrow : true, // arrow down for drop/menu types - hint : '', - group : null, // used for radio buttons - items : null, // for type menu it is an array of items in the menu - onClick : null - }, + // =================================================== + // -- Internal Event Handlers - add: function (items) { - this.insert(null, items); - }, + click: function (id, event) { + var tab = this.get(id); + if (tab === null || tab.disabled) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: id, tab: tab, object: tab, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.active) +' .w2ui-tab').removeClass('active'); + this.active = tab.id; + // route processing + if (tab.route) { + var route = String('/'+ tab.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (this.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(id); + }, - insert: function (id, items) { - if (!$.isArray(items)) items = [items]; - for (var o in items) { - // checks - if (typeof items[o].type == 'undefined') { - console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.'); - return; - } - if ($.inArray(String(items[o].type), ['button', 'check', 'radio', 'drop', 'menu', 'break', 'html', 'spacer']) == -1) { - console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] '+ - 'in w2toolbar.add() method.'); - return; - } - if (typeof items[o].id == 'undefined') { - console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.'); - return; - } - var unique = true; - for (var i = 0; i < this.items.length; i++) { if (this.items[i].id == items[o].id) { unique = false; return; } } - if (!unique) { - console.log('ERROR: The parameter "id" is not unique within the current toolbar.'); - return; - } - if (!w2utils.isAlphaNumeric(items[o].id)) { - console.log('ERROR: The parameter "id" must be alpha-numeric + "-_".'); - return; - } - // add item - var it = $.extend({}, w2toolbar.prototype.item, items[o]); - if (id == null || typeof id == 'undefined') { - this.items.push(it); - } else { - var middle = this.get(id, true); - this.items = this.items.slice(0, middle).concat([it], this.items.slice(middle)); + animateClose: function(id, event) { + var tab = this.get(id); + if (tab === null || tab.disabled) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'close', target: id, object: this.get(id), originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + var obj = this; + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).css({ + '-webkit-transition': '.2s', + '-moz-transition': '2s', + '-ms-transition': '.2s', + '-o-transition': '.2s', + opacity: '0' }); + setTimeout(function () { + var width = $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).width(); + $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)) + .html(''); + setTimeout(function () { + $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).find(':first-child').css({ 'width': '0px' }); + }, 50); + }, 200); + setTimeout(function () { + obj.remove(id); + }, 450); + // event before + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + }, + + animateInsert: function(id, tab) { + if (this.get(id) === null) return; + if (!$.isPlainObject(tab)) return; + // check for unique + if (!w2utils.checkUniqueId(tab.id, this.tabs, 'tabs', this.name)) return; + // insert simple div + var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); + if (jq_el.length !== 0) return; // already exists + // measure width + if (typeof tab.caption !== 'undefined') tab.text = tab.caption; + var tmp = ''+ + ''+ + ''+ + (tab.closable ? '' : '') + + ' '+ tab.text +''+ + ''+ + ''; + $('body').append(tmp); + // create dummy element + var tabHTML = ' '; + var addStyle = ''; + if (tab.hidden) { addStyle += 'display: none;'; } + if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } + var html = ''+ tabHTML +''; + if (this.get(id, true) !== this.tabs.length && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).length > 0) { + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).before(html); + } else { + $(this.box).find('#tabs_'+ this.name +'_right').before(html); + } + // -- move + var obj = this; + setTimeout(function () { + var width = $('#_tmp_simple_tab').width(); + $('#_tmp_tabs').remove(); + $('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id) +' > div').css('width', width+'px'); + }, 1); + setTimeout(function () { + // insert for real + obj.insert(id, tab); + }, 200); } - this.refresh(it.id); - } - }, + }; - remove: function (id) { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - removed++; - // remove from screen - $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)).remove(); - // remove from array - var ind = this.get(it.id, true); - if (ind) this.items.splice(ind, 1); - } - return removed; - }, - - set: function (id, item) { - var index = this.get(id, true); - if (index == null) return false; - $.extend(this.items[index], item); - this.refresh(id); - return true; - }, + $.extend(w2tabs.prototype, w2utils.event); + w2obj.tabs = w2tabs; +})(jQuery); - get: function (id, returnIndex) { - if (arguments.length == 0) { - var all = []; - for (var i = 0; i < this.items.length; i++) if (this.items[i].id != null) all.push(this.items[i].id); - return all; - } - for (var i = 0; i < this.items.length; i++) { - if (this.items[i].id == id) { - if (returnIndex === true) return i; else return this.items[i]; - } - } - return null; - }, - show: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.hidden = false; - this.refresh(it.id); - } - return items; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2toolbar - toolbar widget +* - $().w2toolbar - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - on overflow display << >> +* - verticle toolbar +* +************************************************************************/ - hide: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.hidden = true; - this.refresh(it.id); - } - return items; - }, +(function ($) { + var w2toolbar = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.routeData = {}; // data for dynamic routes + this.items = []; + this.right = ''; // HTML text on the right of toolbar + this.onClick = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.toolbar, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2toolbar = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2toolbar')) return; + // extend items + var items = method.items || []; + var object = new w2toolbar(method); + $.extend(object, { items: [], handlers: [] }); + for (var i = 0; i < items.length; i++) { + object.items[i] = $.extend({}, w2toolbar.prototype.item, items[i]); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; + } else { + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2toolbar' ); + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2toolbar.prototype = { + item: { + id : null, // command to be sent to all event handlers + type : 'button', // button, check, radio, drop, menu, break, html, spacer + text : '', + route : null, // if not null, it is route to go + html : '', + img : null, + icon : null, + count : null, + hidden : false, + disabled : false, + checked : false, // used for radio buttons + arrow : true, // arrow down for drop/menu types + hint : '', + group : null, // used for radio buttons + items : null, // for type menu it is an array of items in the menu + overlay : {}, + onClick : null + }, + + add: function (items) { + this.insert(null, items); + }, + + insert: function (id, items) { + if (!$.isArray(items)) items = [items]; + for (var o = 0; o < items.length; o++) { + // checks + if (typeof items[o].type === 'undefined') { + console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.'); + return; + } + if ($.inArray(String(items[o].type), ['button', 'check', 'radio', 'drop', 'menu', 'break', 'html', 'spacer']) === -1) { + console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] '+ + 'in w2toolbar.add() method.'); + return; + } + if (typeof items[o].id === 'undefined') { + console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.'); + return; + } + if (!w2utils.checkUniqueId(items[o].id, this.items, 'toolbar items', this.name)) return; + // add item + var it = $.extend({}, w2toolbar.prototype.item, items[o]); + if (id == null) { + this.items.push(it); + } else { + var middle = this.get(id, true); + this.items = this.items.slice(0, middle).concat([it], this.items.slice(middle)); + } + this.refresh(it.id); + } + }, + + remove: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + removed++; + // remove from screen + $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)).remove(); + // remove from array + var ind = this.get(it.id, true); + if (ind) this.items.splice(ind, 1); + } + return removed; + }, + + set: function (id, item) { + var index = this.get(id, true); + if (index === null) return false; + $.extend(this.items[index], item); + this.refresh(id); + return true; + }, - enable: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.disabled = false; - this.refresh(it.id); - } - return items; - }, + get: function (id, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var i1 = 0; i1 < this.items.length; i1++) if (this.items[i1].id !== null) all.push(this.items[i1].id); + return all; + } + for (var i2 = 0; i2 < this.items.length; i2++) { + if (this.items[i2].id === id) { + if (returnIndex === true) return i2; else return this.items[i2]; + } + } + return null; + }, + + show: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.hidden = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + hide: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.hidden = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + enable: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.disabled = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + disable: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.disabled = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + check: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.checked = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + uncheck: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.checked = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, - disable: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.disabled = true; - this.refresh(it.id); - } - return items; - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + + if (box != null) { + if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-toolbar') + .html(''); + } + this.box = box; + } + if (!this.box) return; + // render all buttons + var html = ''+ + ''; + for (var i = 0; i < this.items.length; i++) { + var it = this.items[i]; + if (it.id == null) it.id = "item_" + i; + if (it === null) continue; + if (it.type === 'spacer') { + html += ''; + } else { + html += ''+ this.getItemHTML(it) + + ''; + } + } + html += ''+ this.right +''; + html += ''+ + ''; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-toolbar') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - check: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.checked = true; - this.refresh(it.id); - } - return items; - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id !== 'undefined' ? id : this.name), item: this.get(id) }); + if (eventData.isCancelled === true) return; + + if (id == null) { + // refresh all + for (var i = 0; i < this.items.length; i++) { + var it1 = this.items[i]; + if (it1.id == null) it1.id = "item_" + i; + this.refresh(it1.id); + } + } + // create or refresh only one item + var it = this.get(id); + if (it === null) return false; + + var el = $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)); + var html = this.getItemHTML(it); + if (el.length === 0) { + // does not exist - create it + if (it.type === 'spacer') { + html = ''; + } else { + html = ''+ html + + ''; + } + if (this.get(id, true) === this.items.length-1) { + $(this.box).find('#tb_'+ this.name +'_right').before(html); + } else { + $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(this.items[parseInt(this.get(id, true))+1].id)).before(html); + } + } else { + // refresh + el.html(html); + if (it.hidden) { el.css('display', 'none'); } else { el.css('display', ''); } + if (it.disabled) { el.addClass('disabled'); } else { el.removeClass('disabled'); } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - uncheck: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.checked = false; - this.refresh(it.id); - } - return items; - }, + resize: function () { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; - render: function (box) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-toolbar') - .html(''); - } - this.box = box; - } - if (!this.box) return; - // render all buttons - var html = ''+ - ''; - for (var i = 0; i < this.items.length; i++) { - var it = this.items[i]; - if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i; - if (it == null) continue; - if (it.type == 'spacer') { - html += ''; - } else { - html += ''+ this.getItemHTML(it) + - ''; - } - } - html += ''+ this.right +''; - html += ''+ - ''; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-toolbar') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + // intentionaly blank - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id) }); - if (eventData.isCancelled === true) return false; - - if (typeof id == 'undefined') { - // refresh all - for (var i = 0; i < this.items.length; i++) { - var it = this.items[i]; - if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i; - this.refresh(it.id); - } - } - // create or refresh only one item - var it = this.get(id); - if (it == null) return; - - var el = $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)); - var html = this.getItemHTML(it); - if (el.length == 0) { - // does not exist - create it - if (it.type == 'spacer') { - html = ''; - } else { - html = ''+ html + - ''; - } - if (this.get(id, true) == this.items.length-1) { - $(this.box).find('#tb_'+ this.name +'_right').before(html); - } else { - $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(this.items[parseInt(this.get(id, true))+1].id)).before(html); - } - } else { - // refresh - el.html(html); - if (it.hidden) { el.css('display', 'none'); } else { el.css('display', ''); } - if (it.disabled) { el.addClass('disabled'); } else { el.removeClass('disabled'); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - resize: function () { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-toolbar') + .html(''); + } + $(this.box).html(''); + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // ======================================== + // --- Internal Functions + + getItemHTML: function (item) { + var html = ''; + + if (typeof item.caption !== 'undefined') item.text = item.caption; + if (typeof item.hint === 'undefined') item.hint = ''; + if (typeof item.text === 'undefined') item.text = ''; + + switch (item.type) { + case 'menu': + case 'button': + case 'check': + case 'radio': + case 'drop': + var img = ' '; + if (item.img) img = ''; + if (item.icon) img = ''; + html += ''+ + ''+ + ' '+ + ' ' + + img + + (item.text !== '' ? ''+ item.text +'' : '') + + (item.count != null ? ''+ item.count +'' : '') + + (((item.type === 'drop' || item.type === 'menu') && item.arrow !== false) ? + '' : '') + + ' '+ + ''; + break; - // empty function + case 'break': + html += ''+ + ' '+ + ''; + break; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + case 'html': + html += ''+ + ' ' + item.html + ''+ + ''; + break; + } - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-toolbar') - .html(''); - } - $(this.box).html(''); - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + var newHTML = ''; + if (typeof item.onRender === 'function') newHTML = item.onRender.call(this, item.id, html); + if (typeof this.onRender === 'function') newHTML = this.onRender(item.id, html); + if (newHTML !== '' && newHTML != null) html = newHTML; + return html; + }, - // ======================================== - // --- Internal Functions - - getItemHTML: function (item) { - var html = ''; - - if (typeof item.caption != 'undefined') item.text = item.caption; - if (typeof item.hint == 'undefined') item.hint = ''; - if (typeof item.text == 'undefined') item.text = ''; - - switch (item.type) { - case 'menu': - case 'button': - case 'check': - case 'radio': - case 'drop': - var img = ' '; - if (item.img) img = ''; - if (item.icon) img = ''; - html += ''+ - ''+ - ' '+ - ' ' + - img + - (item.text != '' ? ''+ item.text +'' : '') + - (((item.type == 'drop' || item.type == 'menu') && item.arrow !== false) ? - ' ' : '') + - ' '+ - ''; - break; - - case 'break': - html += ''+ - ' '+ - ''; - break; - - case 'html': - html += ''+ - ' ' + item.html + ''+ - ''; - break; - } - - var newHTML = ''; - if (typeof item.onRender == 'function') newHTML = item.onRender.call(this, item.id, html); - if (typeof this.onRender == 'function') newHTML = this.onRender(item.id, html); - if (newHTML != '' && typeof newHTML != 'undefined') html = newHTML; - return html; - }, + menuClick: function (event) { + var obj = this; + if (event.item && !event.item.disabled) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: event.item.id + ':' + event.subItem.id, item: event.item, + subItem: event.subItem, originalEvent: event.originalEvent }); + if (eventData.isCancelled === true) return; + + // route processing + var it = event.subItem; + if (it.route) { + var route = String('/'+ it.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } - menuClick: function (id, menu_index, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var obj = this; - var it = this.get(id); - if (it && !it.disabled) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id), - subItem: (typeof menu_index != 'undefined' && this.get(id) ? this.get(id).items[menu_index] : null), originalEvent: event }); - if (eventData.isCancelled === true) return false; - - // normal processing - - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, - click: function (id, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var obj = this; - var it = this.get(id); - if (it && !it.disabled) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name), - item: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('down'); - - if (it.type == 'radio') { - for (var i = 0; i < this.items.length; i++) { - var itt = this.items[i]; - if (itt == null || itt.id == it.id || itt.type != 'radio') continue; - if (itt.group == it.group && itt.checked) { - itt.checked = false; - this.refresh(itt.id); - } - } - it.checked = true; - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } + click: function (id, event) { + var obj = this; + var it = this.get(id); + if (it && !it.disabled) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id !== 'undefined' ? id : this.name), + item: it, object: it, originalEvent: event }); + if (eventData.isCancelled === true) return; + + var btn = $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button'); + btn.removeClass('down'); + + if (it.type === 'radio') { + for (var i = 0; i < this.items.length; i++) { + var itt = this.items[i]; + if (itt == null || itt.id === it.id || itt.type !== 'radio') continue; + if (itt.group === it.group && itt.checked) { + itt.checked = false; + this.refresh(itt.id); + } + } + it.checked = true; + btn.addClass('checked'); + } - if (it.type == 'drop' || it.type == 'menu') { - if (it.checked) { - // if it was already checked, second click will hide it - it.checked = false; - } else { - // show overlay - setTimeout(function () { - var el = $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id)); - if (!$.isPlainObject(it.overlay)) it.overlay = {}; - if (it.type == 'drop') { - el.w2overlay(it.html, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay)); - } - if (it.type == 'menu') { - el.w2menu(it.items, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay, { - select: function (item, event, index) { obj.menuClick(it.id, index, event); } - })); - } - // window.click to hide it - $(document).on('click', hideDrop); - function hideDrop() { - it.checked = false; - if (it.checked) { - $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } else { - $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked'); + if (it.type === 'drop' || it.type === 'menu') { + if (it.checked) { + // if it was already checked, second click will hide it + it.checked = false; + } else { + // show overlay + setTimeout(function () { + var el = $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id)); + if (!$.isPlainObject(it.overlay)) it.overlay = {}; + var left = (el.width() - 50) / 2; + if (left > 19) left = 19; + if (it.type === 'drop') { + el.w2overlay(it.html, $.extend({ left: left, top: 3 }, it.overlay)); + } + if (it.type === 'menu') { + el.w2menu(it.items, $.extend({ left: left, top: 3 }, it.overlay, { + select: function (event) { + obj.menuClick({ item: it, subItem: event.item, originalEvent: event.originalEvent }); + hideDrop(); + } + })); + } + // window.click to hide it + $(document).on('click', hideDrop); + function hideDrop() { + $(document).off('click', hideDrop); + it.checked = false; + btn.removeClass('checked'); + } + }, 1); + } } - obj.refresh(it.id); - $(document).off('click', hideDrop); - } - }, 1); - } - } - if (it.type == 'check' || it.type == 'drop' || it.type == 'menu') { - it.checked = !it.checked; - if (it.checked) { - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } else { - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked'); - } + if (it.type === 'check' || it.type === 'drop' || it.type === 'menu') { + it.checked = !it.checked; + if (it.checked) { + btn.addClass('checked'); + } else { + btn.removeClass('checked'); + } + } + // route processing + if (it.route) { + var route = String('/'+ it.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - } - } + }; - $.extend(w2toolbar.prototype, w2utils.event); - w2obj.toolbar = w2toolbar; + $.extend(w2toolbar.prototype, w2utils.event); + w2obj.toolbar = w2toolbar; })(jQuery); + /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2sidebar - sidebar widget - * - $().w2sidebar - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - return ids of all subitems - * - add find() method to find nodes by a specific criteria (I want all nodes for exampe) - * - dbl click should be like it is in grid (with timer not HTML dbl click event) - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2sidebar - sidebar widget +* - $().w2sidebar - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - return ids of all subitems +* - add find() method to find nodes by a specific criteria (I want all nodes for exampe) +* - dbl click should be like it is in grid (with timer not HTML dbl click event) +* - reorder with grag and drop +* - add route property that would navigate to a #route +* - node.style is missleading - should be there to apply color for example +* +************************************************************************/ (function ($) { - var w2sidebar = function (options) { - this.name = null; - this.box = null; - this.sidebar = null; - this.parent = null; - this.nodes = []; // Sidebar child nodes - this.menu = []; - this.selected = null; // current selected node (readonly) - this.img = null; - this.icon = null; - this.style = ''; - this.topHTML = ''; - this.bottomHTML = ''; - this.keyboard = true; - this.onClick = null; // Fire when user click on Node Text - this.onDblClick = null; // Fire when user dbl clicks - this.onContextMenu = null; - this.onMenuClick = null; // when context menu item selected - this.onExpand = null; // Fire when node Expands - this.onCollapse = null; // Fire when node Colapses - this.onKeydown = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - - $.extend(true, this, w2obj.sidebar, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2sidebar = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2sidebar().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // extend items - var nodes = method.nodes; - var object = new w2sidebar(method); - $.extend(object, { handlers: [], nodes: [] }); - if (typeof nodes != 'undefined') { - object.add(object, nodes); - } - if ($(this).length != 0) { - object.render($(this)[0]); - } - object.sidebar = object; - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2sidebar' ); - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2sidebar.prototype = { - - node: { - id : null, - text : '', - count : '', - img : null, - icon : null, - nodes : [], - style : '', - selected : false, - expanded : false, - hidden : false, - disabled : false, - group : false, // if true, it will build as a group - plus : false, // if true, plus will be shown even if there is no sub nodes - // events - onClick : null, - onDblClick : null, - onContextMenu : null, - onExpand : null, - onCollapse : null, - // internal - parent : null, // node object - sidebar : null - }, - - add: function (parent, nodes) { - if (arguments.length == 1) { - // need to be in reverse order - nodes = arguments[0]; - parent = this; - } - if (typeof parent == 'string') parent = this.get(parent); - return this.insert(parent, null, nodes); - }, - - insert: function (parent, before, nodes) { - if (arguments.length == 2) { - // need to be in reverse order - nodes = arguments[1]; - before = arguments[0]; - var ind = this.get(before); - if (ind == null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); - return null; - } - parent = this.get(before).parent; - } - if (typeof parent == 'string') parent = this.get(parent); - if (!$.isArray(nodes)) nodes = [nodes]; - for (var o in nodes) { - if (typeof nodes[o].id == 'undefined') { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because it has no id.'); - continue; - } - if (this.get(this, nodes[o].id) != null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node with id='+ nodes[o].id +' (text: '+ txt + ') because another node with the same id already exists.'); - continue; - } - var tmp = $.extend({}, w2sidebar.prototype.node, nodes[o]); - tmp.sidebar= this; - tmp.parent = parent; - var nd = tmp.nodes; - tmp.nodes = []; // very important to re-init empty nodes array - if (before == null) { // append to the end - parent.nodes.push(tmp); + var w2sidebar = function (options) { + this.name = null; + this.box = null; + this.sidebar = null; + this.parent = null; + this.nodes = []; // Sidebar child nodes + this.menu = []; + this.routeData = {}; // data for dynamic routes + this.selected = null; // current selected node (readonly) + this.img = null; + this.icon = null; + this.style = ''; + this.topHTML = ''; + this.bottomHTML = ''; + this.keyboard = true; + this.onClick = null; // Fire when user click on Node Text + this.onDblClick = null; // Fire when user dbl clicks + this.onContextMenu = null; + this.onMenuClick = null; // when context menu item selected + this.onExpand = null; // Fire when node Expands + this.onCollapse = null; // Fire when node Colapses + this.onKeydown = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.sidebar, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2sidebar = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2sidebar')) return; + // extend items + var nodes = method.nodes; + var object = new w2sidebar(method); + $.extend(object, { handlers: [], nodes: [] }); + if (typeof nodes != 'undefined') { + object.add(object, nodes); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + object.sidebar = object; + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - var ind = this.get(parent, before, true); - if (ind == null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); - return null; - } - parent.nodes.splice(ind, 0, tmp); - } - if (typeof nd != 'undefined' && nd.length > 0) { this.insert(tmp, null, nd); } - } - this.refresh(parent.id); - return tmp; - }, - - remove: function () { // multiple arguments - var deleted = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - var ind = this.get(tmp.parent, arguments[a], true); - if (ind == null) continue; - tmp.parent.nodes.splice(ind, 1); - deleted++; - } - if (deleted > 0 && arguments.length == 1) this.refresh(tmp.parent.id); else this.refresh(); - return deleted; - }, + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2sidebar' ); + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2sidebar.prototype = { + + node: { + id : null, + text : '', + count : null, + img : null, + icon : null, + nodes : [], + style : '', // additional style for subitems + route : null, + selected : false, + expanded : false, + hidden : false, + disabled : false, + group : false, // if true, it will build as a group + groupShowHide : true, + plus : false, // if true, plus will be shown even if there is no sub nodes + // events + onClick : null, + onDblClick : null, + onContextMenu : null, + onExpand : null, + onCollapse : null, + // internal + parent : null, // node object + sidebar : null + }, + + add: function (parent, nodes) { + if (arguments.length == 1) { + // need to be in reverse order + nodes = arguments[0]; + parent = this; + } + if (typeof parent == 'string') parent = this.get(parent); + return this.insert(parent, null, nodes); + }, + + insert: function (parent, before, nodes) { + var txt, ind, tmp, node, nd; + if (arguments.length == 2) { + // need to be in reverse order + nodes = arguments[1]; + before = arguments[0]; + ind = this.get(before); + if (ind === null) { + if (!$.isArray(nodes)) nodes = [nodes]; + txt = (nodes[0].caption != null ? nodes[0].caption : nodes[0].text); + console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); + return null; + } + parent = this.get(before).parent; + } + if (typeof parent == 'string') parent = this.get(parent); + if (!$.isArray(nodes)) nodes = [nodes]; + for (var o in nodes) { + node = nodes[o]; + if (typeof node.id == null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node "'+ txt +'" because it has no id.'); + continue; + } + if (this.get(this, node.id) !== null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node with id='+ node.id +' (text: '+ txt + ') because another node with the same id already exists.'); + continue; + } + tmp = $.extend({}, w2sidebar.prototype.node, node); + tmp.sidebar = this; + tmp.parent = parent; + nd = tmp.nodes || []; + tmp.nodes = []; // very important to re-init empty nodes array + if (before === null) { // append to the end + parent.nodes.push(tmp); + } else { + ind = this.get(parent, before, true); + if (ind === null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); + return null; + } + parent.nodes.splice(ind, 0, tmp); + } + if (nd.length > 0) { + this.insert(tmp, null, nd); + } + } + this.refresh(parent.id); + return tmp; + }, + + remove: function () { // multiple arguments + var deleted = 0; + var tmp; + for (var a = 0; a < arguments.length; a++) { + tmp = this.get(arguments[a]); + if (tmp === null) continue; + if (this.selected !== null && this.selected === tmp.id) { + this.selected = null; + } + var ind = this.get(tmp.parent, arguments[a], true); + if (ind === null) continue; + if (tmp.parent.nodes[ind].selected) tmp.sidebar.unselect(tmp.id); + tmp.parent.nodes.splice(ind, 1); + deleted++; + } + if (deleted > 0 && arguments.length == 1) this.refresh(tmp.parent.id); else this.refresh(); + return deleted; + }, + + set: function (parent, id, node) { + if (arguments.length == 2) { + // need to be in reverse order + node = id; + id = parent; + parent = this; + } + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return null; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].id === id) { + // make sure nodes inserted correctly + var nodes = node.nodes; + $.extend(parent.nodes[i], node, { nodes: [] }); + if (nodes != null) { + this.add(parent.nodes[i], nodes); + } + this.refresh(id); + return true; + } else { + var rv = this.set(parent.nodes[i], id, node); + if (rv) return true; + } + } + return false; + }, + + get: function (parent, id, returnIndex) { // can be just called get(id) or get(id, true) + if (arguments.length === 0) { + var all = []; + var tmp = this.find({}); + for (var t = 0; t < tmp.length; t++) { + if (tmp[t].id != null) all.push(tmp[t].id); + } + return all; + } else { + if (arguments.length == 1 || (arguments.length == 2 && id === true) ) { + // need to be in reverse order + returnIndex = id; + id = parent; + parent = this; + } + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return null; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].id == id) { + if (returnIndex === true) return i; else return parent.nodes[i]; + } else { + var rv = this.get(parent.nodes[i], id, returnIndex); + if (rv || rv === 0) return rv; + } + } + return null; + } + }, - set: function (parent, id, node) { - if (arguments.length == 2) { - // need to be in reverse order - node = id; - id = parent; - parent = this; - } - // searches all nested nodes - this._tmp = null; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].id == id) { - // make sure nodes inserted correctly - var nodes = node.nodes; - $.extend(parent.nodes[i], node, { nodes: [] }); - if (typeof nodes != 'undefined') { - this.add(parent.nodes[i], nodes); - } - this.refresh(id); - return true; - } else { - this._tmp = this.set(parent.nodes[i], id, node); - if (this._tmp) return true; - } - } - return false; - }, + find: function (parent, params, results) { // can be just called find({ selected: true }) + if (arguments.length == 1) { + // need to be in reverse order + params = parent; + parent = this; + } + if (!results) results = []; + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return results; + for (var i = 0; i < parent.nodes.length; i++) { + var match = true; + for (var prop in params) { + if (parent.nodes[i][prop] != params[prop]) match = false; + } + if (match) results.push(parent.nodes[i]); + if (parent.nodes[i].nodes.length > 0) results = this.find(parent.nodes[i], params, results); + } + return results; + }, + + hide: function () { // multiple arguments + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.hidden = true; + hidden++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return hidden; + }, + + show: function () { // multiple arguments + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.hidden = false; + shown++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return shown; + }, + + disable: function () { // multiple arguments + var disabled = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.disabled = true; + if (tmp.selected) this.unselect(tmp.id); + disabled++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return disabled; + }, + + enable: function () { // multiple arguments + var enabled = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.disabled = false; + enabled++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return enabled; + }, + + select: function (id) { + var new_node = this.get(id); + if (!new_node) return false; + if (this.selected == id && new_node.selected) return false; + this.unselect(this.selected); + $(this.box).find('#node_'+ w2utils.escapeId(id)) + .addClass('w2ui-selected') + .find('.w2ui-icon').addClass('w2ui-icon-selected'); + new_node.selected = true; + this.selected = id; + return true; + }, + + unselect: function (id) { + var current = this.get(id); + if (!current) return false; + current.selected = false; + $(this.box).find('#node_'+ w2utils.escapeId(id)) + .removeClass('w2ui-selected') + .find('.w2ui-icon').removeClass('w2ui-icon-selected'); + if (this.selected == id) this.selected = null; + return true; + }, + + toggle: function(id) { + var nd = this.get(id); + if (nd === null) return false; + if (nd.plus) { + this.set(id, { plus: false }); + this.expand(id); + this.refresh(id); + return; + } + if (nd.nodes.length === 0) return false; + if (this.get(id).expanded) return this.collapse(id); else return this.expand(id); + }, - get: function (parent, id, returnIndex) { // can be just called get(id) or get(id, true) - if (arguments.length == 1 || (arguments.length == 2 && id === true) ) { - // need to be in reverse order - returnIndex = id; - id = parent; - parent = this; - } - // searches all nested nodes - this._tmp = null; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].id == id) { - if (returnIndex === true) return i; else return parent.nodes[i]; - } else { - this._tmp = this.get(parent.nodes[i], id, returnIndex); - if (this._tmp || this._tmp === 0) return this._tmp; - } - } - return this._tmp; - }, + collapse: function (id) { + var obj = this; + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'collapse', target: id, object: nd }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideUp(200); + $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('+'); + nd.expanded = false; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + setTimeout(function () { obj.refresh(id); }, 200); + return true; + }, + + collapseAll: function (parent) { + if (typeof parent == 'undefined') parent = this; + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return false; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false; + if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); + } + this.refresh(parent.id); + return true; + }, - hide: function () { // multiple arguments - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.hidden = true; - hidden++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return hidden; - }, + expand: function (id) { + var obj = this; + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'expand', target: id, object: nd }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideDown(200); + $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('-'); + nd.expanded = true; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + setTimeout(function () { obj.refresh(id); }, 200); + return true; + }, + + expandAll: function (parent) { + if (typeof parent == 'undefined') parent = this; + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return false; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true; + if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); + } + this.refresh(parent.id); + }, + + expandParents: function (id) { + var node = this.get(id); + if (node === null) return false; + if (node.parent) { + node.parent.expanded = true; + this.expandParents(node.parent.id); + } + this.refresh(id); + return true; + }, - show: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.hidden = false; - shown++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return shown; - }, + click: function (id, event) { + var obj = this; + var nd = this.get(id); + if (nd === null) return; + if (nd.disabled || nd.group) return; // should click event if already selected + // unselect all previsously + $(obj.box).find('.w2ui-node.w2ui-selected').each(function (index, el) { + var oldID = $(el).attr('id').replace('node_', ''); + var oldNode = obj.get(oldID); + if (oldNode != null) oldNode.selected = false; + $(el).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); + }); + // select new one + var newNode = $(obj.box).find('#node_'+ w2utils.escapeId(id)); + var oldNode = $(obj.box).find('#node_'+ w2utils.escapeId(obj.selected)); + newNode.addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); + // need timeout to allow rendering + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'click', target: id, originalEvent: event, node: nd, object: nd }); + if (eventData.isCancelled === true) { + // restore selection + newNode.removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); + oldNode.addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); + return; + } + // default action + if (oldNode !== null) oldNode.selected = false; + obj.get(id).selected = true; + obj.selected = id; + // route processing + if (nd.route) { + var route = String('/'+ nd.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 1); + }, - disable: function () { // multiple arguments - var disabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.disabled = true; - if (tmp.selected) this.unselect(tmp.id); - disabled++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return disabled; - }, + keydown: function (event) { + var obj = this; + var nd = obj.get(obj.selected); + if (!nd || obj.keyboard !== true) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behaviour + if (event.keyCode == 13 || event.keyCode == 32) { // enter or space + if (nd.nodes.length > 0) obj.toggle(obj.selected); + } + if (event.keyCode == 37) { // left + if (nd.nodes.length > 0 && nd.expanded) { + obj.collapse(obj.selected); + } else { + selectNode(nd.parent); + if (!nd.parent.group) obj.collapse(nd.parent.id); + } + } + if (event.keyCode == 39) { // right + if ((nd.nodes.length > 0 || nd.plus) && !nd.expanded) obj.expand(obj.selected); + } + if (event.keyCode == 38) { // up + selectNode(neighbor(nd, prev)); + } + if (event.keyCode == 40) { // down + selectNode(neighbor(nd, next)); + } + // cancel event if needed + if ($.inArray(event.keyCode, [13, 32, 37, 38, 39, 40]) != -1) { + if (event.preventDefault) event.preventDefault(); + if (event.stopPropagation) event.stopPropagation(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); - enable: function () { // multiple arguments - var enabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.disabled = false; - enabled++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return enabled; - }, + function selectNode (node, event) { + if (node !== null && !node.hidden && !node.disabled && !node.group) { + obj.click(node.id, event); + setTimeout(function () { obj.scrollIntoView(); }, 50); + } + } - select: function (id) { - if (this.selected == id) return false; - this.unselect(this.selected); - var new_node = this.get(id); - if (!new_node) return false; - $(this.box).find('#node_'+ w2utils.escapeId(id)) - .addClass('w2ui-selected') - .find('.w2ui-icon').addClass('w2ui-icon-selected'); - new_node.selected = true; - this.selected = id; - }, + function neighbor (node, neighborFunc) { + node = neighborFunc(node); + while (node !== null && (node.hidden || node.disabled)) { + if (node.group) break; else node = neighborFunc(node); + } + return node; + } - unselect: function (id) { - var current = this.get(id); - if (!current) return false; - current.selected = false; - $(this.box).find('#node_'+ w2utils.escapeId(id)) - .removeClass('w2ui-selected') - .find('.w2ui-icon').removeClass('w2ui-icon-selected'); - if (this.selected == id) this.selected = null; - return true; - }, + function next (node, noSubs) { + if (node === null) return null; + var parent = node.parent; + var ind = obj.get(node.id, true); + var nextNode = null; + // jump inside + if (node.expanded && node.nodes.length > 0 && noSubs !== true) { + var t = node.nodes[0]; + if (t.hidden || t.disabled || t.group) nextNode = next(t); else nextNode = t; + } else { + if (parent && ind + 1 < parent.nodes.length) { + nextNode = parent.nodes[ind + 1]; + } else { + nextNode = next(parent, true); // jump to the parent + } + } + if (nextNode !== null && (nextNode.hidden || nextNode.disabled || nextNode.group)) nextNode = next(nextNode); + return nextNode; + } - toggle: function(id) { - var nd = this.get(id); - if (nd == null) return; - if (nd.plus) { - this.set(id, { plus: false }); - this.expand(id); - this.refresh(id); - return; - } - if (nd.nodes.length == 0) return; - if (this.get(id).expanded) this.collapse(id); else this.expand(id); - }, + function prev (node) { + if (node === null) return null; + var parent = node.parent; + var ind = obj.get(node.id, true); + var prevNode = (ind > 0) ? lastChild(parent.nodes[ind - 1]) : parent; + if (prevNode !== null && (prevNode.hidden || prevNode.disabled || prevNode.group)) prevNode = prev(prevNode); + return prevNode; + } - collapse: function (id) { - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'collapse', target: id, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideUp('fast'); - $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('+'); - nd.expanded = false; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + function lastChild (node) { + if (node.expanded && node.nodes.length > 0) { + var t = node.nodes[node.nodes.length - 1]; + if (t.hidden || t.disabled || t.group) return prev(t); else return lastChild(t); + } + return node; + } + }, + + scrollIntoView: function (id) { + if (typeof id == 'undefined') id = this.selected; + var nd = this.get(id); + if (nd === null) return; + var body = $(this.box).find('.w2ui-sidebar-div'); + var item = $(this.box).find('#node_'+ w2utils.escapeId(id)); + var offset = item.offset().top - body.offset().top; + if (offset + item.height() > body.height()) { + body.animate({ 'scrollTop': body.scrollTop() + body.height() / 1.3 }, 250, 'linear'); + } + if (offset <= 0) { + body.animate({ 'scrollTop': body.scrollTop() - body.height() / 1.3 }, 250, 'linear'); + } + }, - collapseAll: function (parent) { - if (typeof parent == 'undefined') parent = this; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false; - if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); - } - this.refresh(parent.id); - }, + dblClick: function (id, event) { + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'dblClick', target: id, originalEvent: event, object: nd }); + if (eventData.isCancelled === true) return; + // default action + this.toggle(id); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - expand: function (id) { - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'expand', target: id, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideDown('fast'); - $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('-'); - nd.expanded = true; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + contextMenu: function (id, event) { + var obj = this; + var nd = obj.get(id); + if (id != obj.selected) obj.click(id); + // need timeout to allow click to finish first + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: id, originalEvent: event, object: nd }); + if (eventData.isCancelled === true) return; + // default action + if (nd.group || nd.disabled) return; + if (obj.menu.length > 0) { + $(obj.box).find('#node_'+ w2utils.escapeId(id)) + .w2menu(obj.menu, { + left : (event ? event.offsetX || event.pageX : 50) - 25, + onSelect: function (event) { + obj.menuClick(id, parseInt(event.index), event.originalEvent); + } + } + ); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 150); // need timer 150 for FF + }, - expandAll: function (parent) { - if (typeof parent == 'undefined') parent = this; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true; - if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); - } - this.refresh(parent.id); - }, + menuClick: function (itemId, index, event) { + var obj = this; + // event before + var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: itemId, originalEvent: event, menuIndex: index, menuItem: obj.menu[index] }); + if (eventData.isCancelled === true) return; + // default action + // -- empty + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, - expandParents: function (id) { - var node = this.get(id); - if (node == null) return; - if (node.parent) { - node.parent.expanded = true; - this.expandParents(node.parent.id); - } - this.refresh(id); - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + // default action + if (typeof box != 'undefined' && box !== null) { + if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-sidebar') + .html(''); + } + this.box = box; + } + if (!this.box) return; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-sidebar') + .html(''+ + '' + + ''+ + ''+ + '' + ); + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height: $(this.box).height() + 'px' + }); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // adjust top and bottom + if (this.topHTML !== '') { + $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); + } + if (this.bottomHTML !== '') { + $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // --- + this.refresh(); + return (new Date()).getTime() - time; + }, - click: function (id, event) { - var obj = this; - var nd = this.get(id); - if (nd == null) return; - var old = this.selected; - if (nd.disabled || nd.group) return; // should click event if already selected - // move selected first - $(obj.box).find('#node_'+ w2utils.escapeId(old)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); - $(obj.box).find('#node_'+ w2utils.escapeId(id)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); - // need timeout to allow rendering - setTimeout(function () { - // event before - var eventData = obj.trigger({ phase: 'before', type: 'click', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) { - // restore selection - $(obj.box).find('#node_'+ w2utils.escapeId(id)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); - $(obj.box).find('#node_'+ w2utils.escapeId(old)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); - return false; - } - // default action - if (old != null) obj.get(old).selected = false; - obj.get(id).selected = true; - obj.selected = id; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name) }); + if (eventData.isCancelled === true) return; + // adjust top and bottom + if (this.topHTML !== '') { + $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); + } + if (this.bottomHTML !== '') { + $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); + } + // default action + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height: $(this.box).height() + 'px' + }); + var obj = this; + var node, nd; + var nm; + if (typeof id == 'undefined') { + node = this; + nm = '.w2ui-sidebar-div'; + } else { + node = this.get(id); + if (node === null) return; + nm = '#node_'+ w2utils.escapeId(node.id) + '_sub'; + } + var nodeHTML; + if (node !== this) { + var tmp = '#node_'+ w2utils.escapeId(node.id); + nodeHTML = getNodeHTML(node); + $(this.box).find(tmp).before(''); + $(this.box).find(tmp).remove(); + $(this.box).find(nm).remove(); + $('#sidebar_'+ this.name + '_tmp').before(nodeHTML); + $('#sidebar_'+ this.name + '_tmp').remove(); + } + // refresh sub nodes + $(this.box).find(nm).html(''); + for (var i = 0; i < node.nodes.length; i++) { + nd = node.nodes[i]; + nodeHTML = getNodeHTML(nd); + $(this.box).find(nm).append(nodeHTML); + if (nd.nodes.length !== 0) { this.refresh(nd.id); } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + + function getNodeHTML(nd) { + var html = ''; + var img = nd.img; + if (img === null) img = this.img; + var icon = nd.icon; + if (icon === null) icon = this.icon; + // -- find out level + var tmp = nd.parent; + var level = 0; + while (tmp && tmp.parent !== null) { + if (tmp.group) level--; + tmp = tmp.parent; + level++; + } + if (typeof nd.caption != 'undefined') nd.text = nd.caption; + if (nd.group) { + html = + ''+ + (nd.groupShowHide ? ''+ (!nd.hidden && nd.expanded ? w2utils.lang('Hide') : w2utils.lang('Show')) +'' : '') + + ' '+ nd.text +''+ + ''+ + ''; + } else { + if (nd.selected && !nd.disabled) obj.selected = nd.id; + tmp = ''; + if (img) tmp = ''; + if (icon) tmp = ''; + html = + ''+ + ''+ + ''+ + ' ' + (nd.nodes.length > 0 ? (nd.expanded ? '-' : '+') : (nd.plus ? '+' : '')) + '' + + ''+ + ''+ + tmp + + (nd.count || nd.count === 0 ? ''+ nd.count +'' : '') + + ''+ nd.text +''+ + ''+ + ''+ + ''+ + ''; + } + return html; + } + }, - keydown: function (event) { - var obj = this; - var nd = obj.get(obj.selected); - if (!nd || obj.keyboard !== true) return; - // trigger event - var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behaviour - if (event.keyCode == 13 || event.keyCode == 32) { // enter or space - if (nd.nodes.length > 0) obj.toggle(obj.selected); - } - if (event.keyCode == 37) { // left - if (nd.nodes.length > 0) { - obj.collapse(obj.selected); - } else { - // collapse parent - if (nd.parent && !nd.parent.disabled && !nd.parent.group) { - obj.collapse(nd.parent.id); - obj.click(nd.parent.id); - setTimeout(function () { obj.scrollIntoView(); }, 50); - } - } - } - if (event.keyCode == 39) { // right - if (nd.nodes.length > 0) obj.expand(obj.selected); - } - if (event.keyCode == 38) { // up - var tmp = prev(nd); - if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); } - } - if (event.keyCode == 40) { // down - var tmp = next(nd); - if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); } - } - // cancel event if needed - if ($.inArray(event.keyCode, [13, 32, 37, 38, 39, 40]) != -1) { - if (event.preventDefault) event.preventDefault(); - if (event.stopPropagation) event.stopPropagation(); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - return; - - function next (node, noSubs) { - if (node == null) return null; - var parent = node.parent; - var ind = obj.get(node.id, true); - var nextNode = null; - // jump inside - if (node.expanded && node.nodes.length > 0 && noSubs !== true) { - var t = node.nodes[0]; - if (!t.disabled && !t.group) nextNode = t; else nextNode = next(t); - } else { - if (parent && ind + 1 < parent.nodes.length) { - nextNode = parent.nodes[ind + 1]; - } else { - nextNode = next(parent, true); // jump to the parent - } - } - if (nextNode != null && (nextNode.disabled || nextNode.group)) nextNode = next(nextNode); - return nextNode; - } - - function prev (node) { - if (node == null) return null; - var parent = node.parent; - var ind = obj.get(node.id, true); - var prevNode = null; - var noSubs = false; - if (ind > 0) { - prevNode = parent.nodes[ind - 1]; - // jump inside parents last node - if (prevNode.expanded && prevNode.nodes.length > 0) { - var t = prevNode.nodes[prevNode.nodes.length - 1]; - if (!t.disabled && !t.group) prevNode = t; else prevNode = prev(t); - } - } else { - prevNode = parent; // jump to the parent - noSubs = true; - } - if (prevNode != null && (prevNode.disabled || prevNode.group)) prevNode = prev(prevNode); - return prevNode; - } - }, + resize: function () { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).css('overflow', 'hidden'); // container should have no overflow + //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'hidden'); + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height : $(this.box).height() + 'px' + }); + //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'auto'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - scrollIntoView: function (id) { - if (typeof id == 'undefined') id = this.selected; - var nd = this.get(id); - if (nd == null) return; - var body = $(this.box).find('.w2ui-sidebar-div'); - var item = $(this.box).find('#node_'+ w2utils.escapeId(id)); - var offset = item.offset().top - body.offset().top; - if (offset + item.height() > body.height()) { - body.animate({ 'scrollTop': body.scrollTop() + body.height() / 1.3 }); - } - if (offset <= 0) { - body.animate({ 'scrollTop': body.scrollTop() - body.height() / 1.3 }); - } - }, + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-sidebar') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - dblClick: function (id, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'dblClick', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - if (nd.nodes.length > 0) this.toggle(id); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + w2utils.lock.apply(window, args); + }, - contextMenu: function (id, event) { - var obj = this; - var nd = obj.get(id); - if (id != obj.selected) obj.click(id); - // need timeout to allow click to finish first - setTimeout(function () { - // event before - var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - if (nd.group || nd.disabled) return; - if (obj.menu.length > 0) { - $(obj.box).find('#node_'+ w2utils.escapeId(id)) - .w2menu(obj.menu, { - left: (event ? event.offsetX || event.pageX : 50) - 25, - select: function (item, event, index) { obj.menuClick(id, index, event); } - } - ); + unlock: function () { + w2utils.unlock(this.box); } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - }, + }; - menuClick: function (itemId, index, event) { - var obj = this; - // event before - var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: itemId, originalEvent: event, menuIndex: index, menuItem: obj.menu[index] }); - if (eventData.isCancelled === true) return false; - // default action - // -- empty - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, + $.extend(w2sidebar.prototype, w2utils.event); + w2obj.sidebar = w2sidebar; +})(jQuery); - render: function (box) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - // default action - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-sidebar') - .html(''); - } - this.box = box; - } - if (!this.box) return; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-sidebar') - .html(''+ - '' + - ''+ - ''+ - '' - ); - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // adjust top and bottom - if (this.topHTML != '') { - $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); - } - if (this.bottomHTML != '') { - $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // --- - this.refresh(); - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2field - various field controls +* - $().w2field - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - upload (regular files) +* - BUG with prefix/postfix and arrows (test in different contexts) +* - prefix and suffix are slow (100ms or so) +* - multiple date selection +* - month selection, year selections +* - arrows no longer work (for int) +* - form to support custom types +* - bug: if input is hidden and then enum is applied, then when it becomes visible, it will be 110px +* +************************************************************************/ - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name) }); - if (eventData.isCancelled === true) return false; - // adjust top and bottom - if (this.topHTML != '') { - $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); - } - if (this.bottomHTML != '') { - $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); - } - // default action - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - var obj = this; - if (typeof id == 'undefined') { - var node = this; - var nm = '.w2ui-sidebar-div'; - } else { - var node = this.get(id); - if (node == null) return; - var nm = '#node_'+ w2utils.escapeId(node.id) + '_sub'; - } - if (node != this) { - var tmp = '#node_'+ w2utils.escapeId(node.id); - var nodeHTML = getNodeHTML(node); - $(this.box).find(tmp).before(''); - $(this.box).find(tmp).remove(); - $(this.box).find(nm).remove(); - $('#sidebar_'+ this.name + '_tmp').before(nodeHTML); - $('#sidebar_'+ this.name + '_tmp').remove(); - } - // refresh sub nodes - $(this.box).find(nm).html(''); - for (var i=0; i < node.nodes.length; i++) { - var nodeHTML = getNodeHTML(node.nodes[i]); - $(this.box).find(nm).append(nodeHTML); - if (node.nodes[i].nodes.length != 0) { this.refresh(node.nodes[i].id); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - - function getNodeHTML(nd) { - var html = ''; - var img = nd.img; - if (img == null) img = this.img; - var icon = nd.icon; - if (icon == null) icon = this.icon; - // -- find out level - var tmp = nd.parent; - var level = 0; - while (tmp && tmp.parent != null) { - if (tmp.group) level--; - tmp = tmp.parent; - level++; - } - if (typeof nd.caption != 'undefined') nd.text = nd.caption; - if (nd.group) { - html = - ''+ - ' '+ (!nd.hidden && nd.expanded ? w2utils.lang('Hide') : w2utils.lang('Show')) +''+ - ' '+ nd.text +''+ - ''+ - ''; +(function ($) { + + var w2field = function (options) { + // public properties + this.el = null + this.helpers = {}; // object or helper elements + this.type = options.type || 'text'; + this.options = $.extend(true, {}, options); + this.onSearch = options.onSearch || null; + this.onRequest = options.onRequest || null; + this.onLoad = options.onLoad || null; + this.onError = options.onError || null; + this.onClick = options.onClick || null; + this.onAdd = options.onAdd || null; + this.onNew = options.onNew || null; + this.onRemove = options.onRemove || null; + this.onMouseOver = options.onMouseOver || null; + this.onMouseOut = options.onMouseOut || null; + this.onIconClick = options.onIconClick || null; + this.tmp = {}; // temp object + // clean up some options + delete this.options.type; + delete this.options.onSearch; + delete this.options.onRequest; + delete this.options.onLoad; + delete this.options.onError; + delete this.options.onClick; + delete this.options.onMouseOver; + delete this.options.onMouseOut; + delete this.options.onIconClick; + // extend with defaults + $.extend(true, this, w2obj.field); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2field = function (method, options) { + // call direct + if (this.length == 0) { + var pr = w2field.prototype; + if (pr[method]) { + return pr[method].apply(pr, Array.prototype.slice.call(arguments, 1)); + } } else { - if (nd.selected && !nd.disabled) obj.selected = nd.id; - var tmp = ''; - if (img) tmp = ''; - if (icon) tmp = ''; - html = - ''+ - ''+ - ''+ - ' ' + (nd.nodes.length > 0 ? (nd.expanded ? '-' : '+') : (nd.plus ? '+' : '')) + '' + - ''+ - ''+ - tmp + - (nd.count !== '' ? ''+ nd.count +'' : '') + - ''+ nd.text +''+ - ''+ - ''+ - ''+ - ''; + // if without arguments - return the object + if (arguments.length == 0) { + var obj = $(this).data('w2field'); + return obj; + } + if (typeof method == 'string' && typeof options == 'object') { + method = $.extend(true, {}, options, { type: method }); + } + if (typeof method == 'string' && typeof options == 'undefined') { + method = { type: method }; + } + method.type = String(method.type).toLowerCase(); + return this.each(function (index, el) { + var obj = $(el).data('w2field'); + // if object is not defined, define it + if (typeof obj == 'undefined') { + var obj = new w2field(method); + $.extend(obj, { handlers: [] }); + if (el) obj.el = $(el)[0]; + obj.init(); + $(el).data('w2field', obj); + return obj; + } else { // fully re-init + obj.clear(); + if (method.type == 'clear') return; + var obj = new w2field(method); + $.extend(obj, { handlers: [] }); + if (el) obj.el = $(el)[0]; + obj.init(); + $(el).data('w2field', obj); + return obj; + } + return null; + }); } - return html; - } - }, + } - resize: function () { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).css('overflow', 'hidden'); // container should have no overflow - //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'hidden'); - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'auto'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + // ==================================================== + // -- Implementation of core functionality - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-sidebar') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + /* To add custom types + $().w2field('addType', 'myType', function (options) { + $(this.el).on('keypress', function (event) { + if (event.metaKey || event.ctrlKey || event.altKey + || (event.charCode != event.keyCode && event.keyCode > 0)) return; + var ch = String.fromCharCode(event.charCode); + if (ch != 'a' && ch != 'b' && ch != 'c') { + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + return false; + } + }); + $(this.el).on('blur', function (event) { // keyCode & charCode differ in FireFox + var ch = this.value; + if (ch != 'a' && ch != 'b' && ch != 'c') { + $(this).w2tag(w2utils.lang("Not a single charecter from the set of 'abc'")); + } + }); + }); + */ + + w2field.prototype = { + + custom: {}, // map of custom types + + pallete: [ + ['000000', '444444', '666666', '999999', 'CCCCCC', 'EEEEEE', 'F3F3F3', 'FFFFFF'], + ['FF011B', 'FF9838', 'FFFD59', '01FD55', '00FFFE', '0424F3', '9B24F4', 'FF21F5'], + ['F4CCCC', 'FCE5CD', 'FFF2CC', 'D9EAD3', 'D0E0E3', 'CFE2F3', 'D9D1E9', 'EAD1DC'], + ['EA9899', 'F9CB9C', 'FEE599', 'B6D7A8', 'A2C4C9', '9FC5E8', 'B4A7D6', 'D5A6BD'], + ['E06666', 'F6B26B', 'FED966', '93C47D', '76A5AF', '6FA8DC', '8E7CC3', 'C27BA0'], + ['CC0814', 'E69138', 'F1C232', '6AA84F', '45818E', '3D85C6', '674EA7', 'A54D79'], + ['99050C', 'B45F17', 'BF901F', '37761D', '124F5C', '0A5394', '351C75', '741B47'], + ['660205', '783F0B', '7F6011', '274E12', '0C343D', '063762', '20124D', '4C1030'] + ], + + addType: function (type, handler) { + type = String(type).toLowerCase(); + this.custom[type] = handler; + return true; + }, + + removeType: function (type) { + type = String(type).toLowerCase(); + if (!this.custom[type]) return false; + delete this.custom[type]; + return true + }, + + init: function () { + var obj = this; + var options = this.options; + var defaults; + + // Custom Types + if (typeof this.custom[this.type] == 'function') { + this.custom[this.type].call(this, options); + return; + } + // only for INPUT or TEXTAREA + if (['INPUT', 'TEXTAREA'].indexOf(this.el.tagName) == -1) { + console.log('ERROR: w2field could only be applied to INPUT or TEXTAREA.', this.el); + return; + } - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - w2utils.lock(box, msg, showSpinner); - }, + switch (this.type) { + case 'text': + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'alphanumeric': + case 'hex': + defaults = { + min : null, + max : null, + step : 1, + placeholder : '', + autoFormat : true, + currencyPrefix : w2utils.settings.currencyPrefix, + currencySuffix : w2utils.settings.currencySuffix, + currencyPrecision : w2utils.settings.currencyPrecision, + decimalSymbol : w2utils.settings.decimalSymbol, + groupSymbol : w2utils.settings.groupSymbol, + arrows : false, + keyboard : true, + precision : null, + silent : true, + prefix : '', + suffix : '' + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + options.numberRE = new RegExp('['+ options.groupSymbol + ']', 'g'); + options.moneyRE = new RegExp('['+ options.currencyPrefix + options.currencySuffix + options.groupSymbol +']', 'g'); + options.percentRE = new RegExp('['+ options.groupSymbol + '%]', 'g'); + // no keyboard support needed + if (['text', 'alphanumeric', 'hex'].indexOf(this.type) != -1) { + options.arrows = false; + options.keyboard = false; + } + this.addPrefix(); // only will add if needed + this.addSuffix(); + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder); + break; - unlock: function () { - w2utils.unlock(this.box); - } - } + case 'color': + defaults = { + prefix : '#', + suffix : ' ', + placeholder : '', + arrows : false, + keyboard : false + }; + $.extend(options, defaults); + this.addPrefix(); // only will add if needed + this.addSuffix(); // only will add if needed + // additional checks + $(this.el).attr('maxlength', 6); + if ($(this.el).val() != '') setTimeout(function () { $(obj.el).change(); }, 1); + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder); + break; - $.extend(w2sidebar.prototype, w2utils.event); - w2obj.sidebar = w2sidebar; -})(jQuery); + case 'date': + defaults = { + format : w2utils.settings.date_format, // date format + placeholder : '', + keyboard : true, + silent : true, + start : '', // string or jquery object + end : '', // string or jquery object + blocked : {}, // { '4/11/2011': 'yes' } + colored : {} // { '4/11/2011': 'red:white' } + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder ? options.placeholder : options.format); + break; -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2field - various field controls - * - $().w2field - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - select - for select, list - for drop down (needs this in grid) - * - enum add events: onLoad, onRequest, onCompare, onSelect, onDelete, onClick for already selected elements - * - upload (regular files) - * - enum - refresh happens on each key press even if not needed (for speed) - * - BUG with prefix/postfix and arrows (test in different contexts) - * - multiple date selection - * - rewrire everythin in objects (w2ftext, w2fenum, w2fdate) - * - render calendar to the div - * - ************************************************************************/ + case 'time': + defaults = { + format : w2utils.settings.time_format, + placeholder : '', + keyboard : true, + silent : true, + start : '', + end : '' + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder ? options.placeholder : (options.format == 'h12' ? 'hh:mi pm' : 'hh:mi')); + break; -(function ($) { + case 'datetime': + break; - /* SINGELTON PATTERN */ + case 'list': + case 'combo': + defaults = { + items : [], + selected : {}, + placeholder : '', + url : null, // url to pull data from + postData : {}, + minLength : 1, + cacheMax : 250, + maxDropHeight : 350, // max height for drop down menu + match : 'begins', // ['contains', 'is', 'begins', 'ends'] + silent : true, + icon : null, + iconStyle : '', + onSearch : null, // when search needs to be performed + onRequest : null, // when request is submitted + onLoad : null, // when data is received + onError : null, // when data fails to load due to server error or other failure modes + onIconClick : null, + renderDrop : null, // render function for drop down item + prefix : '', + suffix : '', + openOnFocus : false, // if to show overlay onclick or when typing + markSearch : false + }; + options.items = this.normMenu(options.items); // need to be first + if (this.type == 'list') { + // defaults.search = (options.items && options.items.length >= 10 ? true : false); + defaults.openOnFocus = true; + defaults.suffix = ''; + $(this.el).addClass('w2ui-select'); + // if simple value - look it up + if (!$.isPlainObject(options.selected)) { + for (var i in options.items) { + var item = options.items[i]; + if (item && item.id == options.selected) { + options.selected = $.extend(true, {}, item); + break; + } + } + } + } + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + altRows : true // alternate row color + }); + this.options = options; + if (!$.isPlainObject(options.selected)) options.selected = {}; + $(this.el).data('selected', options.selected); + if (options.url) this.request(0); + if (this.type == 'list') this.addFocus(); + this.addPrefix(); + this.addSuffix(); + setTimeout(function () { obj.refresh(); }, 10); // need this for icon refresh + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder).attr('autocomplete', 'off'); + if (typeof options.selected.text != 'undefined') $(this.el).val(options.selected.text); + break; - var w2field = new (function () { - this.customTypes = []; - }); + case 'enum': + defaults = { + items : [], + selected : [], + placeholder : '', + max : 0, // max number of selected items, 0 - unlim + url : null, // not implemented + postData : {}, + minLength : 1, + cacheMax : 250, + maxWidth : 250, // max width for a single item + maxHeight : 350, // max height for input control to grow + maxDropHeight : 350, // max height for drop down menu + match : 'contains', // ['contains', 'is', 'begins', 'ends'] + silent : true, + openOnFocus : false, // if to show overlay onclick or when typing + markSearch : true, + renderDrop : null, // render function for drop down item + renderItem : null, // render selected item + style : '', // style for container div + onSearch : null, // when search needs to be performed + onRequest : null, // when request is submitted + onLoad : null, // when data is received + onError : null, // when data fails to load due to server error or other failure modes + onClick : null, // when an item is clicked + onAdd : null, // when an item is added + onNew : null, // when new item should be added + onRemove : null, // when an item is removed + onMouseOver : null, // when an item is mouse over + onMouseOut : null // when an item is mouse out + }; + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + suffix : '', + altRows : true // alternate row color + }); + options.items = this.normMenu(options.items); + options.selected = this.normMenu(options.selected); + this.options = options; + if (!$.isArray(options.selected)) options.selected = []; + $(this.el).data('selected', options.selected); + if (options.url) this.request(0); + this.addSuffix(); + this.addMulti(); + break; - // ==================================================== - // -- Registers as a jQuery plugin + case 'file': + defaults = { + selected : [], + placeholder : w2utils.lang('Attach files by dragging and dropping or Click to Select'), + max : 0, + maxSize : 0, // max size of all files, 0 - unlim + maxFileSize : 0, // max size of a single file, 0 -unlim + maxWidth : 250, // max width for a single item + maxHeight : 350, // max height for input control to grow + maxDropHeight : 350, // max height for drop down menu + silent : true, + renderItem : null, // render selected item + style : '', // style for container div + onClick : null, // when an item is clicked + onAdd : null, // when an item is added + onRemove : null, // when an item is removed + onMouseOver : null, // when an item is mouse over + onMouseOut : null // when an item is mouse out + }; + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + altRows : true // alternate row color + }); + this.options = options; + if (!$.isArray(options.selected)) options.selected = []; + $(this.el).data('selected', options.selected); + if ($(this.el).attr('placeholder')) options.placeholder = $(this.el).attr('placeholder'); + this.addMulti(); + break; + } + // attach events + this.tmp = { + onChange : function (event) { obj.change.call(obj, event) }, + onClick : function (event) { obj.click.call(obj, event) }, + onFocus : function (event) { obj.focus.call(obj, event) }, + onBlur : function (event) { obj.blur.call(obj, event) }, + onKeydown : function (event) { obj.keyDown.call(obj, event) }, + onKeyup : function (event) { obj.keyUp.call(obj, event) }, + onKeypress : function (event) { obj.keyPress.call(obj, event) } + } + $(this.el) + .addClass('w2field') + .data('w2field', this) + .on('change', this.tmp.onChange) + .on('click', this.tmp.onClick) // ignore click because it messes overlays + .on('focus', this.tmp.onFocus) + .on('blur', this.tmp.onBlur) + .on('keydown', this.tmp.onKeydown) + .on('keyup', this.tmp.onKeyup) + .on('keypress', this.tmp.onKeypress) + .css({ + 'box-sizing' : 'border-box', + '-webkit-box-sizing' : 'border-box', + '-moz-box-sizing' : 'border-box', + '-ms-box-sizing' : 'border-box', + '-o-box-sizing' : 'border-box' + }); + // format initial value + this.change($.Event('change')); + }, + + clear: function () { + var obj = this; + var options = this.options; + // if money then clear value + if (['money', 'currency'].indexOf(this.type) != -1) { + $(this.el).val($(this.el).val().replace(options.moneyRE, '')); + } + if (this.type == 'percent') { + $(this.el).val($(this.el).val().replace(/%/g, '')); + } + if (this.type == 'color') { + $(this.el).removeAttr('maxlength'); + } + if (this.type == 'list') { + $(this.el).removeClass('w2ui-select'); + } + if (['date', 'time'].indexOf(this.type) != -1) { + if ($(this.el).attr('placeholder') == options.format) $(this.el).attr('placeholder', ''); + } + this.type = 'clear'; + var tmp = $(this.el).data('tmp'); + if (!this.tmp) return; + // restore paddings + if (typeof tmp != 'undefined') { + if (tmp && tmp['old-padding-left']) $(this.el).css('padding-left', tmp['old-padding-left']); + if (tmp && tmp['old-padding-right']) $(this.el).css('padding-right', tmp['old-padding-right']); + } + // remove events and data + $(this.el) + .val(this.clean($(this.el).val())) + .removeClass('w2field') + .removeData() // removes all attached data + .off('change', this.tmp.onChange) + .off('click', this.tmp.onClick) + .off('focus', this.tmp.onFocus) + .off('blur', this.tmp.onBlur) + .off('keydown', this.tmp.onKeydown) + .off('keyup', this.tmp.onKeyup) + .off('keypress', this.tmp.onKeypress); + // remove helpers + for (var h in this.helpers) $(this.helpers[h]).remove(); + this.helpers = {}; + }, + + refresh: function () { + var obj = this; + var options = this.options; + var selected = $(this.el).data('selected'); + var time = (new Date()).getTime(); + // enum + if (['list'].indexOf(this.type) != -1) { + $(obj.el).parent().css('white-space', 'nowrap'); // needs this for arrow alway to appear on the right side + // hide focus and show text + if (obj.helpers.prefix) obj.helpers.prefix.hide(); + setTimeout(function () { + if (!obj.helpers.focus) return; + // if empty show no icon + if (!$.isEmptyObject(selected) && options.icon) { + options.prefix = ''+ + ''; + obj.addPrefix(); + } else { + options.prefix = ''; + obj.addPrefix(); + } + // focus helpder + var focus = obj.helpers.focus.find('input'); + if ($(focus).val() == '') { + $(focus).css('opacity', 0).prev().css('opacity', 0); + $(obj.el).val(selected && selected.text != null ? selected.text : ''); + $(obj.el).attr('placeholder', options.placeholder || ''); + } else { + $(focus).css('opacity', 1).prev().css('opacity', 1); + $(obj.el).val(''); + $(obj.el).removeAttr('placeholder'); + setTimeout(function () { + if (obj.helpers.prefix) obj.helpers.prefix.hide(); + var tmp = 'position: absolute; opacity: 0; margin: 4px 0px 0px 2px; background-position: left !important;'; + if (options.icon) { + $(focus).css('margin-left', '17px'); + $(obj.helpers.focus).find('.icon-search').attr('style', tmp + 'width: 11px !important; opacity: 1'); + } else { + $(focus).css('margin-left', '0px'); + $(obj.helpers.focus).find('.icon-search').attr('style', tmp + 'width: 0px !important; opacity: 0'); + } + }, 1); + } + // if readonly or disabled + if ($(obj.el).prop('readonly') || $(obj.el).prop('disabled')) { + setTimeout(function () { + $(obj.helpers.prefix).css('opacity', '0.6'); + $(obj.helpers.suffix).css('opacity', '0.6'); + }, 1); + } else { + setTimeout(function () { + $(obj.helpers.prefix).css('opacity', '1'); + $(obj.helpers.suffix).css('opacity', '1'); + }, 1); + } + }, 1); + } + if (['enum', 'file'].indexOf(this.type) != -1) { + var html = ''; + for (var s in selected) { + var it = selected[s]; + var ren = ''; + if (typeof options.renderItem == 'function') { + ren = options.renderItem(it, s, ' '); + } else { + ren = ' '+ + (obj.type == 'enum' ? it.text : it.name + ' - '+ w2utils.size(it.size) +''); + } + html += ''+ + ren +''; + } + var div = obj.helpers.multi; + var ul = div.find('ul'); + div.attr('style', div.attr('style') + ';' + options.style); + if ($(obj.el).prop('readonly') || $(obj.el).prop('disabled')) { + div.addClass('w2ui-readonly'); + div.css('pointer-events', 'none').find('li').css('opacity', '0.6'); + $(obj.helpers.multi).find('input').prop('readonly', true); + } else { + div.removeClass('w2ui-readonly'); + div.css('pointer-events', 'auto').find('li').css('opacity', '1'); + $(obj.helpers.multi).find('input').prop('readonly', false); + } + // celan + div.find('.w2ui-enum-placeholder').remove(); + ul.find('li').not('li.nomouse').remove(); + // add new list + if (html != '') { + ul.prepend(html); + } else if (typeof options.placeholder != 'undefined') { + var style = + 'padding-top: ' + $(this.el).css('padding-top') + ';'+ + 'padding-left: ' + $(this.el).css('padding-left') + '; ' + + 'box-sizing: ' + $(this.el).css('box-sizing') + '; ' + + 'line-height: ' + $(this.el).css('line-height') + '; ' + + 'font-size: ' + $(this.el).css('font-size') + '; ' + + 'font-family: ' + $(this.el).css('font-family') + '; '; + div.prepend(''+ options.placeholder + ''); + } + // ITEMS events + div.find('li') + .data('mouse', 'out') + .on('click', function (event) { + var item = selected[$(event.target).attr('index')]; + if ($(event.target).hasClass('nomouse')) return; + event.stopPropagation(); + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'click', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + if ($(event.target).hasClass('w2ui-list-remove')) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'remove', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + $().w2overlay(); + selected.splice($(event.target).attr('index'), 1); + $(obj.el).trigger('change'); + $(event.target).parent().fadeOut('fast'); + setTimeout(function () { + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 300); + } + if (obj.type == 'file' && !$(event.target).hasClass('w2ui-list-remove')) { + var preview = ''; + if ((/image/i).test(item.type)) { // image + preview = ''+ + ' '+ + ''; + } + var td1 = 'style="padding: 3px; text-align: right; color: #777;"'; + var td2 = 'style="padding: 3px"'; + preview += ''+ + ' '+ + ' '+ w2utils.lang('Name') +':'+ item.name +''+ + ' '+ w2utils.lang('Size') +':'+ w2utils.size(item.size) +''+ + ' '+ w2utils.lang('Type') +':' + + ' '+ item.type +''+ + ' '+ + ' '+ w2utils.lang('Modified') +':'+ w2utils.date(item.modified) +''+ + ' '+ + ''; + $(event.target).w2overlay(preview); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }) + .on('mouseover', function (event) { + var tmp = event.target; + if (tmp.tagName != 'LI') tmp = tmp.parentNode; + if ($(tmp).hasClass('nomouse')) return; + if ($(tmp).data('mouse') == 'out') { + var item = selected[$(tmp).attr('index')]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'mouseOver', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + $(tmp).data('mouse', 'over'); + }) + .on('mouseout', function (event) { + var tmp = event.target; + if (tmp.tagName != 'LI') tmp = tmp.parentNode; + if ($(tmp).hasClass('nomouse')) return; + $(tmp).data('mouse', 'leaving'); + setTimeout(function () { + if ($(tmp).data('mouse') == 'leaving') { + $(tmp).data('mouse', 'out'); + var item = selected[$(tmp).attr('index')]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'f', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + }, 0); + }); + // adjust height + $(this.el).height('auto'); + var cntHeight = $(div).find('> div').height() + w2utils.getSize(div, '+height') * 2; + if (cntHeight < 26) cntHeight = 26; + if (cntHeight > options.maxHeight) cntHeight = options.maxHeight; + if (div.length > 0) div[0].scrollTop = 1000; + var inpHeight = w2utils.getSize($(this.el), 'height') - 2; + if (inpHeight > cntHeight) cntHeight = inpHeight + $(div).css({ 'height': cntHeight + 'px', overflow: (cntHeight == options.maxHeight ? 'auto' : 'hidden') }); + if (cntHeight < options.maxHeight) $(div).prop('scrollTop', 0); + $(this.el).css({ 'height' : (cntHeight + 2) + 'px' }); + } + return (new Date()).getTime() - time; + }, + + reset: function () { + var obj = this; + var type = this.type; + this.clear(); + this.type = type; + this.init(); + }, + + clean: function (val) { + var options = this.options; + val = String(val).trim(); + // clean + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(this.type) != -1) { + if (typeof val == 'string') val = val.replace(options.decimalSymbol, '.'); + if (options.autoFormat && ['money', 'currency'].indexOf(this.type) != -1) val = String(val).replace(options.moneyRE, ''); + if (options.autoFormat && this.type == 'percent') val = String(val).replace(options.percentRE, ''); + if (options.autoFormat && ['int', 'float'].indexOf(this.type) != -1) val = String(val).replace(options.numberRE, ''); + if (parseFloat(val) == val) { + if (options.min !== null && val < options.min) { val = options.min; $(this.el).val(options.min); } + if (options.max !== null && val > options.max) { val = options.max; $(this.el).val(options.max); } + } + if (val !== '' && w2utils.isFloat(val)) val = Number(val); else val = ''; + } + return val; + }, + + format: function (val) { + var options = this.options; + // autoformat numbers or money + if (options.autoFormat && val != '') { + switch (this.type) { + case 'money': + case 'currency': + val = w2utils.formatNumber(Number(val).toFixed(options.currencyPrecision), options.groupSymbol); + if (val != '') val = options.currencyPrefix + val + options.currencySuffix; + break; + case 'percent': + val = w2utils.formatNumber(options.precision ? Number(val).toFixed(options.precision) : val, options.groupSymbol); + if (val != '') val += '%'; + break; + case 'float': + val = w2utils.formatNumber(options.precision ? Number(val).toFixed(options.precision) : val, options.groupSymbol); + break; + case 'int': + val = w2utils.formatNumber(val, options.groupSymbol); + break; + } + } + return val; + }, + + change: function (event) { + var obj = this; + var options = obj.options; + // numeric + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(this.type) != -1) { + // check max/min + var val = $(this.el).val(); + var new_val = this.format(this.clean($(this.el).val())); + // if was modified + if (val != '' && val != new_val) { + $(this.el).val(new_val).change(); + // cancel event + event.stopPropagation(); + event.preventDefault(); + return false; + } + } + // color + if (this.type == 'color') { + var color = '#' + $(this.el).val(); + if ($(this.el).val().length != 6 && $(this.el).val().length != 3) color = ''; + $(this.el).next().find('div').css('background-color', color); + if ($(obj.el).is(':focus')) this.updateOverlay(); + } + // list, enum + if (['list', 'enum', 'file'].indexOf(this.type) != -1) { + obj.refresh(); + // need time out to show icon indent properly + setTimeout(function () { obj.refresh(); }, 5); + } + // date, time + if (['date', 'time'].indexOf(this.type) != -1) { + // convert linux timestamps + var tmp = parseInt(obj.el.value); + if (w2utils.isInt(tmp) && tmp > 1000) { + if (this.type == 'time') $(obj.el).val(w2utils.formatTime(new Date(tmp), options.format)).change(); + if (this.type == 'date') $(obj.el).val(w2utils.formatDate(new Date(tmp), options.format)).change(); + } + } + }, - $.fn.w2field = function(method) { - // Method calling logic - if (w2field[method]) { - return w2field[method].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object') { - return w2field.init.apply( this, arguments ); - } else if ( typeof method === 'string') { - return w2field.init.apply( this, [{ type: method }] ); - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2field'); - } - }; - - $.extend(w2field, { - // CONTEXT: this - is jQuery object - init: function (options) { - var obj = w2field; - return $(this).each(function (field, index) { - // Check for Custom Types - if (typeof w2field.customTypes[options.type.toLowerCase()] == 'function') { - w2field.customTypes[options.type.toLowerCase()].call(this, options); - return; - } - // Common Types - var tp = options.type.toLowerCase(); - switch (tp) { - - case 'clear': // removes any previous field type - $(this) - .off('focus') - .off('blur') - .off('keypress') - .off('keydown') - .off('change') - .removeData(); // removes all attached data - if ($(this).prev().hasClass('w2ui-list')) { // if enum - $(this).prev().remove(); - $(this).removeAttr('tabindex').css('border-color', '').show(); - } - if ($(this).prev().hasClass('w2ui-upload')) { // if upload - $(this).prev().remove(); - $(this).removeAttr('tabindex').css('border-color', '').show(); - } - if ($(this).prev().hasClass('w2ui-field-helper')) { // helpers - $(this).css('padding-left', $(this).css('padding-top')); - $(this).prev().remove(); - } - if ($(this).next().hasClass('w2ui-field-helper')) { // helpers - $(this).css('padding-right', $(this).css('padding-top')); - $(this).next().remove(); - } - if ($(this).next().hasClass('w2ui-field-helper')) { // helpers - $(this).next().remove(); - } - break; - - case 'text': - case 'int': - case 'float': - case 'money': - case 'alphanumeric': - case 'hex': - var el = this; - var defaults = { - min : null, - max : null, - arrows : false, - keyboard: true, - suffix : '', - prefix : '' + click: function (event) { + event.stopPropagation(); + // lists + if (['list', 'combo', 'enum'].indexOf(this.type) != -1) { + if (!$(this.el).is(':focus')) this.focus(event); } - options = $.extend({}, defaults, options); - if (['text', 'alphanumeric', 'hex'].indexOf(tp) != -1) { - options.arrows = false; - options.keyboard = false; - } - // init events - $(this) - .data('options', options) - .on('keypress', function (event) { // keyCode & charCode differ in FireFox + // other fields with drops + if (['date', 'time', 'color'].indexOf(this.type) != -1) { + this.updateOverlay(); + } + }, + + focus: function (event) { + var obj = this; + var options = this.options; + // color, date, time + if (['color', 'date', 'time'].indexOf(obj.type) !== -1) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + setTimeout(function () { obj.updateOverlay(); }, 150); + } + // menu + if (['list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + setTimeout(function () { + if (obj.type == 'list' && $(obj.el).is(':focus')) { + $(obj.helpers.focus).find('input').focus(); + return; + } + obj.search(); + setTimeout(function () { obj.updateOverlay(); }, 1); + }, 1); + } + // file + if (obj.type == 'file') { + $(obj.helpers.multi).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + } + }, + + blur: function (event) { + var obj = this; + var options = obj.options; + var val = $(obj.el).val().trim(); + // hide overlay + if (['color', 'date', 'time', 'list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + } + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(obj.type) != -1) { + if (val !== '' && !obj.checkType(val)) { + $(obj.el).val('').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid number'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + } + // date or time + if (['date', 'time'].indexOf(obj.type) != -1) { + // check if in range + if (val !== '' && !obj.inRange(obj.el.value)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not in range'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } else { + if (obj.type == 'date' && val !== '' && !w2utils.isDate(obj.el.value, options.format)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid date'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + if (obj.type == 'time' && val !== '' && !w2utils.isTime(obj.el.value)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid time'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + } + } + // clear search input + if (obj.type == 'enum') { + $(obj.helpers.multi).find('input').val('').width(20); + } + // file + if (obj.type == 'file') { + $(obj.helpers.multi).css({ 'outline': 'none' }); + } + }, + + keyPress: function (event) { + var obj = this; + var options = obj.options; + // ignore wrong pressed key + if (['int', 'float', 'money', 'currency', 'percent', 'hex', 'color', 'alphanumeric'].indexOf(obj.type) != -1) { + // keyCode & charCode differ in FireFox if (event.metaKey || event.ctrlKey || event.altKey || (event.charCode != event.keyCode && event.keyCode > 0)) return; - if (event.keyCode == 13) $(this).change(); var ch = String.fromCharCode(event.charCode); - if (!checkType(ch, true)) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - return false; + if (!obj.checkType(ch, true) && event.keyCode != 13) { + event.preventDefault(); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + return false; } - }) - .on('keydown', function (event, extra) { - if (!options.keyboard) return; + } + // update date popup + if (['date', 'time'].indexOf(obj.type) != -1) { + setTimeout(function () { obj.updateOverlay(); }, 1); + } + }, + + keyDown: function (event, extra) { + var obj = this; + var options = obj.options; + var key = event.keyCode || (extra && extra.keyCode); + // numeric + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(obj.type) != -1) { + if (!options.keyboard || $(obj.el).attr('readonly')) return; var cancel = false; - var v = $(el).val(); - if (!checkType(v)) v = options.min || 0; else v = parseFloat(v); - var key = event.keyCode || extra.keyCode; - var inc = 1; + var val = parseFloat($(obj.el).val().replace(options.moneyRE, '')) || 0; + var inc = options.step; if (event.ctrlKey || event.metaKey) inc = 10; switch (key) { - case 38: // up - $(el).val((v + inc <= options.max || options.max == null ? v + inc : options.max)).change(); - if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) ); - cancel = true; - break; - case 40: // down - $(el).val((v - inc >= options.min || options.min == null ? v - inc : options.min)).change(); - if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) ); - cancel = true; - break; + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + $(obj.el).val((val + inc <= options.max || options.max === null ? Number((val + inc).toFixed(12)) : options.max)).change(); + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + $(obj.el).val((val - inc >= options.min || options.min === null ? Number((val - inc).toFixed(12)) : options.min)).change(); + cancel = true; + break; } if (cancel) { - event.preventDefault(); - // set cursor to the end - setTimeout(function () { el.setSelectionRange(el.value.length, el.value.length); }, 0); + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + }, 0); + } + } + // date + if (obj.type == 'date') { + if (!options.keyboard || $(obj.el).attr('readonly')) return; + var cancel = false; + var daymil = 24*60*60*1000; + var inc = 1; + if (event.ctrlKey || event.metaKey) inc = 10; + var dt = w2utils.isDate($(obj.el).val(), options.format, true); + if (!dt) { dt = new Date(); daymil = 0; } + switch (key) { + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + var newDT = w2utils.formatDate(dt.getTime() + daymil, options.format); + if (inc == 10) newDT = w2utils.formatDate(new Date(dt.getFullYear(), dt.getMonth()+1, dt.getDate()), options.format); + $(obj.el).val(newDT).change(); + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + var newDT = w2utils.formatDate(dt.getTime() - daymil, options.format); + if (inc == 10) newDT = w2utils.formatDate(new Date(dt.getFullYear(), dt.getMonth()-1, dt.getDate()), options.format); + $(obj.el).val(newDT).change(); + cancel = true; + break; } - }) - .on('change', function (event) { - // check max/min - var v = $(el).val(); - var cancel = false; - if (options.min != null && v != '' && v < options.min) { $(el).val(options.min).change(); cancel = true; } - if (options.max != null && v != '' && v > options.max) { $(el).val(options.max).change(); cancel = true; } if (cancel) { - event.stopPropagation(); - event.preventDefault(); - return false; - } - // check validity - if (this.value != '' && !checkType(this.value)) $(this).val(options.min != null ? options.min : ''); - }); - if ($(this).val() == '' && options.min != null) $(this).val(options.min); - if (options.prefix != '') { - $(this).before( - ''+ - options.prefix + - ''); - var helper = $(this).prev(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : $(this).css('padding-left'), - 'padding-right' : 0, - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px', - 'margin-left' : 0, - 'margin-right' : 0 - }) - .on('click', function () { - $(this).next().focus(); - }); - $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 5) + 'px'); - } - var pr = parseInt($(this).css('padding-right')); - if (options.arrows != '') { - $(this).after( - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''); - var height = w2utils.getSize(this, 'height'); - var helper = $(this).next(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'height' : ($(this).height() + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom')) ) + 'px', - 'padding' : '0px', - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : '0px', - 'border-left' : '1px solid silver' - }) - .css('margin-left', '-'+ (helper.width() + parseInt($(this).css('margin-right')) + 12) + 'px') - .on('mousedown', function (event) { - var btn = this; - var evt = event; - $('body').on('mouseup', tmp); - $('body').data('_field_update_timer', setTimeout(update, 700)); - update(false); - // timer function - function tmp() { - clearTimeout($('body').data('_field_update_timer')); - $('body').off('mouseup', tmp); - } - // update function - function update(notimer) { - $(el).focus().trigger($.Event("keydown"), { - keyCode : ($(evt.target).attr('type') == 'up' ? 38 : 40) + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + obj.updateOverlay(); + }, 0); + } + } + // time + if (obj.type == 'time') { + if (!options.keyboard || $(obj.el).attr('readonly')) return; + var cancel = false; + var inc = (event.ctrlKey || event.metaKey ? 60 : 1); + var val = $(obj.el).val(); + var time = obj.toMin(val) || obj.toMin((new Date()).getHours() + ':' + ((new Date()).getMinutes() - 1)); + switch (key) { + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + time += inc; + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + time -= inc; + cancel = true; + break; + } + if (cancel) { + $(obj.el).val(obj.fromMin(time)).change(); + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + }, 0); + } + } + // color + if (obj.type == 'color') { + if ($(obj.el).attr('readonly')) return; + // paste + if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) { + $(obj.el).prop('maxlength', 7); + setTimeout(function () { + var val = $(obj).val(); + if (val.substr(0, 1) == '#') val = val.substr(1); + if (!w2utils.isHex(val)) val = ''; + $(obj).val(val).prop('maxlength', 6).change(); + }, 20); + } + if ((event.ctrlKey || event.metaKey) && !event.shiftKey) { + if (typeof obj.tmp.cind1 == 'undefined') { + obj.tmp.cind1 = -1; + obj.tmp.cind2 = -1; + } else { + switch (key) { + case 38: // up + obj.tmp.cind1--; + break; + case 40: // down + obj.tmp.cind1++; + break; + case 39: // right + obj.tmp.cind2++; + break; + case 37: // left + obj.tmp.cind2--; + break; + } + if (obj.tmp.cind1 < 0) obj.tmp.cind1 = 0; + if (obj.tmp.cind1 > this.pallete.length - 1) obj.tmp.cind1 = this.pallete.length - 1; + if (obj.tmp.cind2 < 0) obj.tmp.cind2 = 0; + if (obj.tmp.cind2 > this.pallete[0].length - 1) obj.tmp.cind2 = this.pallete[0].length - 1; + } + if ([37, 38, 39, 40].indexOf(key) != -1) { + $(obj.el).val(this.pallete[obj.tmp.cind1][obj.tmp.cind2]).change(); + event.preventDefault(); + } + } + } + // list/select/combo + if (['list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($(obj.el).attr('readonly')) return; + var cancel = false; + var selected = $(obj.el).data('selected'); + var focus = $(obj.helpers.focus).find('input'); + if (obj.type == 'list') { + if ([37, 38, 39, 40].indexOf(key) == -1) obj.refresh(); // arrows + } + // apply arrows + switch (key) { + case 27: // escape + if (obj.type == 'list') { + if ($(focus).val() != '') $(focus).val(''); + event.stopPropagation(); // escape in field should not close popup + } + break; + case 37: // left + case 39: // right + // cancel = true; + break; + case 13: // enter + if ($('#w2ui-overlay').length == 0) break; // no action if overlay not open + var item = options.items[options.index]; + var multi = $(obj.helpers.multi).find('input'); + if (obj.type == 'enum') { + if (item != null) { + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'add', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + item = eventData.item; // need to reassign because it could be recreated by user + // default behavior + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete item.hidden; + delete obj.tmp.force_open; + selected.push(item); + $(obj.el).change(); + multi.val('').width(20); + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } else { + // trigger event + item = { id: multi.val(), text: multi.val() } + var eventData = obj.trigger({ phase: 'before', type: 'new', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + item = eventData.item; // need to reassign because it could be recreated by user + // default behavior + if (typeof obj.onNew == 'function') { + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete obj.tmp.force_open; + selected.push(item); + $(obj.el).change(); + multi.val('').width(20); + obj.refresh(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + if (item) $(obj.el).data('selected', item).val(item.text).change(); + if ($(obj.el).val() == '' && $(obj.el).data('selected')) $(obj.el).removeData('selected').val('').change(); + if (obj.type == 'list') { + focus.val(''); + obj.refresh(); + } + // hide overlay + obj.tmp.force_hide = true; + } + break; + case 8: // backspace + case 46: // delete + if (obj.type == 'enum' && key == 8) { + if ($(obj.helpers.multi).find('input').val() == '' && selected.length > 0) { + var item = selected[selected.length - 1]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'remove', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + selected.pop(); + $(obj.el).trigger('change'); + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } + if (obj.type == 'list' && $(focus).val() == '') { + $(obj.el).data('selected', {}).change(); + obj.refresh(); + } + break; + case 38: // up + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index--; + while (options.index > 0 && options.items[options.index].hidden) options.index--; + if (options.index == 0 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } + cancel = true; + break; + case 40: // down + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : -1; + options.index++; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (options.index == options.items.length-1 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index--; + } + // show overlay if not shown + var input = obj.el; + if (['enum'].indexOf(obj.type) != -1) input = obj.helpers.multi.find('input'); + if ($(input).val() == '' && $('#w2ui-overlay').length == 0) { + obj.tmp.force_open = true; + } else { + cancel = true; + } + break; + } + if (cancel) { + if (options.index < 0) options.index = 0; + if (options.index >= options.items.length) options.index = options.items.length -1; + obj.updateOverlay(); + // cancel event + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + if (obj.type == 'enum') { + var tmp = obj.helpers.multi.find('input').get(0); + tmp.setSelectionRange(tmp.value.length, tmp.value.length); + } else if (obj.type == 'list') { + var tmp = obj.helpers.focus.find('input').get(0); + tmp.setSelectionRange(tmp.value.length, tmp.value.length); + } else { + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + } + }, 0); + return; + } + // expand input + if (obj.type == 'enum') { + var input = obj.helpers.multi.find('input'); + var search = input.val(); + input.width(((search.length + 2) * 8) + 'px'); + } + // run search + if ([16, 17, 18, 20, 37, 39, 91].indexOf(key) == -1) { // no refreah on crtl, shift, left/right arrows, etc + setTimeout(function () { + if (!obj.tmp.force_hide) obj.request(); + obj.search(); + }, 1); + } + } + }, + + keyUp: function (event) { + if (this.type == 'color') { + if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) $(this).prop('maxlength', 6); + } + }, + + clearCache: function () { + var options = this.options; + options.items = []; + this.tmp.xhr_loading = false; + this.tmp.xhr_search = ''; + this.tmp.xhr_total = -1; + this.search(); + }, + + request: function (interval) { + var obj = this; + var options = this.options; + var search = $(obj.el).val() || ''; + // if no url - do nothing + if (!options.url) return; + // -- + if (obj.type == 'enum') { + var tmp = $(obj.helpers.multi).find('input'); + if (tmp.length == 0) search = ''; else search = tmp.val(); + } + if (obj.type == 'list') { + var tmp = $(obj.helpers.focus).find('input'); + if (tmp.length == 0) search = ''; else search = tmp.val(); + } + if (options.minLength != 0 && search.length < options.minLength) { + options.items = []; // need to empty the list + this.updateOverlay(); + return; + } + if (typeof interval == 'undefined') interval = 350; + if (typeof obj.tmp.xhr_search == 'undefined') obj.tmp.xhr_search = ''; + if (typeof obj.tmp.xhr_total == 'undefined') obj.tmp.xhr_total = -1; + // check if need to search + if (options.url && $(obj.el).prop('readonly') != true && ( + (options.items.length === 0 && obj.tmp.xhr_total !== 0) || + (obj.tmp.xhr_total == options.cacheMax && search.length > obj.tmp.xhr_search.length) || + (search.length >= obj.tmp.xhr_search.length && search.substr(0, obj.tmp.xhr_search.length) != obj.tmp.xhr_search) || + (search.length < obj.tmp.xhr_search.length) + )) { + // empty list + obj.tmp.xhr_loading = true; + obj.search(); + // timeout + clearTimeout(obj.tmp.timeout); + obj.tmp.timeout = setTimeout(function () { + // trigger event + var url = options.url; + var postData = { + search : search, + max : options.cacheMax + }; + $.extend(postData, options.postData); + var eventData = obj.trigger({ phase: 'before', type: 'request', target: obj.el, url: url, postData: postData }); + if (eventData.isCancelled === true) return; + url = eventData.url; + postData = eventData.postData; + // console.log('REMOTE SEARCH:', search); + if (obj.tmp.xhr) obj.tmp.xhr.abort(); + var ajaxOptions = { + type : 'GET', + url : url, + data : postData, + dataType : 'JSON' // expected from server + }; + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + obj.tmp.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + // trigger event + var eventData2 = obj.trigger({ phase: 'before', type: 'load', target: obj.el, search: postData.search, data: data, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + data = eventData2.data; + if (typeof data == 'string') data = JSON.parse(data); + if (data.status != 'success') { + console.log('ERROR: server did not return proper structure. It should return', { status: 'success', items: [{ id: 1, text: 'item' }] }); + return; + } + // remove all extra items if more then needed for cache + if (data.items.length > options.cacheMax) data.items.splice(options.cacheMax, 100000); + // remember stats + obj.tmp.xhr_loading = false; + obj.tmp.xhr_search = search; + obj.tmp.xhr_total = data.items.length; + options.items = obj.normMenu(data.items); + if (search == '' && data.items.length == 0) obj.tmp.emptySet = true; else obj.tmp.emptySet = false; + obj.search(); + // console.log('-->', 'retrieved:', obj.tmp.xhr_total); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', target: obj.el, search: search, error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', items: [{ id: 1, text: 'item' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + // reset stats + obj.clearCache(); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, interval); + } + }, + + search: function () { + var obj = this; + var options = this.options; + var search = $(obj.el).val(); + var target = obj.el; + var ids = []; + var selected= $(obj.el).data('selected'); + if (obj.type == 'enum') { + target = $(obj.helpers.multi).find('input'); + search = target.val(); + for (var s in selected) { if (selected[s]) ids.push(selected[s].id); } + } + if (obj.type == 'list') { + target = $(obj.helpers.focus).find('input'); + search = target.val(); + for (var s in selected) { if (selected[s]) ids.push(selected[s].id); } + } + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'search', target: target, search: search }); + if (eventData.isCancelled === true) return; + if (obj.tmp.xhr_loading !== true) { + var shown = 0; + for (var i in options.items) { + var item = options.items[i]; + var prefix = ''; + var suffix = ''; + if (['is', 'begins'].indexOf(options.match) != -1) prefix = '^'; + if (['is', 'ends'].indexOf(options.match) != -1) suffix = '$'; + try { + var re = new RegExp(prefix + search + suffix, 'i'); + if (re.test(item.text) || item.text == '...') item.hidden = false; else item.hidden = true; + } catch (e) {} + // do not show selected items + if (obj.type == 'enum' && $.inArray(item.id, ids) != -1) item.hidden = true; + if (item.hidden !== true) shown++; + } + if (obj.type != 'combo') { // don't preselect first for combo + options.index = 0; + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } else { + options.index = -1; + } + if (shown <= 0) options.index = -1; + options.spinner = false; + obj.updateOverlay(); + setTimeout(function () { + var html = $('#w2ui-overlay').html() || ''; + if (options.markSearch && html.indexOf('$.fn.w2menuHandler') != -1) { // do not highlight when no items + $('#w2ui-overlay').w2marker(search); + } + }, 1); + } else { + options.items.splice(0, options.cacheMax); + options.spinner = true; + obj.updateOverlay(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + updateOverlay: function () { + var obj = this; + var options = this.options; + // color + if (this.type == 'color') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay(obj.getColorHTML()); + } else { + $('#w2ui-overlay').html(obj.getColorHTML()); + } + // bind events + $('#w2ui-overlay .color') + .on('mousedown', function (event) { + var color = $(event.originalEvent.target).attr('name'); + var index = $(event.originalEvent.target).attr('index').split(':'); + obj.tmp.cind1 = index[0]; + obj.tmp.cind2 = index[1]; + $(obj.el).val(color).change(); + $(this).html(''); + }) + .on('mouseup', function () { + setTimeout(function () { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); + }, 10); }); - if (notimer !== false) $('body').data('_field_update_timer', setTimeout(update, 60)); - }; - }); - pr += helper.width() + 12; - $(this).css('padding-right', pr + 'px'); - } - if (options.suffix != '') { - $(this).after( - ''+ - options.suffix + - ''); - var helper = $(this).next(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : '3px', - 'padding-right' : $(this).css('padding-right'), - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px' - }) - .on('click', function () { - $(this).prev().focus(); - }); - helper.css('margin-left', '-'+ (helper.width() + parseInt($(this).css('padding-right')) + 5) + 'px'); - pr += helper.width() + 3; - $(this).css('padding-right', pr + 'px'); } + // date + if (this.type == 'date') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay('', { + css: { "background-color": "#f5f5f5" } + }); + } + var month, year; + var dt = w2utils.isDate($(obj.el).val(), obj.options.format, true); + if (dt) { month = dt.getMonth() + 1; year = dt.getFullYear(); } + (function refreshCalendar(month, year) { + $('#w2ui-overlay > div > div').html(obj.getMonthHTML(month, year)); + $('#w2ui-overlay .w2ui-calendar-title') + .on('mousedown', function () { + if ($(this).next().hasClass('w2ui-calendar-jump')) { + $(this).next().remove(); + } else { + var selYear, selMonth; + $(this).after(''); + $(this).next().hide().html(obj.getYearHTML()).fadeIn(200); + setTimeout(function () { + $('#w2ui-overlay .w2ui-calendar-jump') + .find('.w2ui-jump-month, .w2ui-jump-year') + .on('click', function () { + if ($(this).hasClass('w2ui-jump-month')) { + $(this).parent().find('.w2ui-jump-month').removeClass('selected'); + $(this).addClass('selected'); + selMonth = $(this).attr('name'); + } + if ($(this).hasClass('w2ui-jump-year')) { + $(this).parent().find('.w2ui-jump-year').removeClass('selected'); + $(this).addClass('selected'); + selYear = $(this).attr('name'); + } + if (selYear != null && selMonth != null) { + $('#w2ui-overlay .w2ui-calendar-jump').fadeOut(100); + setTimeout(function () { refreshCalendar(parseInt(selMonth)+1, selYear); }, 100); + } + }); + $('#w2ui-overlay .w2ui-calendar-jump >:last-child').prop('scrollTop', 2000); + }, 1); + } + }); + $('#w2ui-overlay .w2ui-date') + .on('mousedown', function () { + var day = $(this).attr('date'); + $(obj.el).val(day).change(); + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + }) + .on('mouseup', function () { + setTimeout(function () { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); + }, 10); + }); + $('#w2ui-overlay .previous').on('mousedown', function () { + var tmp = obj.options.current.split('/'); + tmp[0] = parseInt(tmp[0]) - 1; + refreshCalendar(tmp[0], tmp[1]); + }); + $('#w2ui-overlay .next').on('mousedown', function () { + var tmp = obj.options.current.split('/'); + tmp[0] = parseInt(tmp[0]) + 1; + refreshCalendar(tmp[0], tmp[1]); + }); + }) (month, year); + } + // date + if (this.type == 'time') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay('', { + css: { "background-color": "#fff" } + }); + } + var h24 = (this.options.format == 'h24' ? true : false); + $('#w2ui-overlay > div').html(obj.getHourHTML()); + $('#w2ui-overlay .w2ui-time') + .on('mousedown', function (event) { + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + var hour = $(this).attr('hour'); + $(obj.el).val((hour > 12 && !h24 ? hour - 12 : hour) + ':00' + (!h24 ? (hour < 12 ? ' am' : ' pm') : '')).change(); + }) + .on('mouseup', function () { + var hour = $(this).attr('hour'); + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + $(obj.el).w2overlay('', { css: { "background-color": "#fff" } }); + $('#w2ui-overlay > div').html(obj.getMinHTML(hour)); + $('#w2ui-overlay .w2ui-time') + .on('mousedown', function () { + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + var min = $(this).attr('min'); + $(obj.el).val((hour > 12 && !h24 ? hour - 12 : hour) + ':' + (min < 10 ? 0 : '') + min + (!h24 ? (hour < 12 ? ' am' : ' pm') : '')).change(); + }) + .on('mouseup', function () { + setTimeout(function () { if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); }, 10); + }); + }); + } + // list + if (['list', 'combo', 'enum'].indexOf(this.type) != -1) { + var el = this.el; + var input = this.el; + if (this.type == 'enum') { + el = $(this.helpers.multi); + input = $(el).find('input'); + } + if (this.type == 'list') { + input = $(this.helpers.focus).find('input'); + } + if ($(input).is(':focus')) { + if (options.openOnFocus === false && $(input).val() == '' && obj.tmp.force_open !== true) { + $().w2overlay(); + return; + } + if (obj.tmp.force_hide) { + $().w2overlay(); + setTimeout(function () { + delete obj.tmp.force_hide; + }, 1); + return; + } + if ($(input).val() != '') delete obj.tmp.force_open; + if ($('#w2ui-overlay').length == 0) options.index = 0; + var msgNoItems = w2utils.lang('No matches'); + if (options.url != null && $(input).val().length < options.minLength && obj.tmp.emptySet !== true) msgNoItems = options.minLength + ' ' + w2utils.lang('letters or more...'); + if (options.url != null && $(input).val() == '' && obj.tmp.emptySet !== true) msgNoItems = w2utils.lang('Type to search....'); + $(el).w2menu('refresh', $.extend(true, {}, options, { + search : false, + render : options.renderDrop, + maxHeight : options.maxDropHeight, + msgNoItems : msgNoItems, + // selected with mouse + onSelect: function (event) { + if (obj.type == 'enum') { + var selected = $(obj.el).data('selected'); + if (event.item) { + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'add', target: obj.el, originalEvent: event.originalEvent, item: event.item }); + if (eventData.isCancelled === true) return; + // default behavior + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete event.item.hidden; + selected.push(event.item); + $(obj.el).data('selected', selected).change(); + $(obj.helpers.multi).find('input').val('').width(20); + obj.refresh(); + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + $(obj.el).data('selected', event.item).val(event.item.text).change(); + if (obj.helpers.focus) obj.helpers.focus.find('input').val(''); + } + } + })); + } + } + }, + + inRange: function (str) { + var inRange = false; + if (this.type == 'date') { + var dt = w2utils.isDate(str, this.options.format, true); + if (dt) { + // enable range + if (this.options.start || this.options.end) { + var st = (typeof this.options.start == 'string' ? this.options.start : $(this.options.start).val()); + var en = (typeof this.options.end == 'string' ? this.options.end : $(this.options.end).val()); + var start = w2utils.isDate(st, this.options.format, true); + var end = w2utils.isDate(en, this.options.format, true); + var current = new Date(dt); + if (!start) start = current; + if (!end) end = current; + if (current >= start && current <= end) inRange = true; + } else { + inRange = true; + } + // block predefined dates + if (this.options.blocked && $.inArray(str, this.options.blocked) != -1) inRange = false; + } + } + if (this.type == 'time') { + if (this.options.start || this.options.end) { + var tm = this.toMin(str); + var tm1 = this.toMin(this.options.start); + var tm2 = this.toMin(this.options.end); + if (!tm1) tm1 = tm; + if (!tm2) tm2 = tm; + if (tm >= tm1 && tm <= tm2) inRange = true; + } else { + inRange = true; + } + } + return inRange; + }, - function checkType(ch, loose) { - switch (tp) { - case 'int': - if (loose && ['-'].indexOf(ch) != -1) return true; - return w2utils.isInt(ch); - break; - case 'float': - if (loose && ['-','.'].indexOf(ch) != -1) return true; - return w2utils.isFloat(ch); - break; - case 'money': - if (loose && ['-','.','$','€','£','¥'].indexOf(ch) != -1) return true; - return w2utils.isMoney(ch); - break; - case 'hex': - return w2utils.isHex(ch); - break; - case 'alphanumeric': - return w2utils.isAlphaNumeric(ch); - break; + /* + * INTERNAL FUNCTIONS + */ + + checkType: function (ch, loose) { + var obj = this; + switch (obj.type) { + case 'int': + if (loose && ['-', obj.options.groupSymbol].indexOf(ch) != -1) return true; + return w2utils.isInt(ch.replace(obj.options.numberRE, '')); + case 'percent': + ch = ch.replace(/%/g, ''); + case 'float': + if (loose && ['-', w2utils.settings.decimalSymbol, obj.options.groupSymbol].indexOf(ch) != -1) return true; + return w2utils.isFloat(ch.replace(obj.options.numberRE, '')); + case 'money': + case 'currency': + if (loose && ['-', obj.options.decimalSymbol, obj.options.groupSymbol, obj.options.currencyPrefix, obj.options.currencySuffix].indexOf(ch) != -1) return true; + return w2utils.isFloat(ch.replace(obj.options.moneyRE, '')); + case 'hex': + case 'color': + return w2utils.isHex(ch); + case 'alphanumeric': + return w2utils.isAlphaNumeric(ch); } return true; - } - break; + }, - case 'date': + addPrefix: function () { var obj = this; - var defaults = { - format : w2utils.settings.date_format, // date format - start : '', // start of selectable range - end : '', // end of selectable range - blocked : {}, // {'4/11/2011': 'yes'} - colored : {} // {'4/11/2011': 'red:white'} - } - options = $.extend({}, defaults, options); - // -- insert div for calendar - $(this) // remove transtion needed for functionality - .css( { 'transition': 'none', '-webkit-transition': 'none', '-moz-transition': 'none', '-ms-transition': 'none', '-o-transition': 'none' }) - .data("options", options) - .on('focus', function () { - var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight); - var left = parseFloat($(obj).offset().left); - clearInterval($(obj).data('mtimer')); - $('#global_calendar_div').remove(); - $('body').append(''+ - ''); - $('#global_calendar_div') - .html($().w2field('calendar_get', obj.value, options)) - .css({ - left: left + 'px', - top: top + 'px' - }) - .data('el', obj) - .show(); - var max = $(window).width() + $(document).scrollLeft() - 1; - if (left + $('#global_calendar_div').width() > max) { - $('#global_calendar_div').css('left', (max - $('#global_calendar_div').width()) + 'px'); - } - // monitors - var mtimer = setInterval(function () { - var max = $(window).width() + $(document).scrollLeft() - 1; - var left = $(obj).offset().left; - if (left + $('#global_calendar_div').width() > max) left = max - $('#global_calendar_div').width(); - // monitor if moved - if ($('#global_calendar_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - $('#global_calendar_div').css({ - '-webkit-transition': '.2s', - left: left + 'px', - top : ($(obj).offset().top + obj.offsetHeight) + 'px' - }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - } - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval(mtimer); - $('#global_calendar_div').remove(); - return; - } - }, 100); - $(obj).data('mtimer', mtimer); - }) - .on('blur', function (event) { - // trim empty spaces - $(obj).val($.trim($(obj).val())); - // check if date is valid - if ($.trim($(obj).val()) != '' && !w2utils.isDate($(obj).val(), options.format)) { - $(this).w2tag(w2utils.lang('Not a valid date') + ': '+ options.format); - } - clearInterval($(obj).data('mtimer')); - $('#global_calendar_div').remove(); - }) - .on('keypress', function (event) { - var obj = this; - setTimeout(function () { - $('#global_calendar_div').html( $().w2field('calendar_get', obj.value, options) ); - }, 10); - }); setTimeout(function () { - // if it is unix time - convert to readable date - if (w2utils.isInt(obj.value)) obj.value = w2utils.formatDate(obj.value, options.format); + if (obj.type === 'clear') return; + var helper; + var tmp = $(obj.el).data('tmp') || {}; + if (tmp['old-padding-left']) $(obj.el).css('padding-left', tmp['old-padding-left']); + tmp['old-padding-left'] = $(obj.el).css('padding-left'); + $(obj.el).data('tmp', tmp); + // remove if already displaed + if (obj.helpers.prefix) $(obj.helpers.prefix).remove(); + if (obj.options.prefix !== '') { + // add fresh + $(obj.el).before( + ''+ + obj.options.prefix + + '' + ); + helper = $(obj.el).prev(); + helper + .css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'padding-top' : $(obj.el).css('padding-top'), + 'padding-bottom' : $(obj.el).css('padding-bottom'), + 'padding-left' : $(obj.el).css('padding-left'), + 'padding-right' : 0, + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 2) + 'px', + 'margin-bottom' : (parseInt($(obj.el).css('margin-bottom'), 10) + 1) + 'px', + 'margin-left' : $(obj.el).css('margin-left'), + 'margin-right' : 0 + }) + .on('click', function (event) { + if (obj.options.icon && typeof obj.onIconClick == 'function') { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'iconClick', target: obj.el, el: $(this).find('span.w2ui-icon')[0] }); + if (eventData.isCancelled === true) return; + + // intentionally empty + + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } else { + if (obj.type == 'list') { + $(obj.helpers.focus).find('input').focus(); + } else { + $(obj.el).focus(); + } + } + }); + $(obj.el).css('padding-left', (helper.width() + parseInt($(obj.el).css('padding-left'), 10)) + 'px'); + // remember helper + obj.helpers.prefix = helper; + } }, 1); - break; - - case 'time': - break; + }, - case 'datetime': - break; - - case 'color': + addSuffix: function () { var obj = this; - var defaults = { - prefix : '#', - suffix : '' - } - options = $.extend({}, defaults, options); - // -- insert div for color - $(this) - .attr('maxlength', 6) - .on('focus', function () { - var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight); - var left = parseFloat($(obj).offset().left); - clearInterval($(obj).data('mtimer')); - $('#global_color_div').remove(); - $('body').append(''+ - ''); - $('#global_color_div') - .html($().w2field('getColorHTML', obj.value)) - .css({ - left: left + 'px', - top: top + 'px' - }) - .data('el', obj) - .show(); - var max = $(window).width() + $(document).scrollLeft() - 1; - if (left + $('#global_color_div').width() > max) { - $('#global_color_div').css('left', (max - $('#global_color_div').width()) + 'px'); - } - // monitors - var mtimer = setInterval(function () { - var max = $(window).width() + $(document).scrollLeft() - 1; - var left = $(obj).offset().left; - if (left + $('#global_color_div').width() > max) left = max - $('#global_color_div').width(); - // monitor if moved - if ($('#global_color_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - $('#global_color_div').css({ - '-webkit-transition': '.2s', - left: left + 'px', - top : ($(obj).offset().top + obj.offsetHeight) + 'px' - }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - } - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval(mtimer); - $('#global_color_div').remove(); - return; - } - }, 100); - $(obj).data('mtimer', mtimer); - }) - .on('click', function () { - $(this).trigger('focus'); - }) - .on('blur', function (event) { - // trim empty spaces - $(obj).val($.trim($(obj).val())); - clearInterval($(obj).data('mtimer')); - $('#global_color_div').remove(); - }) - .on('keydown', function (event) { // need this for cut/paster - if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) { - var obj = this; - $(this).prop('maxlength', 7); - setTimeout(function () { - var val = $(obj).val(); - if (val.substr(0, 1) == '#') val = val.substr(1); - if (!w2utils.isHex(val)) val = ''; - $(obj).val(val).prop('maxlength', 6).change(); - }, 20); - } - }) - .on('keyup', function (event) { - if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) $(this).prop('maxlength', 6); - }) - .on('keypress', function (event) { // keyCode & charCode differ in FireFox - if (event.keyCode == 13) $(this).change(); - //if (event.ct) - var ch = String.fromCharCode(event.charCode); - if (!w2utils.isHex(ch, true)) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - return false; - } - }) - .on('change', function (event) { - var color = '#' + $(this).val(); - if ($(this).val().length != 6 && $(this).val().length != 3) color = ''; - $(this).next().find('div').css('background-color', color); - }); - if (options.prefix != '') { - $(this).before( - ''+ - options.prefix + - ''); - var helper = $(this).prev(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : $(this).css('padding-left'), - 'padding-right' : 0, - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px', - 'margin-left' : 0, - 'margin-right' : 0 + var helper, pr; + setTimeout(function () { + if (obj.type === 'clear') return; + var tmp = $(obj.el).data('tmp') || {}; + if (tmp['old-padding-right']) $(obj.el).css('padding-right', tmp['old-padding-right']); + tmp['old-padding-right'] = $(obj.el).css('padding-right'); + $(obj.el).data('tmp', tmp); + pr = parseInt($(obj.el).css('padding-right'), 10); + if (obj.options.arrows) { + // remove if already displaed + if (obj.helpers.arrows) $(obj.helpers.arrows).remove(); + // add fresh + $(obj.el).after( + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''); + var height = w2utils.getSize(obj.el, 'height'); + helper = $(obj.el).next(); + helper.css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'height' : ($(obj.el).height() + parseInt($(obj.el).css('padding-top'), 10) + parseInt($(obj.el).css('padding-bottom'), 10) ) + 'px', + 'padding' : 0, + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 1) + 'px', + 'margin-bottom' : 0, + 'border-left' : '1px solid silver' + }) + .css('margin-left', '-'+ (helper.width() + parseInt($(obj.el).css('margin-right'), 10) + 12) + 'px') + .on('mousedown', function (event) { + $('body').on('mouseup', tmp); + $('body').data('_field_update_timer', setTimeout(update, 700)); + update(false); + // timer function + function tmp() { + clearTimeout($('body').data('_field_update_timer')); + $('body').off('mouseup', tmp); + } + // update function + function update(notimer) { + $(obj.el).focus(); + obj.keyDown($.Event("keydown"), { + keyCode : ($(event.target).attr('type') == 'up' ? 38 : 40) + }); + if (notimer !== false) $('body').data('_field_update_timer', setTimeout(update, 60)); + } + }); + pr += helper.width() + 12; + $(obj.el).css('padding-right', pr + 'px'); + // remember helper + obj.helpers.arrows = helper; + } + if (obj.options.suffix !== '') { + // remove if already displaed + if (obj.helpers.suffix) $(obj.helpers.suffix).remove(); + // add fresh + $(obj.el).after( + ''+ + obj.options.suffix + + ''); + helper = $(obj.el).next(); + helper + .css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'padding-top' : $(obj.el).css('padding-top'), + 'padding-bottom' : $(obj.el).css('padding-bottom'), + 'padding-left' : '3px', + 'padding-right' : $(obj.el).css('padding-right'), + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 2) + 'px', + 'margin-bottom' : (parseInt($(obj.el).css('margin-bottom'), 10) + 1) + 'px' + }) + .on('click', function (event) { + if (obj.type == 'list') { + $(obj.helpers.focus).find('input').focus(); + } else { + $(obj.el).focus(); + } + }); + + helper.css('margin-left', '-'+ (w2utils.getSize(helper, 'width') + parseInt($(obj.el).css('margin-right'), 10) + 2) + 'px'); + pr += helper.width() + 3; + $(obj.el).css('padding-right', pr + 'px'); + // remember helper + obj.helpers.suffix = helper; + } + }, 1); + }, + + addFocus: function () { + var obj = this; + var options = this.options; + var width = 0; // 11 - show search icon, 0 do not show + // clean up & init + $(obj.helpers.focus).remove(); + // build helper + var html = + ''+ + ' '+ + ' '+ + ''; + $(obj.el).attr('tabindex', -1).before(html); + var helper = $(obj.el).prev(); + obj.helpers.focus = helper; + helper.css({ + width : $(obj.el).width(), + "margin-top" : $(obj.el).css('margin-top'), + "margin-left" : (parseInt($(obj.el).css('margin-left')) + parseInt($(obj.el).css('padding-left'))) + 'px', + "margin-bottom" : $(obj.el).css('margin-bottom'), + "margin-right" : $(obj.el).css('margin-right') }) - .on('click', function () { - $(this).next().focus(); - }); - $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 2) + 'px'); - } - if (options.suffix != '') { - $(this).after( - ''+ - options.suffix + - ''); - var helper = $(this).next(); - helper + .find('input') .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : '3px', - 'padding-right' : $(this).css('padding-right'), - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px' - }) - .on('click', function () { - $(this).prev().focus(); + cursor : 'default', + width : '100%', + outline : 'none', + opacity : 1, + margin : 0, + border : '1px solid transparent', + padding : $(obj.el).css('padding-top'), + "padding-left" : 0, + "margin-left" : (width > 0 ? width + 6 : 0), + "background-color" : 'transparent' }); - helper.css('margin-left', '-'+ (helper.width() + parseInt($(this).css('padding-right')) + 4) + 'px'); - var pr = helper.width() + parseInt($(this).css('padding-right')) + 4; - $(this).css('padding-right', pr + 'px'); - // set color to current - helper.find('div').css('background-color', '#' + $(obj).val()); - } - break; - - case 'select': - case 'list': - if (this.tagName != 'SELECT') { - console.log('ERROR: You can only apply $().w2field(\'list\') to a SELECT element'); - return; - } - var defaults = { - url : '', - items : [], - value : null, - showNone : true - }; - var obj = this; - var settings = $.extend({}, defaults, options); - $(obj).data('settings', settings); - // define refresh method - obj.refresh = function () { - var settings = $(obj).data('settings'); - var html = ''; - var items = w2field.cleanItems(settings.items); - // build options - if (settings.showNone) html = '- '+ w2utils.lang('none') +' -'; - for (var i in items) { - if (!settings.showNone && settings.value == null) settings.value = items[i].id; - html += ''+ items[i].text + ''; - } - $(obj).html(html); - $(obj).val(settings.value); - if ($(obj).val() != settings.value) $(obj).change(); - } - // pull from server - if (settings.url != '' ) { - $.ajax({ - type : 'GET', - dataType : 'text', - url : settings.url, - complete: function (xhr, status) { - if (status == 'success') { - var data = $.parseJSON(xhr.responseText); - var settings = $(obj).data('settings'); - settings.items = w2field.cleanItems(data.items); - $(obj).data('settings', settings); - obj.refresh(); - } - } - }); - } else { // refresh local - obj.refresh(); - } - break; - - case 'enum': - if (this.tagName != 'INPUT') { - console.log('ERROR: You can only apply $().w2field(\'enum\') to an INPUT element'); - return; - } - var defaults = { - url : '', - items : [], - selected : [], // preselected items - max : 0, // maximum number of items that can be selected 0 for unlim - maxHeight : 172, // max height for input control to grow - showAll : false, // if true then show selected item in drop down - match : 'begins with', // ['begins with', 'contains'] - render : null, // render(item, selected) - maxCache : 500, // number items to cache - onShow : null, // when overlay is shown onShow(settings) - onHide : null, // when overlay is hidden onHide(settings) - onAdd : null, // onAdd(item, settings) - onRemove : null, // onRemove(index, settings) - onItemOver : null, - onItemOut : null, - onItemClick : null - } - var obj = this; - var settings = $.extend({}, defaults, options); - - // normalize items and selected - settings.items = w2field.cleanItems(settings.items); - settings.selected = w2field.cleanItems(settings.selected); - - $(this).data('selected', settings.selected); - $(this).css({ - 'padding' : '0px', - 'border-color' : 'transparent', - 'background-color' : 'transparent', - 'outline' : 'none' - }); - - // add item to selected - this.add = function (item) { - if ($(this).attr('readonly')) return; - var selected = $(this).data('selected'); - var settings = $(this).data('settings'); - if (typeof settings.onAdd == 'function') { - var cancel = settings.onAdd(item, settings); - if (cancel === false) return; - } - if (!$.isArray(selected)) selected = []; - if (settings.max != 0 && settings.max <= selected.length) { - // if max reached, replace last - selected.splice(selected.length - 1, 1); - } - selected.push(item); - $(this).data('last_del', null); - $(this).trigger('change'); - } - - this.remove = function (index) { - var settings = $(this).data('settings'); - if (typeof settings.onRemove == 'function') { - var cancel = settings.onRemove(index, settings); - if (cancel === false) return; - } - if ($(this).attr('readonly')) return; - $(this).data('selected').splice(index, 1); - $(this).parent().find('[title=Remove][index='+ index +']').remove(); - this.refresh(); - w2field.list_render.call(this); - $(this).trigger('change'); - } - - this.show = function () { - if ($(this).attr('readonly')) return; - var settings = $(this).data('settings'); - // insert global div - if ($('#w2ui-global-items').length == 0) { - $('body').append(''); - } else { - // ignore second click - return; - } - var div = $('#w2ui-global-items'); - div.css({ - display : 'block', - left : ($(obj).offset().left) + 'px', - top : ($(obj).offset().top + obj.offsetHeight + 3) + 'px' - }) - .width(w2utils.getSize(obj, 'width')) - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - - // show drop content - w2field.list_render.call(obj); - - // monitors - var monitor = function () { - var div = $('#w2ui-global-items'); - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval($(obj).data('mtimer')); - hide(); - return; - } - // monitor if moved - if (div.data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - div.css({ - '-webkit-transition': '.2s', - left: ($(obj).offset().left) + 'px', - top : ($(obj).offset().top + obj.offsetHeight + 3) + 'px' - }) - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - // if moved then resize - setTimeout(function () { - w2field.list_render.call(obj, $(obj).data('last_search')); - }, 200); - } - if (div.length > 0) $(obj).data('mtimer', setTimeout(monitor, 100)); - }; - $(obj).data('mtimer', setTimeout(monitor, 100)); - // onShow - if (typeof settings.onShow == 'function') settings.onShow.call(this, settings); - } - - this.hide = function () { - var settings = $(this).data('settings'); - clearTimeout($(obj).data('mtimer')); - $('#w2ui-global-items').remove(); - // onShow - if (typeof settings.onHide == 'function') settings.onHide.call(this, settings); - } - - // render controls with all items in it - this.refresh = function () { - var obj = this; - // remove all items - $($(this).data('div')).remove(); - // rebuild it - var margin = 'margin-top: ' + $(this).css('margin-top') + '; ' + - 'margin-bottom: ' + $(this).css('margin-bottom') + '; ' + - 'margin-left: ' + $(this).css('margin-left') + '; ' + - 'margin-right: ' + $(this).css('margin-right') + '; '+ - 'width: ' + (w2utils.getSize(this, 'width') - - parseInt($(this).css('margin-left')) - - parseInt($(this).css('margin-right'))) + 'px; '; - var html = ''+ - ''; - var selected = $(this).data('selected'); - for (var s in selected) { - html += ''+ - ' '+ - selected[s].text + - ''; - } - html += ''+ - ' '+ - ''+ - ''+ - ''; - $(this).before(html); - - var div = $(this).prev()[0]; - $(this).data('div', div); - // click on item - $(div).find('li') - .data('mouse', 'out') - .on('click', function (event) { - if ($(event.target).hasClass('nomouse')) return; - if (event.target.title == w2utils.lang('Remove')) { - obj.remove($(event.target).attr('index')); - return; - } - event.stopPropagation(); - if (typeof settings.onItemClick == 'function') settings.onItemClick.call(this, settings); - }) - .on('mouseover', function (event) { - var tmp = event.target; - if (tmp.tagName != 'LI') tmp = tmp.parentNode; - if ($(tmp).hasClass('nomouse')) return; - if ($(tmp).data('mouse') == 'out') { - if (typeof settings.onItemOver == 'function') settings.onItemOver.call(this, settings); - } - $(tmp).data('mouse', 'over'); - }) - .on('mouseout', function (event) { - var tmp = event.target; - if (tmp.tagName != 'LI') tmp = tmp.parentNode; - if ($(tmp).hasClass('nomouse')) return; - $(tmp).data('mouse', 'leaving'); - setTimeout(function () { - if ($(tmp).data('mouse') == 'leaving') { - $(tmp).data('mouse', 'out'); - if (typeof settings.onItemOut == 'function') settings.onItemOut.call(this, settings); - } - }, 0); - }); - $(div) // click on item + // INPUT events + helper.find('input') .on('click', function (event) { - $(this).find('input').focus(); + if ($('#w2ui-overlay').length == 0) obj.focus(event); + event.stopPropagation(); }) - .find('input') .on('focus', function (event) { - $(div).css({ 'outline': 'auto 5px -webkit-focus-ring-color', 'outline-offset': '-2px' }); - obj.show(); - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + $(obj.el).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + $(this).val(''); + $(obj.el).triggerHandler('focus'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; }) .on('blur', function (event) { - $(div).css('outline', 'none'); - obj.hide(); - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }); - // adjust height - obj.resize(); - } - this.resize = function () { - var settings = $(this).data('settings'); - var div = $(this).prev(); - var cntHeight = $(div).find('>div').height(); //w2utils.getSize(div, 'height'); - if (cntHeight < 23) cntHeight = 23; - if (cntHeight > settings.maxHeight) cntHeight = settings.maxHeight; - $(div).height(cntHeight + (cntHeight % 23 == 0 ? 0 : 23 - cntHeight % 23) ); - if (div.length > 0) div[0].scrollTop = 1000; - $(this).height(cntHeight); - } - // init control - $(this).data('settings', settings).attr('tabindex', -1); + $(obj.el).css('outline', 'none'); + $(this).val(''); + obj.refresh(); + $(obj.el).triggerHandler('blur'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('keyup', function (event) { obj.keyUp(event) }) + .on('keydown', function (event) { obj.keyDown(event) }) + .on('keypress', function (event) { obj.keyPress(event); }); + // MAIN div + helper.on('click', function (event) { $(this).find('input').focus(); }); obj.refresh(); - break; - - case 'upload': - if (this.tagName != 'INPUT') { - console.log('ERROR: You can only apply $().w2field(\'upload\') to an INPUT element'); - return; - } - // init defaults - var defaults = { - url : '', // not yet implemented - base64 : true, // if true max file size is 20mb (only tru for now) - hint : w2utils.lang('Attach files by dragging and dropping or Click to Select'), - max : 0, // max number of files, 0 - unlim - maxSize : 0, // max size of all files, 0 - unlim - maxFileSize : 0, // max size of a single file, 0 -unlim - onAdd : null, - onRemove : null, - onItemClick : null, - onItemDblClick : null, - onItemOver : null, - onItemOut : null, - onProgress : null, // not yet implemented - onComplete : null // not yet implemented - } - var obj = this; - var settings = $.extend({}, defaults, options); - if (settings.base64 === true) { - if (settings.maxSize == 0) settings.maxSize = 20 * 1024 * 1024; // 20mb - if (settings.maxFileSize == 0) settings.maxFileSize = 20 * 1024 * 1024; // 20mb - } - var selected = settings.selected; - delete settings.selected; - if (!$.isArray(selected)) selected = []; - $(this).data('selected', selected).data('settings', settings).attr('tabindex', -1); - w2field.upload_init.call(this); - - this.refresh = function () { - var obj = this; - var div = $(this).data('div'); - var settings = $(this).data('settings'); - var selected = $(this).data('selected'); - $(div).find('li').remove(); - $(div).find('> span:first-child').css('line-height', ($(div).height() - w2utils.getSize(div, '+height') - 8) + 'px'); - for (var s in selected) { - var file = selected[s]; - // add li element - var cnt = $(div).find('.file-list li').length; - $(div).find('> span:first-child').remove(); - $(div).find('.file-list').append('' + - ' ' + - ' ' + file.name + '' + - ' - ' + w2utils.size(file.size) + ''+ - ''); - var li = $(div).find('.file-list #file-' + cnt); - var previewHTML = ""; - if ((/image/i).test(file.type)) { // image - previewHTML = ''+ - ' '+ - ''; - } - var td1 = 'style="padding: 3px; text-align: right; color: #777;"'; - var td2 = 'style="padding: 3px"'; - previewHTML += ''+ - ' '+ - ' Name:'+ file.name +''+ - ' Size:'+ w2utils.size(file.size) +''+ - ' Type:' + - ' '+ file.type +''+ - ' '+ - ' Modified:'+ w2utils.date(file.modified) +''+ - ' '+ - ''; - li.data('file', file) - .on('click', function (event) { - if (typeof settings.onItemClick == 'function') { - var ret = settings.onItemClick.call(obj, $(this).data('file')); - if (ret === false) return; - } - if (!$(event.target).hasClass('file-delete')) event.stopPropagation(); - }) - .on('dblclick', function (event) { - if (typeof settings.onItemDblClick == 'function') { - var ret = settings.onItemDblClick.call(obj, $(this).data('file')); - if (ret === false) return; - } - event.stopPropagation(); - if (document.selection) document.selection.empty(); else document.defaultView.getSelection().removeAllRanges(); - }) - .on('mouseover', function (event) { - if (typeof settings.onItemOver == 'function') { - var ret = settings.onItemOver.call(obj, $(this).data('file')); - if (ret === false) return; - } - var file = $(this).data('file'); - $(this).w2overlay( - previewHTML.replace('##FILE##', (file.content ? 'data:'+ file.type +';base64,'+ file.content : '')), - { top: -4 } - ); - }) - .on('mouseout', function () { - if (typeof settings.onItemOut == 'function') { - var ret = settings.onItemOut.call(obj, $(this).data('file')); - if (ret === false) return; - } - $(this).w2overlay(); - }); - } + }, + + addMulti: function () { + var obj = this; + var options = this.options; + // clean up & init + $(obj.helpers.multi).remove(); + // build helper + var html = ''; + var margin = + 'margin-top : 0px; ' + + 'margin-bottom : 0px; ' + + 'margin-left : ' + $(obj.el).css('margin-left') + '; ' + + 'margin-right : ' + $(obj.el).css('margin-right') + '; '+ + 'width : ' + (w2utils.getSize(obj.el, 'width') + - parseInt($(obj.el).css('margin-left'), 10) + - parseInt($(obj.el).css('margin-right'), 10)) + + 'px;'; + if (obj.type == 'enum') { + html = ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' ' + ' '+ + ' '+ + ''; } - this.refresh(); - break; - - case 'slider': - // for future reference - break; - - default: - console.log('ERROR: w2field does not recognize "'+ options.type + '" field type.'); - break; - } - }); - }, - - // ****************************************************** - // -- Implementation - - addType: function (type, handler) { - w2field.customTypes[String(type).toLowerCase()] = handler; - }, - - cleanItems: function (items) { - var newItems = []; - for (var i in items) { - var id = ''; - var text = ''; - var opt = items[i]; - if (opt == null) continue; - if ($.isPlainObject(items)) { - id = i; - text = opt; - } else { - if (typeof opt == 'object') { - if (typeof opt.id != 'undefined') id = opt.id; - if (typeof opt.value != 'undefined') id = opt.value; - if (typeof opt.txt != 'undefined') text = opt.txt; - if (typeof opt.text != 'undefined') text = opt.text; - } - if (typeof opt == 'string') { - if (String(opt) == '') continue; - id = opt; - text = opt; - opt = {}; - } - } - if (w2utils.isInt(id)) id = parseInt(id); - if (w2utils.isFloat(id)) id = parseFloat(id); - newItems.push($.extend({}, opt, { id: id, text: text })); - } - return newItems; - }, - - // ****************************************************** - // -- Upload - - upload_init: function () { - var obj = this; // this -> input element - var settings = $(this).data('settings'); - // create drop area if needed - var el = $(obj).prev(); - if (el.length > 0 && el[0].tagName == 'DIV' && el.hasClass('w2ui-upload')) el.remove(); - // rebuild it - var margin = 'margin-top: ' + $(obj).css('margin-top') + '; ' + - 'margin-bottom: ' + $(obj).css('margin-bottom') + '; ' + - 'margin-left: ' + $(obj).css('margin-left') + '; ' + - 'margin-right: ' + $(obj).css('margin-right') + '; '+ - 'width: ' + (w2utils.getSize(obj, 'width') - - parseInt($(obj).css('margin-left')) - - parseInt($(obj).css('margin-right'))) + 'px; '+ - 'height: ' + (w2utils.getSize(obj, 'height') - - parseInt($(obj).css('margin-top')) - - parseInt($(obj).css('margin-bottom'))) + 'px; '; - var html = - ''+ - ' '+ settings.hint +''+ - ' '+ - ' '+ - ''; - $(obj) - .css({ - 'display1' : 'none', - 'border-color' : 'transparent' - }) - .before(html); - $(obj).data('div', $(obj).prev()[0]); - var div = $(obj).data('div'); - // if user selects files through input control - $(div).find('.file-input') - .off('change') - .on('change', function () { - if (typeof this.files !== "undefined") { - for (var i = 0, l = this.files.length; i < l; i++) { - w2field.upload_add.call(obj, this.files[i]); - } - } - }); - - // if user clicks drop zone - $(div) - .off('click') - .on('click', function (event) { - $(div).w2tag(); - if (event.target.tagName == 'LI' || $(event.target).hasClass('file-size')) { - return; - } - if ($(event.target).hasClass('file-delete')) { - w2field.upload_remove.call(obj, event.target.parentNode); - return; - } - if (event.target.tagName != 'INPUT') { - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var cnt = 0; - for (var s in selected) { cnt++; } - if (cnt < settings.max || settings.max == 0) $(div).find('.file-input').click(); - } - }) - .off('dragenter') - .on('dragenter', function (event) { - $(div).addClass('dragover'); - }) - .off('dragleave') - .on('dragleave', function (event) { - $(div).removeClass('dragover'); - }) - .off('drop') - .on('drop', function (event) { - $(div).removeClass('dragover'); - var files = event.originalEvent.dataTransfer.files; - for (var i=0, l=files.length; i input element - var div = $(obj).data('div'); - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var newItem = { - name : file.name, - type : file.type, - modified : file.lastModifiedDate, - size : file.size, - content : null - }; - var size = 0; - var cnt = 0; - for (var s in selected) { size += selected[s].size; cnt++; } - // check params - if (settings.maxFileSize != 0 && newItem.size > settings.maxFileSize) { - var err = 'Maximum file size is '+ w2utils.size(settings.maxFileSize); - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (settings.maxSize != 0 && size + newItem.size > settings.maxSize) { - var err = 'Maximum total size is '+ w2utils.size(settings.maxFileSize); - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (settings.max != 0 && cnt >= settings.max) { - var err = 'Maximum number of files is '+ settings.max; - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (typeof settings.onAdd == 'function') { - var ret = settings.onAdd.call(obj, newItem); - if (ret === false) return; - } - selected.push(newItem); - // read file as base64 - if (typeof FileReader !== "undefined" && settings.base64 === true) { - var reader = new FileReader(); - // need a closure - reader.onload = (function () { - return function (event) { - var fl = event.target.result; - var ind = fl.indexOf(','); - newItem.content = fl.substr(ind+1); - obj.refresh(); - $(obj).trigger('change'); - }; - })(); - reader.readAsDataURL(file); - } else { - obj.refresh(); - $(obj).trigger('change'); - } - }, - - upload_remove: function (li) { - var obj = this; // this -> input element - var div = $(obj).data('div'); - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var file = $(li).data('file'); - // run event - if (typeof settings.onRemove == 'function') { - var ret = settings.onRemove.call(obj, file); - if (ret === false) return false; - } - // remove from selected - for (var i = selected.length - 1; i >= 0; i--) { - if (selected[i].name == file.name && selected[i].size == file.size) { - selected.splice(i, 1); - } - } - $(li).fadeOut('fast'); - setTimeout(function () { - $(li).remove(); - // if all files remoted - if (selected.length == 0) { - $(div).prepend(''+ settings.hint +''); - } - obj.refresh(); - $(obj).trigger('change'); - }, 300); - }, - - // ****************************************************** - // -- Enum - - list_render: function (search) { - var obj = this; - var div = $('#w2ui-global-items'); - var settings = $(this).data('settings'); - var items = settings.items; - var selected = $(this).data('selected'); - if (div.length == 0) return; // if it is hidden - - // build overall html - if (typeof search == 'undefined') { - var html = ''; - html += ''; - div.html(html); - search = ''; - } - $(this).data('last_search', search); - if (typeof $(obj).data('last_index') == 'undefined' || $(obj).data('last_index') == null) $(obj).data('last_index', 0); - - // pull items from url - if (typeof settings.last_total == 'undefined') settings.last_total = -1; - if (typeof settings.last_search_len == 'undefined') settings.last_search_len = 0; - if (typeof settings.last_search_match == 'undefined') settings.last_search_match = -1; - if (settings.url != '' && ( - (items.length == 0 && settings.last_total != 0) - || (search.length > settings.last_search_len && settings.last_total > settings.maxCache) - || (search.length < settings.last_search_match && search.length != settings.last_search_len) - ) - ) { - var match = false; - if (settings.last_total < settings.maxCache) match = true; - $.ajax({ - type : 'GET', - dataType : 'text', - url : settings.url, - data : { - search : search, - max : settings.maxCache - }, - complete: function (xhr, status) { - settings.last_total = 0; - if (status == 'success') { - var data = $.parseJSON(xhr.responseText); - if (match == false && data.total < settings.maxCache) { settings.last_search_match = search.length; } - settings.last_search_len = search.length; - settings.last_total = data.total - settings.items = data.items; - w2field.list_render.call(obj, search); - } - } - }); - } - - // build items - var i = 0; - var ihtml = ''; - // get ids of all selected items - var ids = []; - for (var a in selected) ids.push(w2utils.isInt(selected[a].id) ? parseInt(selected[a].id) : String(selected[a].id)) - // build list - var group = ''; - for (var a in items) { - var id = items[a].id; - var txt = items[a].text; - // if already selected - if ($.inArray(w2utils.isInt(id) ? parseInt(id) : String(id), ids) != -1 && settings.showAll !== true) continue; - // check match with search - var txt1 = String(search).toLowerCase(); - var txt2 = txt.toLowerCase(); - var match = (txt1.length <= txt2.length && txt2.substr(0, txt1.length) == txt1); - if (settings.match.toLowerCase() == 'contains' && txt2.indexOf(txt1) != -1) match = true; - if (match) { - if (typeof settings['render'] == 'function') { - txt = settings['render'](items[a], selected); - } - if (txt !== false) { - // render group if needed - if (typeof items[a].group != 'undefined' && items[a].group != group) { - group = items[a].group; - ihtml += ''+ group +''; - } - // render item - ihtml += '\n'+ - txt +''; - if (i == $(obj).data('last_index')) $(obj).data('last_item', items[a]); - i++; - } - } - } - ihtml += ''; - if (i == 0) { - ihtml = ''+ w2utils.lang('No items found') +''; - var noItems = true; - } - div.find('.w2ui-items-list').html(ihtml); - $(this).data('last_max', i-1); - - // scroll selected into view - if (div.find('li.selected').length > 0) div.find('li.selected')[0].scrollIntoView(false); - - // if menu goes off screen - add scrollbar - div.css({ '-webkit-transition': '0s', height : 'auto' }); - var max_height = parseInt($(document).height()) - parseInt(div.offset().top) - 8; - if (parseInt(div.height()) > max_height) { - div.css({ - height : (max_height - 5) + 'px', - overflow: 'show' - }); - $(div).find('.w2ui-items-list').css({ - height : (max_height - 15) + 'px', - overflow: 'auto' - }); - } - - // add events - $(div) - .off('mousedown') - .on('mousedown', function (event) { - var target = event.target; - if (target.tagName != "LI") target = $(target).parents('li'); - var id = $(target).attr('index'); - if (!id) return; - var item = settings.items[id]; - if (typeof id == 'undefined') { if (event.preventDefault) event.preventDefault(); else return false; } - obj.add(item); - $(obj).data('last_index', 0); - obj.refresh(); - w2field.list_render.call(obj, ''); - } - ); - $(obj).prev().find('li > input') - .val(search) - .css('max-width', ($(div).width() - 25) + 'px') - .width(((search.length + 2) * 6) + 'px') - .focus() - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }) - .off('keyup') - .on('keyup', function (event) { - var inp = this; - setTimeout(function () { - var curr = $(obj).data('last_index'); - switch (event.keyCode) { - case 38: // up - curr--; - if (curr < 0) curr = 0; - $(obj).data('last_index', curr); - if (event.preventDefault) event.preventDefault(); - break; - case 40: // down - curr++; - if (curr > $(obj).data('last_max')) curr = $(obj).data('last_max'); - $(obj).data('last_index', curr); - if (event.preventDefault) event.preventDefault(); - break; - case 13: // enter - if (typeof $(obj).data('last_item') == 'undefined' || $(obj).data('last_item') == null || noItems === true) break; - var selected = $(obj).data('selected'); - obj.add($(obj).data('last_item')); - // select next - if (curr > $(obj).data('last_max') - 1) curr = $(obj).data('last_max')-1; - $(obj).data('last_index', curr); - $(obj).data('last_item', null); - // refrech - $(inp).val(''); + if (obj.type == 'file') { + html = ''+ + ' '+ + ' '+ + ' ' + ' '+ + ''; + } + $(obj.el) + .before(html) + .css({ + 'background-color' : 'transparent', + 'border-color' : 'transparent' + }); + + var div = $(obj.el).prev(); + obj.helpers.multi = div; + if (obj.type == 'enum') { + $(obj.el).attr('tabindex', -1); + // INPUT events + div.find('input') + .on('click', function (event) { + if ($('#w2ui-overlay').length == 0) obj.focus(event); + $(obj.el).triggerHandler('click'); + }) + .on('focus', function (event) { + $(div).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + $(obj.el).triggerHandler('focus'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('blur', function (event) { + $(div).css('outline', 'none'); + $(obj.el).triggerHandler('blur'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('keyup', function (event) { obj.keyUp(event) }) + .on('keydown', function (event) { obj.keyDown(event) }) + .on('keypress', function (event) { div.find('.w2ui-enum-placeholder').remove(); obj.keyPress(event); }); + // MAIN div + div.on('click', function (event) { $(this).find('input').focus(); }); + } + if (obj.type == 'file') { + $(obj.el).css('outline', 'none'); + div.on('click', function (event) { + $(obj.el).focus(); + if ($(obj.el).attr('readonly')) return; + obj.blur(event); + div.find('input').click(); + }) + .on('dragenter', function (event) { + if ($(obj.el).attr('readonly')) return; + $(div).addClass('w2ui-file-dragover'); + }) + .on('dragleave', function (event) { + if ($(obj.el).attr('readonly')) return; + var tmp = $(event.target).parents('.w2ui-field-helper'); + if (tmp.length == 0) $(div).removeClass('w2ui-file-dragover'); + }) + .on('drop', function (event) { + if ($(obj.el).attr('readonly')) return; + $(div).removeClass('w2ui-file-dragover'); + var files = event.originalEvent.dataTransfer.files; + for (var i=0, l=files.length; i options.maxFileSize) { + err = 'Maximum file size is '+ w2utils.size(options.maxFileSize); + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + if (options.maxSize !== 0 && size + newItem.size > options.maxSize) { + err = 'Maximum total size is '+ w2utils.size(options.maxSize); + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + if (options.max !== 0 && cnt >= options.max) { + err = 'Maximum number of files is '+ options.max; + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + selected.push(newItem); + // read file as base64 + if (typeof FileReader !== "undefined") { + var reader = new FileReader(); + // need a closure + reader.onload = (function () { + return function (event) { + var fl = event.target.result; + var ind = fl.indexOf(','); + newItem.content = fl.substr(ind+1); + obj.refresh(); + $(obj.el).trigger('change'); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }; + })(); + reader.readAsDataURL(file); + } else { obj.refresh(); - if (event.preventDefault) event.preventDefault(); - break; - case 8: // backspace - if (String(inp.value) == '') { - if (typeof $(obj).data('last_del') == 'undefined' || $(obj).data('last_del') == null) { - // mark for deletion - var selected = $(obj).data('selected'); - if (!$.isArray(selected)) selected = []; - $(obj).data('last_del', selected.length-1); - // refrech - obj.refresh(); - } else { - // delete marked one - var selected = $(obj).data('selected'); - obj.remove(selected.length - 1); - } + $(obj.el).trigger('change'); + } + }, + + normMenu: function (menu) { + if ($.isArray(menu)) { + for (var m = 0; m < menu.length; m++) { + if (typeof menu[m] == 'string') { + menu[m] = { id: menu[m], text: menu[m] }; + } else { + if (typeof menu[m].text != 'undefined' && typeof menu[m].id == 'undefined') menu[m].id = menu[m].text; + if (typeof menu[m].text == 'undefined' && typeof menu[m].id != 'undefined') menu[m].text = menu[m].id; + if (typeof menu[m].caption != 'undefined') menu[m].text = menu[m].caption; + } } - break; - default: - $(obj).data('last_index', 0); - $(obj).data('last_del', null); - break; + return menu; + } else if (typeof menu == 'object') { + var tmp = [] + for (var m in menu) tmp.push({ id: m, text: menu[m] }); + return tmp; } - // adjust height - obj.resize(); - - // refresh menu - if (!(event.keyCode == 8 && String(inp.value) == '')) { - $(obj).prev().find('li').css('opacity', '1'); - $(obj).data('last_del', null); + }, + + getColorHTML: function () { + var html = ''+ + ''; + for (var i = 0; i < 8; i++) { + html += ''; + for (var j = 0; j < 8; j++) { + html += ''+ + ' '+ + ' '+ ($(this.el).val() == this.pallete[i][j] ? '' : ' ')+ + ' '+ + ''; + } + html += ''; + if (i < 2) html += ''; } - if ($.inArray(event.keyCode, [16,91,37,39]) == -1) { // command and shift keys and arrows - w2field.list_render.call(obj, inp.value); + html += ''; + return html; + }, + + getMonthHTML: function (month, year) { + var td = new Date(); + var months = w2utils.settings.fullmonths; + var days = w2utils.settings.fulldays; + var daysCount = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']; + var today = td.getFullYear() + '/' + (Number(td.getMonth()) + 1) + '/' + td.getDate(); + // normalize date + year = w2utils.isInt(year) ? parseInt(year) : td.getFullYear(); + month = w2utils.isInt(month) ? parseInt(month) : td.getMonth() + 1; + if (month > 12) { month -= 12; year++; } + if (month < 1 || month === 0) { month += 12; year--; } + if (year/4 == Math.floor(year/4)) { daysCount[1] = '29'; } else { daysCount[1] = '28'; } + this.options.current = month + '/' + year; + + // start with the required date + td = new Date(year, month-1, 1); + var weekDay = td.getDay(); + var tabDays = w2utils.settings.shortdays; + var dayTitle = ''; + for ( var i = 0, len = tabDays.length; i < len; i++) { + dayTitle += '' + tabDays[i] + ''; } - }, 10); - }) - }, - - // ****************************************************** - // -- Calendar - - calendar_get: function (date, options) { - var td = new Date(); - var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900); - if (String(date) == '' || String(date) == 'undefined') date = w2utils.formatDate(today, options.format); - if (!w2utils.isDate(date, options.format)) date = w2utils.formatDate(today, options.format); - // format date - var tmp = date.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); - var tmp2 = options.format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); - var dt = new Date(); - if (tmp2 == 'mm/dd/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]); - if (tmp2 == 'm/d/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]); - if (tmp2 == 'dd/mm/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]); - if (tmp2 == 'd/m/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]); - if (tmp2 == 'yyyy/dd/mm') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]); - if (tmp2 == 'yyyy/d/m') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]); - if (tmp2 == 'yyyy/mm/dd') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]); - if (tmp2 == 'yyyy/m/d') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]); - var html = '' + - ''+ $().w2field('calendar_month', (dt.getMonth() + 1), dt.getFullYear(), options) +''+ - // ''+ - ''; - return html; - }, - - calendar_next: function(month_year) { - var tmp = String(month_year).split('/'); - var month = tmp[0]; - var year = tmp[1]; - if (parseInt(month) < 12) { - month = parseInt(month) + 1; - } else { - month = 1; - year = parseInt(year) + 1; - } - var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options'); - $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) ); - }, - - calendar_previous: function(month_year) { - var tmp = String(month_year).split('/'); - var month = tmp[0]; - var year = tmp[1]; - if (parseInt(month) > 1) { - month = parseInt(month) - 1; - } else { - month = 12; - year = parseInt(year) - 1; - } - var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options'); - $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) ); - }, - - calendar_month: function(month, year, options) { - var td = new Date(); - var months = w2utils.settings.fullmonths; - var days = w2utils.settings.fulldays; - var daysCount = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']; - var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900); - - year = Number(year); - month = Number(month); - if (year === null || year === '') year = String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900; - if (month === null || month === '') month = Number(td.getMonth())+1; - if (month > 12) { month = month - 12; year++; } - if (month < 1 || month == 0) { month = month + 12; year--; } - if (year/4 == Math.floor(year/4)) { daysCount[1] = '29'; } else { daysCount[1] = '28'; } - if (year == null) { year = td.getYear(); } - if (month == null) { month = td.getMonth()-1; } - - // start with the required date - var td = new Date(); - td.setDate(1); - td.setMonth(month-1); - td.setYear(year); - var weekDay = td.getDay(); - var tabDays = w2utils.settings.shortdays; - var dayTitle = ''; - for ( var i = 0, len = tabDays.length; i < len; i++) { - dayTitle += '' + tabDays[i] + ''; - } - var html = - ''+ - ' <- '+ - ' -> '+ - months[month-1] +', '+ year + - ''+ - ''+ - ' ' + dayTitle + ''+ - ' '; - - var day = 1; - for (var ci=1; ci<43; ci++) { - if (weekDay == 0 && ci == 1) { - for (var ti=0; ti<6; ti++) html += ' '; - ci += 6; - } else { - if (ci < weekDay || day > daysCount[month-1]) { - html += ' '; - if ((ci)%7 == 0) html += ''; - continue; - } - } - var dt = month + '/' + day + '/' + year; - - var className = ''; - if (ci % 7 == 6) className = 'w2ui-saturday'; - if (ci % 7 == 0) className = 'w2ui-sunday'; - if (dt == today) className += ' w2ui-today'; - - var dspDay = day; - var col = ''; - var bgcol = ''; - var blocked = ''; - if (options.colored) if (options.colored[dt] != undefined) { // if there is predefined colors for dates - tmp = options.colored[dt].split(':'); - bgcol = 'background-color: ' + tmp[0] + ';'; - col = 'color: ' + tmp[1] + ';'; - } - var noSelect = false; - // enable range - if (options.start || options.end) { - var start = new Date(options.start); - var end = new Date(options.end); - var current = new Date(dt); - if (current < start || current > end) { - blocked = ' w2ui-blocked-date'; - noSelect = true; - } - } - // block predefined dates - if (options.blocked && $.inArray(dt, options.blocked) != -1) { - blocked = ' w2ui-blocked-date'; - noSelect = true; - } - html += ''+ dspDay + ''; - if (ci % 7 == 0 || (weekDay == 0 && ci == 1)) html += ''; - day++; - } - html += ''; - return html; - }, + var html = + ''+ + ' '+ + ' '+ + months[month-1] +', '+ year + + ''+ + ''+ + ' ' + dayTitle + ''+ + ' '; + + var day = 1; + for (var ci=1; ci<43; ci++) { + if (weekDay === 0 && ci == 1) { + for (var ti=0; ti<6; ti++) html += ' '; + ci += 6; + } else { + if (ci < weekDay || day > daysCount[month-1]) { + html += ' '; + if ((ci) % 7 === 0) html += ''; + continue; + } + } + var dt = year + '/' + month + '/' + day; + + var className = ''; + if (ci % 7 == 6) className = ' w2ui-saturday'; + if (ci % 7 === 0) className = ' w2ui-sunday'; + if (dt == today) className += ' w2ui-today'; + + var dspDay = day; + var col = ''; + var bgcol = ''; + var tmp_dt = w2utils.formatDate(dt, this.options.format); + if (this.options.colored && this.options.colored[tmp_dt] !== undefined) { // if there is predefined colors for dates + tmp = this.options.colored[tmp_dt].split(':'); + bgcol = 'background-color: ' + tmp[0] + ';'; + col = 'color: ' + tmp[1] + ';'; + } + html += ''+ + dspDay + + ''; + if (ci % 7 === 0 || (weekDay === 0 && ci == 1)) html += ''; + day++; + } + html += ''; + return html; + }, + + getYearHTML: function () { + var months = w2utils.settings.shortmonths; + var mhtml = ''; + var yhtml = ''; + for (var m in months) { + mhtml += ''+ months[m] + ''; + } + for (var y = 1950; y <= 2020; y++) { + yhtml += ''+ y + '' + } + return ''+ mhtml +''+ yhtml +''; + }, - getColorHTML: function (color) { - var html = ''+ - ''; - var colors = [ - ['000000', '444444', '666666', '999999', 'CCCCCC', 'EEEEEE', 'F3F3F3', 'FFFFFF'], - ['FF011B', 'FF9838', 'FFFD59', '01FD55', '00FFFE', '0424F3', '9B24F4', 'FF21F5'], - ['F4CCCC', 'FCE5CD', 'FFF2CC', 'D9EAD3', 'D0E0E3', 'CFE2F3', 'D9D1E9', 'EAD1DC'], - ['EA9899', 'F9CB9C', 'FEE599', 'B6D7A8', 'A2C4C9', '9FC5E8', 'B4A7D6', 'D5A6BD'], - ['E06666', 'F6B26B', 'FED966', '93C47D', '76A5AF', '6FA8DC', '8E7CC3', 'C27BA0'], - ['CC0814', 'E69138', 'F1C232', '6AA84F', '45818E', '3D85C6', '674EA7', 'A54D79'], - ['99050C', 'B45F17', 'BF901F', '37761D', '124F5C', '0A5394', '351C75', '741B47'], - ['660205', '783F0B', '7F6011', '274E12', '0C343D', '063762', '20124D', '4C1030'] - ]; - for (var i=0; i<8; i++) { - html += ''; - for (var j=0; j<8; j++) { - html += ''+ - ' '+ - ' '+ (color == colors[i][j] ? '' : ' ')+ - ' '+ - ''; + getHourHTML: function () { + var tmp = []; + var h24 = (this.options.format == 'h24' ? true : false); + for (var a=0; a<24; a++) { + var time = (a >= 12 && !h24 ? a - 12 : a) + ':00' + (!h24 ? (a < 12 ? ' am' : ' pm') : ''); + if (a == 12 && !h24) time = '12:00 pm'; + if (!tmp[Math.floor(a/8)]) tmp[Math.floor(a/8)] = ''; + var tm1 = this.fromMin(this.toMin(time)); + var tm2 = this.fromMin(this.toMin(time) + 59); + tmp[Math.floor(a/8)] += ''+ time +''; + } + var html = + ''+ + ' '+ tmp[0] +'' + + ' '+ tmp[1] +'' + + ' '+ tmp[2] +'' + + ''; + return html; + }, + + getMinHTML: function (hour) { + if (typeof hour == 'undefined') hour = 0; + var h24 = (this.options.format == 'h24' ? true : false); + var tmp = []; + for (var a=0; a<60; a+=5) { + var time = (hour > 12 && !h24 ? hour - 12 : hour) + ':' + (a < 10 ? 0 : '') + a + ' ' + (!h24 ? (hour < 12 ? 'am' : 'pm') : ''); + var ind = a < 20 ? 0 : (a < 40 ? 1 : 2); + if (!tmp[ind]) tmp[ind] = ''; + tmp[ind] += ''+ time +''; + } + var html = + ''+ + ' '+ tmp[0] +'' + + ' '+ tmp[1] +'' + + ' '+ tmp[2] +'' + + ''; + return html; + }, + + toMin: function (str) { + if (typeof str != 'string') return null; + var tmp = str.split(':'); + if (tmp.length == 2) { + tmp[0] = parseInt(tmp[0]); + tmp[1] = parseInt(tmp[1]); + if (str.indexOf('pm') != -1 && tmp[0] != 12) tmp[0] += 12; + } else { + return null; + } + return tmp[0] * 60 + tmp[1]; + }, + + fromMin: function (time) { + var ret = ''; + if (time >= 24 * 60) time = time % (24 * 60); + if (time < 0) time = 24 * 60 + time; + var hour = Math.floor(time/60); + var min = ((time % 60) < 10 ? '0' : '') + (time % 60); + if (this.options.format.indexOf('h24') != -1) { + ret = hour + ':' + min; + } else { + ret = (hour <= 12 ? hour : hour - 12) + ':' + min + ' ' + (hour >= 12 ? 'pm' : 'am'); + } + return ret; } - html += ''; - if (i < 2) html += ''; - } - html += ''; - return html; } - }); - w2obj.field = w2field; + $.extend(w2field.prototype, w2utils.event); + w2obj.field = w2field; }) (jQuery); /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2form - form widget - * - $().w2form - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2fields, w2tabs, w2toolbar, w2alert - * - * == NICE TO HAVE == - * - refresh(field) - would refresh only one field - * - include delta on save - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2form - form widget +* - $().w2form - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2fields, w2tabs, w2toolbar, w2alert +* +* == NICE TO HAVE == +* - refresh(field) - would refresh only one field +* - include delta on save +* - create an example how to do cascadic dropdown +* - form should read into items +* - two way data bindings +* - verify validation of fields +* - when field is blank, set record.field = null +* - show/hide a field +* - added getChanges() - not complete +* +************************************************************************/ (function ($) { - var w2form = function(options) { - // public properties - this.name = null; - this.header = ''; - this.box = null; // HTML element that hold this element - this.url = ''; - this.formURL = ''; // url where to get form HTML - this.formHTML = ''; // form HTML (might be loaded from the url) - this.page = 0; // current page - this.recid = 0; // can be null or 0 - this.fields = []; - this.actions = {}; - this.record = {}; - this.original = {}; - this.postData = {}; - this.toolbar = {}; // if not empty, then it is toolbar - this.tabs = {}; // if not empty, then it is tabs object - - this.style = ''; - this.focus = 0; // focus first or other element - this.msgNotJSON = w2utils.lang('Return data is not in JSON format.'); - this.msgRefresh = w2utils.lang('Refreshing...'); - this.msgSaving = w2utils.lang('Saving...'); - - // events - this.onRequest = null; - this.onLoad = null; - this.onValidate = null; - this.onSubmit = null; - this.onSave = null; - this.onChange = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - this.onAction = null; - this.onToolbar = null; - this.onError = null; - - // internal - this.isGenerated = false; - this.last = { - xhr : null // jquery xhr requests - } + var w2form = function(options) { + // public properties + this.name = null; + this.header = ''; + this.box = null; // HTML element that hold this element + this.url = ''; + this.routeData = {}; // data for dynamic routes + this.formURL = ''; // url where to get form HTML + this.formHTML = ''; // form HTML (might be loaded from the url) + this.page = 0; // current page + this.recid = 0; // can be null or 0 + this.fields = []; + this.actions = {}; + this.record = {}; + this.original = {}; + this.postData = {}; + this.toolbar = {}; // if not empty, then it is toolbar + this.tabs = {}; // if not empty, then it is tabs object + + this.style = ''; + this.focus = 0; // focus first or other element + this.msgNotJSON = w2utils.lang('Return data is not in JSON format.'); + this.msgAJAXerror = w2utils.lang('AJAX error. See console for more details.'); + this.msgRefresh = w2utils.lang('Refreshing...'); + this.msgSaving = w2utils.lang('Saving...'); + + // events + this.onRequest = null; + this.onLoad = null; + this.onValidate = null; + this.onSubmit = null; + this.onSave = null; + this.onChange = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + this.onAction = null; + this.onToolbar = null; + this.onError = null; + + // internal + this.isGenerated = false; + this.last = { + xhr: null // jquery xhr requests + } + + $.extend(true, this, w2obj.form, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2form = function(method) { + if (typeof method === 'object' || !method ) { + var obj = this; + // check name parameter + if (!w2utils.checkName(method, 'w2form')) return; + // remember items + var record = method.record; + var original = method.original; + var fields = method.fields; + var toolbar = method.toolbar; + var tabs = method.tabs; + // extend items + var object = new w2form(method); + $.extend(object, { record: {}, original: {}, fields: [], tabs: {}, toolbar: {}, handlers: [] }); + if ($.isArray(tabs)) { + $.extend(true, object.tabs, { tabs: [] }); + for (var t in tabs) { + var tmp = tabs[t]; + if (typeof tmp === 'object') object.tabs.tabs.push(tmp); else object.tabs.tabs.push({ id: tmp, caption: tmp }); + } + } else { + $.extend(true, object.tabs, tabs); + } + $.extend(true, object.toolbar, toolbar); + // reassign variables + for (var p in fields) { + var field = $.extend(true, {}, fields[p]); + if (typeof field.name == 'undefined' && typeof field.field != 'undefined') field.name = field.field; + if (typeof field.field == 'undefined' && typeof field.name != 'undefined') field.field = field.name; + object.fields[p] = field; + } + for (var p in record) { + if ($.isPlainObject(record[p])) { + object.record[p] = $.extend(true, {}, record[p]); + } else { + object.record[p] = record[p]; + } + } + for (var p in original) { + if ($.isPlainObject(original[p])) { + object.original[p] = $.extend(true, {}, original[p]); + } else { + object.original[p] = original[p]; + } + } + if (obj.length > 0) object.box = obj[0]; + // render if necessary + if (object.formURL != '') { + $.get(object.formURL, function (data) { // should always be $.get as it is template + object.formHTML = data; + object.isGenerated = true; + if ($(object.box).length != 0 || data.length != 0) { + $(object.box).html(data); + object.render(object.box); + } + }); + } else if (object.formHTML != '') { + // it is already loaded into formHTML + } else if ($(this).length != 0 && $.trim($(this).html()) != '') { + object.formHTML = $(this).html(); + } else { // try to generate it + object.formHTML = object.generateHTML(); + } + // register new object + w2ui[object.name] = object; + // render if not loaded from url + if (object.formURL == '') { + if (String(object.formHTML).indexOf('w2ui-page') == -1) { + object.formHTML = ''+ object.formHTML +''; + } + $(object.box).html(object.formHTML); + object.isGenerated = true; + object.render(object.box); + } + return object; - $.extend(true, this, w2obj.form, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2form = function(method) { - if (typeof method === 'object' || !method ) { - var obj = this; - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2form().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // remember items - var record = method.record; - var original = method.original; - var fields = method.fields; - var toolbar = method.toolbar; - var tabs = method.tabs; - // extend items - var object = new w2form(method); - $.extend(object, { record: {}, original: {}, fields: [], tabs: {}, toolbar: {}, handlers: [] }); - if ($.isArray(tabs)) { - $.extend(true, object.tabs, { tabs: [] }); - for (var t in tabs) { - var tmp = tabs[t]; - if (typeof tmp == 'object') object.tabs.tabs.push(tmp); else object.tabs.tabs.push({ id: tmp, caption: tmp }); - } - } else { - $.extend(true, object.tabs, tabs); - } - $.extend(true, object.toolbar, toolbar); - // reassign variables - for (var p in fields) object.fields[p] = $.extend(true, {}, fields[p]); - for (var p in record) { - if ($.isPlainObject(record[p])) { - object.record[p] = $.extend(true, {}, record[p]); - } else { - object.record[p] = record[p]; - } - } - for (var p in original) { - if ($.isPlainObject(original[p])) { - object.original[p] = $.extend(true, {}, original[p]); + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - object.original[p] = original[p]; - } - } - if (obj.length > 0) object.box = obj[0]; - // render if necessary - if (object.formURL != '') { - $.get(object.formURL, function (data) { - object.formHTML = data; - object.isGenerated = true; - if ($(object.box).length != 0 || data.length != 0) { - $(object.box).html(data); - object.render(object.box); - } - }); - } else if (object.formHTML != '') { - // it is already loaded into formHTML - } else if ($(this).length != 0 && $.trim($(this).html()) != '') { - object.formHTML = $(this).html(); - } else { // try to generate it - object.formHTML = object.generateHTML(); - } - // register new object - w2ui[object.name] = object; - // render if not loaded from url - if (object.formURL == '') { - if (String(object.formHTML).indexOf('w2ui-page') == -1) { - object.formHTML = ''+ object.formHTML +''; - } - $(object.box).html(object.formHTML); - object.isGenerated = true; - object.render(object.box); - } - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2form'); - } - } - - // ==================================================== - // -- Implementation of core functionality - - w2form.prototype = { - - get: function (field, returnIndex) { - for (var f in this.fields) { - if (this.fields[f].name == field) { - if (returnIndex === true) return f; else return this.fields[f]; - } - } - return null; - }, - - set: function (field, obj) { - for (var f in this.fields) { - if (this.fields[f].name == field) { - $.extend(this.fields[f] , obj); - this.refresh(); - return true; + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2form'); } - } - return false; - }, - - reload: function (callBack) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url && this.recid != 0) { - //this.clear(); - this.request(callBack); - } else { - this.refresh(); - if (typeof callBack == 'function') callBack(); - } - }, + }; - clear: function () { - this.recid = 0; - this.record = {}; - // clear all enum fields - for (var f in this.fields) { - var field = this.fields[f]; - } - $().w2tag(); - this.refresh(); - }, + // ==================================================== + // -- Implementation of core functionality - error: function (msg) { - var obj = this; - // let the management of the error outside of the grid - var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // need a time out because message might be already up) - setTimeout(function () { w2alert(msg, 'Error'); }, 1); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + w2form.prototype = { - validate: function (showErrors) { - if (typeof showErrors == 'undefined') showErrors = true; - // validate before saving - var errors = []; - for (var f in this.fields) { - var field = this.fields[f]; - if (this.record[field.name] == null) this.record[field.name] = ''; - switch (field.type) { - case 'int': - if (this.record[field.name] && !w2utils.isInt(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not an integer') }); - } - break; - case 'float': - if (this.record[field.name] && !w2utils.isFloat(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a float') }); - } - break; - case 'money': - if (this.record[field.name] && !w2utils.isMoney(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not in money format') }); - } - break; - case 'hex': - if (this.record[field.name] && !w2utils.isHex(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a hex number') }); - } - break; - case 'email': - if (this.record[field.name] && !w2utils.isEmail(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a valid email') }); - } - break; - case 'checkbox': - // convert true/false - if (this.record[field.name] == true) this.record[field.name] = 1; else this.record[field.name] = 0; - break; - case 'date': - // format date before submit - if (this.record[field.name] && !w2utils.isDate(this.record[field.name], field.options.format)) { - errors.push({ field: field, error: w2utils.lang('Not a valid date') + ': ' + field.options.format }); + get: function (field, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var f1 in this.fields) { + if (this.fields[f1].name != null) all.push(this.fields[f1].name); + } + return all; } else { - // convert to universal timestamp with time zone - //var d = new Date(this.record[field.name]); - //var tz = (d.getTimezoneOffset() > 0 ? '+' : '-') + Math.floor(d.getTimezoneOffset()/60) + ':' + (d.getTimezoneOffset() % 60); - //this.record[field.name] = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + ' ' - // + d.getHours() + ':' + d.getSeconds() + ':' + d.getMilliseconds() + tz; - //this.record[field.name + '_unix'] = Math.round(d.getTime() / 1000); - //this.record[field.name] = w2utils.formatDate(this.record[field.name], 'mm/dd/yyyy'); - } - break; - case 'select': - case 'list': - break; - case 'enum': - break; - } - // === check required - if field is '0' it should be considered not empty - var val = this.record[field.name]; - if ( field.required && (val === '' || ($.isArray(val) && val.length == 0)) ) { - errors.push({ field: field, error: w2utils.lang('Required field') }); - } - if ( field.equalto && this.record[field.name]!=this.record[field.equalto] ) { - errors.push({ field: field, error: w2utils.lang('Field should be equal to ')+field.equalto }); - } - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'validate', errors: errors }); - if (eventData.isCancelled === true) return errors; - // show error - if (showErrors) for (var e in eventData.errors) { - var err = eventData.errors[e]; - $(err.field.el).w2tag(err.error, { "class": 'w2ui-error' }); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return errors; - }, - - request: function (postData, callBack) { // if (1) param then it is call back if (2) then postData and callBack - var obj = this; - // check for multiple params - if (typeof postData == 'function') { - callBack = postData; - postData = null; - } - if (typeof postData == 'undefined' || postData == null) postData = {}; - if (!this.url || (typeof this.url == 'object' && !this.url.get)) return; - if (this.recid == null || typeof this.recid == 'undefined') this.recid = 0; - // build parameters list - var params = {}; - // add list params - params['cmd'] = 'get-record'; - params['name'] = this.name; - params['recid'] = this.recid; - // append other params - $.extend(params, this.postData); - $.extend(params, postData); - // event before - var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: this.url, postData: params }); - if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return false; } - // default action - this.record = {}; - this.original = {}; - // call server to get data - this.lock(this.msgRefresh); - var url = eventData.url; - if (typeof eventData.url == 'object' && eventData.url.get) url = eventData.url.get; - if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; - this.last.xhr = $.ajax({ - type : 'GET', - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - complete : function (xhr, status) { - obj.unlock(); - // event before - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'load', xhr: xhr, status: status }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + for (var f2 in this.fields) { + if (this.fields[f2].name == field) { + if (returnIndex === true) return f2; else return this.fields[f2]; + } + } + return null; + } + }, + + set: function (field, obj) { + for (var f in this.fields) { + if (this.fields[f].name == field) { + $.extend(this.fields[f] , obj); + this.refresh(); + return true; + } + } return false; - } - // parse server response - var responseText = obj.last.xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } - } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : obj.msgNotJSON, - responseText : responseText - } - } - if (data['status'] == 'error') { - obj.error(data['message']); - } else { - obj.record = $.extend({}, data.record); - obj.original = $.extend({}, data.record); - } - } - } else { - obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.refresh(); - // call back - if (typeof callBack == 'function') callBack(data); - } - }); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }, - submit: function (postData, callBack) { - return this.save(postData, callBack); - }, + reload: function (callBack) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && this.recid != 0) { + // this.clear(); + this.request(callBack); + } else { + // this.refresh(); // no need to refresh + if (typeof callBack == 'function') callBack(); + } + }, - save: function (postData, callBack) { - var obj = this; - // check for multiple params - if (typeof postData == 'function') { - callBack = postData; - postData = null; - } - // validation - var errors = obj.validate(true); - if (errors.length !== 0) { - obj.goto(errors[0].field.page); - return; - } - // submit save - if (typeof postData == 'undefined' || postData == null) postData = {}; - if (!obj.url || (typeof obj.url == 'object' && !obj.url.save)) { - console.log("ERROR: Form cannot be saved because no url is defined."); - return; - } - obj.lock(obj.msgSaving + ' '); - // need timer to allow to lock - setTimeout(function () { - // build parameters list - var params = {}; - // add list params - params['cmd'] = 'save-record'; - params['name'] = obj.name; - params['recid'] = obj.recid; - // append other params - $.extend(params, obj.postData); - $.extend(params, postData); - params.record = $.extend(true, {}, obj.record); - // convert before submitting - for (var f in obj.fields) { - var field = obj.fields[f]; - switch (String(field.type).toLowerCase()) { - case 'date': // to yyyy-mm-dd format - var dt = params.record[field.name]; - if (field.options.format.toLowerCase() == 'dd/mm/yyyy' || field.options.format.toLowerCase() == 'dd-mm-yyyy' - || field.options.format.toLowerCase() == 'dd.mm.yyyy') { - var tmp = dt.replace(/-/g, '/').replace(/\./g, '/').split('/'); - var dt = new Date(tmp[2] + '-' + tmp[1] + '-' + tmp[0]); - } - params.record[field.name] = w2utils.formatDate(dt, 'yyyy-mm-dd'); - break; - } - } - // event before - var eventData = obj.trigger({ phase: 'before', type: 'submit', target: obj.name, url: obj.url, postData: params }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Saving aborted.' }); - return false; - } - // default action - var url = eventData.url; - if (typeof eventData.url == 'object' && eventData.url.save) url = eventData.url.save; - if (obj.last.xhr) try { obj.last.xhr.abort(); } catch (e) {}; - obj.last.xhr = $.ajax({ - type : (w2utils.settings.RESTfull ? (obj.recid == 0 ? 'POST' : 'PUT') : 'POST'), - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - xhr : function() { - var xhr = new window.XMLHttpRequest(); - // upload - xhr.upload.addEventListener("progress", function(evt) { - if (evt.lengthComputable) { - var percent = Math.round(evt.loaded / evt.total * 100); - $('#'+ obj.name + '_progress').text(''+ percent + '%'); - } - }, false); - return xhr; - }, - complete : function (xhr, status) { - obj.unlock(); + clear: function () { + this.recid = 0; + this.record = {}; + $().w2tag(); + this.refresh(); + }, - // event before - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'save', xhr: xhr, status: status }); + error: function (msg) { + var obj = this; + // let the management of the error outside of the grid + var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Saving aborted.' }); - return false; + if (typeof callBack == 'function') callBack(); + return; } - // parse server response - var responseText = xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } + // need a time out because message might be already up) + setTimeout(function () { w2alert(msg, 'Error'); }, 1); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + validate: function (showErrors) { + if (typeof showErrors == 'undefined') showErrors = true; + $().w2tag(); // hide all tags before validating + // validate before saving + var errors = []; + for (var f in this.fields) { + var field = this.fields[f]; + if (this.record[field.name] == null) this.record[field.name] = ''; + switch (field.type) { + case 'int': + if (this.record[field.name] && !w2utils.isInt(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not an integer') }); + } + break; + case 'float': + if (this.record[field.name] && !w2utils.isFloat(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a float') }); + } + break; + case 'money': + if (this.record[field.name] && !w2utils.isMoney(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not in money format') }); + } + break; + case 'color': + case 'hex': + if (this.record[field.name] && !w2utils.isHex(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a hex number') }); + } + break; + case 'email': + if (this.record[field.name] && !w2utils.isEmail(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a valid email') }); + } + break; + case 'checkbox': + // convert true/false + if (this.record[field.name] == true) this.record[field.name] = 1; else this.record[field.name] = 0; + break; + case 'date': + // format date before submit + if (!field.options.format) field.options.format = w2utils.settings.date_format; + if (this.record[field.name] && !w2utils.isDate(this.record[field.name], field.options.format)) { + errors.push({ field: field, error: w2utils.lang('Not a valid date') + ': ' + field.options.format }); + } else { + } + break; + case 'list': + case 'combo': + break; + case 'enum': + break; } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : obj.msgNotJSON, - responseText : responseText - } + // === check required - if field is '0' it should be considered not empty + var val = this.record[field.name]; + if (field.required && (val === '' || ($.isArray(val) && val.length == 0) || ($.isPlainObject(val) && $.isEmptyObject(val)))) { + errors.push({ field: field, error: w2utils.lang('Required field') }); + } + if (field.equalto && this.record[field.name] != this.record[field.equalto]) { + errors.push({ field: field, error: w2utils.lang('Field should be equal to ') + field.equalto }); } - if (data['status'] == 'error') { - obj.error(data['message']); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'validate', errors: errors }); + if (eventData.isCancelled === true) return; + // show error + if (showErrors) for (var e in eventData.errors) { + var err = eventData.errors[e]; + if (err.field.type == 'radio') { // for radio and checkboxes + $($(err.field.el).parents('div')[0]).w2tag(err.error, { "class": 'w2ui-error' }); + } else if (['enum', 'file'].indexOf(err.field.type) != -1) { + (function (err) { + setTimeout(function () { + var fld = $(err.field.el).data('w2field').helpers.multi; + $(err.field.el).w2tag(err.error); + $(fld).addClass('w2ui-error'); + }, 1); + })(err); } else { - obj.original = $.extend({}, obj.record); + $(err.field.el).w2tag(err.error, { "class": 'w2ui-error' }); } - } - } else { - obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + this.goto(errors[0].field.page); } // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.refresh(); - // call back - if (typeof callBack == 'function') callBack(data); - } - }); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 50); - }, + this.trigger($.extend(eventData, { phase: 'after' })); + return errors; + }, + + getChanges: function () { + var differ = function(record, original, result) { + for (var i in record) { + if (typeof record[i] == "object") { + result[i] = differ(record[i], original[i] || {}, {}); + if (!result[i] || $.isEmptyObject(result[i])) delete result[i]; + } else if (record[i] != original[i]) { + result[i] = record[i]; + } + } + return result; + } + return differ(this.record, this.original, {}); + }, - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - w2utils.lock(box, msg, showSpinner); - }, + request: function (postData, callBack) { // if (1) param then it is call back if (2) then postData and callBack + var obj = this; + // check for multiple params + if (typeof postData == 'function') { + callBack = postData; + postData = null; + } + if (typeof postData == 'undefined' || postData == null) postData = {}; + if (!this.url || (typeof this.url == 'object' && !this.url.get)) return; + if (this.recid == null || typeof this.recid == 'undefined') this.recid = 0; + // build parameters list + var params = {}; + // add list params + params['cmd'] = 'get-record'; + params['recid'] = this.recid; + // append other params + $.extend(params, this.postData); + $.extend(params, postData); + // event before + var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: this.url, postData: params }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + // default action + this.record = {}; + this.original = {}; + // call server to get data + this.lock(this.msgRefresh); + var url = eventData.url; + if (typeof eventData.url == 'object' && eventData.url.get) url = eventData.url.get; + if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text' // expected from server + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'RESTFULL') { + ajaxOptions.type = 'GET'; + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + this.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.unlock(); + // event before + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'load', xhr: xhr }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + // parse server response + var data; + var responseText = obj.last.xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : obj.msgNotJSON, + responseText : responseText + } + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + obj.record = $.extend({}, data.record); + obj.original = $.extend({}, data.record); + } + } + } else { + obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + data = { + status : 'error', + message : obj.msgAJAXerror, + responseText : responseText + }; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.refresh(); + // call back + if (typeof callBack == 'function') callBack(data); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', items: [{ id: 1, text: 'item' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - unlock: function () { - var obj = this; - setTimeout(function () { w2utils.unlock(obj.box); }, 25); // needed timer so if server fast, it will not flash - }, + submit: function (postData, callBack) { + return this.save(postData, callBack); + }, - goto: function (page) { - if (typeof page != 'undefined') this.page = page; - // if it was auto size, resize it - if ($(this.box).data('auto-size') === true) $(this.box).height(0); - this.refresh(); - }, + save: function (postData, callBack) { + var obj = this; + $(this.box).find(':focus').change(); // trigger onchange + // check for multiple params + if (typeof postData == 'function') { + callBack = postData; + postData = null; + } + // validation + var errors = obj.validate(true); + if (errors.length !== 0) return; + // submit save + if (typeof postData == 'undefined' || postData == null) postData = {}; + if (!obj.url || (typeof obj.url == 'object' && !obj.url.save)) { + console.log("ERROR: Form cannot be saved because no url is defined."); + return; + } + obj.lock(obj.msgSaving + ' '); + // need timer to allow to lock + setTimeout(function () { + // build parameters list + var params = {}; + // add list params + params['cmd'] = 'save-record'; + params['recid'] = obj.recid; + // append other params + $.extend(params, obj.postData); + $.extend(params, postData); + params.record = $.extend(true, {}, obj.record); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'submit', target: obj.name, url: obj.url, postData: params }); + if (eventData.isCancelled === true) return; + // default action + var url = eventData.url; + if (typeof eventData.url == 'object' && eventData.url.save) url = eventData.url.save; + if (obj.last.xhr) try { obj.last.xhr.abort(); } catch (e) {}; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text', // expected from server + xhr : function() { + var xhr = new window.XMLHttpRequest(); + // upload + xhr.upload.addEventListener("progress", function(evt) { + if (evt.lengthComputable) { + var percent = Math.round(evt.loaded / evt.total * 100); + $('#'+ obj.name + '_progress').text(''+ percent + '%'); + } + }, false); + return xhr; + } + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'RESTFULL') { + if (obj.recid != 0) ajaxOptions.type = 'PUT'; + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } - generateHTML: function () { - var pages = []; // array for each page - for (var f in this.fields) { - var html = ''; - var field = this.fields[f]; - if (typeof field.html == 'undefined') field.html = {}; - field.html = $.extend(true, { caption: '', span: 6, attr: '', text: '', page: 0 }, field.html); - if (field.html.caption == '') field.html.caption = field.name; - var input = ''; - if (field.type == 'list') input = ''; - if (field.type == 'checkbox') input = ''; - if (field.type == 'textarea') input = ''; - html += '\n '+ field.html.caption +':'+ - '\n '+ - input + field.html.text + - ''; - if (typeof pages[field.html.page] == 'undefined') pages[field.html.page] = ''; - pages[field.html.page] += html; - } - for (var p in pages) pages[p] += '\n'; - // buttons if any - var buttons = ''; - if (!$.isEmptyObject(this.actions)) { - buttons += '\n'; - for (var a in this.actions) { - buttons += '\n '; - } - buttons += '\n'; - } - return pages.join('') + buttons; - }, + obj.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.unlock(); + // event before + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'save', xhr: xhr, status: status }); + if (eventData.isCancelled === true) return; + // parse server response + var data; + var responseText = xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : obj.msgNotJSON, + responseText : responseText + } + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + obj.original = $.extend({}, obj.record); + } + } + } else { + obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + data = { + status : 'error', + message : obj.msgAJAXerror, + responseText : responseText + }; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.refresh(); + // call back + if (data.status == 'success' && typeof callBack == 'function') callBack(data); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + console.log('ERROR: server communication failed. The server should return', + { status: 'success' }, 'OR', { status: 'error', message: 'error message' }, + ', instead the AJAX request produced this: ', errorObj); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 50); + }, + + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + w2utils.lock.apply(window, args); + }, + + unlock: function () { + var obj = this; + setTimeout(function () { w2utils.unlock(obj.box); }, 25); // needed timer so if server fast, it will not flash + }, - action: function (action, event) { - // event before - var eventData = this.trigger({ phase: 'before', target: action, type: 'action', originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default actions - if (typeof (this.actions[action]) == 'function') { - this.actions[action].call(this, event); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + goto: function (page) { + if (typeof page != 'undefined') this.page = page; + // if it was auto size, resize it + if ($(this.box).data('auto-size') === true) $(this.box).height(0); + this.refresh(); + }, + + generateHTML: function () { + var pages = []; // array for each page + var group = ''; + var page; + for (var f in this.fields) { + var html = ''; + var field = this.fields[f]; + if (typeof field.html == 'undefined') field.html = {}; + field.html = $.extend(true, { caption: '', span: 6, attr: '', text: '', page: 0 }, field.html); + if (typeof page == 'undefined') page = field.html.page; + if (field.html.caption == '') field.html.caption = field.name; + var input = ''; + if ((field.type === 'pass') || (field.type === 'password')){ + input = ''; + } + if (field.type == 'checkbox') input = ''; + if (field.type == 'textarea') input = ''; + if (field.type == 'toggle') input = ''; + if (field.html.group) { + if (group != '') html += '\n '; + html += '\n '+ field.html.group + '\n '; + group = field.html.group; + } + if (field.html.page != page && group != '') { + pages[pages.length-1] += '\n '; + group = ''; + } + html += '\n '+ + '\n ' + w2utils.lang(field.html.caption) +''+ + '\n '+ input + w2utils.lang(field.html.text) + ''+ + '\n '; + if (typeof pages[field.html.page] == 'undefined') pages[field.html.page] = ''; + pages[field.html.page] += html; + page = field.html.page; + } + if (group != '') pages[pages.length-1] += '\n '; + if (this.tabs.tabs) { + for (var i = 0; i < this.tabs.tabs.length; i++) if (typeof pages[i] == 'undefined') pages[i] = ''; + } + for (var p in pages) pages[p] = '' + pages[p] + '\n'; + // buttons if any + var buttons = ''; + if (!$.isEmptyObject(this.actions)) { + var addClass = ''; + buttons += '\n'; + for (var a in this.actions) { + if (['save', 'update', 'create'].indexOf(a.toLowerCase()) != -1) addClass = 'btn-green'; else addClass = ''; + buttons += '\n '+ w2utils.lang(a) +''; + } + buttons += '\n'; + } + return pages.join('') + buttons; + }, - resize: function () { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'resize' }); - if (eventData.isCancelled === true) return false; - // default behaviour - var main = $(this.box).find('> div'); - var header = $(this.box).find('> div .w2ui-form-header'); - var toolbar = $(this.box).find('> div .w2ui-form-toolbar'); - var tabs = $(this.box).find('> div .w2ui-form-tabs'); - var page = $(this.box).find('> div .w2ui-page'); - var cpage = $(this.box).find('> div .w2ui-page.page-'+ this.page); - var dpage = $(this.box).find('> div .w2ui-page.page-'+ this.page + ' > div'); - var buttons = $(this.box).find('> div .w2ui-buttons'); - // if no height, calculate it - resizeElements(); - if (parseInt($(this.box).height()) == 0 || $(this.box).data('auto-size') === true) { - $(this.box).height( - (header.length > 0 ? w2utils.getSize(header, 'height') : 0) + - (this.tabs.tabs.length > 0 ? w2utils.getSize(tabs, 'height') : 0) + - (this.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') : 0) + - (page.length > 0 ? w2utils.getSize(dpage, 'height') + w2utils.getSize(cpage, '+height') + 12 : 0) + // why 12 ??? - (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0) - ); - $(this.box).data('auto-size', true); - } - resizeElements(); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - - function resizeElements() { - // resize elements - main.width($(obj.box).width()).height($(obj.box).height()); - toolbar.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0)); - tabs.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) - + (obj.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') : 0)); - page.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) - + (obj.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') + 5 : 0) - + (obj.tabs.tabs.length > 0 ? w2utils.getSize(tabs, 'height') + 5 : 0)); - page.css('bottom', (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0)); - } - }, + action: function (action, event) { + // event before + var eventData = this.trigger({ phase: 'before', target: action, type: 'action', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default actions + if (typeof (this.actions[action]) == 'function') { + this.actions[action].call(this, event); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - refresh: function () { - var obj = this; - if (!this.box) return; - if (!this.isGenerated || typeof $(this.box).html() == 'undefined') return; - // update what page field belongs - $(this.box).find('input, textarea, select').each(function (index, el) { - var name = (typeof $(el).attr('name') != 'undefined' ? $(el).attr('name') : $(el).attr('id')); - var field = obj.get(name); - if (field) { - // find page - var div = $(el).parents('.w2ui-page'); - if (div.length > 0) { - for (var i = 0; i < 100; i++) { - if (div.hasClass('page-'+i)) { field.page = i; break; } - } - } - } - }); - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh', page: this.page }) - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('.w2ui-page').hide(); - $(this.box).find('.w2ui-page.page-' + this.page).show(); - $(this.box).find('.w2ui-form-header').html(this.header); - // refresh tabs if needed - if (typeof this.tabs == 'object' && this.tabs.tabs.length > 0) { - $('#form_'+ this.name +'_tabs').show(); - this.tabs.active = this.tabs.tabs[this.page].id; - this.tabs.refresh(); - } else { - $('#form_'+ this.name +'_tabs').hide(); - } - // refresh tabs if needed - if (typeof this.toolbar == 'object' && this.toolbar.items.length > 0) { - $('#form_'+ this.name +'_toolbar').show(); - this.toolbar.refresh(); - } else { - $('#form_'+ this.name +'_toolbar').hide(); - } - // refresh values of all fields - for (var f in this.fields) { - var field = this.fields[f]; - field.el = $(this.box).find('[name="'+ String(field.name).replace(/\\/g, '\\\\') +'"]')[0]; - if (typeof field.el == 'undefined') { - console.log('ERROR: Cannot associate field "'+ field.name + '" with html control. Make sure html control exists with the same name.'); - //return; - } - if (field.el) field.el.id = field.name; - $(field.el).off('change').on('change', function () { - var value_new = this.value; - var value_previous = obj.record[this.name] ? obj.record[this.name] : ''; - var field = obj.get(this.name); - if ((field.type == 'enum' || field.type == 'upload') && $(this).data('selected')) { - var new_arr = $(this).data('selected'); - var cur_arr = obj.record[this.name]; - var value_new = []; - var value_previous = []; - if ($.isArray(new_arr)) for (var i in new_arr) value_new[i] = $.extend(true, {}, new_arr[i]); // clone array - if ($.isArray(cur_arr)) for (var i in cur_arr) value_previous[i] = $.extend(true, {}, cur_arr[i]); // clone array - } - // event before - var eventData = obj.trigger({ phase: 'before', target: this.name, type: 'change', value_new: value_new, value_previous: value_previous }); - if (eventData.isCancelled === true) { - $(this).val(obj.record[this.name]); // return previous value - return false; - } - // default action - var val = this.value; - if (this.type == 'checkbox') val = this.checked ? true : false; - if (this.type == 'radio') val = this.checked ? true : false; - if (field.type == 'enum') val = value_new; - if (field.type == 'upload') val = value_new; - obj.record[this.name] = val; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - if (field.required) { - $(field.el).parent().addClass('w2ui-required'); - } else { - $(field.el).parent().removeClass('w2ui-required'); - } - } - // attach actions on buttons - $(this.box).find('button, input[type=button]').each(function (index, el) { - $(el).off('click').on('click', function (event) { - var action = this.value; - if (this.name) action = this.name; - if (this.id) action = this.id; - obj.action(action, event); - }); - }); - // init controls with record - for (var f in this.fields) { - var field = this.fields[f]; - var value = (typeof this.record[field.name] != 'undefined' ? this.record[field.name] : ''); - if (!field.el) continue; - switch (String(field.type).toLowerCase()) { - case 'email': - case 'text': - case 'textarea': - field.el.value = value; - break; - case 'date': - if (!field.options) field.options = {}; - if (!field.options.format) field.options.format = w2utils.settings.date_format; - field.el.value = value; - this.record[field.name] = value; - $(field.el).w2field($.extend({}, field.options, { type: 'date' })); - break; - case 'int': - field.el.value = value; - $(field.el).w2field('int'); - break; - case 'float': - field.el.value = value; - $(field.el).w2field('float'); - break; - case 'money': - field.el.value = value; - $(field.el).w2field('money'); - break; - case 'hex': - field.el.value = value; - $(field.el).w2field('hex'); - break; - case 'alphanumeric': - field.el.value = value; - $(field.el).w2field('alphaNumeric'); - break; - case 'checkbox': - if (this.record[field.name] == true || this.record[field.name] == 1 || this.record[field.name] == 't') { - $(field.el).prop('checked', true); + resize: function () { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'resize' }); + if (eventData.isCancelled === true) return; + // default behaviour + var main = $(this.box).find('> div'); + var header = $(this.box).find('> div .w2ui-form-header'); + var toolbar = $(this.box).find('> div .w2ui-form-toolbar'); + var tabs = $(this.box).find('> div .w2ui-form-tabs'); + var page = $(this.box).find('> div .w2ui-page'); + var cpage = $(this.box).find('> div .w2ui-page.page-'+ this.page); + var dpage = $(this.box).find('> div .w2ui-page.page-'+ this.page + ' > div'); + var buttons = $(this.box).find('> div .w2ui-buttons'); + // if no height, calculate it + resizeElements(); + if (parseInt($(this.box).height()) == 0 || $(this.box).data('auto-size') === true) { + $(this.box).height( + (header.length > 0 ? w2utils.getSize(header, 'height') : 0) + + ((typeof this.tabs === 'object' && $.isArray(this.tabs.tabs) && this.tabs.tabs.length > 0) ? w2utils.getSize(tabs, 'height') : 0) + + ((typeof this.toolbar == 'object' && $.isArray(this.toolbar.items) && this.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') : 0) + + (page.length > 0 ? w2utils.getSize(dpage, 'height') + w2utils.getSize(cpage, '+height') + 12 : 0) + // why 12 ??? + (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0) + ); + $(this.box).data('auto-size', true); + } + resizeElements(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + + function resizeElements() { + // resize elements + main.width($(obj.box).width()).height($(obj.box).height()); + toolbar.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0)); + tabs.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) + + ((typeof obj.toolbar == 'object' && $.isArray(obj.toolbar.items) && obj.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') : 0)); + page.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) + + ((typeof obj.toolbar == 'object' && $.isArray(obj.toolbar.items) && obj.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') + 5 : 0) + + ((typeof obj.tabs === 'object' && $.isArray(obj.tabs.tabs) && obj.tabs.tabs.length > 0) ? w2utils.getSize(tabs, 'height') + 5 : 0)); + page.css('bottom', (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0)); + } + }, + + refresh: function () { + var time = (new Date()).getTime(); + var obj = this; + if (!this.box) return; + if (!this.isGenerated || typeof $(this.box).html() == 'undefined') return; + // update what page field belongs + $(this.box).find('input, textarea, select').each(function (index, el) { + var name = (typeof $(el).attr('name') != 'undefined' ? $(el).attr('name') : $(el).attr('id')); + var field = obj.get(name); + if (field) { + // find page + var div = $(el).parents('.w2ui-page'); + if (div.length > 0) { + for (var i = 0; i < 100; i++) { + if (div.hasClass('page-'+i)) { field.page = i; break; } + } + } + } + }); + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh', page: this.page }) + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('.w2ui-page').hide(); + $(this.box).find('.w2ui-page.page-' + this.page).show(); + $(this.box).find('.w2ui-form-header').html(this.header); + // refresh tabs if needed + if (typeof this.tabs === 'object' && $.isArray(this.tabs.tabs) && this.tabs.tabs.length > 0) { + $('#form_'+ this.name +'_tabs').show(); + this.tabs.active = this.tabs.tabs[this.page].id; + this.tabs.refresh(); } else { - $(field.el).prop('checked', false); - } - break; - case 'password': - // hide passwords - field.el.value = value; - break; - case 'select': - case 'list': - $(field.el).w2field($.extend({}, field.options, { type: 'list', value: value })); - break; - case 'enum': - if (typeof field.options == 'undefined' || (typeof field.options.url == 'undefined' && typeof field.options.items == 'undefined')) { - console.log("ERROR: (w2form."+ obj.name +") the field "+ field.name +" defined as enum but not field.options.url or field.options.items provided."); - break; - } - // normalize value - this.record[field.name] = w2obj.field.cleanItems(value); - value = this.record[field.name]; - $(field.el).w2field( $.extend({}, field.options, { type: 'enum', selected: value }) ); - break; - case 'upload': - $(field.el).w2field($.extend({}, field.options, { type: 'upload', selected: value })); - break; - default: - console.log('ERROR: field type "'+ field.type +'" is not recognized.'); - break; - } - } - // wrap pages in div - var tmp = $(this.box).find('.w2ui-page'); - for (var i = 0; i < tmp.length; i++) { - if ($(tmp[i]).find('> *').length > 1) $(tmp[i]).wrapInner(''); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + $('#form_'+ this.name +'_tabs').hide(); + } + // refresh tabs if needed + if (typeof this.toolbar == 'object' && $.isArray(this.toolbar.items) && this.toolbar.items.length > 0) { + $('#form_'+ this.name +'_toolbar').show(); + this.toolbar.refresh(); + } else { + $('#form_'+ this.name +'_toolbar').hide(); + } + // refresh values of all fields + for (var f in this.fields) { + var field = this.fields[f]; + if (typeof field.name == 'undefined' && typeof field.field != 'undefined') field.name = field.field; + if (typeof field.field == 'undefined' && typeof field.name != 'undefined') field.field = field.name; + field.$el = $(this.box).find('[name="'+ String(field.name).replace(/\\/g, '\\\\') +'"]'); + field.el = field.$el[0]; + if (typeof field.el == 'undefined') { + console.log('ERROR: Cannot associate field "'+ field.name + '" with html control. Make sure html control exists with the same name.'); + //return; + } + if (field.el) field.el.id = field.name; + var tmp = $(field).data('w2field'); + if (tmp) tmp.clear(); + $(field.$el).off('change').on('change', function () { + var value_new = this.value; + var value_previous = obj.record[this.name] ? obj.record[this.name] : ''; + var field = obj.get(this.name); + if (['list', 'enum', 'file'].indexOf(field.type) != -1 && $(this).data('selected')) { + var nv = $(this).data('selected'); + var cv = obj.record[this.name]; + if ($.isArray(nv)) { + value_new = []; + for (var i in nv) value_new[i] = $.extend(true, {}, nv[i]); // clone array + } + if ($.isPlainObject(nv)) { + value_new = $.extend(true, {}, nv); // clone object + } + if ($.isArray(cv)) { + value_previous = []; + for (var i in cv) value_previous[i] = $.extend(true, {}, cv[i]); // clone array + } + if ($.isPlainObject(cv)) { + value_previous = $.extend(true, {}, cv); // clone object + } + } + if (field.type == 'toggle') value_new = ($(this).prop('checked') ? 1 : 0); + // clean extra chars + if (['int', 'float', 'percent', 'money', 'currency'].indexOf(field.type) != -1) { + value_new = $(this).data('w2field').clean(value_new); + } + if (value_new === value_previous) return; + // event before + var eventData = obj.trigger({ phase: 'before', target: this.name, type: 'change', value_new: value_new, value_previous: value_previous }); + if (eventData.isCancelled === true) { + $(this).val(obj.record[this.name]); // return previous value + return; + } + // default action + var val = this.value; + if (this.type == 'select') val = this.value; + if (this.type == 'checkbox') val = this.checked ? true : false; + if (this.type == 'radio') { + field.$el.each(function (index, el) { + if (el.checked) val = el.value; + }); + } + if (['int', 'float', 'percent', 'money', 'currency', 'list', 'combo', 'enum', 'file', 'toggle'].indexOf(field.type) != -1) { + val = value_new; + } + if (['enum', 'file'].indexOf(field.type) != -1) { + if (val.length > 0) { + var fld = $(field.el).data('w2field').helpers.multi; + $(fld).removeClass('w2ui-error'); + } + } + obj.record[this.name] = val; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + if (field.required) { + $(field.el).parent().parent().addClass('w2ui-required'); + } else { + $(field.el).parent().parent().removeClass('w2ui-required'); + } + } + // attach actions on buttons + $(this.box).find('button, input[type=button]').each(function (index, el) { + $(el).off('click').on('click', function (event) { + var action = this.value; + if (this.id) action = this.id; + if (this.name) action = this.name; + obj.action(action, event); + }); + }); + // init controls with record + for (var f in this.fields) { + var field = this.fields[f]; + var value = (typeof this.record[field.name] != 'undefined' ? this.record[field.name] : ''); + if (!field.el) continue; + field.type = String(field.type).toLowerCase(); + if (!field.options) field.options = {}; + switch (field.type) { + case 'text': + case 'textarea': + case 'email': + case 'pass': + case 'password': + field.el.value = value; + break; + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'hex': + case 'alphanumeric': + case 'color': + case 'date': + case 'time': + field.el.value = value; + $(field.el).w2field($.extend({}, field.options, { type: field.type })); + break; + case 'toggle': + if (w2utils.isFloat(value)) value = parseFloat(value); + $(field.el).prop('checked', (value ? true : false)); + this.record[field.name] = (value ? 1 : 0); + break; + // enums + case 'list': + case 'combo': + if (field.type == 'list') { + var tmp_value = ($.isPlainObject(value) ? value.id : value); + // normalized options + var items = field.options.items; + if ($.isArray(items) && items.length > 0 && !$.isPlainObject(items[0])) { + field.options.items = w2obj.field.prototype.normMenu(items); + } + // find value from items + for (var i in field.options.items) { + var item = field.options.items[i]; + if (item.id == tmp_value) { + value = $.extend(true, {}, item); + obj.record[field.name] = value; + console.log(1); + break; + } + } + } else if (field.type == 'combo' && !$.isPlainObject(value)) { + field.el.value = value; + } else if ($.isPlainObject(value) && typeof value.text != 'undefined') { + field.el.value = value.text; + } else { + field.el.value = ''; + } + if (!$.isPlainObject(value)) value = {}; + $(field.el).w2field($.extend({}, field.options, { type: field.type, selected: value })); + break; + case 'enum': + case 'file': + if (!$.isArray(value)) value = []; + $(field.el).w2field($.extend({}, field.options, { type: field.type, selected: value })); + break; + + // standard HTML + case 'select': + // generate options + var items = field.options.items; + if (typeof items != 'undefined' && items.length > 0) { + items = w2obj.field.prototype.normMenu(items); + $(field.el).html(''); + for (var it in items) { + $(field.el).append('' + items[it].text + ' *').length > 1) $(tmp[i]).wrapInner(''); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.resize(); + return (new Date()).getTime() - time; + }, - render: function (box) { - var obj = this; - if (typeof box == 'object') { - // remove from previous box - if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { - $(this.box).removeAttr('name') - .removeClass('w2ui-reset w2ui-form') - .html(''); - } - this.box = box; - } - if (!this.isGenerated) return; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: (typeof box != 'undefined' ? box : this.box) }); - if (eventData.isCancelled === true) return false; - // default actions - var html = '' + - (this.header != '' ? '' + this.header + '' : '') + - ' ' + - ' ' + - this.formHTML + - ''; - $(this.box).attr('name', this.name) - .addClass('w2ui-reset w2ui-form') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - - // init toolbar regardless it is defined or not - if (typeof this.toolbar['render'] == 'undefined') { - this.toolbar = $().w2toolbar($.extend({}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - this.toolbar.on('click', function (event) { - var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // no default action - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - } - if (typeof this.toolbar == 'object' && typeof this.toolbar.render == 'function') { - this.toolbar.render($('#form_'+ this.name +'_toolbar')[0]); - } - // init tabs regardless it is defined or not - if (typeof this.tabs['render'] == 'undefined') { - this.tabs = $().w2tabs($.extend({}, this.tabs, { name: this.name +'_tabs', owner: this })); - this.tabs.on('click', function (event) { - obj.goto(this.get(event.target, true)); - }); - } - if (typeof this.tabs == 'object' && typeof this.tabs.render == 'function') { - this.tabs.render($('#form_'+ this.name +'_tabs')[0]); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // after render actions - this.resize(); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url && this.recid != 0) { - this.request(); - } else { - this.refresh(); - } - // attach to resize event - if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event - this.tmp_resize = function (event) { w2ui[obj.name].resize(); } - $(window).off('resize', 'body').on('resize', 'body', this.tmp_resize); - } - setTimeout(function () { obj.resize(); obj.refresh(); }, 150); // need timer because resize is on timer - // focus on load - function focusEl() { - var inputs = $(obj.box).find('input, select, textarea'); - if (inputs.length > obj.focus) inputs[obj.focus].focus(); - } - if (this.focus >= 0) setTimeout(focusEl, 500); // need timeout to allow form to render - }, + render: function (box) { + var time = (new Date()).getTime(); + var obj = this; + if (typeof box == 'object') { + // remove from previous box + if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { + $(this.box).removeAttr('name') + .removeClass('w2ui-reset w2ui-form') + .html(''); + } + this.box = box; + } + if (!this.isGenerated) return; + if (!this.box) return; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: (typeof box != 'undefined' ? box : this.box) }); + if (eventData.isCancelled === true) return; + // default actions + if ($.isEmptyObject(this.original) && !$.isEmptyObject(this.record)) { + this.original = $.extend(true, {}, this.record); + } + var html = '' + + (this.header != '' ? '' + this.header + '' : '') + + ' ' + + ' ' + + this.formHTML + + ''; + $(this.box).attr('name', this.name) + .addClass('w2ui-reset w2ui-form') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + + // init toolbar regardless it is defined or not + if (typeof this.toolbar.render !== 'function') { + this.toolbar = $().w2toolbar($.extend({}, this.toolbar, { name: this.name +'_toolbar', owner: this })); + this.toolbar.on('click', function (event) { + var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); + if (eventData.isCancelled === true) return; + // no default action + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + } + if (typeof this.toolbar == 'object' && typeof this.toolbar.render == 'function') { + this.toolbar.render($('#form_'+ this.name +'_toolbar')[0]); + } + // init tabs regardless it is defined or not + if (typeof this.tabs.render !== 'function') { + this.tabs = $().w2tabs($.extend({}, this.tabs, { name: this.name +'_tabs', owner: this })); + this.tabs.on('click', function (event) { + obj.goto(this.get(event.target, true)); + }); + } + if (typeof this.tabs == 'object' && typeof this.tabs.render == 'function') { + this.tabs.render($('#form_'+ this.name +'_tabs')[0]); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // after render actions + this.resize(); + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && this.recid != 0) { + this.request(); + } else { + this.refresh(); + } + // attach to resize event + if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event + this.tmp_resize = function (event) { w2ui[obj.name].resize(); } + $(window).off('resize', 'body').on('resize', 'body', this.tmp_resize); + } + setTimeout(function () { obj.resize(); obj.refresh(); }, 150); // need timer because resize is on timer + // focus on load + function focusEl() { + var inputs = $(obj.box).find('input, select, textarea'); + if (inputs.length > obj.focus) inputs[obj.focus].focus(); + } + if (this.focus >= 0) setTimeout(focusEl, 500); // need timeout to allow form to render + return (new Date()).getTime() - time; + }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); - if (eventData.isCancelled === true) return false; - // clean up - if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); - if (typeof this.tabs == 'object' && this.tabs.destroy) this.tabs.destroy(); - if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-form') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - $(window).off('resize', 'body') - } - } + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); + if (eventData.isCancelled === true) return; + // clean up + if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); + if (typeof this.tabs == 'object' && this.tabs.destroy) this.tabs.destroy(); + if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-form') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + $(window).off('resize', 'body') + } + }; - $.extend(w2form.prototype, w2utils.event); - w2obj.form = w2form; + $.extend(w2form.prototype, w2utils.event); + w2obj.form = w2form; })(jQuery); diff --git a/js/w2ui.min.js b/js/w2ui.min.js index 2135cb1..1db7571 100644 --- a/js/w2ui.min.js +++ b/js/w2ui.min.js @@ -1 +1 @@ -var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function nt(n){var t=/^[-]?[0-9]+$/;return t.test(n)}function tt(n){var t=new RegExp(w2utils.settings.float);return t.test(n)}function d(n){var t=new RegExp(w2utils.settings.currency);return t.test(n)}function w(n){var t=/^[a-fA-F0-9]+$/;return t.test(n)}function b(n){var t=/^[a-zA-Z0-9_-]+$/;return t.test(n)}function k(n){var t=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return t.test(n)}function et(n,t,i){if(!n)return!1;t||(t=w2utils.settings.date_format);var r=n.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),o=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase(),s="Invalid Date",u,f,e;return(o=="mm/dd/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="m/d/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="dd/mm/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="d/m/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="yyyy/dd/mm"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/d/m"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/mm/dd"&&(u=r[1],f=r[2],e=r[0]),o=="yyyy/m/d"&&(u=r[1],f=r[2],e=r[0]),s=new Date(u+"/"+f+"/"+e),typeof u=="undefined")?!1:s=="Invalid Date"?!1:s.getMonth()+1!=u||s.getDate()!=f||s.getFullYear()!=e?!1:i===!0?s:!0}function ot(t){var r,i;return String(t)=="undefined"?!1:(t=t.toUpperCase(),r=t.indexOf("PM")>=0||t.indexOf("AM")>=0?12:23,t=n.trim(t.replace("AM","")),t=n.trim(t.replace("PM","")),i=t.split(":"),i.length!=2)?!1:i[0]==""||parseInt(i[0])<0||parseInt(i[0])>r||!this.isInt(i[0])?!1:i[1]==""||parseInt(i[1])<0||parseInt(i[1])>59||!this.isInt(i[1])?!1:!0}function st(n){var f,i;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),f=new Date(n),w2utils.isInt(n)&&(f=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(f=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(f=new Date(i[2],Number(i[0])-1,i[1])),f=="Invalid Time"))return"";var e=new Date,t=(e.getTime()-f.getTime())/1e3,r="",u="";return t<60?(r=Math.floor(t),u="sec",t<0&&(r=0,u="sec")):t<3600?(r=Math.floor(t/60),u="min"):t<86400?(r=Math.floor(t/3600),u="hour"):t<2592e3?(r=Math.floor(t/86400),u="day"):t<31104e3?(r=Math.floor(t/259200)/10,u="month"):t>=31104e3&&(r=Math.floor(t/3110400)/10,u="year"),r+" "+u+(r>1?"s":"")}function ft(n){var o=w2utils.settings.shortmonths,t,i,f,r;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(t=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(t=new Date(i[2],Number(i[0])-1,i[1])),t=="Invalid Date"))return"";f=new Date,r=new Date,r.setTime(r.getTime()-864e5);var u=o[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),h=o[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),c=o[r.getMonth()]+" "+r.getDate()+", "+r.getFullYear(),l=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),s=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=u;return u==h&&(e=l),u==c&&(e=w2utils.lang("Yesterday")),''+e+""}function it(n){if(!w2utils.isFloat(n)||n=="")return"";if(n=parseFloat(n),n==0)return 0;var i=["Bt","KB","MB","GB","TB"],t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t==0?0:1)+" "+i[t]}function rt(n){var t="";return(w2utils.isFloat(n)||w2utils.isInt(n)||w2utils.isMoney(n))&&(t=String(n).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")),t}function ut(n,t){var s=w2utils.settings.shortmonths,o=w2utils.settings.fullmonths,r,i;if((typeof t=="undefined"&&(t=this.settings.date_format),typeof n=="undefined"||n==""||n==null)||(r=new Date(n),w2utils.isInt(n)&&(r=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(r=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(r=new Date(i[2],Number(i[0])-1,i[1])),r=="Invalid Date"))return"";var f=r.getFullYear(),u=r.getMonth(),e=r.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[u]).replace("mon",w2utils.settings.shortmonths[u]).replace(/yyyy/g,f).replace(/yyy/g,f).replace(/yy/g,String(f).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+f).replace(/mm/g,(u+1<10?"0":"")+(u+1)).replace(/dd/g,(e<10?"0":"")+e).replace(/(^|[^a-z$])m/g,"$1"+(u+1)).replace(/(^|[^a-z$])d/g,"$1"+e)}function e(n,t){var h=w2utils.settings.shortmonths,s=w2utils.settings.fullmonths,i;if((typeof t=="undefined"&&(t=this.settings.time_format),typeof n=="undefined"||n==""||n==null)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),i=="Invalid Date"))return"";var e="am",u=i.getHours(),o=i.getHours(),r=i.getMinutes(),f=i.getSeconds();return r<10&&(r="0"+r),f<10&&(f="0"+f),(t.indexOf("am")!=-1||t.indexOf("pm")!=-1)&&(u>=12&&(e="pm"),u>12&&(u=u-12)),t.toLowerCase().replace("am",e).replace("pm",e).replace("hh",u).replace("h24",o).replace("mm",r).replace("mi",r).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+u).replace(/(^|[^a-z$])m/g,"$1"+r).replace(/(^|[^a-z$])s/g,"$1"+f)}function o(n,t){var i;return i=typeof t!="string"?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1])}function s(t){if(t==null)return t;switch(typeof t){case"string":t=n.trim(String(t).replace(/(<([^>]+)>)/ig,""));break;case"object":for(var i in t)t[i]=this.stripTags(t[i])}return t}function f(n){if(n==null)return n;switch(typeof n){case"string":n=String(n).replace(/&/g,"&").replace(/>/g,">").replace(/\|\/? {}\\])/g,"\\$1")}function r(n){function l(n){for(var n=String(n).replace(/\r\n/g,"\n"),i="",t,r=0;r127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",s,f,u,h,c,o,r,i=0,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);i>2,c=(s&3)<<4|f>>4,o=(f&15)<<2|u>>6,r=u&63,isNaN(f)?o=r=64:isNaN(u)&&(r=64),e=e+t.charAt(h)+t.charAt(c)+t.charAt(o)+t.charAt(r);return e}function u(n){function l(n){for(var u="",t=0,i=0,f=0,r=0;t191&&i<224?(r=n.charCodeAt(t+1),u+=String.fromCharCode((i&31)<<6|r&63),t+=2):(r=n.charCodeAt(t+1),c3=n.charCodeAt(t+2),u+=String.fromCharCode((i&15)<<12|(r&63)<<6|c3&63),t+=3);return u}var t="",s,o,c,h,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i>4,o=(f&15)<<4|r>>2,c=(r&3)<<6|e,t=t+String.fromCharCode(s),r!=64&&(t=t+String.fromCharCode(o)),e!=64&&(t=t+String.fromCharCode(c));return t=l(t)}function v(t,i,r,u){function f(n,t,i){var r=!!window.webkitURL;return r||typeof i=="undefined"||(t=i),";"+n+": "+t+"; -webkit-"+n+": "+t+"; -moz-"+n+": "+t+"; -ms-"+n+": "+t+"; -o-"+n+": "+t+";"}var o=n(t).width(),s=n(t).height(),e=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+=f("perspective","700px")+"; overflow: hidden;",t.style.cssText+="; position: absolute; z-index: 1019; "+f("backface-visibility","hidden"),i.style.cssText+="; position: absolute; z-index: 1020; "+f("backface-visibility","hidden");switch(r){case"slide-left":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)")},1);break;case"slide-right":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0px, 0, 0)","translate(0px, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)")},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; z-index: 0; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)")},1);break;case"slide-up":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":t.style.cssText+="overflow: hidden; "+f("-transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(180deg)")},1);break;case"flip-right":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(-180deg)")},1);break;case"flip-down":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(-180deg)")},1);break;case"flip-up":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(180deg)")},1);break;case"pop-in":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(.8)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1)")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+";"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(1)")+"; opacity: 1;",i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")},1)}setTimeout(function(){r=="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020")),i&&n(i).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t&&(n(t).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t.parentNode&&n(t.parentNode).css({"-webkit-perspective":"","-moz-perspective":"","-ms-perspective":"","-o-perspective":""})),typeof u=="function"&&u()},e*1e3)}function y(t,i,r){i||i==0||(i=""),w2utils.unlock(t),n(t).find(">:first-child").before(''),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg");f.data("old_opacity",f.css("opacity")).css("opacity","0").show(),u.data("old_opacity",u.css("opacity")).css("opacity","0").show(),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg"),o=(n(t).width()-w2utils.getSize(u,"width"))/2,e=(n(t).height()*.9-w2utils.getSize(u,"height"))/2;f.css({opacity:f.data("old_opacity"),left:"0px",top:"0px",width:"100%",height:"100%"}),i||u.css({"background-color":"transparent",border:"0px"}),r===!0&&(i='"+i),u.html(i).css({opacity:u.data("old_opacity"),left:o+"px",top:e+"px"})},10)},10),n().w2tag()}function p(t){n(t).find(".w2ui-lock").remove(),n(t).find(".w2ui-lock-msg").remove()}function a(t,i){var f={left:parseInt(n(t).css("border-left-width"))||0,right:parseInt(n(t).css("border-right-width"))||0,top:parseInt(n(t).css("border-top-width"))||0,bottom:parseInt(n(t).css("border-bottom-width"))||0},u={left:parseInt(n(t).css("margin-left"))||0,right:parseInt(n(t).css("margin-right"))||0,top:parseInt(n(t).css("margin-top"))||0,bottom:parseInt(n(t).css("margin-bottom"))||0},r={left:parseInt(n(t).css("padding-left"))||0,right:parseInt(n(t).css("padding-right"))||0,top:parseInt(n(t).css("padding-top"))||0,bottom:parseInt(n(t).css("padding-bottom"))||0};switch(i){case"top":return f.top+u.top+r.top;case"bottom":return f.bottom+u.bottom+r.bottom;case"left":return f.left+u.left+r.left;case"right":return f.right+u.right+r.right;case"width":return f.left+f.right+u.left+u.right+r.left+r.right+parseInt(n(t).width());case"height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom+parseInt(n(t).height());case"+width":return f.left+f.right+u.left+u.right+r.left+r.right;case"+height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom}return 0}function h(n){var t=this.settings.phrases[n];return typeof t=="undefined"?n:t}function c(t){t||(t="en-us"),t.length==5&&(t="locale/"+t+".json"),n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(t){w2utils.settings=n.extend(!0,w2utils.settings,t)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function l(){if(t.scrollBarSize)return t.scrollBarSize;var i='\t1';return n("body").append(i),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}var t={};return{settings:{locale:"en-us",date_format:"m/d/yyyy",date_display:"Mon d, yyyy",time_format:"hh:mi pm",currency:"^[$€£¥]?[-]?[0-9]*[.]?[0-9]+$",currencySymbol:"$",float:"^[-]?[0-9]*[.]?[0-9]+$",shortmonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],fullmonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortdays:["M","T","W","T","F","S","S"],fulldays:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],RESTfull:!1,phrases:{}},isInt:nt,isFloat:tt,isMoney:d,isHex:w,isAlphaNumeric:b,isEmail:k,isDate:et,isTime:ot,age:st,date:ft,size:it,formatNumber:rt,formatDate:ut,formatTime:e,formatDateTime:o,stripTags:s,encodeTags:f,escapeId:i,base64encode:r,base64decode:u,transition:v,lock:y,unlock:p,lang:h,locale:c,getSize:a,scrollBarSize:l}}(jQuery),w2popup,w2alert,w2confirm;w2utils.event={on:function(n,t){if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .on() method of "+this.name);return}if(typeof t=="undefined"){console.log("ERROR: You must specify event handler function when calling .on() method of "+this.name);return}this.handlers.push({event:n,handler:t})},off:function(n,t){var r,u,i;if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({},{type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .off() method of "+this.name);return}typeof t=="undefined"&&(t=null),r=[];for(u in this.handlers)i=this.handlers[u],(i.event.type==n.type||n.type=="*")&&(i.event.target==n.target||n.target==null)&&(i.handler==t||t==null)||r.push(i);this.handlers=r},trigger:function(n){var n=jQuery.extend({type:null,phase:"before",target:null,isStopped:!1,isCancelled:!1},n,{preventDefault:function(){this.isCancelled=!0},stopPropagation:function(){this.isStopped=!0}}),e,t,r,i,f;for(typeof n.target=="undefined"&&(n.target=null),e=this.handlers.length-1;e>=0;e--)if(t=this.handlers[e],(t.event.type==n.type||t.event.type=="*")&&(t.event.target==n.target||t.event.target==null)&&(t.event.execute==n.phase||t.event.execute=="*"||t.event.phase=="*")&&(n=jQuery.extend({},t.event,n),r=[],i=RegExp(/\((.*?)\)/).exec(t.handler),i&&(r=i[1].split(/\s*,\s*/)),r.length==2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;if(f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase=="before"&&typeof this[f]=="function"){var u=this[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}if(typeof n.object!="undefined"&&n.object!=null&&n.phase=="before"&&typeof n.object[f]=="function"){var u=n.object[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}return n.phase=="after"&&n.onComplete!=null&&n.onComplete.call(this,n),n}},w2utils.keyboard=function(n){function f(){jQuery(document).on("keydown",e);jQuery(document).on("mousedown",o)}function e(n){var i=n.target.tagName;jQuery.inArray(i,["INPUT","SELECT","TEXTAREA"])==-1&&jQuery(n.target).prop("contenteditable")!="true"&&t&&w2ui[t]&&typeof w2ui[t].keydown=="function"&&w2ui[t].keydown.call(w2ui[t],n)}function o(n){var r=n.target.tagName,i=jQuery(n.target).parents(".w2ui-reset");i.length>0&&(t=i.attr("name"))}function i(n){if(typeof n=="undefined")return t;t=n}function r(){t=null}function u(){}var t=null;return n.active=i,n.clear=r,n.register=u,f(),n}({}),function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))},n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name")),typeof n=="string"&&w2ui[n]&&w2ui[n].destroy(),typeof n=="object"&&n.destroy()},n.fn.w2marker=function(t){return t==""||typeof t=="undefined"?n(this).each(function(n,t){t.innerHTML=t.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1")}):n(this).each(function(n,i){var f,r,u;typeof t=="string"&&(t=[t]),i.innerHTML=i.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1");for(f in t)r=t[f],typeof r!="string"&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(//g,"<"),u=new RegExp(r+"(?!([^<]+)?>)","gi"),i.innerHTML=i.innerHTML.replace(u,function(n){return''+n+""})})},n.fn.w2tag=function(t,i){if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),typeof i["class"]=="undefined"&&(i["class"]=""),n(this).length==0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");typeof r=="undefined"&&(r={}),n(n(i).data("taged-el")).removeClass(r["class"]),clearInterval(n(i).data("timer")),n(i).remove()});return}return n(this).each(function(r,u){var h=u.id,f=w2utils.escapeId(u.id),s,o;if(t==""||t==null||typeof t=="undefined")n("#w2ui-tag-"+f).css("opacity",0),setTimeout(function(){clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove()},300);else{clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n("body").append('0?"w2ui-tag-popup":"")+'" \tstyle="">'),s=setInterval(function(){if(n(u).length==0||n(u).offset().left==0&&n(u).offset().top==0){clearInterval(n("#w2ui-tag-"+f).data("timer")),e();return}n("#w2ui-tag-"+f).data("position")!=n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top&&n("#w2ui-tag-"+f).css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top)},100),setTimeout(function(){n(u).offset()&&(n("#w2ui-tag-"+f).css({opacity:"1",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).html(' '+t+" ").data("text",t).data("taged-el",u).data("options",i).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top).data("timer",s),n(u).off("keypress",e).on("keypress",e).off("change",e).on("change",e).css(i.css).addClass(i["class"]),typeof i.onShow=="function"&&i.onShow())},1),o="",n(u).length>0&&(o=n(u)[0].style.cssText);function e(){n("#w2ui-tag-"+f).length<=0||(clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n(u).off("keypress",e).removeClass(i["class"]),n(u).length>0&&(n(u)[0].style.cssText=o),typeof i.onHide=="function"&&i.onHide())}}})},n.fn.w2overlay=function(t,i){function e(){var t;(typeof i.onHide=="function"&&(t=i.onHide()),t!==!1)&&(n("#w2ui-overlay").remove(),n(document).off("click",e))}function o(){n(document).on("click",e);if(n("#w2ui-overlay > div").length>0){var u=n("#w2ui-overlay > div").height(),r=n("#w2ui-overlay> div").width(),t=window.innerHeight-n("#w2ui-overlay > div").offset().top-7;u>t&&n("#w2ui-overlay> div").height(t).width(r+w2utils.scrollBarSize()).css({"overflow-y":"auto"}),r=n("#w2ui-overlay> div").width(),t=window.innerWidth-n("#w2ui-overlay > div").offset().left-7,r>t&&n("#w2ui-overlay> div").width(t).css({"overflow-x":"auto"}),typeof i.onShow=="function"&&i.onShow()}}var u,f,r;if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),this.length==0||t==""||typeof t=="undefined")return e(),n(this);n("#w2ui-overlay").length>0&&n(document).click(),n("body").append('0?"w2ui-overlay-popup":"")+'">\t'),u=this,r=n("#w2ui-overlay div"),r.css(i.css).html(t),typeof i["class"]!="undefined"&&r.addClass(i["class"]),typeof i.top=="undefined"&&(i.top=0),typeof i.left=="undefined"&&(i.left=0),typeof i.width=="undefined"&&(i.width=100),typeof i.height=="undefined"&&(i.height=0),f=r.css("background-color"),r=n("#w2ui-overlay"),typeof f!="undefined"&&f!="rgba(0, 0, 0, 0)"&&f!="transparent"&&r.css("background-color",f);r.css({display:"none",left:n(u).offset().left+i.left+"px",top:n(u).offset().top+w2utils.getSize(n(u),"height")+3+i.top+"px","min-width":i.width?i.width:"auto","min-height":i.height?i.height:"auto"}).fadeIn("fast").data("position",n(u).offset().left+"x"+(n(u).offset().top+u.offsetHeight)).on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0});return setTimeout(o,0),n(this)},n.fn.w2menu=function(t,i){function r(){for(var f='',n,i,u,r=0;r ",n.img&&(u=''),n.icon&&(u=''),f+=""+u+"\t"+n.text+"";return f+=""}return(typeof i.select=="undefined"&&typeof i.onSelect=="function"&&(i.select=i.onSelect),typeof i.select!="function")?(console.log("ERROR: options.select is required to be a function, not "+typeof i.select+" in $().w2menu(menu, options)"),n(this)):n.isArray(t)?(n.fn.w2menuHandler=function(n,r){i.select(t[r],n,r)},n(this).w2overlay(r(),i)):(console.log("ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)"),n(this))}}(jQuery),function($){var w2grid=function(n){this.name=null,this.box=null,this.header="",this.url="",this.columns=[],this.columnGroups=[],this.records=[],this.summary=[],this.searches=[],this.searchData=[],this.sortData=[],this.postData={},this.toolbar={},this.show={header:!1,toolbar:!1,footer:!1,columnHeaders:!0,lineNumbers:!1,expandColumn:!1,selectColumn:!1,emptyRecords:!0,toolbarReload:!0,toolbarColumns:!0,toolbarSearch:!0,toolbarAdd:!1,toolbarEdit:!1,toolbarDelete:!1,toolbarSave:!1,selectionBorder:!0,recordTitles:!0},this.autoLoad=!0,this.fixedBody=!0,this.recordHeight=24,this.keyboard=!0,this.selectType="row",this.multiSearch=!0,this.multiSelect=!0,this.multiSort=!0,this.markSearchResults=!0,this.total=0,this.buffered=0,this.limit=100,this.offset=0,this.style="",this.ranges=[],this.onAdd=null,this.onEdit=null,this.onRequest=null,this.onLoad=null,this.onDelete=null,this.onDeleted=null,this.onSave=null,this.onSaved=null,this.onSelect=null,this.onUnselect=null,this.onClick=null,this.onDblClick=null,this.onColumnClick=null,this.onColumnResize=null,this.onSort=null,this.onSearch=null,this.onChange=null,this.onExpand=null,this.onCollapse=null,this.onError=null,this.onKeydown=null,this.onToolbar=null,this.onColumnOnOff=null,this.onCopy=null,this.onPaste=null,this.onSelectionExtend=null,this.onEditField=null,this.onRender=null,this.onRefresh=null,this.onReload=null,this.onResize=null,this.onDestroy=null,this.last={field:"all",caption:w2utils.lang("All Fields"),logic:"OR",search:"",searchIds:[],multi:!1,scrollTop:0,scrollLeft:0,selected:[],sortData:null,sortCount:0,xhr:null,range_start:null,range_end:null,sel_ind:null,sel_col:null,sel_type:null},this.isIOS=navigator.userAgent.toLowerCase().indexOf("iphone")!=-1||navigator.userAgent.toLowerCase().indexOf("ipod")!=-1||navigator.userAgent.toLowerCase().indexOf("ipad")!=-1?!0:!1,$.extend(!0,this,w2obj.grid,n)};$.fn.w2grid=function(n){var i,u,a,r,e,o,s;if(typeof n!="object"&&n){if(w2ui[$(this).attr("name")])return s=w2ui[$(this).attr("name")],s[n].apply(s,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+n+" does not exist on jQuery.w2grid")}else{if(!n||typeof n.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().');return}if(typeof w2ui[n.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+").");return}if(!w2utils.isAlphaNumeric(n.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var h=n.columns,l=n.columnGroups,f=n.records,c=n.searches,y=n.searchData,v=n.sortData,w=n.postData,p=n.toolbar,t=new w2grid(n);$.extend(t,{postData:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]}),t.onExpand!=null&&(t.show.expandColumn=!0),$.extend(!0,t.toolbar,p);for(i in h)t.columns[i]=$.extend(!0,{},h[i]);for(i in l)t.columnGroups[i]=$.extend(!0,{},l[i]);for(i in c)t.searches[i]=$.extend(!0,{},c[i]);for(i in y)t.searchData[i]=$.extend(!0,{},y[i]);for(i in v)t.sortData[i]=$.extend(!0,{},v[i]);t.postData=$.extend(!0,{},w);for(u in f){if(f[u].recid==null||typeof f[u].recid=="undefined"){console.log("ERROR: Cannot add records without recid. (obj: "+t.name+")");return}t.records[u]=$.extend(!0,{},f[u])}t.records.length>0&&(t.buffered=t.records.length);for(a in t.columns)(r=t.columns[a],typeof r.searchable!="undefined"&&t.getSearch(r.field)==null)&&(e=r.searchable,o="",r.searchable===!0&&(e="text",o='size="20"'),t.addSearch({field:r.field,caption:r.caption,type:e,attr:o}));return t.initToolbar(),$(this).length!=0&&t.render($(this)[0]),w2ui[t.name]=t,t}},w2grid.prototype={msgDelete:w2utils.lang("Are you sure you want to delete selected records?"),msgNotJSON:w2utils.lang("Returned data is not in valid JSON format."),msgRefresh:w2utils.lang("Refreshing..."),buttons:{reload:{type:"button",id:"reload",img:"icon-reload",hint:w2utils.lang("Reload data in the list")},columns:{type:"drop",id:"column-on-off",img:"icon-columns",hint:w2utils.lang("Show/hide columns"),arrow:!1,html:""},search:{type:"html",id:"search",html:'"},"search-go":{type:"check",id:"search-advanced",caption:w2utils.lang("Search..."),hint:w2utils.lang("Open Search Fields")},add:{type:"button",id:"add",caption:w2utils.lang("Add New"),hint:w2utils.lang("Add new record"),img:"icon-add"},edit:{type:"button",id:"edit",caption:w2utils.lang("Edit"),hint:w2utils.lang("Edit selected record"),img:"icon-edit",disabled:!0},"delete":{type:"button",id:"delete",caption:w2utils.lang("Delete"),hint:w2utils.lang("Delete selected records"),img:"icon-delete",disabled:!0},save:{type:"button",id:"save",caption:w2utils.lang("Save"),hint:w2utils.lang("Save changed records"),img:"icon-save"}},add:function(n){var i,t,r;$.isArray(n)||(n=[n]),i=0;for(t in n){if(n[t].recid==null||typeof n[t].recid=="undefined"){console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");continue}this.records.push(n[t]),i++}return this.buffered=this.records.length,r=typeof this.url!="object"?this.url:this.url.get,r||(this.localSort(),this.localSearch()),this.refresh(),i},find:function(n,t){var f,i,u,r,e;for((typeof n=="undefined"||n==null)&&(n={}),f=[],i=0;i0&&!o)for(f in this.last.searchIds)this.last.searchIds[f]==r&&(r=f);$(u).replaceWith(this.getRecordHTML(r,s))}}return!0},get:function(n,t){for(var i=0;i=0;n--)this.records[n].recid==arguments[t]&&(this.records.splice(n,1),r++);return i=typeof this.url!="object"?this.url:this.url.get,i||(this.buffered=this.records.length,this.localSort(),this.localSearch()),this.refresh(),r},addColumn:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.columns.length):(typeof n=="string"&&(n=this.getColumn(n,!0)),n===null&&(n=this.columns.length)),$.isArray(t)||(t=[t]);for(i in t)this.columns.splice(n,0,t[i]),n++,r++;return this.initColumnOnOff(),this.refresh(),r},removeColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&(this.columns.splice(n,1),i++);return this.initColumnOnOff(),this.refresh(),i},getColumn:function(n,t){for(var i=0;i=0;n--)this.columns[n].field==arguments[t]&&(this.columns[n].hidden=!this.columns[n].hidden,i++);return this.refresh(),i},showColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!1&&(this.columns[n].hidden=!1,i++);return this.refresh(),i},hideColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!0&&(this.columns[n].hidden=!0,i++);return this.refresh(),i},addSearch:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.searches.length):(typeof n=="string"&&(n=this.getSearch(n,!0)),n===null&&(n=this.searches.length)),$.isArray(t)||(t=[t]);for(i in t)this.searches.splice(n,0,t[i]),n++,r++;return this.searchClose(),r},removeSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&(this.searches.splice(n,1),i++);return this.searchClose(),i},getSearch:function(n,t){for(var i=0;i=0;n--)this.searches[n].field==arguments[t]&&(this.searches[n].hidden=!this.searches[n].hidden,i++);return this.searchClose(),i},showSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!1&&(this.searches[n].hidden=!1,i++);return this.searchClose(),i},hideSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!0&&(this.searches[n].hidden=!0,i++);return this.searchClose(),i},getSearchData:function(n){for(var t in this.searchData)if(this.searchData[t].field==n)return this.searchData[t];return null},localSort:function(n){var r=typeof this.url!="object"?this.url:this.url.get,i,t;if(r){console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");return}if(!$.isEmptyObject(this.sortData))return i=+new Date,t=this,this.records.sort(function(n,i){var e=0,f,r,u;for(f in t.sortData)if(r=n[t.sortData[f].field],u=i[t.sortData[f].field],String(t.sortData[f].field).indexOf(".")!=-1&&(r=t.parseField(n,t.sortData[f].field),u=t.parseField(i,t.sortData[f].field)),typeof r=="string"&&(r=$.trim(r.toLowerCase())),typeof u=="string"&&(u=$.trim(u.toLowerCase())),r>u&&(e=t.sortData[f].direction=="asc"?1:-1),r0&&!a){this.total=0;for(l in this.records){s=this.records[l],u=0;for(v in this.searchData)if(i=this.searchData[v],t=this.getSearch(i.field),i!=null){t==null&&(t={field:i.field,type:i.type}),f=String(c.parseField(s,t.field)).toLowerCase(),typeof i.value!="undefined"&&($.isArray(i.value)?(r=i.value[0],e=i.value[1]):r=String(i.value).toLowerCase());switch(i.operator){case"is":s[t.field]==i.value&&u++,t.type=="date"&&(o=new Date(Number(f)),f=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),r=Number(r),e=Number(f)+864e5,r>=f&&r<=e&&u++);break;case"between":t.type=="int"&&parseInt(s[t.field])>=parseInt(r)&&parseInt(s[t.field])<=parseInt(e)&&u++,t.type=="float"&&parseFloat(s[t.field])>=parseFloat(r)&&parseFloat(s[t.field])<=parseFloat(e)&&u++,t.type=="date"&&(o=new Date(Number(e)),e=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),e=Number(e)+864e5,f>=r&&f=0&&u++;break;case"ends with":f.indexOf(r)==f.length-r.length&&u++}}(this.last.logic=="OR"&&u!=0||this.last.logic=="AND"&&u==this.searchData.length)&&this.last.searchIds.push(parseInt(l))}this.total=this.last.searchIds.length}return this.buffered=this.total,h=+new Date-h,n!==!0&&setTimeout(function(){c.status("Search took "+h/1e3+" sec")},10),h},getRangeData:function(n,t){var o=this.get(n[0].recid,!0),c=this.get(n[1].recid,!0),s=n[0].column,h=n[1].column,r=[],u,f,i,e;if(s==h)for(u=o;u<=c;u++)f=this.records[u],e=f[this.columns[s].field]||null,t!==!0?r.push(e):r.push({data:e,column:s,index:u,record:f});else if(o==c)for(f=this.records[o],i=s;i<=h;i++)e=f[this.columns[i].field]||null,t!==!0?r.push(e):r.push({data:e,column:i,index:o,record:f});else for(u=o;u<=c;u++)for(f=this.records[u],r.push([]),i=s;i<=h;i++)e=f[this.columns[i].field],t!==!0?r[r.length-1].push(e):r[r.length-1].push({data:e,column:i,index:u,record:f});return r},addRange:function(n){var o=0,t,u,e,f,s;if(this.selectType=="row")return o;$.isArray(n)||(n=[n]);for(t in n){if(typeof n[t]!="object"&&(n[t]={name:"selection"}),n[t].name=="selection"){if(this.show.selectionBorder===!1)continue;if(u=this.getSelection(),u.length==0){this.removeRange(n[t].name);continue}else var i=u[0],r=u[u.length-1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]")}else var i=n[t].range[0],r=n[t].range[1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]");if(i){e={name:n[t].name,range:[{recid:i.recid,column:i.column},{recid:r.recid,column:r.column}],style:n[t].style||""},f=!1;for(s in this.ranges)if(this.ranges[s].name==n[t].name){f=t;break}f!==!1?this.ranges[f]=e:this.ranges.push(e),o++}}return this.refreshRanges(),o},removeRange:function(){for(var r=0,i,n,t=0;t=0;n--)this.ranges[n].name==i&&(this.ranges.splice(n,1),r++);return r},refreshRanges:function(){function l(t){var i=n.getSelection();n.last.move={type:"expand",x:t.screenX,y:t.screenY,divX:0,divY:0,recid:i[0].recid,column:i[0].column,originalRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}],newRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}]};$(document).off("mousemove",f).on("mousemove",f);$(document).off("mouseup",e).on("mouseup",e)}function f(t){var r=n.last.move,e,o,u,f;if(r&&r.type=="expand"&&(r.divX=t.screenX-r.x,r.divY=t.screenY-r.y,u=t.originalEvent.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(o=parseInt($(u).attr("col"))),u=$(u).parents("tr")[0],e=$(u).attr("recid"),r.newRange[1].recid!=e||r.newRange[1].column!=o)){if(f=$.extend({},r.newRange),r.newRange=[{recid:r.recid,column:r.column},{recid:e,column:o}],i=n.trigger($.extend(i,{originalRange:r.originalRange,newRange:r.newRange})),i.isCancelled===!0){r.newRange=f,i.newRange=f;return}n.removeRange("grid-selection-expand"),n.addRange({name:"grid-selection-expand",range:i.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"})}}function e(){n.removeRange("grid-selection-expand"),delete n.last.move,$(document).off("mousemove",f),$(document).off("mouseup",e),n.trigger($.extend(i,{phase:"after"}))}var n=this,a=+new Date,o=$("#grid_"+this.name+"_records"),c,i;for(c in this.ranges){var t=this.ranges[c],h=t.range[0],s=t.range[1],r=$("#grid_"+this.name+"_rec_"+h.recid+" td[col="+h.column+"]"),u=$("#grid_"+this.name+"_rec_"+s.recid+" td[col="+s.column+"]");$("#grid_"+this.name+"_"+t.name).length==0?o.append(''+(t.name=="selection"?'':"")+""):$("#grid_"+this.name+"_"+t.name).attr("style",t.style),r.length>0&&u.length>0&&$("#grid_"+this.name+"_"+t.name).css({left:r.position().left-1+o.scrollLeft()+"px",top:r.position().top-1+o.scrollTop()+"px",width:u.position().left-r.position().left+u.width()+3+"px",height:u.position().top-r.position().top+u.height()+3+"px"})}$(this.box).find("#grid_"+this.name+"_resizer").off("mousedown").on("mousedown",l);return i={phase:"before",type:"selectionExtend",target:n.name,originalRange:null,newRange:null},+new Date-a},select:function(){for(var s=0,r,o,e,f,u,i=0;i td[col="+r+"]").addClass("w2ui-selected"),s++,n.selected&&($("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)).data("selected","yes"),$("#grid_"+this.name+"_cell_"+h+"_select_check").prop("checked",!0))}this.trigger($.extend(u,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},unselect:function(){for(var s=0,f,i,h,o,r,e,t=0;t td[col="+i+"]").removeClass("w2ui-selected"),s++,r.length==0&&(n.selected=!1,$("#grid_"+this.name+"_rec_"+w2utils.escapeId(u)).removeData("selected"),$("#grid_"+this.name+"_cell_"+c+"_select_check").prop("checked",!1))}this.trigger($.extend(e,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},selectAll:function(){var r,n,u,f,t,i;if(this.multiSelect!==!1&&(r=this.trigger({phase:"before",type:"select",target:this.name,all:!0}),r.isCancelled!==!0)){n=[];for(u in this.columns)n.push(parseInt(u));if(f=typeof this.url!="object"?this.url:this.url.get,f)this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()}),this.refresh();else if(this.searchData.length==0)this.set({selected:!0}),this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()});else{for(t=0;t=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"),this.addRange("selection"),this.trigger($.extend(r,{phase:"after"}))}},selectNone:function(){var f=this.trigger({phase:"before",type:"unselect",target:this.name,all:!0}),r,n,t,i,u;if(f.isCancelled!==!0){this.last.selected=[];for(r in this.records)if(n=this.records[r],n.selected===!0&&(n.selected=!1,t=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.recid)),t.removeClass("w2ui-selected").removeData("selected"),$("#grid_"+this.name+"_cell_"+r+"_select_check").prop("checked",!1),this.selectType!="row")){i=n.selectedColumns;for(u in i)t.find(" > td[col="+i[u]+"]").removeClass("w2ui-selected");n.selectedColumns=[]}this.toolbar.disable("edit","delete"),this.removeRange("selection"),this.trigger($.extend(f,{phase:"after"}))}},getSelection:function(n){var t,i,r,u,f;if(this.selectType=="row"){t=this.find({selected:!0},!0),i=[];for(r in t)n===!0?i.push(t[r]):i.push(this.records[t[r]].recid);return i}t=this.find({selected:!0},!0),i=[];for(r in t){u=this.records[t[r]];for(f in u.selectedColumns)i.push({recid:u.recid,index:parseInt(t[r]),column:u.selectedColumns[f]})}return i},search:function(n,t){var it=this,nt=typeof this.url!="object"?this.url:this.url.get,u=[],v=this.last.multi,a=this.last.logic,g=this.last.field,p=this.last.search,f,d,h,s,c,r,o,k,b,i,y;if(arguments.length==0){p="";for(f in this.searches){var i=this.searches[f],l=$("#grid_"+this.name+"_operator_"+f).val(),e=$("#grid_"+this.name+"_field_"+f).val(),w=$("#grid_"+this.name+"_field2_"+f).val();if(e!=""&&e!=null||typeof w!="undefined"&&w!=""){r={field:i.field,type:i.type,operator:l},l=="between"?$.extend(r,{value:[e,w]}):l=="in"?$.extend(r,{value:e.split(",")}):$.extend(r,{value:e});try{i.type=="date"&&l=="between"&&(r.value[0]=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime(),r.value[1]=w2utils.isDate(w,w2utils.settings.date_format,!0).getTime()),i.type=="date"&&l=="is"&&(r.value=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime())}catch(tt){}u.push(r)}}u.length>0&&!nt?(v=!0,a="AND"):(v=!0,a="AND")}if(typeof n=="string"&&(g=n,p=t,v=!1,a="OR",typeof t!="undefined"))if(n.toLowerCase()=="all")if(this.searches.length>0)for(f in this.searches)i=this.searches[f],(i.type=="text"||i.type=="int"&&w2utils.isInt(t)||i.type=="float"&&w2utils.isFloat(t)||i.type=="money"&&w2utils.isMoney(t)||i.type=="hex"&&w2utils.isHex(t)||i.type=="date"&&w2utils.isDate(t)||i.type=="alphaNumeric"&&w2utils.isAlphaNumeric(t))&&(r={field:i.field,type:i.type,operator:i.type=="text"?"contains":"is",value:t},u.push(r)),i.type=="int"&&String(t).indexOf("-")!=-1&&(c=String(t).split("-"),r={field:i.field,type:i.type,operator:"between",value:[c[0],c[1]]},u.push(r));else for(d in this.columns)r={field:this.columns[d].field,type:"text",operator:"contains",value:t},u.push(r);else if(i=this.getSearch(n),i==null&&(i={field:n,type:"text"}),i.field==n&&(this.last.caption=i.caption),t!=""){if(h="contains",s=t,w2utils.isInt(t)&&(h="is",s=t),i.type=="int"&&t!=""&&(String(t).indexOf("-")!=-1&&(r=t.split("-"),r.length==2&&(h="between",s=[parseInt(r[0]),parseInt(r[1])])),String(t).indexOf(",")!=-1)){r=t.split(","),h="in",s=[];for(c in r)s.push(r[c])}r={field:i.field,type:i.type,operator:h,value:s},u.push(r)}if($.isArray(n)){o="AND",typeof t=="string"&&(o=t.toUpperCase(),o!="OR"&&o!="AND"&&(o="AND")),p="",v=!0,a=o;for(k in n)b=n[k],i=this.getSearch(b.field),i==null&&(i={type:"text",operator:"contains"}),u.push($.extend(!0,{},i,b))}(y=this.trigger({phase:"before",type:"search",target:this.name,searchData:u,searchField:n?n:"multi",searchValue:t?t:"multi"}),y.isCancelled!==!0)&&(this.searchData=y.searchData,this.last.field=g,this.last.search=p,this.last.multi=v,this.last.logic=a,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),this.set({expanded:!1}),nt?(this.last.xhr_offset=0,this.reload()):(this.localSearch(),this.refresh()),this.trigger($.extend(y,{phase:"after"})))},searchOpen:function(){if(this.box&&this.searches.length!=0){var n=this;$("#tb_"+this.name+"_toolbar_item_search-advanced").w2overlay(this.getSearchesHTML(),{left:-10,"class":"w2ui-grid-searches",onShow:function(){n.last.logic=="OR"&&(n.searchData=[]),n.initSearches(),$("#w2ui-overlay .w2ui-grid-searches").data("grid-name",n.name);var t=$("#w2ui-overlay .w2ui-grid-searches *[rel=search]");t.length>0&&t[0].focus()}})}},searchClose:function(){this.box&&this.searches.length!=0&&(this.toolbar&&this.toolbar.uncheck("search-advanced"),$("#w2ui-overlay .w2ui-grid-searches").length>0&&$().w2overlay())},searchShowFields:function(n){var r,i,t;for(typeof n=="undefined"&&(n=$("#grid_"+this.name+"_search_all")),r='',i=-1;i"+t.caption+""}r+="",$(n).w2overlay(r,{left:-15,top:7})},searchReset:function(n){var t=this.trigger({phase:"before",type:"search",target:this.name,searchData:[]});t.isCancelled!==!0&&(this.searchData=[],this.last.search="",this.last.logic="OR",this.last.multi&&(this.multiSearch?(this.last.field="all",this.last.caption=w2utils.lang("All Fields")):(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption)),this.last.multi=!1,this.last.xhr_offset=0,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),n||this.reload(),this.trigger($.extend(t,{phase:"after"})))},clear:function(n){this.offset=0,this.total=0,this.buffered=0,this.records=[],this.summary=[],this.last.scrollTop=0,this.last.scrollLeft=0,this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,n||this.refresh()},reset:function(n){this.offset=0,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,this.searchReset(n),this.last.sortData!=null&&(this.sortData=this.last.sortData),this.set({selected:!1,expanded:!1},!0),n||this.refresh()},skip:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.offset=parseInt(n),(this.offset<0||!w2utils.isInt(this.offset))&&(this.offset=0),this.offset>this.total&&(this.offset=this.total-this.limit),this.records=[],this.buffered=0,this.last.xhr_offset=0,this.last.pull_more=!0,this.last.scrollTop=0,this.last.scrollLeft=0,$("#grid_"+this.name+"_records").prop("scrollTop",0),this.initColumnOnOff(),this.reload()):console.log("ERROR: grid.skip() can only be called when you have remote data source.")},load:function(n,t){if(typeof n=="undefined"){console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.');return}this.request("get-records",{},n,t)},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.last.xhr_offset>0&&this.last.xhr_offset div"),o.type=="enum"&&console.log("ERROR: Grid's inline editing does not support enum field type."),(o.type=="list"||o.type=="select")&&console.log("ERROR: Grid's inline editing does not support list/select field type."),typeof o.inTag=="undefined"&&(o.inTag=""),typeof o.outTag=="undefined"&&(o.outTag=""),typeof o.style=="undefined"&&(o.style=""),typeof o.items=="undefined"&&(o.items=[]),h=f.changed&&f.changes[e.field]?w2utils.stripTags(f.changes[e.field]):w2utils.stripTags(f[e.field]),(h==null||typeof h=="undefined")&&(h=""),typeof i!="undefined"&&i!=null&&(h=i),v=typeof e.style!="undefined"?e.style+";":"",$.inArray(e.render,["number","int","float","money","percent"])!=-1&&(v+="text-align: right;"),c.addClass("w2ui-editable").html('"+o.outTag);c.find("input").w2field(o.type).on("blur",function(){if(u.parseField(f,e.field)!=this.value){var r=u.trigger({phase:"before",type:"change",target:u.name,input_id:this.id,recid:n,column:t,value_new:this.value,value_previous:f.changes?f.changes[e.field]:u.parseField(f,e.field),value_original:u.parseField(f,e.field)});r.isCancelled===!0||(f.changed=!0,f.changes=f.changes||{},f.changes[e.field]=r.value_new,u.trigger($.extend(r,{phase:"after"})))}else f.changes&&delete f.changes[e.field],$.isEmptyObject(f.changes)&&delete f.changes;$(a).replaceWith(u.getRecordHTML(s,a.attr("line")))}).on("keydown",function(i){function a(n){var t=n+1;return u.columns.length==t?n:u.columns[t].hidden?a(t):t}function v(n){var t=n-1;return t<0?n:u.columns[t].hidden?v(t):t}function c(n){var t=n+1;return u.records.length==t?n:t}function l(n){var t=n-1;return t<0?n:t}var o=!1,r,h;switch(i.keyCode){case 9:o=!0,r=i.shiftKey?v(t):a(t),r!=t&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:n,column:r})):u.editField(n,r,null,i)},1));break;case 13:o=!0,r=i.shiftKey?l(s):c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 38:o=!0,r=l(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 40:o=!0,r=c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 27:h=f.changed&&f.changes[e.field]?f.changes[e.field]:u.parseField(f,e.field),this.value=typeof h!="undefined"?h:"",this.blur(),setTimeout(function(){u.select({recid:n,column:t})},1)}o&&i.preventDefault&&i.preventDefault()});typeof i=="undefined"||i==null?c.find("input").focus():c.find("input").val("").focus().val(i),u.trigger($.extend(l,{phase:"after"}))}},"delete":function(n){var o=this,f=this.trigger({phase:"before",target:this.name,type:"delete",force:n}),t,e,u,r,i;if(f.isCancelled===!0)return!1;if(n=f.force,t=this.getSelection(),t.length!=0){if(this.msgDelete!=""&&!n){w2confirm(o.msgDelete,w2utils.lang("Delete Confirmation"),function(n){n=="Yes"&&w2ui[o.name].delete(!0)});return}if(e=typeof this.url!="object"?this.url:this.url.remove,e)this.request("delete-records");else if(typeof t[0]!="object")this.remove.apply(this,t);else{for(u in t)r=this.columns[t[u].column].field,i=this.get(t[u].recid,!0),i!=null&&r!="recid"&&(this.records[i][r]="",this.records[i].changed&&(this.records[i].changes[r]=""));this.refresh()}this.trigger($.extend(f,{phase:"after"}))}},click:function(n,t){var g=+new Date,i=null,b,c,nt,f,r,p,y,a,h,s,v,u,tt,e,k,o;if(typeof n=="object"&&(i=n.column,n=n.recid),w2utils.isInt(n)&&(n=parseInt(n)),typeof t=="undefined"&&(t={}),g-parseInt(this.last.click_time)<250&&t.type=="click"){this.dblClick(n,t);return}if(this.last.click_time=g,i==null&&t.target&&(u=t.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(i=parseInt($(u).attr("col")))),b=this.trigger({phase:"before",target:this.name,type:"click",recid:n,column:i,originalEvent:t}),b.isCancelled===!0)return!1;c=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n)).parents("tr"),c.length>0&&String(c.attr("id")).indexOf("expanded_row")!=-1&&(nt=c.parents(".w2ui-grid").attr("name"),w2ui[nt].selectNone(),c.parents(".w2ui-grid").find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()})),$(this.box).find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()}),f=this,r=this.getSelection(),$("#grid_"+this.name+"_check_all").prop("checked",!1);var d=this.get(n,!0),l=this.records[d],w=[];if(f.last.sel_ind=d,f.last.sel_col=i,f.last.sel_recid=n,f.last.sel_type="click",t.shiftKey&&r.length>0){if(r[0].recid)for(h=this.get(r[0].recid,!0),s=this.get(n,!0),i>r[0].column?(p=r[0].column,y=i):(p=i,y=r[0].column),a=p;a<=y;a++)w.push(a);else h=this.get(r[0],!0),s=this.get(n,!0);for(v=[],h>s&&(u=h,h=s,s=u),tt=typeof this.url!="object"?this.url:this.url.get,e=h;e<=s;e++)if(!(this.searchData.length>0)||tt||$.inArray(e,this.last.searchIds)!=-1)if(this.selectType=="row")v.push(this.records[e].recid);else for(k in w)v.push({recid:this.records[e].recid,column:w[k]});this.select.apply(this,v)}else(t.ctrlKey||t.shiftKey||t.metaKey)&&this.multiSelect||this.showSelectColumn?(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),o===!0?this.unselect({recid:n,column:i}):this.select({recid:l.recid,column:i}),setTimeout(function(){window.getSelection&&window.getSelection().removeAllRanges()},10)):(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),r.length>300?this.selectNone():this.unselect.apply(this,r),o===!0?this.unselect({recid:n,column:i}):this.select({recid:n,column:i}));this.status(),f.last.selected=this.getSelection(),f.initResize(),this.trigger($.extend(b,{phase:"after"}))},columnClick:function(n,t){var i=this.trigger({phase:"before",type:"columnClick",target:this.name,field:n,originalEvent:t});if(i.isCancelled===!0)return!1;this.sort(n,null,t&&(t.ctrlKey||t.metaKey)?!0:!1),this.trigger($.extend(i,{phase:"after"}))},keydown:function(n){function st(n){if(n+10&&n0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n>t.records.length)break;n++}return n}return null}function ht(n){if(n>0&&t.last.searchIds.length==0||t.last.searchIds.length>0&&n>t.last.searchIds[0]){if(n--,t.last.searchIds.length>0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n<0)break;n--}return n}return null}function et(n){var i=n+1;return t.columns.length==i?n:t.columns[i].hidden?findNext(i):i}function ot(n){var i=n-1;return i<0?n:t.columns[i].hidden?findPrev(i):i}function g(){if(t.last.sel_type!="click")return!1;if(t.selectType!="row"){if(t.last.sel_type="key",i.length>1){for(var n in i)if(i[n].recid==t.last.sel_recid&&i[n].column==t.last.sel_col){i.splice(n,1);break}return t.unselect.apply(t,i),!0}return!1}return(t.last.sel_type="key",i.length>1)?(i.splice(i.indexOf(t.records[t.last.sel_ind].recid),1),t.unselect.apply(t,i),!0):!1}var t=this,it,b,i,c,y,d,a,v,h,l,f,o,rt,e,u;if(t.keyboard===!0){if(it=t.trigger({phase:"before",type:"keydown",target:t.name,originalEvent:n}),it.isCancelled===!0)return!1;if(i=t.getSelection(),i.length!=0){var ct=$("#grid_"+t.name+"_records"),f=i[0],r=[],ft=i[i.length-1];if(typeof f=="object"){for(f=i[0].recid,r=[],b=0;;){if(!i[b]||i[b].recid!=f)break;r.push(i[b].column),b++}ft=i[i.length-1].recid}var p=t.get(f,!0),w=t.get(ft,!0),ut=t.get(f),k=$("#grid_"+t.name+"_rec_"+w2utils.escapeId(t.records[p].recid)),s=!1;switch(n.keyCode){case 8:case 46:t.delete(),s=!0,n.stopPropagation();break;case 27:i=t.getSelection(),t.selectNone(),i.length>0&&(typeof i[0]=="object"?t.select({recid:i[0].recid,column:i[0].column}):t.select(i[0])),s=!0;break;case 13:case 32:r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 65:if(!n.metaKey&&!n.ctrlKey)break;t.selectAll(),s=!0;break;case 70:if(!n.metaKey&&!n.ctrlKey)break;$("#grid_"+t.name+"_search_all").focus(),s=!0;break;case 13:if(this.selectType=="row"){if(k.length<=0||t.show.expandColumn!==!0)break;t.toggle(f,n),s=!0}else r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 37:if(l=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[p].recid)).parents("tr"),l.length>0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].set(f,{expanded:!1}),w2ui[o].collapse(f),w2ui[o].click(f),s=!0;break}if(this.selectType=="row"){if(k.length<=0||ut.expanded!==!0)break;t.set(f,{expanded:!1},!0),t.collapse(f,n)}else if(c=ot(r[0]),c!=r[0])if(n.shiftKey){if(g())return;var u=[],tt=[],nt=[];if(r.indexOf(this.last.sel_col)==0&&r.length>1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[r.length-1]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:c});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:c},n);else if(!n.shiftKey)for(h=1;h1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[0]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:a});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:a},n);else if(!n.shiftKey)for(h=0;h0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[d.length-1].recid),s=!0;break}if(n.shiftKey){if(g())return;if(t.selectType=="row")t.last.sel_ind>c&&t.last.sel_ind!=w?t.unselect(t.records[w].recid):t.select(t.records[c].recid);else if(t.last.sel_ind>c&&t.last.sel_ind!=w){c=w,u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.unselect.apply(t,u)}else{u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.select.apply(t,u)}}else t.selectNone(),t.click({recid:t.records[c].recid,column:r[0]},n);t.scrollIntoView(c),n.preventDefault&&n.preventDefault()}else{if(!n.shiftKey)for(h=1;h0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 40:if(k.length<=0)break;if(t.records[w].expanded&&(y=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[w].recid)+"_expanded_row").find(".w2ui-grid"),y.length>0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[0].recid),s=!0;break}if(a=st(w),a!=null){if(n.shiftKey){if(g())return;if(t.selectType=="row")this.last.sel_ind0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.next().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 86:(n.ctrlKey||n.metaKey)&&($("body").append(''),$("#_tmp_copy_data").focus(),setTimeout(function(){t.paste($("#_tmp_copy_data").val()),$("#_tmp_copy_data").remove()},50));break;case 88:(n.ctrlKey||n.metaKey)&&setTimeout(function(){t.delete(!0)},100);case 67:(n.ctrlKey||n.metaKey)&&(rt=t.copy(),$("body").append(''+rt+""),$("#_tmp_copy_data").focus().select(),setTimeout(function(){$("#_tmp_copy_data").remove()},50))}for(u=[187,189],e=48;e<=90;e++)u.push(e);u.indexOf(n.keyCode)==-1||n.ctrlKey||n.metaKey||s||(r.length==0&&r.push(0),u=String.fromCharCode(n.keyCode),n.keyCode==187&&(u="="),n.keyCode==189&&(u="-"),n.shiftKey||(u=u.toLowerCase()),t.editField(f,r[0],u,n),s=!0),s&&n.preventDefault&&n.preventDefault(),t.trigger($.extend(it,{phase:"after"}))}}},scrollIntoView:function(n){var f,t,r,i,u;if(typeof n=="undefined"){if(f=this.getSelection(),f.length==0)return;n=this.get(f[0],!0)}(t=$("#grid_"+this.name+"_records"),t.length!=0)&&((r=this.last.searchIds.length,t.height()>this.recordHeight*(r>0?r:this.records.length))||(r>0&&(n=this.last.searchIds.indexOf(n)),i=Math.floor(t[0].scrollTop/this.recordHeight),u=i+Math.floor(t.height()/this.recordHeight),n==i&&t.animate({scrollTop:t.scrollTop()-t.height()/1.3}),n==u&&t.animate({scrollTop:t.scrollTop()+t.height()/1.3}),(nu)&&t.animate({scrollTop:(n-1)*this.recordHeight})))},dblClick:function(n,t){var i,r,f,u;if(window.getSelection&&window.getSelection().removeAllRanges(),i=null,typeof n=="object"&&(i=n.column,n=n.recid),typeof t=="undefined"&&(t={}),i==null&&t.target&&(r=t.target,r.tagName!="TD"&&(r=$(r).parents("td")[0]),i=parseInt($(r).attr("col"))),f=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:n,column:i,originalEvent:t}),f.isCancelled===!0)return!1;this.selectNone(),u=this.columns[i],u&&$.isPlainObject(u.editable)?this.editField(n,i,null,t):(this.select({recid:n,column:i}),this.last.selected=this.getSelection()),this.trigger($.extend(f,{phase:"after"}))},toggle:function(n){var t=this.get(n);return t.expanded===!0?this.collapse(n):this.expand(n)},expand:function(n){function u(){var r=$("#grid_"+i.name+"_rec_"+t+"_expanded"),u=$("#grid_"+i.name+"_rec_"+t+"_expanded_row .w2ui-expanded1 > div");r.height()<5||(r.css("opacity",1),u.show().css("opacity",1),$("#grid_"+i.name+"_cell_"+i.get(n,!0)+"_expand div").html("-"))}var e=this.get(n),i=this,t=w2utils.escapeId(n),o,f,r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length>0?!1:e.expanded=="none"?!1:(o=1+(this.show.selectColumn?1:0),f="",$("#grid_"+this.name+"_rec_"+t).after(''+(this.show.lineNumbers?'':"")+'\t\t\t\t\t'),r=this.trigger({phase:"before",type:"expand",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded",ready:u}),r.isCancelled===!0)?($("#grid_"+this.name+"_rec_"+t+"_expanded_row").remove(),!1):($("#grid_"+this.name+"_rec_"+t).attr("expanded","yes").addClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded_row").show(),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html(''),e.expanded=!0,setTimeout(u,300),this.trigger($.extend(r,{phase:"after"})),this.resizeRecords(),!0)},collapse:function(n){var u=this.get(n),i=this,t=w2utils.escapeId(n),r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length==0?!1:(r=this.trigger({phase:"before",type:"collapse",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded"}),r.isCancelled===!0)?!1:($("#grid_"+this.name+"_rec_"+t).removeAttr("expanded").removeClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded").css("opacity",0),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html("+"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded").height("0px"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded_row").remove(),delete u.expanded,i.trigger($.extend(r,{phase:"after"})),i.resizeRecords()},300)},200),!0)},sort:function(n,t,i){var f=this.trigger({phase:"before",type:"sort",target:this.name,field:n,direction:t,multiField:i}),r,u,e;if(f.isCancelled===!0)return!1;if(typeof n!="undefined"){r=this.sortData.length;for(u in this.sortData)if(this.sortData[u].field==n){r=u;break}if(typeof t=="undefined"||t==null)if(typeof this.sortData[r]=="undefined")t="asc";else switch(String(this.sortData[r].direction)){case"asc":t="desc";break;case"desc":t="asc";break;default:t="asc"}this.multiSort===!1&&(this.sortData=[],r=0),i!=!0&&(this.sortData=[],r=0),typeof this.sortData[r]=="undefined"&&(this.sortData[r]={}),this.sortData[r].field=n,this.sortData[r].direction=t}else this.sortData=[];e=typeof this.url!="object"?this.url:this.url.get,e?(this.trigger($.extend(f,{phase:"after"})),this.last.xhr_offset=0,this.reload()):(this.localSort(),this.searchData.length>0&&this.localSearch(!0),this.trigger($.extend(f,{phase:"after"})),this.refresh())},copy:function(){var t=this.getSelection(),n,c,i,f,r,o,e;if(t.length==0)return"";if(n="",typeof t[0]=="object"){var s=t[0].column,h=t[0].column,u=[];for(i in t)t[i].columnh&&(h=t[i].column),u.indexOf(t[i].index)==-1&&u.push(t[i].index);u.sort();for(c in u){for(f=u[c],r=s;r<=h;r++)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}}else for(i in t){f=this.get(t[i],!0);for(r in this.columns)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}return(n=n.substr(0,n.length-1),e=this.trigger({phase:"before",type:"copy",target:this.name,text:n}),e.isCancelled===!0)?"":(n=e.text,this.trigger($.extend(e,{phase:"after"})),n)},paste:function(n){var e=this.getSelection(),o=this.get(e[0].recid,!0),u=e[0].column,i=this.trigger({phase:"before",type:"paste",target:this.name,text:n,index:o,column:u}),s,n,a,l,c,h;if(i.isCancelled!==!0){if(n=i.text,this.selectType=="row"||e.length==0){console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected."),this.trigger($.extend(i,{phase:"after"}));return}s=[],n=n.split("\n");for(a in n){var v=n[a].split("\t"),r=0,t=this.records[o],f=[];for(l in v)this.columns[u+r]&&(c=this.columns[u+r].field,t.changed=!0,t.changes=t.changes||{},t.changes[c]=v[l],f.push(u+r),r++);for(h in f)s.push({recid:t.recid,column:f[h]});o++}this.selectNone(),this.select.apply(this,s),this.refresh(),this.trigger($.extend(i,{phase:"after"}))}},resize:function(){var t=this,i=+new Date,n;if(window.getSelection&&window.getSelection().removeAllRanges(),this.box&&$(this.box).attr("name")==this.name)return($(this.box).find("> div").css("width",$(this.box).width()).css("height",$(this.box).height()),n=this.trigger({phase:"before",type:"resize",target:this.name}),n.isCancelled===!0)?!1:(t.resizeBoxes(),t.resizeRecords(),this.trigger($.extend(n,{phase:"after"})),+new Date-i)},refresh:function(){var n=this,h=+new Date,c=typeof this.url!="object"?this.url:this.url.get,o,u,t,r,f,i,e,s;if(this.total<=0&&!c&&this.searchData.length==0&&(this.total=this.records.length,this.buffered=this.total),window.getSelection&&window.getSelection().removeAllRanges(),this.toolbar.disable("edit","delete"),this.box){if(o=this.trigger({phase:"before",target:this.name,type:"refresh"}),o.isCancelled===!0)return!1;this.show.header?$("#grid_"+this.name+"_header").html(this.header+" ").show():$("#grid_"+this.name+"_header").hide(),this.show.toolbar?this.toolbar&&this.toolbar.get("column-on-off")&&this.toolbar.get("column-on-off").checked||($("#grid_"+this.name+"_toolbar").show(),typeof this.toolbar=="object"&&(this.toolbar.refresh(),t=$("#grid_"+n.name+"_search_all"),t.val(this.last.search))):$("#grid_"+this.name+"_toolbar").hide(),this.searchClose(),u=$("#grid_"+n.name+"_search_all"),this.searches.length==0&&(this.last.field="all"),!this.multiSearch&&this.last.field=="all"&&this.searches.length>0&&(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption);for(i in this.searches)this.searches[i].field==this.last.field&&(this.last.caption=this.searches[i].caption);if(this.last.multi?u.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]"):u.attr("placeholder",this.last.caption),this._focus_when_refreshed===!0&&(clearTimeout(n._focus_timer),n._focus_timer=setTimeout(function(){u.length>0&&u[0].focus(),delete n._focus_when_refreshed,delete n._focus_timer},600)),t=this.find({summary:!0},!0),t.length>0){for(r in t)this.summary.push(this.records[t[r]]);for(r=t.length-1;r>=0;r--)this.records.splice(t[r],1);this.total=this.total-t.length,this.buffered=this.buffered-t.length}if(f="",f+='"+this.getRecordsHTML()+'\t'+this.getColumnsHTML()+"",$("#grid_"+this.name+"_body").html(f),this.summary.length>0?$("#grid_"+this.name+"_summary").html(this.getSummaryHTML()).show():$("#grid_"+this.name+"_summary").hide(),this.show.footer?$("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show():$("#grid_"+this.name+"_footer").hide(),this.last.selected.length>0)for(i in this.last.selected)this.get(this.last.selected[i])!=null&&this.select(this.get(this.last.selected[i]).recid);this.searchData.length>0?$("#grid_"+this.name+"_searchClear").show():$("#grid_"+this.name+"_searchClear").hide(),$("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),e=n.find({expanded:!0},!0);for(s in e)n.records[e[s]].expanded=!1;return setTimeout(function(){var t=$.trim($("#grid_"+n.name+"_search_all").val());t!=""&&$(n.box).find(".w2ui-grid-data > div").w2marker(t)},50),this.trigger($.extend(o,{phase:"after"})),n.resize(),n.addRange("selection"),setTimeout(function(){n.resize(),n.scroll()},1),+new Date-h}},render:function(n){function e(n){if(!t.last.move||t.last.move.type!="expand"){t.last.move={x:n.screenX,y:n.screenY,divX:0,divY:0,recid:$(n.target).parents("tr").attr("recid"),column:n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"),type:"select",start:!0};$(document).on("mousemove",r);$(document).on("mouseup",u)}}function r(n){var i,y,o,v,u,s,r,e,f;if(t.last.move&&t.last.move.type=="select"&&(t.last.move.divX=n.screenX-t.last.move.x,t.last.move.divY=n.screenY-t.last.move.y,!(Math.abs(t.last.move.divX)<=1)||!(Math.abs(t.last.move.divY)<=1))&&(t.last.move.start&&t.last.move.recid&&(t.selectNone(),t.last.move.start=!1),i=[],y=n.target.tagName=="TR"?$(n.target).attr("recid"):$(n.target).parents("tr").attr("recid"),typeof y!="undefined")){var h=t.get(t.last.move.recid,!0),l=t.get(y,!0),a=parseInt(t.last.move.column),c=parseInt(n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"));if(h>l&&(u=h,h=l,l=u),u="ind1:"+h+",ind2;"+l+",col1:"+a+",col2:"+c,t.last.move.range!=u){for(t.last.move.range=u,o=h;o<=l;o++)if(!(t.last.searchIds.length>0)||t.last.searchIds.indexOf(o)!=-1)if(t.selectType!="row")for(a>c&&(u=a,a=c,c=u),u=[],v=a;v<=c;v++)t.columns[v].hidden||i.push({recid:t.records[o].recid,column:parseInt(v)});else i.push(t.records[o].recid);if(t.selectType!="row"){r=t.getSelection(),u=[];for(e in i){s=!1;for(f in r)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:i[e].recid,column:i[e].column})}t.select.apply(t,u),u=[];for(f in r){s=!1;for(e in i)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:r[f].recid,column:r[f].column})}t.unselect.apply(t,u)}else if(t.multiSelect){r=t.getSelection();for(e in i)r.indexOf(i[e])==-1&&t.select(i[e]);for(f in r)i.indexOf(r[f])==-1&&t.unselect(r[f])}}}}function u(){t.last.move&&t.last.move.type=="select"&&(delete t.last.move,$(document).off("mousemove",r),$(document).off("mouseup",u))}var t=this,f=+new Date,i;if(window.getSelection&&window.getSelection().removeAllRanges(),typeof n!="undefined"&&n!=null&&($(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),this.box=n),this.box){if(this.last.sortData==null&&(this.last.sortData=this.sortData),i=this.trigger({phase:"before",target:this.name,type:"render",box:n}),i.isCancelled===!0)return!1;$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html('\t\t\t\t\t'),this.selectType!="row"&&$(this.box).addClass("w2ui-ss"),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.initToolbar(),this.toolbar!=null&&this.toolbar.render($("#grid_"+this.name+"_toolbar")[0]),$("#grid_"+this.name+"_footer").html(this.getFooterHTML()),this.refresh(),this.reload();$(this.box).on("mousedown",e);$(this.box).on("selectstart",function(){return!1});if(this.trigger($.extend(i,{phase:"after"})),$(".w2ui-layout").length==0){this.tmp_resize=function(){w2ui[t.name].resize()};$(window).off("resize",this.tmp_resize).on("resize",this.tmp_resize)}return+new Date-f}},destroy:function(){var n=this.trigger({phase:"before",target:this.name,type:"destroy"});if(n.isCancelled===!0)return!1;$(window).off("resize",this.tmp_resize),typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),$(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),delete w2ui[this.name],this.trigger($.extend(n,{phase:"after"}))},initColumnOnOff:function(){var i,n,t,r,u;if(this.show.toolbarColumns){i=this,n='';for(t in this.columns)r=this.columns[t],n+='\t\t'+(this.columns[t].caption==""?"- column "+(t+1)+" -":this.columns[t].caption)+"";n+='',u=typeof this.url!="object"?this.url:this.url.get,u&&(n+='\t\t\t'+w2utils.lang("Skip")+' "+w2utils.lang("Records")+"\t"),n+='\t"+w2utils.lang("Toggle Line Numbers")+'\t"+w2utils.lang("Reset Column Size")+"",n+="",this.toolbar.get("column-on-off").html=n}},columnOnOff:function(n,t,i,r){var h=this.trigger({phase:"before",target:this.name,type:"columnOnOff",checkbox:n,field:i,originalEvent:t}),o,s,e,u,f;if(h.isCancelled===!0)return!1;o=this;for(s in this.records)this.records[s].expanded===!0&&(this.records[s].expanded=!1);if(e=!0,i=="line-numbers")this.show.lineNumbers=!this.show.lineNumbers,this.refresh();else if(i=="skip")w2utils.isInt(r)||(r=0),o.skip(r);else if(i=="resize"){for(u in this.columns)typeof this.columns[u].sizeOriginal!="undefined"&&(this.columns[u].size=this.columns[u].sizeOriginal);this.initResize(),this.resize()}else f=this.getColumn(i),f.hidden?($(n).prop("checked",!0),this.showColumn(f.field)):($(n).prop("checked",!1),this.hideColumn(f.field)),e=!1;this.initColumnOnOff(),e&&setTimeout(function(){$().w2overlay(),o.toolbar.uncheck("column-on-off")},100),this.trigger($.extend(h,{phase:"after"}))},initToolbar:function(){var t,i,r,n;if(typeof this.toolbar.render=="undefined"){t=this.toolbar.items,this.toolbar.items=[],this.toolbar=$().w2toolbar($.extend(!0,{},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.show.toolbarReload&&this.toolbar.items.push($.extend(!0,{},this.buttons.reload)),this.show.toolbarColumns&&(this.toolbar.items.push($.extend(!0,{},this.buttons.columns)),this.initColumnOnOff()),(this.show.toolbarReload||this.show.toolbarColumn)&&this.toolbar.items.push({type:"break",id:"break0"}),this.show.toolbarSearch&&(i='\t'+this.buttons.search.html+'\t\t\t\t\t\t\t \t",this.toolbar.items.push({type:"html",id:"search",html:i}),this.multiSearch&&this.searches.length>0&&this.toolbar.items.push($.extend(!0,{},this.buttons["search-go"]))),this.show.toolbarSearch&&(this.show.toolbarAdd||this.show.toolbarEdit||this.show.toolbarDelete||this.show.toolbarSave)&&this.toolbar.items.push({type:"break",id:"break1"}),this.show.toolbarAdd&&this.toolbar.items.push($.extend(!0,{},this.buttons.add)),this.show.toolbarEdit&&this.toolbar.items.push($.extend(!0,{},this.buttons.edit)),this.show.toolbarDelete&&this.toolbar.items.push($.extend(!0,{},this.buttons["delete"])),this.show.toolbarSave&&((this.show.toolbarAdd||this.show.toolbarDelete||this.show.toolbarEdit)&&this.toolbar.items.push({type:"break",id:"break2"}),this.toolbar.items.push($.extend(!0,{},this.buttons.save)));for(r in t)this.toolbar.items.push(t[r]);n=this;this.toolbar.on("click",function(t){var i=n.trigger({phase:"before",type:"toolbar",target:t.target,originalEvent:t}),r,s,h,u,f,c,e,o;if(i.isCancelled===!0)return!1;r=t.target;switch(r){case"reload":if(s=n.trigger({phase:"before",type:"reload",target:n.name}),s.isCancelled===!0)return!1;h=typeof n.url!="object"?n.url:n.url.get,h?n.clear(!0):(n.last.scrollTop=0,n.last.scrollLeft=0,n.last.range_start=null,n.last.range_end=null),n.reload(),n.trigger($.extend(s,{phase:"after"}));break;case"column-on-off":for(u in n.columns)n.columns[u].hidden?$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!1):$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!0);n.initResize(),n.resize();break;case"search-advanced":if(f=this,c=this.get(r),c.checked)n.searchClose(),setTimeout(function(){f.uncheck(r)},1);else{n.searchOpen(),t.originalEvent.stopPropagation();function l(){f.uncheck(r),$(document).off("click","body",l)}$(document).on("click","body",l)}break;case"add":i=n.trigger({phase:"before",target:n.name,type:"add",recid:null}),n.trigger($.extend(i,{phase:"after"}));break;case"edit":e=n.getSelection(),o=null,e.length==1&&(o=e[0]),i=n.trigger({phase:"before",target:n.name,type:"edit",recid:o}),n.trigger($.extend(i,{phase:"after"}));break;case"delete":n.delete();break;case"save":n.save()}n.trigger($.extend(i,{phase:"after"}))})}return},initSearches:function(){var o=this,t,n,r,e,i,u,f;for(t in this.searches){n=this.searches[t],r=this.getSearchData(n.field);switch(String(n.type).toLowerCase()){case"alphaNumeric":case"text":$("#grid_"+this.name+"_operator_"+t).val("begins with");break;case"int":case"float":case"hex":case"money":case"date":$("#grid_"+this.name+"_field_"+t).w2field("clear").w2field(n.type),$("#grid_"+this.name+"_field2_"+t).w2field("clear").w2field(n.type);break;case"list":e='--';for(i in n.items)$.isPlainObject(n.items[i])?(u=n.items[i].id,f=n.items[i].text,typeof u=="undefined"&&typeof n.items[i].value!="undefined"&&(u=n.items[i].value),typeof f=="undefined"&&typeof n.items[i].caption!="undefined"&&(f=n.items[i].caption),u==null&&(u=""),e+=''+f+""):e+=''+n.items[i]+"";$("#grid_"+this.name+"_field_"+t).html(e)}r!=null&&($("#grid_"+this.name+"_operator_"+t).val(r.operator).trigger("change"),$.isArray(r.value)?r.operator=="in"?$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"):($("#grid_"+this.name+"_field_"+t).val(r.value[0]).trigger("change"),$("#grid_"+this.name+"_field2_"+t).val(r.value[1]).trigger("change")):typeof r.value!="udefined"&&$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"))}$("#w2ui-overlay .w2ui-grid-searches *[rel=search]").on("keypress",function(n){n.keyCode==13&&o.search()})},initResize:function(){var n=this;$(this.box).find(".w2ui-resizer").off("click").on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault&&n.preventDefault()}).off("mousedown").on("mousedown",function(t){var r,i,f,u;t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),n.resizing=!0,n.last.tmp={x:t.screenX,y:t.screenY,gx:t.screenX,gy:t.screenY,col:parseInt($(this).attr("name"))},t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault&&t.preventDefault();for(r in n.columns)typeof n.columns[r].sizeOriginal=="undefined"&&(n.columns[r].sizeOriginal=n.columns[r].size),n.columns[r].size=n.columns[r].sizeCalculated;i={phase:"before",type:"columnResize",target:n.name,column:n.last.tmp.col,field:n.columns[n.last.tmp.col].field},i=n.trigger($.extend(i,{resizeBy:0,originalEvent:t})),f=function(t){if(n.resizing==!0){if(t||(t=window.event),i=n.trigger($.extend(i,{resizeBy:t.screenX-n.last.tmp.gx,originalEvent:t})),i.isCancelled===!0){i.isCancelled=!1;return}n.last.tmp.x=t.screenX-n.last.tmp.x,n.last.tmp.y=t.screenY-n.last.tmp.y,n.columns[n.last.tmp.col].size=parseInt(n.columns[n.last.tmp.col].size)+n.last.tmp.x+"px",n.resizeRecords(),n.last.tmp.x=t.screenX,n.last.tmp.y=t.screenY}},u=function(t){delete n.resizing,$(document).off("mousemove","body"),$(document).off("mouseup","body"),n.resizeRecords(),n.trigger($.extend(i,{phase:"after",originalEvent:t}))};$(document).on("mousemove","body",f);$(document).on("mouseup","body",u)}).each(function(n,t){var i=$(t).parent();$(t).css({height:"25px","margin-left":i.width()-3+"px"})})},resizeBoxes:function(){var o=$(this.box).find("> div"),n=$("#grid_"+this.name+"_header"),i=$("#grid_"+this.name+"_toolbar"),r=$("#grid_"+this.name+"_summary"),t=$("#grid_"+this.name+"_footer"),u=$("#grid_"+this.name+"_body"),e=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");this.show.header&&n.css({top:"0px",left:"0px",right:"0px"}),this.show.toolbar&&i.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+"px",left:"0px",right:"0px"}),this.show.footer&&t.css({bottom:"0px",left:"0px",right:"0px"}),this.summary.length>0&&r.css({bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+"px",left:"0px",right:"0px"}),u.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+(this.show.toolbar?w2utils.getSize(i,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+(this.summary.length>0?w2utils.getSize(r,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){var i=this,rt,c,h,d,y,e,s,b,u,t,n;$(this.box).find(".w2ui-empty-record").remove();var g=$(this.box),v=$(this.box).find("> div"),nt=$("#grid_"+this.name+"_header"),tt=$("#grid_"+this.name+"_toolbar"),a=$("#grid_"+this.name+"_summary"),it=$("#grid_"+this.name+"_footer"),l=$("#grid_"+this.name+"_body"),r=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");if(this.fixedBody?(rt=v.height()-(this.show.header?w2utils.getSize(nt,"height"):0)-(this.show.toolbar?w2utils.getSize(tt,"height"):0)-(a.css("display")!="none"?w2utils.getSize(a,"height"):0)-(this.show.footer?w2utils.getSize(it,"height"):0),l.css("height",rt)):setTimeout(function(){var n=w2utils.getSize(r,"height")+w2utils.getSize($("#grid_"+i.name+"_records table"),"height");i.height=n+w2utils.getSize(v,"+height")+(i.show.header?w2utils.getSize(nt,"height"):0)+(i.show.toolbar?w2utils.getSize(tt,"height"):0)+(a.css("display")!="none"?w2utils.getSize(a,"height"):0)+(i.show.footer?w2utils.getSize(it,"height"):0),v.css("height",i.height),l.css("height",n),g.css("height",w2utils.getSize(v,"height")+w2utils.getSize(g,"+height"))},1),c=!1,h=!1,l.width()<$(f).find(">table").width()&&(c=!0),l.height()-r.height()<$(f).find(">table").height()+(c?w2utils.scrollBarSize():0)&&(h=!0),this.fixedBody||(h=!1,c=!1),c||h?(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":c?"auto":"hidden","overflow-y":h?"auto":"hidden"})):(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px",overflow:"hidden"}),f.length>0&&(this.last.scrollTop=0,this.last.scrollLeft=0)),this.show.emptyRecords&&!h&&(d=Math.floor(f.height()/this.recordHeight)+1,this.fixedBody))for(y=this.buffered;y<=d;y++){for(e="",e+='',this.show.lineNumbers&&(e+=''),this.show.selectColumn&&(e+=''),this.show.expandColumn&&(e+=''),s=0;!0&&this.columns.length>0;){if(n=this.columns[s],n.hidden)if(s++,typeof this.columns[s]=="undefined")break;else continue;if(e+='',s++,typeof this.columns[s]=="undefined")break}e+='',e+="",$("#grid_"+this.name+"_records > table").append(e)}if(l.length>0){var p=parseInt(l.width())-(h?w2utils.scrollBarSize():0)-(this.show.lineNumbers?34:0)-(this.show.selectColumn?26:0)-(this.show.expandColumn?26:0),k=p,o=0,w=!1;for(t=0;tk&&n.hidden!==!0&&(n.hidden=!0,w=!0),n.gridMinWidth0)for(t=0;tparseInt(n.max)&&(n.sizeCalculated=n.max+"px"),b+=parseInt(n.sizeCalculated));if(u=parseInt(k)-parseInt(b),u>0&&o>0)for(t=0;;){if(n=this.columns[t],typeof n=="undefined"){t=0;continue}if(n.hidden||n.sizeType=="px"){t++;continue}if(n.sizeCalculated=parseInt(n.sizeCalculated)+1+"px",u--,u==0)break;t++}else u>0&&r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();r.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-head-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),r.find("> table > tbody > tr").length==3&&r.find("> table > tbody > tr:nth-child(1) td").html("").css({height:"0px",border:"0px",padding:"0px",margin:"0px"}),f.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",(u>0&&o==0?u:0)+"px")}),a.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),this.initResize(),this.refreshRanges(),this.last.scrollTop!=""&&f.length>0&&(r.prop("scrollLeft",this.last.scrollLeft),f.prop("scrollTop",this.last.scrollTop),f.prop("scrollLeft",this.last.scrollLeft))},getSearchesHTML:function(){for(var i='',f=!1,n,u,r,t=0;t",f=!0),typeof n.inTag=="undefined"&&(n.inTag=""),typeof n.outTag=="undefined"&&(n.outTag=""),typeof n.type=="undefined"&&(n.type="text"),n.type=="text"&&(r='\t'+w2utils.lang("is")+'\t'+w2utils.lang("begins with")+'\t'+w2utils.lang("contains")+'\t'+w2utils.lang("ends with")+""),(n.type=="int"||n.type=="float"||n.type=="date")&&(r='\t"+w2utils.lang("is")+""+(n.type=="date"?"":''+w2utils.lang("in")+"")+'\t'+w2utils.lang("between")+""),n.type=="list"&&(r='is '),i+='\t'+u+'\t'+n.caption+'\t'+r+'\t';switch(n.type){case"alphaNumeric":case"text":i+='";break;case"int":case"float":case"hex":case"money":case"date":i+=' - ";break;case"list":i+='"}i+=n.outTag+"\t"}return i+='\t\t\t\t\t\t\t\t\t\t'},getColumnsHTML:function(){function r(){var i="",u,f,t,r,e,o,s;for(n.columnGroups[n.columnGroups.length-1].caption!=""&&n.columnGroups.push({caption:""}),n.show.lineNumbers&&(i+='\t '),n.show.selectColumn&&(i+='\t '),n.show.expandColumn&&(i+='\t '),u=0,f=0;f'),i+='"+s+'\t'+(r.caption==""?" ":r.caption)+"\t"}else i+='\t'+(t.caption==""?" ":t.caption)+"\t";u+=t.span}return i+=""}function t(t){var u="",f,s,r,i,c,e,o,h;for(n.show.lineNumbers&&(u+='\t#"),n.show.selectColumn&&(u+='\t\t\t\t"),n.show.expandColumn&&(u+='\t '),f=0,s=0,r=0;r'),u+='"+h+'\t'+(i.caption==""?" ":i.caption)+"\t")}return u+=' ',u+=""}var n=this,i="";return this.show.columnHeaders&&(i=this.columnGroups.length>0?t(!0)+r()+t(!1):t(!0)),i},getRecordsHTML:function(){var r,i,n,t;for(this.show_extra=this.buffered>300?30:300,r=$("#grid_"+this.name+"_records"),i=Math.floor(r.height()/this.recordHeight)+this.show_extra+1,this.fixedBody||(i=this.buffered),n=""+this.getRecordHTML(-1,0),n+='\t',t=0;t\t\t',this.last.range_start=0,this.last.range_end=i,n},getSummaryHTML:function(){var t,n;if(this.summary.length!=0){for(t="",n=0;n"}},scroll:function(){function d(){i.markSearchResults!==!1&&(clearTimeout(i.last.marker_timer),i.last.marker_timer=setTimeout(function(){var n=[],r,t;for(r in i.searchData)t=i.searchData[r],$.inArray(t.value,n)==-1&&n.push(t.value);n.length>0&&$(i.box).find(".w2ui-grid-data > div").w2marker(n)},50))}var nt=+new Date,i=this,t=$("#grid_"+this.name+"_records"),l,v,p,f,e,h,s,y,k,u,o,r,g,a,b,w,c;if(this.records.length!=0&&t.length!=0&&t.height()!=0){if(this.show_extra=this.buffered>300?30:300,t.height()0&&this.refresh();return}if(l=Math.floor(t[0].scrollTop/this.recordHeight+1),v=Math.floor(t[0].scrollTop/this.recordHeight+1)+Math.round(t.height()/this.recordHeight),l>this.buffered&&(l=this.buffered),v>this.buffered&&(v=this.buffered),p=typeof this.url!="object"?this.url:this.url.get,$("#grid_"+this.name+"_footer .w2ui-footer-right").html(w2utils.formatNumber(this.offset+l)+"-"+w2utils.formatNumber(this.offset+v)+" "+w2utils.lang("of")+" "+w2utils.formatNumber(this.total)+(p?" ("+w2utils.lang("buffered")+" "+w2utils.formatNumber(this.buffered)+(this.offset>0?", skip "+w2utils.formatNumber(this.offset):"")+")":"")),p||this.fixedBody&&!(this.total<=300)){if(f=Math.floor(t[0].scrollTop/this.recordHeight)-this.show_extra,e=f+Math.floor(t.height()/this.recordHeight)+this.show_extra*2+1,f<1&&(f=1),e>this.total&&(e=this.total),h=t.find("#grid_"+this.name+"_rec_top"),s=t.find("#grid_"+this.name+"_rec_bottom"),String(h.next().prop("id")).indexOf("_expanded_row")!=-1&&h.next().remove(),String(s.prev().prop("id")).indexOf("_expanded_row")!=-1&&s.prev().remove(),y=parseInt(h.next().attr("line")),k=parseInt(s.prev().attr("line")),y=y-this.show_extra+2&&f>1)return;for(;;){if(u=t.find("#grid_"+this.name+"_rec_bottom").prev(),u.attr("line")=="top")break;if(parseInt(u.attr("line"))>e)u.remove();else break}for(u=t.find("#grid_"+this.name+"_rec_top").next(),o=u.attr("line"),o=="bottom"&&(o=e),r=parseInt(o)-1;r>=f;r--)this.records[r-1]&&(this.records[r-1].expanded===!0&&(this.records[r-1].expanded=!1),h.after(this.getRecordHTML(r-1,r)));d(),setTimeout(function(){i.refreshRanges()},0)}if(g=(f-1)*i.recordHeight,a=(this.buffered-e)*i.recordHeight,a<0&&(a=0),h.css("height",g+"px"),s.css("height",a+"px"),i.last.range_start=f,i.last.range_end=e,b=Math.floor(t[0].scrollTop/this.recordHeight),w=b+Math.floor(t.height()/this.recordHeight),w+10>this.buffered&&this.last.pull_more!==!0&&this.buffered'),i.last.pull_more=!0,i.last.xhr_offset+=i.limit,i.request("get-records")});c.find("td").text().indexOf("Load")==-1&&c.find("td").html("Load "+i.limit+" More...")}this.buffered>=this.total-this.offset&&$("#grid_"+this.name+"_rec_more").hide();return}}},getRecordHTML:function(n,t,i){var r="",c,a,v,o,e,u,f,s,l;if(n==-1){r+='',this.show.lineNumbers&&(r+=''),this.show.selectColumn&&(r+=''),this.show.expandColumn&&(r+='');for(c in this.columns)this.columns[c].hidden||(r+='');return r+='',r+=""}if(a=typeof this.url!="object"?this.url:this.url.get,i!==!0)if(this.searchData.length>0&&!a){if(n>=this.last.searchIds.length)return"";n=this.last.searchIds[n],record=this.records[n]}else{if(n>=this.records.length)return"";record=this.records[n]}else{if(n>=this.summary.length)return"";record=this.summary[n]}if(!record)return"";for(v=w2utils.escapeId(record.recid),o=!1,record.selected&&this.selectType=="row"&&(o=!0),r+='",this.show.lineNumbers&&(r+=''+(i!==!0?""+t+"":"")+""),this.show.selectColumn&&(r+=''+(i!==!0?'\t\t\t\t":"")+""),this.show.expandColumn&&(e="",e=record.expanded===!0?"-":"+",record.expanded=="none"&&(e=""),record.expanded=="spinner"&&(e=''),r+=''+(i!==!0?'\t\t\t"+e+" ":"")+""),u=0;;){if(f=this.columns[u],f.hidden)if(u++,typeof this.columns[u]=="undefined")break;else continue;var y=record.changed&&record.changes[f.field],p=this.getCellHTML(n,u,i),h="";if(typeof f.render=="string"&&(s=f.render.toLowerCase().split(":"),$.inArray(s[0],["number","int","float","money","percent"])!=-1&&(h="text-align: right"),$.inArray(s[0],["date"])!=-1&&(h="text-align: right")),l=!1,record.selected&&$.inArray(u,record.selectedColumns)!=-1&&(l=!0),r+='"+p+"",u++,typeof this.columns[u]=="undefined")break}return r+='',r+=""},getCellHTML:function(n,t,i){var f=this.columns[t],e=i!==!0?this.records[n]:this.summary[n],r=this.parseField(e,f.field),c=e.changed&&typeof e.changes[f.field]!="undefined",s;if(c&&(r=e.changes[f.field]),(r==null||typeof r=="undefined")&&(r=""),typeof f.render!="undefined"){if(typeof f.render=="function"&&(r=f.render.call(this,e,n,t),r.length>=4&&r.substr(0,4)!=""+r+"")),typeof f.render=="object"&&(r=""+f.render[r]+""),typeof f.render=="string"){var u=f.render.toLowerCase().split(":"),h="",o="";$.inArray(u[0],["number","int","float","money","percent"])!=-1&&(typeof u[1]!="undefined"&&w2utils.isInt(u[1])||(u[1]=0),u[1]>20&&(u[1]=20),u[1]<0&&(u[1]=0),u[0]=="money"&&(u[1]=2,h=w2utils.settings.currencySymbol),u[0]=="percent"&&(o="%",u[1]!=="0"&&(u[1]=1)),u[0]=="int"&&(u[1]=0),r=""+h+w2utils.formatNumber(Number(r).toFixed(u[1]))+o+""),u[0]=="date"&&((typeof u[1]=="undefined"||u[1]=="")&&(u[1]=w2utils.settings.date_display),r=""+h+w2utils.formatDate(r,u[1])+o+""),u[0]=="age"&&(r=""+h+w2utils.age(r)+o+"")}}else this.show.recordTitles?(s=String(r).replace(/"/g,"''"),typeof f.title!="undefined"&&(typeof f.title=="function"&&(s=f.title.call(this,e,n,t)),typeof f.title=="string"&&(s=f.title)),r=''+r+""):r=""+r+"";return(r==null||typeof r=="undefined")&&(r=""),r},getFooterHTML:function(){return'\t\t\t'},status:function(n){var r,t,i;typeof n!="undefined"?$("#grid_"+this.name+"_footer").find(".w2ui-footer-left").html(n):(r="",t=this.getSelection(),t.length>0&&(r=String(t.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")+" "+w2utils.lang("selected"),i=t[0],typeof i=="object"&&(i=i.recid+", "+w2utils.lang("Column")+": "+i.column),t.length==1&&(r=w2utils.lang("Record ID")+": "+i+" ")),$("#grid_"+this.name+"_footer .w2ui-footer-left").html(r),t.length==1?this.toolbar.enable("edit"):this.toolbar.disable("edit"),t.length>=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"))},lock:function(n,t){var i=$(this.box).find("> div:first-child");setTimeout(function(){w2utils.lock(i,n,t)},10)},unlock:function(){var n=this.box;setTimeout(function(){w2utils.unlock(n)},25)},parseField:function(n,t){var i="",r,u;try{i=n,r=String(t).split(".");for(u in r)i=i[r[u]]}catch(f){i=""}return i}},$.extend(w2grid.prototype,w2utils.event),w2obj.grid=w2grid}(jQuery),function(n){var t=function(t){this.box=null,this.name=null,this.panels=[],this.tmp={},this.padding=1,this.resizer=4,this.style="",this.onShow=null,this.onHide=null,this.onResizing=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.layout,t)};n.fn.w2layout=function(i){function s(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.tabs),u==null||r==null)?!1:(n.isArray(r)&&(r={tabs:r}),n().w2destroy(t.name+"_"+i+"_tabs"),u.tabs=n().w2tabs(n.extend({},r,{owner:t,name:t.name+"_"+i+"_tabs"})),u.show.tabs=!0,!0)}function o(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.toolbar),u==null||r==null)?!1:(n.isArray(r)&&(r={items:r}),n().w2destroy(t.name+"_"+i+"_toolbar"),u.toolbar=n().w2toolbar(n.extend({},r,{owner:t,name:t.name+"_"+i+"_toolbar"})),u.show.toolbar=!0,!0)}var f,r,u,e;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return e=w2ui[n(this).attr("name")],e[i].apply(e,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2layout")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}f=i.panels,r=new t(i),n.extend(r,{handlers:[],panels:[]});for(u in f)r.panels[u]=n.extend(!0,{},t.prototype.panel,f[u]),(n.isPlainObject(r.panels[u].tabs)||n.isArray(r.panels[u].tabs))&&s(r,f[u].type),(n.isPlainObject(r.panels[u].toolbar)||n.isArray(r.panels[u].toolbar))&&o(r,f[u].type);for(u in{top:"",left:"",main:"",preview:"",right:"",bottom:""})r.get(u)==null&&(r.panels[u]=n.extend(!0,{},t.prototype.panel,{type:u,hidden:!0,size:50}));return n(this).length>0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={panel:{type:null,size:100,minSize:20,hidden:!1,resizable:!1,overflow:"auto",style:"",content:"",tabs:null,toolbar:null,width:null,height:null,show:{toolbar:!1,tabs:!1},onRefresh:null,onShow:null,onHide:null},html:function(n,t,i){return this.content(n,t,i)},content:function(t,i,r){var s=this,u=this.get(t),o,h,c,e,f;return t=="css"?(n("#layout_"+s.name+"_panel_css").html(""),!0):u==null?!1:n("#layout_"+this.name+"_panel2_"+u.type).length>0?!1:(n("#layout_"+this.name+"_panel_"+u.type).scrollTop(0),i==null||typeof i=="undefined")?u.content:i instanceof jQuery?(console.log("ERROR: You can not pass jQuery object to w2layout.content() method"),!1):(o=n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-content"),h=n(o).position().top,o.attr("class","w2ui-panel-content"),o.length>0&&typeof u.style!="undefined"&&(o[0].style.cssText=u.style),u.content==""?(u.content=i,u.hidden||this.refresh(t)):(u.content=i,u.hidden||(r!=null&&r!=""&&typeof r!="undefined"?(c="layout_"+this.name+"_panel_"+u.type,e=n("#"+c+" > .w2ui-panel-content"),e.after(''),f=n("#"+c+" > .w2ui-panel-content.new-panel"),e.css("top",h),f.css("top",h),typeof i=="object"?(i.box=f[0],i.render()):f.html(i),w2utils.transition(e[0],f[0],r,function(){e.remove(),f.removeClass("new-panel"),f.css("overflow",u.overflow),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100)})):u.hidden||this.refresh(t))),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100),!0)},load:function(t,i,r,u){var f=this;return t=="css"?(n.get(i,function(n,i,r){f.content(t,r.responseText),u&&u()}),!0):this.get(t)!=null?(n.get(i,function(n,i,e){f.content(t,e.responseText,r),u&&u(),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){f.resize()},100)}),!0):!1},sizeTo:function(t,i){var r=this,u=r.get(t);return u==null?!1:(n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".35s","-moz-transition":".35s","-ms-transition":".35s","-o-transition":".35s"}),setTimeout(function(){r.set(t,{size:i})},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.resize()},500),!0)},show:function(t,i){var r=this,f=this.trigger({phase:"before",type:"show",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!1,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"}),u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"})},250),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},hide:function(t,i){var r=this,f=this.trigger({phase:"before",type:"hide",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!0,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n("#layout_"+r.name+"_resizer_"+t).hide(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(n("#layout_"+r.name+"_resizer_"+t).hide(),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},toggle:function(n,t){var i=this.get(n);return i==null?!1:i.hidden?this.show(n,t):this.hide(n,t)},set:function(t,i){var r=this.get(t,!0);return r==null?!1:(n.extend(this.panels[r],i),this.refresh(t),this.resize(),!0)},get:function(n,t){var r=null,i;for(i in this.panels)if(this.panels[i].type==n)return t===!0?i:this.panels[i];return null},el:function(t){var i=n("#layout_"+this.name+"_panel_"+t+" .w2ui-panel-content");return i.length!=1?null:i[0]},hideToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").hide(),this.resize())},showToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").show(),this.resize())},toggleToolbar:function(n){var t=this.get(n);t&&(t.show.toolbar?this.hideToolbar(n):this.showToolbar(n))},hideTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").hide(),this.resize())},showTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").show(),this.resize())},toggleTabs:function(n){var t=this.get(n);t&&(t.show.tabs?this.hideTabs(n):this.showTabs(n))},render:function(t){function a(){i.tmp.events={resize:function(){w2ui[i.name].resize()},resizeStart:c,mousemove:h,mouseup:s};n(window).on("resize",i.tmp.events.resize);n(document).on("mousemove",i.tmp.events.mousemove);n(document).on("mouseup",i.tmp.events.mouseup)}function c(t,r){i.box&&(r||(r=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.tmp.resize={type:t,x:r.screenX,y:r.screenY,div_x:0,div_y:0,value:0},(t=="left"||t=="right")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.left)),(t=="top"||t=="preview"||t=="bottom")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.top)))}function s(t){var u,f;if(i.box&&(t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),typeof i.tmp.resize!="undefined")){if(i.tmp.div_x!=0||i.tmp.resize.div_y!=0){var e=i.get("top"),o=i.get("bottom"),r=i.get(i.tmp.resize.type),h=parseInt(n(i.box).height()),c=parseInt(n(i.box).width()),s=String(r.size);switch(i.tmp.resize.type){case"top":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_y,f=0;break;case"bottom":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=0;break;case"preview":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=(e&&!e.hidden?e.sizeCalculated:0)+(o&&!o.hidden?o.sizeCalculated:0);break;case"left":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_x,f=0;break;case"right":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_x,f=0}r.size=s.substr(s.length-1)=="%"?Math.floor(u*100/(r.type=="left"||r.type=="right"?c:h-f)*100)/100+"%":u,i.resize()}n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type).removeClass("active"),delete i.tmp.resize}}function h(t){var f,u,r;if(i.box&&(t||(t=window.event),typeof i.tmp.resize!="undefined")){if(f=i.get(i.tmp.resize.type),u=i.trigger({phase:"before",type:"resizing",target:i.tmp.resize.type,object:f,originalEvent:t}),u.isCancelled===!0)return!1;r=n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type),r.hasClass("active")||r.addClass("active"),i.tmp.resize.div_x=t.screenX-i.tmp.resize.x,i.tmp.resize.div_y=t.screenY-i.tmp.resize.y,i.tmp.resizing=="left"&&i.get("left").minSize-i.tmp.resize.div_x>i.get("left").width&&(i.tmp.resize.div_x=i.get("left").minSize-i.get("left").width),i.tmp.resize.type=="left"&&i.get("main").minSize+i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").width-i.get("main").minSize),i.tmp.resize.type=="right"&&i.get("right").minSize+i.tmp.resize.div_x>i.get("right").width&&(i.tmp.resize.div_x=i.get("right").width-i.get("right").minSize),i.tmp.resize.type=="right"&&i.get("main").minSize-i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").minSize-i.get("main").width),i.tmp.resize.type=="top"&&i.get("top").minSize-i.tmp.resize.div_y>i.get("top").height&&(i.tmp.resize.div_y=i.get("top").minSize-i.get("top").height),i.tmp.resize.type=="top"&&i.get("main").minSize+i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").height-i.get("main").minSize),i.tmp.resize.type=="bottom"&&i.get("bottom").minSize+i.tmp.resize.div_y>i.get("bottom").height&&(i.tmp.resize.div_y=i.get("bottom").height-i.get("bottom").minSize),i.tmp.resize.type=="bottom"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height),i.tmp.resize.type=="preview"&&i.get("preview").minSize+i.tmp.resize.div_y>i.get("preview").height&&(i.tmp.resize.div_y=i.get("preview").height-i.get("preview").minSize),i.tmp.resize.type=="preview"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height);switch(i.tmp.resize.type){case"top":case"preview":case"bottom":i.tmp.resize.div_x=0,r.length>0&&(r[0].style.top=i.tmp.resize.value+i.tmp.resize.div_y+"px");break;case"left":case"right":i.tmp.resize.div_y=0,r.length>0&&(r[0].style.left=i.tmp.resize.value+i.tmp.resize.div_x+"px")}i.trigger(n.extend(u,{phase:"after"}))}}var i=this,o,f,r,u,l,e;if((window.getSelection&&window.getSelection().removeAllRanges(),o=+new Date,f=i.trigger({phase:"before",type:"render",target:i.name,box:t}),f.isCancelled===!0)||(typeof t!="undefined"&&t!=null&&(n(i.box).find("#layout_"+i.name+"_panel_main").length>0&&n(i.box).removeAttr("name").removeClass("w2ui-layout").html(""),i.box=t),!i.box))return!1;n(i.box).attr("name",i.name).addClass("w2ui-layout").html(""),n(i.box).length>0&&(n(i.box)[0].style.cssText+=i.style),r=["top","left","main","preview","right","bottom"];for(u in r)l=i.get(r[u]),e='\t\t\t',n(i.box).find(" > div").append(e);return n(i.box).find(" > div").append('0&&(f.css("overflow",i.overflow)[0].style.cssText+=";"+i.style),i.resizable===!0?n("#layout_"+this.name+"_resizer_"+t).show():n("#layout_"+this.name+"_resizer_"+t).hide(),typeof i.content=="object"&&i.content.render?(i.content.box=n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content")[0],i.content.render()):n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content").html(i.content),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-tabs"),i.show.tabs?u.find("[name="+i.tabs.name+"]").length==0&&i.tabs!=null?u.w2render(i.tabs):i.tabs.refresh():u.html("").removeClass("w2ui-tabs").hide(),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-toolbar"),i.show.toolbar?u.find("[name="+i.toolbar.name+"]").length==0&&i.toolbar!=null?u.w2render(i.toolbar):i.toolbar.refresh():u.html("").removeClass("w2ui-toolbar").hide()}else{if(n("#layout_"+r.name+"_panel_main").length<=0){r.render();return}r.resize();for(i in this.panels)r.refresh(this.panels[i].type)}return r.trigger(n.extend(e,{phase:"after"})),+new Date-o}},resize:function(){var ut,nt,y,h,u,tt,b,a,p;if((window.getSelection&&window.getSelection().removeAllRanges(),!this.box)||(ut=+new Date,nt=this.trigger({phase:"before",type:"resize",target:this.name,panel:this.tmp.resizing}),nt.isCancelled===!0))return!1;this.padding<0&&(this.padding=0),y=parseInt(n(this.box).width()),h=parseInt(n(this.box).height()),n(this.box).find(" > div").css({width:y+"px",height:h+"px"});var p=this,it=this.get("main"),l=this.get("preview"),s=this.get("left"),c=this.get("right"),r=this.get("top"),f=this.get("bottom"),et=!0,ft=l!=null&&l.hidden!=!0?!0:!1,d=s!=null&&s.hidden!=!0?!0:!1,rt=c!=null&&c.hidden!=!0?!0:!1,w=r!=null&&r.hidden!=!0?!0:!1,g=f!=null&&f.hidden!=!0?!0:!1;for(a in{top:"",left:"",right:"",bottom:"",preview:""})u=this.get(a),tt=String(u.size),u&&tt.substr(tt.length-1)=="%"?(b=h,u.type=="preview"&&(b=b-(r&&!r.hidden?r.sizeCalculated:0)-(f&&!f.hidden?f.sizeCalculated:0)),u.sizeCalculated=parseInt((u.type=="left"||u.type=="right"?y:b)*parseFloat(u.size)/100)):u.sizeCalculated=parseInt(u.size),u.sizeCalculatedthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_top").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("top",n),!1}))}else n("#layout_"+this.name+"_panel_top").hide();if(s!=null&&s.hidden!=!0){var o=0,e=0+(w?r.sizeCalculated+this.padding:0),t=s.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_left");window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_left").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("left",n),!1}))}else n("#layout_"+this.name+"_panel_left").hide(),n("#layout_"+this.name+"_resizer_left").hide();if(c!=null&&c.hidden!=!0){var o=y-c.sizeCalculated,e=0+(w?r.sizeCalculated+this.padding:0),t=c.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0);n("#layout_"+this.name+"_panel_right").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),c.width=t,c.height=i,c.resizable&&(o=o-this.padding,t=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_right").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("right",n),!1}))}else n("#layout_"+this.name+"_panel_right").hide();if(f!=null&&f.hidden!=!0){var o=0,e=h-f.sizeCalculated,t=y,i=f.sizeCalculated;n("#layout_"+this.name+"_panel_bottom").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),f.width=t,f.height=i,f.resizable&&(e=e-(this.padding==0?0:this.padding),i=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_bottom").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("bottom",n),!1}))}else n("#layout_"+this.name+"_panel_bottom").hide();var o=0+(d?s.sizeCalculated+this.padding:0),e=0+(w?r.sizeCalculated+this.padding:0),t=y-(d?s.sizeCalculated+this.padding:0)-(rt?c.sizeCalculated+this.padding:0),i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0)-(ft?l.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_main");if(window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeight0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_preview").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("preview",n),!1}))}else n("#layout_"+this.name+"_panel_preview").hide();for(a in{top:"",left:"",main:"",preview:"",right:"",bottom:""}){var k=this.get(a),u="#layout_"+this.name+"_panel_"+a+" > .w2ui-panel-",h=0;k.show.tabs&&(k.tabs!=null&&w2ui[this.name+"_"+a+"_tabs"]&&w2ui[this.name+"_"+a+"_tabs"].resize(),h+=w2utils.getSize(n(u+"tabs").css({display:"block"}),"height")),k.show.toolbar&&(k.toolbar!=null&&w2ui[this.name+"_"+a+"_toolbar"]&&w2ui[this.name+"_"+a+"_toolbar"].resize(),h+=w2utils.getSize(n(u+"toolbar").css({top:h+"px",display:"block"}),"height")),n(u+"content").css({display:"block"}).css({top:h+"px"})}return p=this,clearTimeout(this._resize_timer),this._resize_timer=setTimeout(function(){var t,i;for(t in w2ui)typeof w2ui[t].resize=="function"&&(w2ui[t].panels=="undefined"&&w2ui[t].resize(),i=n(w2ui[t].box).parents(".w2ui-layout"),i.length>0&&i.attr("name")==p.name&&w2ui[t].resize())},100),this.trigger(n.extend(nt,{phase:"after"})),+new Date-ut},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});return t.isCancelled===!0?!1:typeof w2ui[this.name]=="undefined"?!1:(n(this.box).find("#layout_"+this.name+"_panel_main").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-layout").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})),this.tmp.events&&this.tmp.events.resize&&n(window).off("resize",this.tmp.events.resize),this.tmp.events&&this.tmp.events.mousemove&&n(document).off("mousemove",this.tmp.events.mousemove),this.tmp.events&&this.tmp.events.mouseup&&n(document).off("mouseup",this.tmp.events.mouseup),!0)},lock:function(t,i,r){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var u="#layout_"+this.name+"_panel_"+t;w2utils.lock(u,i,r)},unlock:function(t){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var i="#layout_"+this.name+"_panel_"+t;w2utils.unlock(i)}},n.extend(t.prototype,w2utils.event),w2obj.layout=t}(jQuery),w2popup={},function(n){n.fn.w2popup=function(t,i){typeof t=="undefined"&&(i={},t="open"),n.isPlainObject(t)&&(i=t,t="open"),t=t.toLowerCase(),t=="load"&&typeof i=="string"&&(i={url:i}),t=="open"&&typeof i.url!="undefined"&&(t="load"),typeof i=="undefined"&&(i={});var r={};return n(this).length>0&&(n(this).find("div[rel=title], div[rel=body], div[rel=buttons]").length>0?(n(this).find("div[rel=title]").length>0&&(r.title=n(this).find("div[rel=title]").html()),n(this).find("div[rel=body]").length>0&&(r.body=n(this).find("div[rel=body]").html(),r.style=n(this).find("div[rel=body]")[0].style.cssText),n(this).find("div[rel=buttons]").length>0&&(r.buttons=n(this).find("div[rel=buttons]").html())):(r.title=" ",r.body=n(this).html()),parseInt(n(this).css("width"))!=0&&(r.width=parseInt(n(this).css("width"))),parseInt(n(this).css("height"))!=0&&(r.height=parseInt(n(this).css("height")))),w2popup[t](n.extend({},r,i))},w2popup={defaults:{title:"",body:"",buttons:"",style:"",color:"#000",opacity:.4,speed:.3,modal:!1,maximized:!1,keyboard:!0,width:500,height:300,showClose:!0,showMax:!1,transition:null},handlers:[],onOpen:null,onClose:null,onMax:null,onMin:null,onKeydown:null,open:function(t){function w(n){if(n||(n=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.resizing=!0,i.tmp_x=n.screenX,i.tmp_y=n.screenY,n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault)n.preventDefault();else return!1}function c(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}))}function h(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-popup").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-popup").css("top"))+parseInt(i.tmp_div_y)+"px"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-panel").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-panel").css("top"))+parseInt(i.tmp_div_y)+"px"}),i.resizing=!1)}var p=this,o=n("#w2ui-popup").data("options"),t=n.extend({},this.defaults,{body:""},o,t),e,f,v,y,r,u,a,l,s,i;if(n("#w2ui-popup").length==0&&(w2popup.handlers=[],w2popup.onMax=null,w2popup.onMin=null,w2popup.onOpen=null,w2popup.onClose=null,w2popup.onKeydown=null),t.onOpen&&(w2popup.onOpen=t.onOpen),t.onClose&&(w2popup.onClose=t.onClose),t.onMax&&(w2popup.onMax=t.onMax),t.onMin&&(w2popup.onMin=t.onMin),t.onKeydown&&(w2popup.onKeydown=t.onKeydown),window.innerHeight==undefined?(e=document.documentElement.offsetWidth,f=document.documentElement.offsetHeight,w2utils.engine=="IE7"&&(e+=21,f+=4)):(e=window.innerWidth,f=window.innerHeight),parseInt(e)-10',t.title!=""&&(r+=''+(t.showClose?'Close':"")+(t.showMax?'Max':"")+t.title+""),r+='',r+=''+t.body+"",r+="",r+='',r+='',r+="",t.buttons!=""&&(r+=''+t.buttons+""),r+="",n("body").append(r),setTimeout(function(){n("#w2ui-popup .w2ui-box2").hide(),n("#w2ui-popup").css({"-webkit-transition":t.speed+"s opacity, "+t.speed+"s -webkit-transform","-webkit-transform":"scale(1)","-moz-transition":t.speed+"s opacity, "+t.speed+"s -moz-transform","-moz-transform":"scale(1)","-ms-transition":t.speed+"s opacity, "+t.speed+"s -ms-transform","-ms-transform":"scale(1)","-o-transition":t.speed+"s opacity, "+t.speed+"s -o-transform","-o-transform":"scale(1)",opacity:"1"})},1),setTimeout(function(){n("#w2ui-popup").css({"-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":""}),p.trigger(n.extend(u,{phase:"after"}))},t.speed*1e3)}else{if(u=this.trigger({phase:"before",type:"open",target:"popup",options:t,present:!0}),u.isCancelled===!0)return;(typeof o=="undefined"||o.width!=t.width||o.height!=t.height)&&(n("#w2ui-panel").remove(),w2popup.resize(t.width,t.height)),a=n("#w2ui-popup .w2ui-box2 > .w2ui-msg-body").html(t.body),a.length>0&&(a[0].style.cssText=t.style),n("#w2ui-popup .w2ui-msg-buttons").html(t.buttons),n("#w2ui-popup .w2ui-msg-title").html((t.showClose?'Close':"")+(t.showMax?'Max':"")+t.title),l=n("#w2ui-popup .w2ui-box1")[0],s=n("#w2ui-popup .w2ui-box2")[0],w2utils.transition(l,s,t.transition),s.className="w2ui-box1",l.className="w2ui-box2",n(s).addClass("w2ui-current-box"),n("#w2ui-popup").data("prev-size",null),setTimeout(function(){p.trigger(n.extend(u,{phase:"after"}))},1)}if(t._last_w2ui_name=w2utils.keyboard.active(),w2utils.keyboard.active(null),n("#w2ui-popup").data("options",t),t.keyboard)n(document).on("keydown",this.keydown);i={resizing:!1};n("#w2ui-popup .w2ui-msg-title").on("mousedown",function(n){w(n)}).on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});n("#w2ui-popup .w2ui-msg-body").on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});n("#w2ui-lock").on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});return this},keydown:function(t){var r=n("#w2ui-popup").data("options"),i;if(r.keyboard&&(i=w2popup.trigger({phase:"before",type:"keydown",target:"popup",options:r,object:w2popup,originalEvent:t}),i.isCancelled!==!0)){switch(t.keyCode){case 27:t.preventDefault(),n("#w2ui-popup .w2ui-popup-message").length>0?w2popup.message():w2popup.close()}w2popup.trigger(n.extend(i,{phase:"after"}))}},close:function(t){var r=this,t=n.extend({},n("#w2ui-popup").data("options"),t),i=this.trigger({phase:"before",type:"close",target:"popup",options:t});i.isCancelled!==!0&&(n("#w2ui-popup, #w2ui-panel").css({"-webkit-transition":t.speed+"s opacity, "+t.speed+"s -webkit-transform","-webkit-transform":"scale(0.9)","-moz-transition":t.speed+"s opacity, "+t.speed+"s -moz-transform","-moz-transform":"scale(0.9)","-ms-transition":t.speed+"s opacity, "+t.speed+"s -ms-transform","-ms-transform":"scale(0.9)","-o-transition":t.speed+"s opacity, "+t.speed+"s -o-transform","-o-transform":"scale(0.9)",opacity:"0"}),w2popup.unlockScreen(),setTimeout(function(){n("#w2ui-popup").remove(),n("#w2ui-panel").remove(),r.trigger(n.extend(i,{phase:"after"}))},t.speed*1e3),w2utils.keyboard.active(t._last_w2ui_name),t.keyboard&&n(document).off("keydown",this.keydown))},toggle:function(){var t=n("#w2ui-popup").data("options");t.maximized===!0?w2popup.min():w2popup.max()},max:function(){var r=this,t=n("#w2ui-popup").data("options"),i;t.maximized!==!0&&(i=this.trigger({phase:"before",type:"max",target:"popup",options:t}),i.isCancelled!==!0)&&(t.maximized=!0,t.prevSize=n("#w2ui-popup").css("width")+":"+n("#w2ui-popup").css("height"),n("#w2ui-popup").data("options",t),w2popup.resize(1e4,1e4,function(){r.trigger(n.extend(i,{phase:"after"}))}))},min:function(){var u=this,t=n("#w2ui-popup").data("options"),i,r;t.maximized===!0&&(i=t.prevSize.split(":"),r=this.trigger({phase:"before",type:"min",target:"popup",options:t}),r.isCancelled!==!0)&&(t.maximized=!1,t.prevSize=null,n("#w2ui-popup").data("options",t),w2popup.resize(i[0],i[1],function(){u.trigger(n.extend(r,{phase:"after"}))}))},get:function(){return n("#w2ui-popup").data("options")},set:function(n){w2popup.open(n)},clear:function(){n("#w2ui-popup .w2ui-msg-title").html(""),n("#w2ui-popup .w2ui-msg-body").html(""),n("#w2ui-popup .w2ui-msg-buttons").html("")},reset:function(){w2popup.open(w2popup.defaults)},load:function(t){function u(i,r){if(delete t.url,n("body").append(''+i+""),typeof r!="undefined"&&n("#w2ui-tmp #"+r).length>0?n("#w2ui-tmp #"+r).w2popup(t):n("#w2ui-tmp > div").w2popup(t),n("#w2ui-tmp > style").length>0){var u=n("").append(n("#w2ui-tmp > style").clone()).html();n("#w2ui-popup #div-style").length==0&&n("#w2ui-ppopup").append(''),n("#w2ui-popup #div-style").html(u)}n("#w2ui-tmp").remove()}var i;if(String(t.url)=="undefined"){console.log("ERROR: The url parameter is empty.");return}var f=String(t.url).split("#"),r=f[0],e=f[1];String(t)=="undefined"&&(t={}),i=n("#w2ui-popup").data(r),typeof i!="undefined"&&i!=null?u(i,e):n.get(r,function(t,i,f){u(f.responseText,e),n("#w2ui-popup").data(r,f.responseText)})},message:function(t){var r,u,i,t;n().w2tag(),t||(t={width:200,height:100}),parseInt(t.width)<10&&(t.width=10),parseInt(t.height)<10&&(t.height=10),typeof t.hideOnClick=="undefined"&&(t.hideOnClick=!1),r=n("#w2ui-popup .w2ui-msg-title"),n("#w2ui-popup .w2ui-popup-message").length==0?(u=parseInt(n("#w2ui-popup").width()),n("#w2ui-popup .w2ui-box1").before('"),n("#w2ui-popup .w2ui-popup-message").data("options",t)):(typeof t.width=="undefined"&&(t.width=w2utils.getSize(n("#w2ui-popup .w2ui-popup-message"),"width")),typeof t.height=="undefined"&&(t.height=w2utils.getSize(n("#w2ui-popup .w2ui-popup-message"),"height"))),i=n("#w2ui-popup .w2ui-popup-message").css("display"),n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-moz-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-ms-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-o-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)"}),i=="none"?(n("#w2ui-popup .w2ui-popup-message").show().html(t.html),setTimeout(function(){n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s","z-Index":1500}),w2popup.lock(),typeof t.onOpen=="function"&&t.onOpen()},300)):(n("#w2ui-popup .w2ui-popup-message").css("z-Index",250),t=n("#w2ui-popup .w2ui-popup-message").data("options"),n("#w2ui-popup .w2ui-popup-message").remove(),w2popup.unlock(),typeof t.onClose=="function"&&t.onClose()),setTimeout(function(){n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-moz-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-ms-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-o-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)"})},1)},lock:function(t,i){w2utils.lock(n("#w2ui-popup"),t,i)},unlock:function(){w2utils.unlock(n("#w2ui-popup"))},lockScreen:function(t){if(n("#w2ui-lock").length>0)return!1;if(typeof t=="undefined"&&(t=n("#w2ui-popup").data("options")),typeof t=="undefined"&&(t={}),t=n.extend({},w2popup.defaults,t),n("body").append(''),setTimeout(function(){n("#w2ui-lock").css({"-webkit-transition":t.speed+"s opacity","-moz-transition":t.speed+"s opacity","-ms-transition":t.speed+"s opacity","-o-transition":t.speed+"s opacity",opacity:t.opacity})},1),t.modal==!0){n("#w2ui-lock").on("mousedown",function(){n("#w2ui-lock").css({"-webkit-transition":".1s","-moz-transition":".1s","-ms-transition":".1s","-o-transition":".1s",opacity:"0.6"}),window.getSelection&&window.getSelection().removeAllRanges()});n("#w2ui-lock").on("mouseup",function(){setTimeout(function(){n("#w2ui-lock").css({"-webkit-transition":".1s","-moz-transition":".1s","-ms-transition":".1s","-o-transition":".1s",opacity:t.opacity})},100),window.getSelection&&window.getSelection().removeAllRanges()})}else n("#w2ui-lock").on("mouseup",function(){w2popup.close()});return!0},unlockScreen:function(){if(n("#w2ui-lock").length==0)return!1;var t=n.extend({},n("#w2ui-popup").data("options"),t);return n("#w2ui-lock").css({"-webkit-transition":t.speed+"s opacity","-moz-transition":t.speed+"s opacity","-ms-transition":t.speed+"s opacity","-o-transition":t.speed+"s opacity",opacity:0}),setTimeout(function(){n("#w2ui-lock").remove()},t.speed*1e3),!0},resize:function(t,i,r){var u=n("#w2ui-popup").data("options"),e,f;parseInt(n(window).width())-100?w2popup.message({width:400,height:150,html:'\t\t'+n+'\t\t',onClose:function(){typeof i=="function"&&i()}}):w2popup.open({width:450,height:200,showMax:!1,title:t,body:''+n+"",buttons:'',onClose:function(){typeof i=="function"&&i()}})},w2confirm=function(n,t,i){(typeof i=="undefined"||typeof t=="function")&&(i=t,t=w2utils.lang("Confirmation")),typeof t=="undefined"&&(t=w2utils.lang("Confirmation")),jQuery("#w2ui-popup").length>0?w2popup.message({width:400,height:150,html:'\t\t'+n+'\t\t\t\t',onOpen:function(){jQuery("#w2ui-popup .w2ui-popup-message .w2ui-popup-button").on("click",function(n){w2popup.message(),typeof i=="function"&&i(n.target.id)})},onKeydown:function(n){switch(n.originalEvent.keyCode){case 13:typeof i=="function"&&i("Yes"),w2popup.message();break;case 27:typeof i=="function"&&i("No"),w2popup.message()}}}):w2popup.open({width:450,height:200,title:t,modal:!0,showClose:!1,body:''+n+"",buttons:'',onOpen:function(n){n.onComplete=function(){jQuery("#w2ui-popup .w2ui-popup-button").on("click",function(n){w2popup.close(),typeof i=="function"&&i(n.target.id)})}},onKeydown:function(n){switch(n.originalEvent.keyCode){case 13:typeof i=="function"&&i("Yes"),w2popup.close();break;case 27:typeof i=="function"&&i("No"),w2popup.close()}}})},function(n){var t=function(t){this.box=null,this.name=null,this.active=null,this.tabs=[],this.right="",this.style="",this.onClick=null,this.onClose=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.tabs,t)};n.fn.w2tabs=function(i){var e,r,f,u;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return u=w2ui[n(this).attr("name")],u[i].apply(u,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2tabs")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2tabs().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}e=i.tabs,r=new t(i),n.extend(r,{tabs:[],handlers:[]});for(f in e)r.tabs[f]=n.extend({},t.prototype.tab,e[f]);return n(this).length!=0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={tab:{id:null,text:"",hidden:!1,disabled:!1,closable:!1,hint:"",onClick:null,onRefresh:null,onClose:null},add:function(n){return this.insert(null,n)},insert:function(t,i){var r,f,e,i,u;n.isArray(i)||(i=[i]);for(r in i){if(String(i[r].id)=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+this.name+")");return}f=!0;for(e in this.tabs)if(this.tabs[e].id==i[r].id){f=!1;break}if(!f){console.log('ERROR: The parameter "id='+i[r].id+'" is not unique within the current tabs. (obj: '+this.name+")");return}if(!w2utils.isAlphaNumeric(i[r].id)){console.log('ERROR: The parameter "id='+i[r].id+'" must be alpha-numeric + "-_". (obj: '+this.name+")");return}i=n.extend({},i,i[r]),t==null||typeof t=="undefined"?this.tabs.push(i):(u=this.get(t,!0),this.tabs=this.tabs.slice(0,u).concat([i],this.tabs.slice(u))),this.refresh(i[r].id)}},remove:function(){for(var u=0,r,i=0;i":"")+'\t"+i.text+"",r.length==0?(u="",i.hidden&&(u+="display: none;"),i.disabled&&(u+="opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);"),html=''+f+"",this.get(t,!0)!=this.tabs.length-1&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).before(html):n(this.box).find("#tabs_"+this.name+"_right").before(html)):(r.html(f),i.hidden?r.css("display","none"):r.css("display",""),i.disabled?r.css({opacity:"0.2","-moz-opacity":"0.2","-webkit-opacity":"0.2","-o-opacity":"0.2",filter:"alpha(opacity=20)"}):r.css({opacity:"1","-moz-opacity":"1","-webkit-opacity":"1","-o-opacity":"1",filter:"alpha(opacity=100)"})),this.trigger(n.extend(e,{phase:"after"})),+new Date-s)},render:function(t){var u=+new Date,i=this.trigger({phase:"before",type:"render",target:this.name,box:t}),r;return i.isCancelled===!0?!1:(window.getSelection&&window.getSelection().removeAllRanges(),String(t)!="undefined"&&t!=null&&(n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),this.box=t),!this.box)?void 0:(r='\t'+this.right+"",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-tabs").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.trigger(n.extend(i,{phase:"after"})),this.refresh(),+new Date-u)},resize:function(){window.getSelection&&window.getSelection().removeAllRanges();var t=this.trigger({phase:"before",type:"resize",target:this.name});if(t.isCancelled===!0)return!1;this.trigger(n.extend(t,{phase:"after"}))},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},click:function(t,i){var u=this.get(t),r;if(u==null||u.disabled||(r=this.trigger({phase:"before",type:"click",target:t,object:this.get(t),originalEvent:i}),r.isCancelled===!0))return!1;n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.active)+" .w2ui-tab").removeClass("active"),this.active=u.id,this.trigger(n.extend(r,{phase:"after"})),this.refresh(t)},animateClose:function(t,i){var u=this.get(t),f,r;if(u==null||u.disabled||(f=this.trigger({phase:"before",type:"close",target:t,object:this.get(t),originalEvent:i}),f.isCancelled===!0))return!1;r=this,n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(u.id)).css({"-webkit-transition":".2s","-moz-transition":"2s","-ms-transition":".2s","-o-transition":".2s",opacity:"0"}),setTimeout(function(){var t=n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).width();n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).html(''),setTimeout(function(){n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).find(":first-child").css({width:"0px"})},50)},200),setTimeout(function(){r.remove(t)},450),this.trigger(n.extend(f,{phase:"after"})),this.refresh()},animateInsert:function(t,i){var f,e,o,s,r,u;if(this.get(t)!=null&&n.isPlainObject(i)){f=!0;for(e in this.tabs)if(this.tabs[e].id==i.id){f=!1;break}if(!f){console.log('ERROR: The parameter "id='+i.id+'" is not unique within the current tabs. (obj: '+this.name+")");return}(o=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id)),o.length==0)&&(typeof i.caption!="undefined"&&(i.text=i.caption),s=''+(i.closable?'':"")+'\t'+i.text+"",n("body").append(s),tabHTML=' ',r="",i.hidden&&(r+="display: none;"),i.disabled&&(r+="opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);"),html=''+tabHTML+"",this.get(t,!0)!=this.tabs.length&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).before(html):n(this.box).find("#tabs_"+this.name+"_right").before(html),u=this,setTimeout(function(){var t=n("#_tmp_simple_tab").width();n("#_tmp_tabs").remove(),n("#tabs_"+u.name+"_tab_"+w2utils.escapeId(i.id)+" > div").css("width",t+"px")},1),setTimeout(function(){u.insert(t,i)},200))}}},n.extend(t.prototype,w2utils.event),w2obj.tabs=t}(jQuery),function(n){var t=function(t){this.box=null,this.name=null,this.items=[],this.right="",this.onClick=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.toolbar,t)};n.fn.w2toolbar=function(i){var e,r,f,u;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return u=w2ui[n(this).attr("name")],u[i].apply(u,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2toolbar")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2toolbar().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}e=i.items,r=new t(i),n.extend(r,{items:[],handlers:[]});for(f in e)r.items[f]=n.extend({},t.prototype.item,e[f]);return n(this).length!=0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={item:{id:null,type:"button",text:"",html:"",img:null,icon:null,hidden:!1,disabled:!1,checked:!1,arrow:!0,hint:"",group:null,items:null,onClick:null},add:function(n){this.insert(null,n)},insert:function(i,r){var u,s,e,f,o;n.isArray(r)||(r=[r]);for(u in r){if(typeof r[u].type=="undefined"){console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.');return}if(n.inArray(String(r[u].type),["button","check","radio","drop","menu","break","html","spacer"])==-1){console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] in w2toolbar.add() method.');return}if(typeof r[u].id=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.');return}for(s=!0,e=0;e table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),this.box=t),this.box){for(r='',u=0;u':''+this.getItemHTML(i)+"");r+=''+this.right+"",r+="",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-toolbar").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.trigger(n.extend(f,{phase:"after"}))}},refresh:function(t){var o=+new Date,e,f,i,r,u;if(window.getSelection&&window.getSelection().removeAllRanges(),e=this.trigger({phase:"before",type:"refresh",target:typeof t!="undefined"?t:this.name,item:this.get(t)}),e.isCancelled===!0)return!1;if(typeof t=="undefined")for(f=0;f':''+u+"",this.get(t,!0)==this.items.length-1?n(this.box).find("#tb_"+this.name+"_right").before(u):n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(this.items[parseInt(this.get(t,!0))+1].id)).before(u)):(r.html(u),i.hidden?r.css("display","none"):r.css("display",""),i.disabled?r.addClass("disabled"):r.removeClass("disabled")),this.trigger(n.extend(e,{phase:"after"})),+new Date-o},resize:function(){var i=+new Date,t;return(window.getSelection&&window.getSelection().removeAllRanges(),t=this.trigger({phase:"before",type:"resize",target:this.name}),t.isCancelled===!0)?!1:(this.trigger(n.extend(t,{phase:"after"})),+new Date-i)},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),n(this.box).html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},getItemHTML:function(n){var t="",r,i;typeof n.caption!="undefined"&&(n.text=n.caption),typeof n.hint=="undefined"&&(n.hint=""),typeof n.text=="undefined"&&(n.text="");switch(n.type){case"menu":case"button":case"check":case"radio":case"drop":r=" ",n.img&&(r=''),n.icon&&(r=''),t+=' '+r+(n.text!=""?''+n.text+"":"")+((n.type=="drop"||n.type=="menu")&&n.arrow!==!1?' ':"")+" ";break;case"break":t+=' ';break;case"html":t+=' '+n.html+""}return i="",typeof n.onRender=="function"&&(i=n.onRender.call(this,n.id,t)),typeof this.onRender=="function"&&(i=this.onRender(n.id,t)),i!=""&&typeof i!="undefined"&&(t=i),t},menuClick:function(t,i,r){var e,f,u;if(window.getSelection&&window.getSelection().removeAllRanges(),e=this,f=this.get(t),f&&!f.disabled){if(u=this.trigger({phase:"before",type:"click",target:typeof t!="undefined"?t:this.name,item:this.get(t),subItem:typeof i!="undefined"&&this.get(t)?this.get(t).items[i]:null,originalEvent:r}),u.isCancelled===!0)return!1;this.trigger(n.extend(u,{phase:"after"}))}},click:function(t,i){var f,r,o,e,u;if(window.getSelection&&window.getSelection().removeAllRanges(),f=this,r=this.get(t),r&&!r.disabled){if(o=this.trigger({phase:"before",type:"click",target:typeof t!="undefined"?t:this.name,item:this.get(t),originalEvent:i}),o.isCancelled===!0)return!1;if(n("#tb_"+this.name+"_item_"+w2utils.escapeId(r.id)+" table.w2ui-button").removeClass("down"),r.type=="radio"){for(e=0;e0&&this.insert(e,null,h)}return this.refresh(i.id),e},remove:function(){for(var r=0,n,i,t=0;t0&&arguments.length==1?this.refresh(n.parent.id):this.refresh(),r},set:function(t,i,r){var u,f;if(arguments.length==2&&(r=i,i=t,t=this),this._tmp=null,typeof t=="string"&&(t=this.get(t)),t.nodes==null)return null;for(u=0;u+'),r.expanded=!1,this.trigger(n.extend(i,{phase:"after"})),this.resize()},collapseAll:function(n){if(typeof n=="undefined"&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return null;for(var t=0;t0&&this.collapseAll(n.nodes[t]);this.refresh(n.id)},expand:function(t){var r=this.get(t),i=this.trigger({phase:"before",type:"expand",target:t,object:r});if(i.isCancelled===!0)return!1;n(this.box).find("#node_"+w2utils.escapeId(t)+"_sub").slideDown("fast"),n(this.box).find("#node_"+w2utils.escapeId(t)+" .w2ui-node-dots:first-child").html('-'),r.expanded=!0,this.trigger(n.extend(i,{phase:"after"})),this.resize()},expandAll:function(n){if(typeof n=="undefined"&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return null;for(var t=0;t0&&this.collapseAll(n.nodes[t]);this.refresh(n.id)},expandParents:function(n){var t=this.get(n);t!=null&&(t.parent&&(t.parent.expanded=!0,this.expandParents(t.parent.id)),this.refresh(n))},click:function(t,i){var r=this,f=this.get(t),u;f!=null&&((u=this.selected,f.disabled||f.group)||(n(r.box).find("#node_"+w2utils.escapeId(u)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),n(r.box).find("#node_"+w2utils.escapeId(t)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),setTimeout(function(){var e=r.trigger({phase:"before",type:"click",target:t,originalEvent:i,object:f});if(e.isCancelled===!0)return n(r.box).find("#node_"+w2utils.escapeId(t)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),n(r.box).find("#node_"+w2utils.escapeId(u)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),!1;u!=null&&(r.get(u).selected=!1),r.get(t).selected=!0,r.selected=t,r.trigger(n.extend(e,{phase:"after"}))},1)))},keydown:function(t){function f(n,t){var u;if(n==null)return null;var e=n.parent,o=i.get(n.id,!0),r=null;return n.expanded&&n.nodes.length>0&&t!==!0?(u=n.nodes[0],r=u.disabled||u.group?f(u):u):r=e&&o+10?(t=f.nodes[u-1],t.expanded&&t.nodes.length>0&&(r=t.nodes[t.nodes.length-1],t=r.disabled||r.group?e(r):r)):(t=f,o=!0),t!=null&&(t.disabled||t.group)&&(t=e(t)),t}var i=this,r=i.get(i.selected),o,u;if(r&&i.keyboard===!0){if(o=i.trigger({phase:"before",type:"keydown",target:i.name,originalEvent:t}),o.isCancelled===!0)return!1;(t.keyCode==13||t.keyCode==32)&&r.nodes.length>0&&i.toggle(i.selected),t.keyCode==37&&(r.nodes.length>0?i.collapse(i.selected):!r.parent||r.parent.disabled||r.parent.group||(i.collapse(r.parent.id),i.click(r.parent.id),setTimeout(function(){i.scrollIntoView()},50))),t.keyCode==39&&r.nodes.length>0&&i.expand(i.selected),t.keyCode==38&&(u=e(r),u!=null&&(i.click(u.id,t),setTimeout(function(){i.scrollIntoView()},50))),t.keyCode==40&&(u=f(r),u!=null&&(i.click(u.id,t),setTimeout(function(){i.scrollIntoView()},50))),n.inArray(t.keyCode,[13,32,37,38,39,40])!=-1&&(t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()),i.trigger(n.extend(o,{phase:"after"}));return}},scrollIntoView:function(t){var f;if(typeof t=="undefined"&&(t=this.selected),f=this.get(t),f!=null){var i=n(this.box).find(".w2ui-sidebar-div"),u=n(this.box).find("#node_"+w2utils.escapeId(t)),r=u.offset().top-i.offset().top;r+u.height()>i.height()&&i.animate({scrollTop:i.scrollTop()+i.height()/1.3}),r<=0&&i.animate({scrollTop:i.scrollTop()-i.height()/1.3})}},dblClick:function(t,i){window.getSelection&&window.getSelection().removeAllRanges();var u=this.get(t),r=this.trigger({phase:"before",type:"dblClick",target:t,originalEvent:i,object:u});if(r.isCancelled===!0)return!1;u.nodes.length>0&&this.toggle(t),this.trigger(n.extend(r,{phase:"after"}))},contextMenu:function(t,i){var r=this,u=r.get(t);t!=r.selected&&r.click(t),setTimeout(function(){var f=r.trigger({phase:"before",type:"contextMenu",target:t,originalEvent:i,object:u});if(f.isCancelled===!0)return!1;u.group||u.disabled||(r.menu.length>0&&n(r.box).find("#node_"+w2utils.escapeId(t)).w2menu(r.menu,{left:(i?i.offsetX||i.pageX:50)-25,select:function(n,i,u){r.menuClick(t,u,i)}}),r.trigger(n.extend(f,{phase:"after"})))},1)},menuClick:function(t,i,r){var u=this,f=u.trigger({phase:"before",type:"menuClick",target:t,originalEvent:r,menuIndex:i,menuItem:u.menu[i]});if(f.isCancelled===!0)return!1;u.trigger(n.extend(f,{phase:"after"}))},render:function(t){var i=this.trigger({phase:"before",type:"render",target:this.name,box:t});if(i.isCancelled===!0)return!1;(typeof t!="undefined"&&t!=null&&(n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),this.box=t),this.box)&&(n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-sidebar").html(''),n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.topHTML!=""&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px")),this.bottomHTML!=""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px")),this.trigger(n.extend(i,{phase:"after"})),this.refresh())},refresh:function(t){function h(n){var e="",f=n.img,i,u,t;for(f==null&&(f=this.img),i=n.icon,i==null&&(i=this.icon),t=n.parent,u=0;t&&t.parent!=null;)t.group&&u--,t=t.parent,u++;return typeof n.caption!="undefined"&&(n.text=n.caption),n.group?e='\t"+(!n.hidden&&n.expanded?w2utils.lang("Hide"):w2utils.lang("Show"))+"\t"+n.text+'':(n.selected&&!n.disabled&&(r.selected=n.id),t="",f&&(t=''),i&&(t=''),e='\t'+(n.nodes.length>0?n.expanded?"-":"+":n.plus?"+":"")+''+t+(n.count!==""?''+n.count+"":"")+''+n.text+''),e}var c=+new Date,s,r,i,f,o,u,e;if(window.getSelection&&window.getSelection().removeAllRanges(),s=this.trigger({phase:"before",type:"refresh",target:typeof t!="undefined"?t:this.name}),s.isCancelled===!0)return!1;if(this.topHTML!=""&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px")),this.bottomHTML!=""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px")),n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),r=this,typeof t=="undefined")i=this,f=".w2ui-sidebar-div";else{if(i=this.get(t),i==null)return;f="#node_"+w2utils.escapeId(i.id)+"_sub"}for(i!=this&&(o="#node_"+w2utils.escapeId(i.id),e=h(i),n(this.box).find(o).before(''),n(this.box).find(o).remove(),n(this.box).find(f).remove(),n("#sidebar_"+this.name+"_tmp").before(e),n("#sidebar_"+this.name+"_tmp").remove()),n(this.box).find(f).html(""),u=0;u div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),this.trigger(n.extend(t,{phase:"after"})),+new Date-i)},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},lock:function(t,i){var r=n(this.box).find("> div:first-child");w2utils.lock(r,t,i)},unlock:function(){w2utils.unlock(this.box)}},n.extend(t.prototype,w2utils.event),w2obj.sidebar=t}(jQuery),function(n){var t=new function(){this.customTypes=[]};n.fn.w2field=function(n){if(t[n])return t[n].apply(this,Array.prototype.slice.call(arguments,1));if(typeof n=="object")return t.init.apply(this,arguments);if(typeof n=="string")return t.init.apply(this,[{type:n}]);console.log("ERROR: Method "+n+" does not exist on jQuery.w2field")},n.extend(t,{init:function(i){var r=t;return n(this).each(function(){var l,s,y,f,h,o,c,a;if(typeof t.customTypes[i.type.toLowerCase()]=="function"){t.customTypes[i.type.toLowerCase()].call(this,i);return}l=i.type.toLowerCase();switch(l){case"clear":n(this).off("focus").off("blur").off("keypress").off("keydown").off("change").removeData(),n(this).prev().hasClass("w2ui-list")&&(n(this).prev().remove(),n(this).removeAttr("tabindex").css("border-color","").show()),n(this).prev().hasClass("w2ui-upload")&&(n(this).prev().remove(),n(this).removeAttr("tabindex").css("border-color","").show()),n(this).prev().hasClass("w2ui-field-helper")&&(n(this).css("padding-left",n(this).css("padding-top")),n(this).prev().remove()),n(this).next().hasClass("w2ui-field-helper")&&(n(this).css("padding-right",n(this).css("padding-top")),n(this).next().remove()),n(this).next().hasClass("w2ui-field-helper")&&n(this).next().remove();break;case"text":case"int":case"float":case"money":case"alphanumeric":case"hex":s=this,h={min:null,max:null,arrows:!1,keyboard:!0,suffix:"",prefix:""},i=n.extend({},h,i),["text","alphanumeric","hex"].indexOf(l)!=-1&&(i.arrows=!1,i.keyboard=!1);n(this).data("options",i).on("keypress",function(t){if(!t.metaKey&&!t.ctrlKey&&!t.altKey&&(t.charCode==t.keyCode||!(t.keyCode>0))){t.keyCode==13&&n(this).change();var i=String.fromCharCode(t.charCode);if(!v(i,!0))return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,!1}}).on("keydown",function(t,r){var e,u,o,f;if(i.keyboard){e=!1,u=n(s).val(),u=v(u)?parseFloat(u):i.min||0,o=t.keyCode||r.keyCode,f=1,(t.ctrlKey||t.metaKey)&&(f=10);switch(o){case 38:n(s).val(u+f<=i.max||i.max==null?u+f:i.max).change(),l=="money"&&n(s).val(Number(n(s).val()).toFixed(2)),e=!0;break;case 40:n(s).val(u-f>=i.min||i.min==null?u-f:i.min).change(),l=="money"&&n(s).val(Number(n(s).val()).toFixed(2)),e=!0}e&&(t.preventDefault(),setTimeout(function(){s.setSelectionRange(s.value.length,s.value.length)},0))}}).on("change",function(t){var r=n(s).val(),u=!1;if(i.min!=null&&r!=""&&ri.max&&(n(s).val(i.max).change(),u=!0),u)return t.stopPropagation(),t.preventDefault(),!1;this.value==""||v(this.value)||n(this).val(i.min!=null?i.min:"")});if(n(this).val()==""&&i.min!=null&&n(this).val(i.min),i.prefix!=""){n(this).before(''+i.prefix+""),o=n(this).prev();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":n(this).css("padding-left"),"padding-right":0,"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px","margin-left":0,"margin-right":0}).on("click",function(){n(this).next().focus()});n(this).css("padding-left",o.width()+parseInt(n(this).css("padding-left"))+5+"px")}if(c=parseInt(n(this).css("padding-right")),i.arrows!=""){n(this).after(' \t\t\t\t\t\t\t\t\t'),y=w2utils.getSize(this,"height"),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),height:n(this).height()+parseInt(n(this).css("padding-top"))+parseInt(n(this).css("padding-bottom"))+"px",padding:"0px","margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":"0px","border-left":"1px solid silver"}).css("margin-left","-"+(o.width()+parseInt(n(this).css("margin-right"))+12)+"px").on("mousedown",function(t){function r(){clearTimeout(n("body").data("_field_update_timer")),n("body").off("mouseup",r)}function i(t){n(s).focus().trigger(n.Event("keydown"),{keyCode:n(u.target).attr("type")=="up"?38:40}),t!==!1&&n("body").data("_field_update_timer",setTimeout(i,60))}var f=this,u=t;n("body").on("mouseup",r);n("body").data("_field_update_timer",setTimeout(i,700)),i(!1)});c+=o.width()+12,n(this).css("padding-right",c+"px")}if(i.suffix!=""){n(this).after(''+i.suffix+""),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":"3px","padding-right":n(this).css("padding-right"),"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px"}).on("click",function(){n(this).prev().focus()});o.css("margin-left","-"+(o.width()+parseInt(n(this).css("padding-right"))+5)+"px"),c+=o.width()+3,n(this).css("padding-right",c+"px")}function v(n,t){switch(l){case"int":return t&&["-"].indexOf(n)!=-1?!0:w2utils.isInt(n);case"float":return t&&["-","."].indexOf(n)!=-1?!0:w2utils.isFloat(n);case"money":return t&&["-",".","$","€","£","¥"].indexOf(n)!=-1?!0:w2utils.isMoney(n);case"hex":return w2utils.isHex(n);case"alphanumeric":return w2utils.isAlphaNumeric(n)}return!0}break;case"date":f=this,h={format:w2utils.settings.date_format,start:"",end:"",blocked:{},colored:{}},i=n.extend({},h,i);n(this).css({transition:"none","-webkit-transition":"none","-moz-transition":"none","-ms-transition":"none","-o-transition":"none"}).data("options",i).on("focus",function(){var e=parseFloat(n(f).offset().top)+parseFloat(f.offsetHeight),u=parseFloat(n(f).offset().left),t,r;clearInterval(n(f).data("mtimer")),n("#global_calendar_div").remove(),n("body").append(''),n("#global_calendar_div").html(n().w2field("calendar_get",f.value,i)).css({left:u+"px",top:e+"px"}).data("el",f).show(),t=n(window).width()+n(document).scrollLeft()-1,u+n("#global_calendar_div").width()>t&&n("#global_calendar_div").css("left",t-n("#global_calendar_div").width()+"px"),r=setInterval(function(){var i=n(window).width()+n(document).scrollLeft()-1,t=n(f).offset().left;if(t+n("#global_calendar_div").width()>i&&(t=i-n("#global_calendar_div").width()),n("#global_calendar_div").data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&n("#global_calendar_div").css({"-webkit-transition":".2s",left:t+"px",top:n(f).offset().top+f.offsetHeight+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(r),n("#global_calendar_div").remove();return}},100),n(f).data("mtimer",r)}).on("blur",function(){n(f).val(n.trim(n(f).val())),n.trim(n(f).val())==""||w2utils.isDate(n(f).val(),i.format)||n(this).w2tag(w2utils.lang("Not a valid date")+": "+i.format),clearInterval(n(f).data("mtimer")),n("#global_calendar_div").remove()}).on("keypress",function(){var r=this;setTimeout(function(){n("#global_calendar_div").html(n().w2field("calendar_get",r.value,i))},10)});setTimeout(function(){w2utils.isInt(f.value)&&(f.value=w2utils.formatDate(f.value,i.format))},1);break;case"time":break;case"datetime":break;case"color":f=this,h={prefix:"#",suffix:''},i=n.extend({},h,i);n(this).attr("maxlength",6).on("focus",function(){var u=parseFloat(n(f).offset().top)+parseFloat(f.offsetHeight),r=parseFloat(n(f).offset().left),t,i;clearInterval(n(f).data("mtimer")),n("#global_color_div").remove(),n("body").append(''),n("#global_color_div").html(n().w2field("getColorHTML",f.value)).css({left:r+"px",top:u+"px"}).data("el",f).show(),t=n(window).width()+n(document).scrollLeft()-1,r+n("#global_color_div").width()>t&&n("#global_color_div").css("left",t-n("#global_color_div").width()+"px"),i=setInterval(function(){var r=n(window).width()+n(document).scrollLeft()-1,t=n(f).offset().left;if(t+n("#global_color_div").width()>r&&(t=r-n("#global_color_div").width()),n("#global_color_div").data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&n("#global_color_div").css({"-webkit-transition":".2s",left:t+"px",top:n(f).offset().top+f.offsetHeight+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(i),n("#global_color_div").remove();return}},100),n(f).data("mtimer",i)}).on("click",function(){n(this).trigger("focus")}).on("blur",function(){n(f).val(n.trim(n(f).val())),clearInterval(n(f).data("mtimer")),n("#global_color_div").remove()}).on("keydown",function(t){if(t.keyCode==86&&(t.ctrlKey||t.metaKey)){var i=this;n(this).prop("maxlength",7),setTimeout(function(){var t=n(i).val();t.substr(0,1)=="#"&&(t=t.substr(1)),w2utils.isHex(t)||(t=""),n(i).val(t).prop("maxlength",6).change()},20)}}).on("keyup",function(t){t.keyCode==86&&(t.ctrlKey||t.metaKey)&&n(this).prop("maxlength",6)}).on("keypress",function(t){t.keyCode==13&&n(this).change();var i=String.fromCharCode(t.charCode);if(!w2utils.isHex(i,!0))return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,!1}).on("change",function(){var i="#"+n(this).val();n(this).val().length!=6&&n(this).val().length!=3&&(i=""),n(this).next().find("div").css("background-color",i)});if(i.prefix!=""){n(this).before(''+i.prefix+""),o=n(this).prev();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":n(this).css("padding-left"),"padding-right":0,"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px","margin-left":0,"margin-right":0}).on("click",function(){n(this).next().focus()});n(this).css("padding-left",o.width()+parseInt(n(this).css("padding-left"))+2+"px")}if(i.suffix!=""){n(this).after(''+i.suffix+""),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":"3px","padding-right":n(this).css("padding-right"),"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px"}).on("click",function(){n(this).prev().focus()});o.css("margin-left","-"+(o.width()+parseInt(n(this).css("padding-right"))+4)+"px"),c=o.width()+parseInt(n(this).css("padding-right"))+4,n(this).css("padding-right",c+"px"),o.find("div").css("background-color","#"+n(f).val())}break;case"select":case"list":if(this.tagName!="SELECT"){console.log("ERROR: You can only apply $().w2field('list') to a SELECT element");return}var h={url:"",items:[],value:null,showNone:!0},f=this,e=n.extend({},h,i);n(f).data("settings",e),f.refresh=function(){var i=n(f).data("settings"),e="",r=t.cleanItems(i.items),u;i.showNone&&(e='- '+w2utils.lang("none")+" -");for(u in r)i.showNone||i.value!=null||(i.value=r[u].id),e+=''+r[u].text+"";n(f).html(e),n(f).val(i.value),n(f).val()!=i.value&&n(f).change()},e.url!=""?n.ajax({type:"GET",dataType:"text",url:e.url,complete:function(i,r){if(r=="success"){var e=n.parseJSON(i.responseText),u=n(f).data("settings");u.items=t.cleanItems(e.items),n(f).data("settings",u),f.refresh()}}}):f.refresh();break;case"enum":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('enum') to an INPUT element");return}var h={url:"",items:[],selected:[],max:0,maxHeight:172,showAll:!1,match:"begins with",render:null,maxCache:500,onShow:null,onHide:null,onAdd:null,onRemove:null,onItemOver:null,onItemOut:null,onItemClick:null},f=this,e=n.extend({},h,i);e.items=t.cleanItems(e.items),e.selected=t.cleanItems(e.selected),n(this).data("selected",e.selected),n(this).css({padding:"0px","border-color":"transparent","background-color":"transparent",outline:"none"}),this.add=function(t){var i,r,u;n(this).attr("readonly")||(i=n(this).data("selected"),r=n(this).data("settings"),typeof r.onAdd!="function"||(u=r.onAdd(t,r),u!==!1))&&(n.isArray(i)||(i=[]),r.max!=0&&r.max<=i.length&&i.splice(i.length-1,1),i.push(t),n(this).data("last_del",null),n(this).trigger("change"))},this.remove=function(i){var r=n(this).data("settings"),u;(typeof r.onRemove!="function"||(u=r.onRemove(i,r),u!==!1))&&(n(this).attr("readonly")||(n(this).data("selected").splice(i,1),n(this).parent().find("[title=Remove][index="+i+"]").remove(),this.refresh(),t.list_render.call(this),n(this).trigger("change")))},this.show=function(){var i,u,r;if(!n(this).attr("readonly")){if(i=n(this).data("settings"),n("#w2ui-global-items").length==0)n("body").append('');else return;u=n("#w2ui-global-items"),u.css({display:"block",left:n(f).offset().left+"px",top:n(f).offset().top+f.offsetHeight+3+"px"}).width(w2utils.getSize(f,"width")).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),t.list_render.call(f),r=function(){var i=n("#w2ui-global-items");if(n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(n(f).data("mtimer")),hide();return}i.data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&(i.css({"-webkit-transition":".2s",left:n(f).offset().left+"px",top:n(f).offset().top+f.offsetHeight+3+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),setTimeout(function(){t.list_render.call(f,n(f).data("last_search"))},200)),i.length>0&&n(f).data("mtimer",setTimeout(r,100))},n(f).data("mtimer",setTimeout(r,100)),typeof i.onShow=="function"&&i.onShow.call(this,i)}},this.hide=function(){var t=n(this).data("settings");clearTimeout(n(f).data("mtimer")),n("#w2ui-global-items").remove(),typeof t.onHide=="function"&&t.onHide.call(this,t)},this.refresh=function(){var r=this,i,t;n(n(this).data("div")).remove();var o="margin-top: "+n(this).css("margin-top")+"; margin-bottom: "+n(this).css("margin-bottom")+"; margin-left: "+n(this).css("margin-left")+"; margin-right: "+n(this).css("margin-right")+"; width: "+(w2utils.getSize(this,"width")-parseInt(n(this).css("margin-left"))-parseInt(n(this).css("margin-right")))+"px; ",u='',f=n(this).data("selected");for(i in f)u+='\t '+f[i].text+"";u+='\t',n(this).before(u),t=n(this).prev()[0],n(this).data("div",t);n(t).find("li").data("mouse","out").on("click",function(t){if(!n(t.target).hasClass("nomouse")){if(t.target.title==w2utils.lang("Remove")){r.remove(n(t.target).attr("index"));return}t.stopPropagation(),typeof e.onItemClick=="function"&&e.onItemClick.call(this,e)}}).on("mouseover",function(t){var i=t.target;(i.tagName!="LI"&&(i=i.parentNode),n(i).hasClass("nomouse"))||(n(i).data("mouse")=="out"&&typeof e.onItemOver=="function"&&e.onItemOver.call(this,e),n(i).data("mouse","over"))}).on("mouseout",function(t){var i=t.target;(i.tagName!="LI"&&(i=i.parentNode),n(i).hasClass("nomouse"))||(n(i).data("mouse","leaving"),setTimeout(function(){n(i).data("mouse")=="leaving"&&(n(i).data("mouse","out"),typeof e.onItemOut=="function"&&e.onItemOut.call(this,e))},0))});n(t).on("click",function(){n(this).find("input").focus()}).find("input").on("focus",function(i){n(t).css({outline:"auto 5px -webkit-focus-ring-color","outline-offset":"-2px"}),r.show(),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0}).on("blur",function(i){n(t).css("outline","none"),r.hide(),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0});r.resize()},this.resize=function(){var r=n(this).data("settings"),i=n(this).prev(),t=n(i).find(">div").height();t<23&&(t=23),t>r.maxHeight&&(t=r.maxHeight),n(i).height(t+(t%23==0?0:23-t%23)),i.length>0&&(i[0].scrollTop=1e3),n(this).height(t)},n(this).data("settings",e).attr("tabindex",-1),f.refresh();break;case"upload":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('upload') to an INPUT element");return}var h={url:"",base64:!0,hint:w2utils.lang("Attach files by dragging and dropping or Click to Select"),max:0,maxSize:0,maxFileSize:0,onAdd:null,onRemove:null,onItemClick:null,onItemDblClick:null,onItemOver:null,onItemOut:null,onProgress:null,onComplete:null},f=this,e=n.extend({},h,i);e.base64===!0&&(e.maxSize==0&&(e.maxSize=20971520),e.maxFileSize==0&&(e.maxFileSize=20971520)),a=e.selected,delete e.selected,n.isArray(a)||(a=[]),n(this).data("selected",a).data("settings",e).attr("tabindex",-1),t.upload_init.call(this),this.refresh=function(){var o=this,r=n(this).data("div"),i=n(this).data("settings"),c=n(this).data("selected"),h,t,s,l,e,f,u;n(r).find("li").remove(),n(r).find("> span:first-child").css("line-height",n(r).height()-w2utils.getSize(r,"+height")-8+"px");for(h in c){t=c[h],s=n(r).find(".file-list li").length,n(r).find("> span:first-child").remove(),n(r).find(".file-list").append('\t \t'+t.name+'\t - '+w2utils.size(t.size)+""),l=n(r).find(".file-list #file-"+s),e="",/image/i.test(t.type)&&(e='\t= h && w > 300) $(this).width(300);\t\t\tif (w < h && h > 300) $(this).height(300);"\t\tonerror="this.style.display = \'none\'"\t>'),f='style="padding: 3px; text-align: right; color: #777;"',u='style="padding: 3px"',e+='\t\tName:"+t.name+"\tSize:"+w2utils.size(t.size)+"\tType:\t\t'+t.type+"\t\tModified:"+w2utils.date(t.modified)+"\t";l.data("file",t).on("click",function(t){if(typeof i.onItemClick=="function"){var r=i.onItemClick.call(o,n(this).data("file"));if(r===!1)return}n(t.target).hasClass("file-delete")||t.stopPropagation()}).on("dblclick",function(t){if(typeof i.onItemDblClick=="function"){var r=i.onItemDblClick.call(o,n(this).data("file"));if(r===!1)return}t.stopPropagation(),document.selection?document.selection.empty():document.defaultView.getSelection().removeAllRanges()}).on("mouseover",function(){var u,r;(typeof i.onItemOver!="function"||(u=i.onItemOver.call(o,n(this).data("file")),u!==!1))&&(r=n(this).data("file"),n(this).w2overlay(e.replace("##FILE##",r.content?"data:"+r.type+";base64,"+r.content:""),{top:-4}))}).on("mouseout",function(){if(typeof i.onItemOut=="function"){var t=i.onItemOut.call(o,n(this).data("file"));if(t===!1)return}n(this).w2overlay()})}},this.refresh();break;case"slider":break;default:console.log('ERROR: w2field does not recognize "'+i.type+'" field type.')}})},addType:function(n,i){t.customTypes[String(n).toLowerCase()]=i},cleanItems:function(t){var e=[],f;for(f in t){var r="",u="",i=t[f];if(i!=null){if(n.isPlainObject(t))r=f,u=i;else if(typeof i=="object"&&(typeof i.id!="undefined"&&(r=i.id),typeof i.value!="undefined"&&(r=i.value),typeof i.txt!="undefined"&&(u=i.txt),typeof i.text!="undefined"&&(u=i.text)),typeof i=="string"){if(String(i)=="")continue;r=i,u=i,i={}}w2utils.isInt(r)&&(r=parseInt(r)),w2utils.isFloat(r)&&(r=parseFloat(r)),e.push(n.extend({},i,{id:r,text:u}))}}return e},upload_init:function(){var i=this,o=n(this).data("settings"),u=n(i).prev(),e,f,r;u.length>0&&u[0].tagName=="DIV"&&u.hasClass("w2ui-upload")&&u.remove(),e="margin-top: "+n(i).css("margin-top")+"; margin-bottom: "+n(i).css("margin-bottom")+"; margin-left: "+n(i).css("margin-left")+"; margin-right: "+n(i).css("margin-right")+"; width: "+(w2utils.getSize(i,"width")-parseInt(n(i).css("margin-left"))-parseInt(n(i).css("margin-right")))+"px; height: "+(w2utils.getSize(i,"height")-parseInt(n(i).css("margin-top"))-parseInt(n(i).css("margin-bottom")))+"px; ",f='\t'+o.hint+'\t\t',n(i).css({display1:"none","border-color":"transparent"}).before(f),n(i).data("div",n(i).prev()[0]),r=n(i).data("div");n(r).find(".file-input").off("change").on("change",function(){if(typeof this.files!="undefined")for(var n=0,r=this.files.length;ni.maxFileSize){r="Maximum file size is "+w2utils.size(i.maxFileSize),n(o).w2tag(r),console.log("ERROR: "+r);return}if(i.maxSize!=0&&l+f.size>i.maxSize){r="Maximum total size is "+w2utils.size(i.maxFileSize),n(o).w2tag(r),console.log("ERROR: "+r);return}if(i.max!=0&&a>=i.max){r="Maximum number of files is "+i.max,n(o).w2tag(r),console.log("ERROR: "+r);return}(typeof i.onAdd!="function"||(h=i.onAdd.call(u,f),h!==!1))&&(s.push(f),typeof FileReader!="undefined"&&i.base64===!0?(e=new FileReader,e.onload=function(){return function(t){var i=t.target.result,r=i.indexOf(",");f.content=i.substr(r+1),u.refresh(),n(u).trigger("change")}}(),e.readAsDataURL(t)):(u.refresh(),n(u).trigger("change")))},upload_remove:function(t){var r=this,s=n(r).data("div"),e=n(r).data("settings"),u=n(r).data("selected"),f=n(t).data("file"),o,i;if(typeof e.onRemove=="function"&&(o=e.onRemove.call(r,f),o===!1))return!1;for(i=u.length-1;i>=0;i--)u[i].name==f.name&&u[i].size==f.size&&u.splice(i,1);n(t).fadeOut("fast"),setTimeout(function(){n(t).remove(),u.length==0&&n(s).prepend(""+e.hint+""),r.refresh(),n(r).trigger("change")},300)},list_render:function(i){var r=this,e=n("#w2ui-global-items"),u=n(this).data("settings"),o=u.items,v=n(this).data("selected"),k,a,w,f,c,h,g,y;if(e.length!=0){typeof i=="undefined"&&(k="",k+='',e.html(k),i=""),n(this).data("last_search",i),(typeof n(r).data("last_index")=="undefined"||n(r).data("last_index")==null)&&n(r).data("last_index",0),typeof u.last_total=="undefined"&&(u.last_total=-1),typeof u.last_search_len=="undefined"&&(u.last_search_len=0),typeof u.last_search_match=="undefined"&&(u.last_search_match=-1),u.url!=""&&(o.length==0&&u.last_total!=0||i.length>u.last_search_len&&u.last_total>u.maxCache||i.length",d=[];for(f in v)d.push(w2utils.isInt(v[f].id)?parseInt(v[f].id):String(v[f].id));w="";for(f in o)if(c=o[f].id,h=o[f].text,n.inArray(w2utils.isInt(c)?parseInt(c):String(c),d)==-1||u.showAll===!0){var p=String(i).toLowerCase(),b=h.toLowerCase(),a=p.length<=b.length&&b.substr(0,p.length)==p;u.match.toLowerCase()=="contains"&&b.indexOf(p)!=-1&&(a=!0),a&&(typeof u.render=="function"&&(h=u.render(o[f],v)),h!==!1&&(typeof o[f].group!="undefined"&&o[f].group!=w&&(w=o[f].group,l+=''+w+""),l+='\n'+h+"",s==n(r).data("last_index")&&n(r).data("last_item",o[f]),s++))}l+="",s==0&&(l=''+w2utils.lang("No items found")+"",g=!0),e.find(".w2ui-items-list").html(l),n(this).data("last_max",s-1),e.find("li.selected").length>0&&e.find("li.selected")[0].scrollIntoView(!1),e.css({"-webkit-transition":"0s",height:"auto"}),y=parseInt(n(document).height())-parseInt(e.offset().top)-8,parseInt(e.height())>y&&(e.css({height:y-5+"px",overflow:"show"}),n(e).find(".w2ui-items-list").css({height:y-15+"px",overflow:"auto"}));n(e).off("mousedown").on("mousedown",function(i){var e=i.target,f,o;if(e.tagName!="LI"&&(e=n(e).parents("li")),f=n(e).attr("index"),f){if(o=u.items[f],typeof f=="undefined")if(i.preventDefault)i.preventDefault();else return!1;r.add(o),n(r).data("last_index",0),r.refresh(),t.list_render.call(r,"")}});n(r).prev().find("li > input").val(i).css("max-width",n(e).width()-25+"px").width((i.length+2)*6+"px").focus().on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0}).off("keyup").on("keyup",function(i){var u=this;setTimeout(function(){var f=n(r).data("last_index"),e;switch(i.keyCode){case 38:f--,f<0&&(f=0),n(r).data("last_index",f),i.preventDefault&&i.preventDefault();break;case 40:f++,f>n(r).data("last_max")&&(f=n(r).data("last_max")),n(r).data("last_index",f),i.preventDefault&&i.preventDefault();break;case 13:if(typeof n(r).data("last_item")=="undefined"||n(r).data("last_item")==null||g===!0)break;e=n(r).data("selected"),r.add(n(r).data("last_item")),f>n(r).data("last_max")-1&&(f=n(r).data("last_max")-1),n(r).data("last_index",f),n(r).data("last_item",null),n(u).val(""),r.refresh(),i.preventDefault&&i.preventDefault();break;case 8:String(u.value)==""&&(typeof n(r).data("last_del")=="undefined"||n(r).data("last_del")==null?(e=n(r).data("selected"),n.isArray(e)||(e=[]),n(r).data("last_del",e.length-1),r.refresh()):(e=n(r).data("selected"),r.remove(e.length-1)));break;default:n(r).data("last_index",0),n(r).data("last_del",null)}r.resize(),i.keyCode==8&&String(u.value)==""||(n(r).prev().find("li").css("opacity","1"),n(r).data("last_del",null)),n.inArray(i.keyCode,[16,91,37,39])==-1&&t.list_render.call(r,u.value)},10)})}},calendar_get:function(t,i){var e=new Date,s=Number(e.getMonth())+1+"/"+e.getDate()+"/"+(String(e.getYear()).length>3?e.getYear():e.getYear()+1900),o;(String(t)==""||String(t)=="undefined")&&(t=w2utils.formatDate(s,i.format)),w2utils.isDate(t,i.format)||(t=w2utils.formatDate(s,i.format));var r=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),f=i.format.replace(/-/g,"/").replace(/\./g,"/").toLowerCase(),u=new Date;return f=="mm/dd/yyyy"&&(u=new Date(r[0]+"/"+r[1]+"/"+r[2])),f=="m/d/yyyy"&&(u=new Date(r[0]+"/"+r[1]+"/"+r[2])),f=="dd/mm/yyyy"&&(u=new Date(r[1]+"/"+r[0]+"/"+r[2])),f=="d/m/yyyy"&&(u=new Date(r[1]+"/"+r[0]+"/"+r[2])),f=="yyyy/dd/mm"&&(u=new Date(r[2]+"/"+r[1]+"/"+r[0])),f=="yyyy/d/m"&&(u=new Date(r[2]+"/"+r[1]+"/"+r[0])),f=="yyyy/mm/dd"&&(u=new Date(r[1]+"/"+r[2]+"/"+r[0])),f=="yyyy/m/d"&&(u=new Date(r[1]+"/"+r[2]+"/"+r[0])),o=''+n().w2field("calendar_month",u.getMonth()+1,u.getFullYear(),i)+""},calendar_next:function(t){var f=String(t).split("/"),i=f[0],u=f[1],r;parseInt(i)<12?i=parseInt(i)+1:(i=1,u=parseInt(u)+1),r=n(n("#global_calendar_div.w2ui-calendar").data("el")).data("options"),n("#global_calendar_div.w2ui-calendar").html(n().w2field("calendar_get",w2utils.formatDate(i+"/1/"+u,r.format),r))},calendar_previous:function(t){var f=String(t).split("/"),i=f[0],u=f[1],r;parseInt(i)>1?i=parseInt(i)-1:(i=12,u=parseInt(u)-1),r=n(n("#global_calendar_div.w2ui-calendar").data("el")).data("options"),n("#global_calendar_div.w2ui-calendar").html(n().w2field("calendar_get",w2utils.formatDate(i+"/1/"+u,r.format),r))},calendar_month:function(t,i,r){var u=new Date,rt=w2utils.settings.fullmonths,et=w2utils.settings.fulldays,p=["31","28","31","30","31","30","31","31","30","31","30","31"],ft=Number(u.getMonth())+1+"/"+u.getDate()+"/"+(String(u.getYear()).length>3?u.getYear():u.getYear()+1900),c,g,e,s,f,v,o,h,l;i=Number(i),t=Number(t),(i===null||i==="")&&(i=String(u.getYear()).length>3?u.getYear():u.getYear()+1900),(t===null||t==="")&&(t=Number(u.getMonth())+1),t>12&&(t=t-12,i++),(t<1||t==0)&&(t=t+12,i--),p[1]=i/4==Math.floor(i/4)?"29":"28",i==null&&(i=u.getYear()),t==null&&(t=u.getMonth()-1),u=new Date,u.setDate(1),u.setMonth(t-1),u.setYear(i);var y=u.getDay(),nt=w2utils.settings.shortdays,d="";for(c=0,g=nt.length;c"+nt[c]+"";for(e='\t <- \t -> "+rt[t-1]+", "+i+'\t'+d+"\t",s=1,f=1;f<43;f++){if(y==0&&f==1){for(v=0;v<6;v++)e+=' ';f+=6}else if(fp[t-1]){e+=' ',f%7==0&&(e+="");continue}o=t+"/"+s+"/"+i,h="",f%7==6&&(h="w2ui-saturday"),f%7==0&&(h="w2ui-sunday"),o==ft&&(h+=" w2ui-today");var ut=s,b="",w="",a="";if(r.colored&&r.colored[o]!=undefined&&(tmp=r.colored[o].split(":"),w="background-color: "+tmp[0]+";",b="color: "+tmp[1]+";"),l=!1,r.start||r.end){var tt=new Date(r.start),it=new Date(r.end),k=new Date(o);(kit)&&(a=" w2ui-blocked-date",l=!0)}r.blocked&&n.inArray(o,r.blocked)!=-1&&(a=" w2ui-blocked-date",l=!0),e+='"+ut+"",(f%7==0||y==0&&f==1)&&(e+=""),s++}return e+=""},getColorHTML:function(n){for(var r='',u=[["000000","444444","666666","999999","CCCCCC","EEEEEE","F3F3F3","FFFFFF"],["FF011B","FF9838","FFFD59","01FD55","00FFFE","0424F3","9B24F4","FF21F5"],["F4CCCC","FCE5CD","FFF2CC","D9EAD3","D0E0E3","CFE2F3","D9D1E9","EAD1DC"],["EA9899","F9CB9C","FEE599","B6D7A8","A2C4C9","9FC5E8","B4A7D6","D5A6BD"],["E06666","F6B26B","FED966","93C47D","76A5AF","6FA8DC","8E7CC3","C27BA0"],["CC0814","E69138","F1C232","6AA84F","45818E","3D85C6","674EA7","A54D79"],["99050C","B45F17","BF901F","37761D","124F5C","0A5394","351C75","741B47"],["660205","783F0B","7F6011","274E12","0C343D","063762","20124D","4C1030"]],i,t=0;t<8;t++){for(r+="",i=0;i<8;i++)r+="\t\t\t'+(n==u[t][i]?"":" ")+"\t";r+="",t<2&&(r+='')}return r+=""}}),w2obj.field=t}(jQuery),function($){var w2form=function(n){this.name=null,this.header="",this.box=null,this.url="",this.formURL="",this.formHTML="",this.page=0,this.recid=0,this.fields=[],this.actions={},this.record={},this.original={},this.postData={},this.toolbar={},this.tabs={},this.style="",this.focus=0,this.msgNotJSON=w2utils.lang("Return data is not in JSON format."),this.msgRefresh=w2utils.lang("Refreshing..."),this.msgSaving=w2utils.lang("Saving..."),this.onRequest=null,this.onLoad=null,this.onValidate=null,this.onSubmit=null,this.onSave=null,this.onChange=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,this.onAction=null,this.onToolbar=null,this.onError=null,this.isGenerated=!1,this.last={xhr:null},$.extend(!0,this,w2obj.form,n)};$.fn.w2form=function(n){var s,u,i,r;if(typeof n!="object"&&n){if(w2ui[$(this).attr("name")])return r=w2ui[$(this).attr("name")],r[n].apply(r,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+n+" does not exist on jQuery.w2form")}else{if(r=this,!n||typeof n.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2form().');return}if(typeof w2ui[n.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+").");return}if(!w2utils.isAlphaNumeric(n.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var o=n.record,e=n.original,h=n.fields,c=n.toolbar,f=n.tabs,t=new w2form(n);if($.extend(t,{record:{},original:{},fields:[],tabs:{},toolbar:{},handlers:[]}),$.isArray(f)){$.extend(!0,t.tabs,{tabs:[]});for(s in f)u=f[s],typeof u=="object"?t.tabs.tabs.push(u):t.tabs.tabs.push({id:u,caption:u})}else $.extend(!0,t.tabs,f);$.extend(!0,t.toolbar,c);for(i in h)t.fields[i]=$.extend(!0,{},h[i]);for(i in o)t.record[i]=$.isPlainObject(o[i])?$.extend(!0,{},o[i]):o[i];for(i in e)t.original[i]=$.isPlainObject(e[i])?$.extend(!0,{},e[i]):e[i];return r.length>0&&(t.box=r[0]),t.formURL!=""?$.get(t.formURL,function(n){t.formHTML=n,t.isGenerated=!0,($(t.box).length!=0||n.length!=0)&&($(t.box).html(n),t.render(t.box))}):t.formHTML!=""||(t.formHTML=$(this).length!=0&&$.trim($(this).html())!=""?$(this).html():t.generateHTML()),w2ui[t.name]=t,t.formURL==""&&(String(t.formHTML).indexOf("w2ui-page")==-1&&(t.formHTML=''+t.formHTML+""),$(t.box).html(t.formHTML),t.isGenerated=!0,t.render(t.box)),t}},w2form.prototype={get:function(n,t){for(var i in this.fields)if(this.fields[i].name==n)return t===!0?i:this.fields[i];return null},set:function(n,t){for(var i in this.fields)if(this.fields[i].name==n)return $.extend(this.fields[i],t),this.refresh(),!0;return!1},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t&&this.recid!=0?this.request(n):(this.refresh(),typeof n=="function"&&n())},clear:function(){var n,t;this.recid=0,this.record={};for(n in this.fields)t=this.fields[n];$().w2tag(),this.refresh()},error:function(n){var i=this,t=this.trigger({target:this.name,type:"error",message:n,xhr:this.last.xhr});if(t.isCancelled===!0)return typeof callBack=="function"&&callBack(),!1;setTimeout(function(){w2alert(n,"Error")},1),this.trigger($.extend(t,{phase:"after"}))},validate:function(n){var i,e,t,u,r,o,f;typeof n=="undefined"&&(n=!0),i=[];for(e in this.fields){t=this.fields[e],this.record[t.name]==null&&(this.record[t.name]="");switch(t.type){case"int":this.record[t.name]&&!w2utils.isInt(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not an integer")});break;case"float":this.record[t.name]&&!w2utils.isFloat(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a float")});break;case"money":this.record[t.name]&&!w2utils.isMoney(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not in money format")});break;case"hex":this.record[t.name]&&!w2utils.isHex(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a hex number")});break;case"email":this.record[t.name]&&!w2utils.isEmail(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a valid email")});break;case"checkbox":this.record[t.name]=this.record[t.name]==!0?1:0;break;case"date":this.record[t.name]&&!w2utils.isDate(this.record[t.name],t.options.format)&&i.push({field:t,error:w2utils.lang("Not a valid date")+": "+t.options.format})}u=this.record[t.name],t.required&&(u===""||$.isArray(u)&&u.length==0)&&i.push({field:t,error:w2utils.lang("Required field")}),t.equalto&&this.record[t.name]!=this.record[t.equalto]&&i.push({field:t,error:w2utils.lang("Field should be equal to ")+t.equalto})}if(r=this.trigger({phase:"before",target:this.name,type:"validate",errors:i}),r.isCancelled===!0)return i;if(n)for(o in r.errors)f=r.errors[o],$(f.field.el).w2tag(f.error,{"class":"w2ui-error"});return this.trigger($.extend(r,{phase:"after"})),i},request:function(postData,callBack){var obj=this,params,eventData,url;if(typeof postData=="function"&&(callBack=postData,postData=null),(typeof postData=="undefined"||postData==null)&&(postData={}),this.url&&(typeof this.url!="object"||this.url.get)){if((this.recid==null||typeof this.recid=="undefined")&&(this.recid=0),params={},params.cmd="get-record",params.name=this.name,params.recid=this.recid,$.extend(params,this.postData),$.extend(params,postData),eventData=this.trigger({phase:"before",type:"request",target:this.name,url:this.url,postData:params}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."}),!1;if(this.record={},this.original={},this.lock(this.msgRefresh),url=eventData.url,typeof eventData.url=="object"&&eventData.url.get&&(url=eventData.url.get),this.last.xhr)try{this.last.xhr.abort()}catch(e){}this.last.xhr=$.ajax({type:"GET",url:url,data:String($.param(eventData.postData,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",complete:function(xhr,status){var eventData,responseText,data;if(obj.unlock(),eventData=obj.trigger({phase:"before",target:obj.name,type:"load",xhr:xhr,status:status}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."}),!1;if(responseText=obj.last.xhr.responseText,status!="error"){if(typeof responseText!="undefined"&&responseText!=""){if(typeof responseText=="object")data=responseText;else try{eval("data = "+responseText)}catch(e){}typeof data=="undefined"&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),data.status=="error"?obj.error(data.message):(obj.record=$.extend({},data.record),obj.original=$.extend({},data.record))}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText);obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),typeof callBack=="function"&&callBack(data)}}),this.trigger($.extend(eventData,{phase:"after"}))}},submit:function(n,t){return this.save(n,t)},save:function(postData,callBack){var obj=this,errors;if(typeof postData=="function"&&(callBack=postData,postData=null),errors=obj.validate(!0),errors.length!==0){obj.goto(errors[0].field.page);return}if((typeof postData=="undefined"||postData==null)&&(postData={}),!obj.url||typeof obj.url=="object"&&!obj.url.save){console.log("ERROR: Form cannot be saved because no url is defined.");return}obj.lock(obj.msgSaving+' '),setTimeout(function(){var params={},f,field,tmp,dt,eventData,url;params.cmd="save-record",params.name=obj.name,params.recid=obj.recid,$.extend(params,obj.postData),$.extend(params,postData),params.record=$.extend(!0,{},obj.record);for(f in obj.fields){field=obj.fields[f];switch(String(field.type).toLowerCase()){case"date":dt=params.record[field.name],(field.options.format.toLowerCase()=="dd/mm/yyyy"||field.options.format.toLowerCase()=="dd-mm-yyyy"||field.options.format.toLowerCase()=="dd.mm.yyyy")&&(tmp=dt.replace(/-/g,"/").replace(/\./g,"/").split("/"),dt=new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0])),params.record[field.name]=w2utils.formatDate(dt,"yyyy-mm-dd")}}if(eventData=obj.trigger({phase:"before",type:"submit",target:obj.name,url:obj.url,postData:params}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Saving aborted."}),!1;if(url=eventData.url,typeof eventData.url=="object"&&eventData.url.save&&(url=eventData.url.save),obj.last.xhr)try{obj.last.xhr.abort()}catch(e){}obj.last.xhr=$.ajax({type:w2utils.settings.RESTfull?obj.recid==0?"POST":"PUT":"POST",url:url,data:String($.param(eventData.postData,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",xhr:function(){var n=new window.XMLHttpRequest;return n.upload.addEventListener("progress",function(n){if(n.lengthComputable){var t=Math.round(n.loaded/n.total*100);$("#"+obj.name+"_progress").text(""+t+"%")}},!1),n},complete:function(xhr,status){var eventData,responseText,data;if(obj.unlock(),eventData=obj.trigger({phase:"before",target:obj.name,type:"save",xhr:xhr,status:status}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Saving aborted."}),!1;if(responseText=xhr.responseText,status!="error"){if(typeof responseText!="undefined"&&responseText!=""){if(typeof responseText=="object")data=responseText;else try{eval("data = "+responseText)}catch(e){}typeof data=="undefined"&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),data.status=="error"?obj.error(data.message):obj.original=$.extend({},obj.record)}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText);obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),typeof callBack=="function"&&callBack(data)}}),obj.trigger($.extend(eventData,{phase:"after"}))},50)},lock:function(n,t){var i=$(this.box).find("> div:first-child");w2utils.lock(i,n,t)},unlock:function(){var n=this;setTimeout(function(){w2utils.unlock(n.box)},25)},goto:function(n){typeof n!="undefined"&&(this.page=n),$(this.box).data("auto-size")===!0&&$(this.box).height(0),this.refresh()},generateHTML:function(){var t=[],e,f,n,r,o,i,u;for(e in this.fields)f="",n=this.fields[e],typeof n.html=="undefined"&&(n.html={}),n.html=$.extend(!0,{caption:"",span:6,attr:"",text:"",page:0},n.html),n.html.caption==""&&(n.html.caption=n.name),r='",n.type=="list"&&(r='"),n.type=="checkbox"&&(r='"),n.type=="textarea"&&(r='"),f+='\n '+n.html.caption+':\n '+r+n.html.text+"",typeof t[n.html.page]=="undefined"&&(t[n.html.page]=''),t[n.html.page]+=f;for(o in t)t[o]+="\n";if(i="",!$.isEmptyObject(this.actions)){i+='\n';for(u in this.actions)i+='\n ';i+="\n"}return t.join("")+i},action:function(n,t){var i=this.trigger({phase:"before",target:n,type:"action",originalEvent:t});if(i.isCancelled===!0)return!1;typeof this.actions[n]=="function"&&this.actions[n].call(this,t),this.trigger($.extend(i,{phase:"after"}))},resize:function(){function o(){s.width($(n.box).width()).height($(n.box).height()),i.css("top",n.header!=""?w2utils.getSize(t,"height"):0),f.css("top",(n.header!=""?w2utils.getSize(t,"height"):0)+(n.toolbar.items.length>0?w2utils.getSize(i,"height"):0)),u.css("top",(n.header!=""?w2utils.getSize(t,"height"):0)+(n.toolbar.items.length>0?w2utils.getSize(i,"height")+5:0)+(n.tabs.tabs.length>0?w2utils.getSize(f,"height")+5:0)),u.css("bottom",r.length>0?w2utils.getSize(r,"height"):0)}var n=this,e=this.trigger({phase:"before",target:this.name,type:"resize"});if(e.isCancelled===!0)return!1;var s=$(this.box).find("> div"),t=$(this.box).find("> div .w2ui-form-header"),i=$(this.box).find("> div .w2ui-form-toolbar"),f=$(this.box).find("> div .w2ui-form-tabs"),u=$(this.box).find("> div .w2ui-page"),h=$(this.box).find("> div .w2ui-page.page-"+this.page),c=$(this.box).find("> div .w2ui-page.page-"+this.page+" > div"),r=$(this.box).find("> div .w2ui-buttons");o(),(parseInt($(this.box).height())==0||$(this.box).data("auto-size")===!0)&&($(this.box).height((t.length>0?w2utils.getSize(t,"height"):0)+(this.tabs.tabs.length>0?w2utils.getSize(f,"height"):0)+(this.toolbar.items.length>0?w2utils.getSize(i,"height"):0)+(u.length>0?w2utils.getSize(c,"height")+w2utils.getSize(h,"+height")+12:0)+(r.length>0?w2utils.getSize(r,"height"):0)),$(this.box).data("auto-size",!0)),o(),n.trigger($.extend(e,{phase:"after"}))},refresh:function(){var i=this,e,f,n,t,u,r;if(this.box&&this.isGenerated&&typeof $(this.box).html()!="undefined"){if($(this.box).find("input, textarea, select").each(function(n,t){var e=typeof $(t).attr("name")!="undefined"?$(t).attr("name"):$(t).attr("id"),f=i.get(e),u,r;if(f&&(u=$(t).parents(".w2ui-page"),u.length>0))for(r=0;r<100;r++)if(u.hasClass("page-"+r)){f.page=r;break}}),e=this.trigger({phase:"before",target:this.name,type:"refresh",page:this.page}),e.isCancelled===!0)return!1;$(this.box).find(".w2ui-page").hide(),$(this.box).find(".w2ui-page.page-"+this.page).show(),$(this.box).find(".w2ui-form-header").html(this.header),typeof this.tabs=="object"&&this.tabs.tabs.length>0?($("#form_"+this.name+"_tabs").show(),this.tabs.active=this.tabs.tabs[this.page].id,this.tabs.refresh()):$("#form_"+this.name+"_tabs").hide(),typeof this.toolbar=="object"&&this.toolbar.items.length>0?($("#form_"+this.name+"_toolbar").show(),this.toolbar.refresh()):$("#form_"+this.name+"_toolbar").hide();for(f in this.fields){n=this.fields[f],n.el=$(this.box).find('[name="'+String(n.name).replace(/\\/g,"\\\\")+'"]')[0],typeof n.el=="undefined"&&console.log('ERROR: Cannot associate field "'+n.name+'" with html control. Make sure html control exists with the same name.'),n.el&&(n.el.id=n.name);$(n.el).off("change").on("change",function(){var r=this.value,s=i.record[this.name]?i.record[this.name]:"",u=i.get(this.name),n,f,t;if((u.type=="enum"||u.type=="upload")&&$(this).data("selected")){var e=$(this).data("selected"),o=i.record[this.name],r=[],s=[];if($.isArray(e))for(n in e)r[n]=$.extend(!0,{},e[n]);if($.isArray(o))for(n in o)s[n]=$.extend(!0,{},o[n])}if(f=i.trigger({phase:"before",target:this.name,type:"change",value_new:r,value_previous:s}),f.isCancelled===!0)return $(this).val(i.record[this.name]),!1;t=this.value,this.type=="checkbox"&&(t=this.checked?!0:!1),this.type=="radio"&&(t=this.checked?!0:!1),u.type=="enum"&&(t=r),u.type=="upload"&&(t=r),i.record[this.name]=t,i.trigger($.extend(f,{phase:"after"}))});n.required?$(n.el).parent().addClass("w2ui-required"):$(n.el).parent().removeClass("w2ui-required")}$(this.box).find("button, input[type=button]").each(function(n,t){$(t).off("click").on("click",function(n){var t=this.value;this.name&&(t=this.name),this.id&&(t=this.id),i.action(t,n)})});for(f in this.fields)if(n=this.fields[f],t=typeof this.record[n.name]!="undefined"?this.record[n.name]:"",n.el)switch(String(n.type).toLowerCase()){case"email":case"text":case"textarea":n.el.value=t;break;case"date":n.options||(n.options={}),n.options.format||(n.options.format=w2utils.settings.date_format),n.el.value=t,this.record[n.name]=t,$(n.el).w2field($.extend({},n.options,{type:"date"}));break;case"int":n.el.value=t,$(n.el).w2field("int");break;case"float":n.el.value=t,$(n.el).w2field("float");break;case"money":n.el.value=t,$(n.el).w2field("money");break;case"hex":n.el.value=t,$(n.el).w2field("hex");break;case"alphanumeric":n.el.value=t,$(n.el).w2field("alphaNumeric");break;case"checkbox":this.record[n.name]==!0||this.record[n.name]==1||this.record[n.name]=="t"?$(n.el).prop("checked",!0):$(n.el).prop("checked",!1);break;case"password":n.el.value=t;break;case"select":case"list":$(n.el).w2field($.extend({},n.options,{type:"list",value:t}));break;case"enum":if(typeof n.options=="undefined"||typeof n.options.url=="undefined"&&typeof n.options.items=="undefined"){console.log("ERROR: (w2form."+i.name+") the field "+n.name+" defined as enum but not field.options.url or field.options.items provided.");break}this.record[n.name]=w2obj.field.cleanItems(t),t=this.record[n.name],$(n.el).w2field($.extend({},n.options,{type:"enum",selected:t}));break;case"upload":$(n.el).w2field($.extend({},n.options,{type:"upload",selected:t}));break;default:console.log('ERROR: field type "'+n.type+'" is not recognized.')}for(u=$(this.box).find(".w2ui-page"),r=0;r *").length>1&&$(u[r]).wrapInner("");this.trigger($.extend(e,{phase:"after"})),this.resize()}},render:function(n){function f(){var n=$(t.box).find("input, select, textarea");n.length>t.focus&&n[t.focus].focus()}var t=this,i,u,r;if(typeof n=="object"&&($(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),this.box=n),this.isGenerated){if(i=this.trigger({phase:"before",target:this.name,type:"render",box:typeof n!="undefined"?n:this.box}),i.isCancelled===!0)return!1;if(u=""+(this.header!=""?''+this.header+"":"")+'\t\t'+this.formHTML+"",$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-form").html(u),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),typeof this.toolbar.render=="undefined"){this.toolbar=$().w2toolbar($.extend({},this.toolbar,{name:this.name+"_toolbar",owner:this}));this.toolbar.on("click",function(n){var i=t.trigger({phase:"before",type:"toolbar",target:n.target,originalEvent:n});if(i.isCancelled===!0)return!1;t.trigger($.extend(i,{phase:"after"}))})}if(typeof this.toolbar=="object"&&typeof this.toolbar.render=="function"&&this.toolbar.render($("#form_"+this.name+"_toolbar")[0]),typeof this.tabs.render=="undefined"){this.tabs=$().w2tabs($.extend({},this.tabs,{name:this.name+"_tabs",owner:this}));this.tabs.on("click",function(n){t.goto(this.get(n.target,!0))})}if(typeof this.tabs=="object"&&typeof this.tabs.render=="function"&&this.tabs.render($("#form_"+this.name+"_tabs")[0]),this.trigger($.extend(i,{phase:"after"})),this.resize(),r=typeof this.url!="object"?this.url:this.url.get,r&&this.recid!=0?this.request():this.refresh(),$(".w2ui-layout").length==0){this.tmp_resize=function(){w2ui[t.name].resize()};$(window).off("resize","body").on("resize","body",this.tmp_resize)}setTimeout(function(){t.resize(),t.refresh()},150),this.focus>=0&&setTimeout(f,500)}},destroy:function(){var n=this.trigger({phase:"before",target:this.name,type:"destroy"});if(n.isCancelled===!0)return!1;typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),typeof this.tabs=="object"&&this.tabs.destroy&&this.tabs.destroy(),$(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),delete w2ui[this.name],this.trigger($.extend(n,{phase:"after"})),$(window).off("resize","body")}},$.extend(w2form.prototype,w2utils.event),w2obj.form=w2form}(jQuery); \ No newline at end of file +var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function i(n){var t=/^[-+]?[0-9]+$/;return t.test(n)}function r(n){return typeof n=="string"&&(n=n.replace(w2utils.settings.decimalSymbol,".")),(typeof n=="number"||typeof n=="string"&&n!=="")&&!isNaN(Number(n))}function u(n){var t=w2utils.settings,i=new RegExp("^"+(t.currencyPrefix?"\\"+t.currencyPrefix+"?":"")+"[-+]?[0-9]*[\\"+w2utils.settings.decimalSymbol+"]?[0-9]+"+(t.currencySuffix?"\\"+t.currencySuffix+"?":"")+"$","i");return(typeof n=="string"&&(n=n.replace(new RegExp(t.groupSymbol,"g"),"")),typeof n=="object"||n==="")?!1:i.test(n)}function f(n){return/^[a-fA-F0-9]+$/.test(n)}function e(n){return/^[a-zA-Z0-9_-]+$/.test(n)}function o(n){return/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(n)}function s(n,t,r){var h,f,e,o,c,a,l,u,s;if(!n)return!1;if(h="Invalid Date",t==null&&(t=w2utils.settings.date_format),typeof n.getUTCFullYear=="function"&&typeof n.getUTCMonth=="function"&&typeof n.getUTCDate=="function")o=n.getUTCFullYear(),f=n.getUTCMonth(),e=n.getUTCDate();else if(typeof n.getFullYear=="function"&&typeof n.getMonth=="function"&&typeof n.getDate=="function")o=n.getFullYear(),f=n.getMonth(),e=n.getDate();else{if(n=String(n),RegExp("mon","ig").test(t))for(t=t.replace(/month/ig,"m").replace(/mon/ig,"m").replace(/dd/ig,"d").replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),n=n.replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),c=0,a=w2utils.settings.fullmonths.length;c=0;f=s||t.indexOf("AM")>=0;o=f?12:24;t=t.replace("AM","").replace("PM","");t=n.trim(t);var r=t.split(":"),u=parseInt(r[0]||0),e=parseInt(r[1]||0);return(!f||r.length!==1)&&r.length!==2?!1:r[0]===""||u<0||u>o||!this.isInt(r[0])||r[0].length>2?!1:r.length===2&&(r[1]===""||e<0||e>59||!this.isInt(r[1])||r[1].length!==2)?!1:!f&&o===u&&e!==0?!1:f&&r.length===1&&u===0?!1:i===!0?(s&&(u+=12),{hours:u,minutes:e}):!0}function c(n){var u;if(n===""||n==null||(u=new Date(n),w2utils.isInt(n)&&(u=new Date(Number(n))),u==="Invalid Date"))return"";var f=new Date,t=(f.getTime()-u.getTime())/1e3,i="",r="";return t<0?(i='future<\/span>',r=""):t<60?(i=Math.floor(t),r="sec",t<0&&(i=0,r="sec")):t<3600?(i=Math.floor(t/60),r="min"):t<86400?(i=Math.floor(t/3600),r="hour"):t<2592e3?(i=Math.floor(t/86400),r="day"):t<365.25*86400?(i=Math.floor(t/365.25/8640)/10,r="month"):t>=365.25*86400&&(i=Math.floor(t/365.25/8640)/10,r="year"),i+" "+r+(i>1?"s":"")}function l(n){var t;if(n===""||n==null||(t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),t==="Invalid Date"))return"";var u=w2utils.settings.shortmonths,f=new Date,i=new Date;i.setTime(i.getTime()-864e5);var r=u[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),o=u[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),s=u[i.getMonth()]+" "+i.getDate()+", "+i.getFullYear(),h=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),c=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=r;return r===o&&(e=h),r===s&&(e=w2utils.lang("Yesterday")),''+e+"<\/span>"}function a(n){if(!w2utils.isFloat(n)||n==="")return"";if(n=parseFloat(n),n===0)return 0;var t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t===0?0:1)+" "+["Bt","KB","MB","GB","TB"][t]}function v(n,i,r){var u="";return i==null&&(i=w2utils.settings.groupSymbol||","),r==null&&(r=w2utils.settings.decimalSymbol||"."),(w2utils.isFloat(n)||w2utils.isInt(n)||w2utils.isMoney(n))&&(t=String(n).split("."),u=String(t[0]).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+i),t[1]!=null&&(u+=w2utils.settings.decimalSymbol+t[1])),u}function y(n,t){var e=w2utils.settings.shortmonths,o=w2utils.settings.fullmonths,i;if((t||(t=this.settings.date_format),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),i==="Invalid Date"))return"";var r=i.getFullYear(),f=i.getMonth(),u=i.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[f]).replace("mon",w2utils.settings.shortmonths[f]).replace(/yyyy/g,r).replace(/yyy/g,r).replace(/yy/g,r>2e3?100+parseInt(String(r).substr(2)):String(r).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+r).replace(/mm/g,(f+1<10?"0":"")+(f+1)).replace(/dd/g,(u<10?"0":"")+u).replace(/th/g,u==1?"st":"th").replace(/th/g,u==2?"nd":"th").replace(/th/g,u==3?"rd":"th").replace(/(^|[^a-z$])m/g,"$1"+(f+1)).replace(/(^|[^a-z$])d/g,"$1"+u)}function p(n,t){var h=w2utils.settings.shortmonths,c=w2utils.settings.fullmonths,i,o;if((t||(t=this.settings.time_format),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),w2utils.isTime(n)&&(o=w2utils.isTime(n,!0),i=new Date,i.setHours(o.hours),i.setMinutes(o.minutes)),i==="Invalid Date"))return"";var s="am",r=i.getHours(),e=i.getHours(),u=i.getMinutes(),f=i.getSeconds();return u<10&&(u="0"+u),f<10&&(f="0"+f),(t.indexOf("am")!==-1||t.indexOf("pm")!==-1)&&(r>=12&&(s="pm"),r>12&&(r=r-12)),t.toLowerCase().replace("am",s).replace("pm",s).replace("hhh",r<10?"0"+r:r).replace("hh24",e<10?"0"+e:e).replace("h24",e).replace("hh",r).replace("mm",u).replace("mi",u).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+r).replace(/(^|[^a-z$])m/g,"$1"+u).replace(/(^|[^a-z$])s/g,"$1"+f)}function w(n,t){var i;return n===""||n==null||typeof n=="object"&&!n.getMonth?"":(i=typeof t!="string"?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1]))}function b(t){if(t===null)return t;switch(typeof t){case"string":t=n.trim(String(t).replace(/(<([^>]+)>)/ig,""));break;case"object":for(var i in t)t[i]=this.stripTags(t[i])}return t}function k(n){if(n===null)return n;switch(typeof n){case"string":n=String(n).replace(/&/g,"&").replace(/>/g,">").replace(/\|\/? {}\\])/g,"\\$1")}function g(n){function l(n){for(var t,n=String(n).replace(/\r\n/g,"\n"),i="",r=0;r127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",o,t,i,h,c,s,r,u=0,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);u>2,c=(o&3)<<4|t>>4,s=(t&15)<<2|i>>6,r=i&63,isNaN(t)?s=r=64:isNaN(i)&&(r=64),e=e+f.charAt(h)+f.charAt(c)+f.charAt(s)+f.charAt(r);return e}function nt(n){function l(n){for(var r="",t=0,i=0,u,f;t191&&i<224?(u=n.charCodeAt(t+1),r+=String.fromCharCode((i&31)<<6|u&63),t+=2):(u=n.charCodeAt(t+1),f=n.charCodeAt(t+2),r+=String.fromCharCode((i&15)<<12|(u&63)<<6|f&63),t+=3);return r}var t="",o,s,h,c,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i>4,s=(f&15)<<4|r>>2,h=(r&3)<<6|e,t=t+String.fromCharCode(o),r!==64&&(t=t+String.fromCharCode(s)),e!==64&&(t=t+String.fromCharCode(h));return l(t)}function tt(t,i,r,u){function f(n,t,i){var r=!!window.webkitURL;return r||typeof i=="undefined"||(t=i),";"+n+": "+t+"; -webkit-"+n+": "+t+"; -moz-"+n+": "+t+"; -ms-"+n+": "+t+"; -o-"+n+": "+t+";"}var o=n(t).width(),s=n(t).height(),e=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+=f("perspective","700px")+"; overflow: hidden;";t.style.cssText+="; position: absolute; z-index: 1019; "+f("backface-visibility","hidden");i.style.cssText+="; position: absolute; z-index: 1020; "+f("backface-visibility","hidden");switch(r){case"slide-left":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)")},1);break;case"slide-right":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0px, 0, 0)","translate(0px, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)")},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; z-index: 0; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)")},1);break;case"slide-up":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateY(-180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(180deg)")},1);break;case"flip-right":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateY(180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(-180deg)")},1);break;case"flip-down":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateX(180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(-180deg)")},1);break;case"flip-up":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateX(-180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(180deg)")},1);break;case"pop-in":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(.8)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1)")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")+";"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(1)")+"; opacity: 1;";i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")},1)}setTimeout(function(){r==="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020"));i&&n(i).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""});t&&(n(t).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t.parentNode&&n(t.parentNode).css({"-webkit-perspective":"","-moz-perspective":"","-ms-perspective":"","-o-perspective":""}));typeof u=="function"&&u()},e*1e3)}function it(t,i,r){var u={},f,e;typeof i=="object"?u=i:(u.msg=i,u.spinner=r);u.msg||u.msg===0||(u.msg="");w2utils.unlock(t);n(t).prepend('<\/div><\/div>');f=n(t).find(".w2ui-lock");e=n(t).find(".w2ui-lock-msg");u.msg||e.css({"background-color":"transparent",border:"0px"});u.spinner===!0&&(u.msg='<\/div>"+u.msg);u.opacity!=null&&f.css("opacity",u.opacity);typeof f.fadeIn=="function"?(f.fadeIn(200),e.html(u.msg).fadeIn(200)):(f.show(),e.html(u.msg).show(0));n().w2tag()}function rt(t){n(t).find(".w2ui-lock").remove();n(t).find(".w2ui-lock-msg").remove()}function ut(t,i){var r=n(t),u={left:parseInt(r.css("border-left-width"))||0,right:parseInt(r.css("border-right-width"))||0,top:parseInt(r.css("border-top-width"))||0,bottom:parseInt(r.css("border-bottom-width"))||0},f={left:parseInt(r.css("margin-left"))||0,right:parseInt(r.css("margin-right"))||0,top:parseInt(r.css("margin-top"))||0,bottom:parseInt(r.css("margin-bottom"))||0},e={left:parseInt(r.css("padding-left"))||0,right:parseInt(r.css("padding-right"))||0,top:parseInt(r.css("padding-top"))||0,bottom:parseInt(r.css("padding-bottom"))||0};switch(i){case"top":return u.top+f.top+e.top;case"bottom":return u.bottom+f.bottom+e.bottom;case"left":return u.left+f.left+e.left;case"right":return u.right+f.right+e.right;case"width":return u.left+u.right+f.left+f.right+e.left+e.right+parseInt(r.width());case"height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom+parseInt(r.height());case"+width":return u.left+u.right+f.left+f.right+e.left+e.right;case"+height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom}return 0}function ft(n){var t=this.settings.phrases[n];return t==null?n:t}function et(t){t||(t="en-us");t.length===5&&(t="locale/"+t+".json");n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(t){var i,r;w2utils.settings=n.extend(!0,w2utils.settings,t);i=w2obj.grid.prototype;for(r in i.buttons)i.buttons[r].caption=w2utils.lang(i.buttons[r].caption),i.buttons[r].hint=w2utils.lang(i.buttons[r].hint);i.msgDelete=w2utils.lang(i.msgDelete);i.msgNotJSON=w2utils.lang(i.msgNotJSON);i.msgRefresh=w2utils.lang(i.msgRefresh)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function ot(){if(t.scrollBarSize)return t.scrollBarSize;return n("body").append(' 1<\/div><\/div>'),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}function st(n,t){return!n||typeof n.name=="undefined"?(console.log('ERROR: The parameter "name" is required but not supplied in $().'+t+"()."),!1):typeof w2ui[n.name]!="undefined"?(console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+")."),!1):w2utils.isAlphaNumeric(n.name)?!0:(console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '),!1)}function ht(t,i,r,u){n.isArray(i)||(i=[i]);for(var f=0;f=0;e--)if(t=this.handlers[e],(t.event.type===n.type||t.event.type==="*")&&(t.event.target===n.target||t.event.target===null)&&(t.event.execute===n.phase||t.event.execute==="*"||t.event.phase==="*")&&(n=jQuery.extend({},t.event,n),i=[],r=RegExp(/\((.*?)\)/).exec(t.handler),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;return(f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase==="before"&&typeof this[f]=="function"&&(u=this[f],i=[],r=RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0))?n:n.object!=null&&n.phase==="before"&&typeof n.object[f]=="function"&&(u=n.object[f],i=[],r=RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)?n:(n.phase==="after"&&typeof n.onComplete=="function"&&n.onComplete.call(this,n),n)}};w2utils.keyboard=function(n){function i(){jQuery(document).on("keydown",r);jQuery(document).on("mousedown",u)}function r(n){var i=n.target.tagName;jQuery.inArray(i,["INPUT","SELECT","TEXTAREA"])===-1&&jQuery(n.target).prop("contenteditable")!=="true"&&t&&w2ui[t]&&typeof w2ui[t].keydown=="function"&&w2ui[t].keydown.call(w2ui[t],n)}function u(n){var u=n.target.tagName,r=jQuery(n.target).parents(".w2ui-reset"),i;r.length>0&&(i=r.attr("name"),w2ui[i]&&w2ui[i].keyboard&&(t=i))}function f(n){return typeof n!="undefined"&&(t=n),t}function e(){t=null}var t=null;return n.active=f,n.clear=e,i(),n}({}),function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))};n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name"));typeof n=="string"&&w2ui[n]&&w2ui[n].destroy();typeof n=="object"&&n.destroy()};n.fn.w2marker=function(t){return t===""||t==null?n(this).each(function(n,t){t.innerHTML=t.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1")}):n(this).each(function(n,i){function e(n){return''+n+"<\/span>"}var u,r,f;typeof t=="string"&&(t=[t]);i.innerHTML=i.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1");for(u in t)r=t[u],typeof r!="string"&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(//g,"<"),f=new RegExp(r+"(?!([^<]+)?>)","gi"),i.innerHTML=i.innerHTML.replace(f,e)})};n.fn.w2tag=function(t,i){if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),typeof i["class"]=="undefined"&&(i["class"]=""),n(this).length===0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");r==null&&(r={});n(n(i).data("taged-el")).removeClass(r["class"]);clearInterval(n(i).data("timer"));n(i).remove()});return}return n(this).each(function(r,u){var h=u.id,f=w2utils.escapeId(u.id),s,o;if(t===""||t==null)n("#w2ui-tag-"+f).css("opacity",0),setTimeout(function(){clearInterval(n("#w2ui-tag-"+f).data("timer"));n("#w2ui-tag-"+f).remove()},300);else{clearInterval(n("#w2ui-tag-"+f).data("timer"));n("#w2ui-tag-"+f).remove();n("body").append('0?"w2ui-tag-popup":"")+'" style=""><\/div>');s=setInterval(function(){if(n(u).length===0||n(u).offset().left===0&&n(u).offset().top===0){clearInterval(n("#w2ui-tag-"+f).data("timer"));e();return}n("#w2ui-tag-"+f).data("position")!==n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top&&n("#w2ui-tag-"+f).css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top)},100);setTimeout(function(){n(u).offset()&&(n("#w2ui-tag-"+f).css({opacity:"1",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).html(' '+t+"<\/div> <\/div>").data("text",t).data("taged-el",u).data("options",i).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top).data("timer",s),n(u).off("keypress",e).on("keypress",e).off("change",e).on("change",e).css(i.css).addClass(i["class"]),typeof i.onShow=="function"&&i.onShow())},1);o="";n(u).length>0&&(o=n(u)[0].style.cssText);function e(){($tag=n("#w2ui-tag-"+f),$tag.length<=0)||(clearInterval($tag.data("timer")),$tag.remove(),n(u).off("keypress",e).removeClass(i["class"]),n(u).length>0&&(n(u)[0].style.cssText=o),typeof i.onHide=="function"&&i.onHide())}}})};n.fn.w2overlay=function(t,i){function l(){var t=n("#w2ui-overlay"+r),i;t.data("element")===u[0]&&t.length!==0&&(i=n(u).offset().left+"x"+n(u).offset().top,t.data("position")!==i?s():setTimeout(l,250))}function s(){var t=n("#w2ui-overlay"+r),u;if(t.data("keepOpen")===!0){t.removeData("keepOpen");return}(typeof i.onHide=="function"&&(u=i.onHide()),u!==!1)&&(t.remove(),n(document).off("click",s),clearInterval(t.data("timer")))}function h(){var o=n("#w2ui-overlay"+r),t=o.find(" > div"),e,l;if(o.length>0){t.height("auto").width("auto");var a=!1,s=t.height(),f=t.width();i.width&&i.widtht.find("div.menu > table").height()&&t.find("div.menu").css("overflow-y","hidden")},1),setTimeout(function(){t.find("div.menu").css("overflow-y","auto")},10));i.tmp.contentWidth&&(f=i.tmp.contentWidth,t.width(f),setTimeout(function(){t.width()>t.find("div.menu > table").width()&&t.find("div.menu").css("overflow-x","hidden")},1),setTimeout(function(){t.find("div.menu").css("overflow-y","auto")},10));switch(i.align){case"both":i.left=17;i.width===0&&(i.width=w2utils.getSize(n(u),"width"));break;case"left":i.left=17;break;case"right":i.tipLeft=f-45;i.left=w2utils.getSize(n(u),"width")-f+10}var v=(f-17)/2,p=i.left,y=i.width,c=i.tipLeft;y=f!==30||y?i.width?i.width:"auto":30;v<25&&(p=25-v,c=Math.floor(v));o.css({top:u.offset().top+w2utils.getSize(u,"height")+i.top+7+"px",left:(u.offset().left>25?u.offset().left:25)+p+"px","min-width":y,"min-height":i.height?i.height:"auto"});e=window.innerHeight+n(document).scrollTop()-t.offset().top-7;l=window.innerWidth+n(document).scrollLeft()-t.offset().left-7;e>-50&&e<210||i.openAbove===!0?(e=t.offset().top-n(document).scrollTop()-7,i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),s>e&&(a=!0,t.height(e).width(f).css({"overflow-y":"auto"}),s=e),o.css("top",n(u).offset().top-s-24+i.top+"px"),o.find(">style").html("#w2ui-overlay"+r+":before { display: none; margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { display: block; margin-left: "+parseInt(c)+"px; }")):(i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),s>e&&(a=!0,t.height(e).width(f).css({"overflow-y":"auto"})),o.find(">style").html("#w2ui-overlay"+r+":before { display: block; margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { display: none; margin-left: "+parseInt(c)+"px; }"));f=t.width();l=window.innerWidth+n(document).scrollLeft()-t.offset().left-7;i.maxWidth&&l>i.maxWidth&&(l=i.maxWidth);f>l&&i.align!=="both"&&(i.align="right",setTimeout(function(){h()},1));a&&!1&&t.width(f+w2utils.scrollBarSize()+2)}}var u=this,r="",f,e,c,o;if(arguments.length==1&&(i=typeof t=="object"?t:{html:t}),arguments.length==2&&(i.html=t),n.isPlainObject(i)||(i={}),i=n.extend({},{name:null,html:"",align:"none",left:0,top:0,tipLeft:30,width:0,height:0,maxWidth:null,maxHeight:null,style:"","class":"",onShow:null,onHide:null,openAbove:!1,tmp:{}},i),i.name&&(r="-"+i.name),this.length===0||i.html===""||i.html==null)return n("#w2ui-overlay"+r).length>0?(f=n("#w2ui-overlay"+r)[0].hide,typeof f=="function"&&f()):n("#w2ui-overlay"+r).remove(),n(this);n("#w2ui-overlay"+r).length>0&&(f=n("#w2ui-overlay"+r)[0].hide,n(document).off("click",f),typeof f=="function"&&f());n("body").append('0?"w2ui-overlay-popup":"")+'">
"+r.file+" "+i[0].name+" "+r.uploaded+"<\/p>").addClass("updated").delay(3e3).fadeOut(1e3,function(){n(this).remove()})},Error:function(t,i){n('
Error("+i.code+"): "+i.message+"<\/p>").addClass("error").delay(3e3).fadeOut(1e3,function(){n(this).remove()})}}});uf.init();n("#adv_nick").combogrid({url:w+"?action=load_combo_data",datatype:"json",munit:"px",alternate:!0,colModel:i.comboGrid,select:function(t,i){return n("#adv_nick").val(i.item.slug),n("#adv_name").val(i.item.title),n("#adv_mail").val(i.item.email),!1}});n("#add-file-button").click(function(){var t=u.url+n("select#files_list option:selected").val();return n("#ad_img").val(t),!1});e("ctt-grid",fi,su,"slug",i.customTaxes,kt.cTax);e("x-ctt-grid",ei,hu,"slug",i.customTaxes,kt.cTax);e("cust-grid",pi,du,"slug",i.customs,kt.customs);e("x-cust-grid",wi,gu,"slug",i.customs,kt.customs);nr=w+"?action=load_posts&cstr="+samEditorOptions.data.custList+"&sp="+nf+"&spg="+tf;ar("posts-grid",oi,cu,"id",i.posts,nr);ar("x-posts-grid",si,au,"id",i.posts,nr);n("#tabs").tabs({activate:function(t,i){var r=i.newPanel[0].id;r=="tabs-1"&&w2ui["posts-grid"]&&oi.w2render("posts-grid");r=="tabs-2"&&(vt.is(":visible")&&w2ui["ctt-grid"]&&fi.w2render("ctt-grid"),rt.is(":visible")&&w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid"),g.is(":visible")&&w2ui["x-posts-grid"]&&si.w2render("x-posts-grid"),at.is(":visible")&&w2ui["cats-grid"]&&hi.w2render("cats-grid"),tt.is(":visible")&&w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid"),yt.is(":visible")&&w2ui["auth-grid"]&&li.w2render("auth-grid"),ft.is(":visible")&&w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid"),pt.is(":visible")&&w2ui["tags-grid"]&&vi.w2render("tags-grid"),ot.is(":visible")&&w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid"),wt.is(":visible")&&w2ui["cust-grid"]&&pi.w2render("cust-grid"),ht.is(":visible")&&w2ui["xcust-grid"]&&wi.w2render("x-cust-grid"));r=="tabs-3"&&ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid");r=="tabs-5"&&o&&(o.destroy(),o=n.jqplot("graph",b,dt))}});n(window).resize(function(){o&&(o.destroy(),o=n.jqplot("graph",b,dt))});n("#code_mode_false").click(function(){ur.show("blind",{direction:"vertical"},500);fr.hide("blind",{direction:"vertical"},500)});n("#code_mode_true").click(function(){ur.hide("blind",{direction:"vertical"},500);fr.show("blind",{direction:"vertical"},500)});2==n("input:radio[name=view_type]:checked").val()&&(f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)),f.attr("disabled",!0));n("input:radio[name=view_type]").click(function(){var t=n("input:radio[name=view_type]:checked").val();switch(t){case"0":s.is(":hidden")&&s.show("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"1":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"2":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":hidden")&&(h.show("blind",{direction:"vertical"},500,function(){w2ui["posts-grid"]&&oi.w2render("posts-grid")}),f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)));f.attr("disabled",!0)}});vr=n.ajax({url:w,data:{action:"load_authors",level:3},type:"POST"});vr.done(function(n){tr=n;e("auth-grid",li,pu,"slug",i.authors,tr);e("x-auth-grid",ai,wu,"slug",i.authors,tr)});yr=n.ajax({url:w,data:{action:"load_users",subscriber:encodeURI(u.subscriber),contributor:encodeURI(u.contributor),author:encodeURI(u.author),editor:encodeURI(u.editor),admin:encodeURI(u.admin),sadmin:encodeURI(u.superAdmin)},type:"POST"});yr.done(function(n){pr=n;e("users-grid",lt,lu,"slug",i.users,pr)});wr=n.ajax({url:w,data:{action:"load_cats",level:3},type:"POST"});wr.done(function(n){ir=n;e("cats-grid",hi,vu,"slug",i.cats,ir);e("x-cats-grid",ci,yu,"slug",i.cats,ir)});br=n.ajax({url:w,data:{action:"load_tags",level:3},type:"POST"});br.done(function(n){rr=n;e("tags-grid",vi,bu,"slug",i.tags,rr);e("x-tags-grid",yi,ku,"slug",i.tags,rr)});f.click(function(){f.is(":checked")?2==n("input:radio[name=view_type]:checked").val()?f.attr("checked",!1):g.show("blind",{direction:"vertical"},500,function(){w2ui["x-posts-grid"]&&si.w2render("x-posts-grid")}):g.hide("blind",{direction:"vertical"},500)});n("input:radio[name=ad_users]").click(function(){var t=n("input:radio[name=ad_users]:checked").val();t=="0"?bt.is(":visible")&&bt.hide("blind",{direction:"vertical"},500):bt.is(":hidden")&&bt.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")})});er.click(function(){er.is(":checked")?or.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")}):or.hide("blind",{direction:"vertical"},500)});sr.click(function(){sr.is(":checked")?ct.show("blind",{direction:"vertical"},500,function(){w2ui["users-grid"]&<.w2render("users-grid")}):ct.hide("blind",{direction:"vertical"},500)});n("#ad_swf").click(function(){n("#ad_swf").is(":checked")?n("#swf-params").show("blind",{direction:"vertical"},500):n("#swf-params").hide("blind",{direction:"vertical"},500)});nt.is(":checked")&&c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500));nt.click(function(){nt.is(":checked")?(at.show("blind",{direction:"vertical"},500,function(){w2ui["cats-grid"]&&hi.w2render("cats-grid")}),ni.show("blind",{direction:"vertical"},500),c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500))):(at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))});c.click(function(){c.is(":checked")?(tt.show("blind",{direction:"vertical"},500,function(){w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid")}),nt.is(":checked")&&(nt.attr("checked",!1),at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))):tt.hide("blind",{direction:"vertical"},500)});it.is(":checked")&&l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500));it.click(function(){it.is(":checked")?(vt.show("blind",{direction:"vertical"},500,function(){w2ui["ctt-grid"]&&fi.w2render("ctt-grid")}),ti.show("blind",{direction:"vertical"},500),l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500))):(vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))});l.click(function(){l.is(":checked")?(rt.show("blind",{direction:"vertical"},500,function(){w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid")}),it.is(":checked")&&(it.attr("checked",!1),vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))):rt.hide("blind",{direction:"vertical"},500)});ut.is(":checked")&&a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500));ut.click(function(){ut.is(":checked")?(yt.show("blind",{direction:"vertical"},500,function(){w2ui["auth-grid"]&&li.w2render("auth-grid")}),ii.show("blind",{direction:"vertical"},500),a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500))):(yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))});a.click(function(){a.is(":checked")?(ft.show("blind",{direction:"vertical"},500,function(){w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid")}),ut.is(":checked")&&(ut.attr("checked",!1),yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))):ft.hide("blind",{direction:"vertical"},500)});et.is(":checked")&&v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500));et.click(function(){et.is(":checked")?(pt.show("blind",{direction:"vertical"},500,function(){w2ui["tags-grid"]&&vi.w2render("tags-grid")}),ri.show("blind",{direction:"vertical"},500),v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500))):(pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))});v.click(function(){v.is(":checked")?(ot.show("blind",{direction:"vertical"},500,function(){w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid")}),et.is(":checked")&&(et.attr("checked",!1),pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))):ot.hide("blind",{direction:"vertical"},500)});st.is(":checked")&&y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500));st.click(function(){st.is(":checked")?(wt.show("blind",{direction:"vertical"},500,function(){w2ui["cust-grid"]&&pi.w2render("cust-grid")}),ui.show("blind",{direction:"vertical"},500),y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500))):(wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))});y.click(function(){y.is(":checked")?(ht.show("blind",{direction:"vertical"},500,function(){w2ui["x-cust-grid"]&&wi.w2render("x-cust-grid")}),st.is(":checked")&&(st.attr("checked",!1),wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))):ht.hide("blind",{direction:"vertical"},500)});n("#ad_start_date, #ad_end_date").datepicker({dateFormat:"yy-mm-dd",showButtonPanel:!0});n("#ad_schedule").click(function(){n("#ad_schedule").is(":checked")?n("#rc-sc").show("blind",{direction:"vertical"},500):n("#rc-sc").hide("blind",{direction:"vertical"},500)});n("#limit_hits").click(function(){n("#limit_hits").is(":checked")?n("#rc-hl").show("blind",{direction:"vertical"},500):n("#rc-hl").hide("blind",{direction:"vertical"},500)});n("#limit_clicks").click(function(){n("#limit_clicks").is(":checked")?n("#rc-cl").show("blind",{direction:"vertical"},500):n("#rc-cl").hide("blind",{direction:"vertical"},500)});p=samEditorOptions.ads;p.pointer="ads";(p.enabled||""==gt.val())&>.pointer({content:"
"+p.content+"<\/p>",position:"top",close:function(){n.ajax({url:ajaxurl,data:{action:"close_pointer",pointer:p.pointer},async:!0})}}).pointer("open");var k=n("#is_singular"),kr=n("#is_single"),dr=n("#is_page"),gr=n("#is_attachment"),nu=n("#is_posttype");k.click(function(){k.is(":checked")&&n("#is_single, #is_page, #is_attachment, #is_posttype").attr("checked",!0)});n("#is_single, #is_page, #is_attachment, #is_posttype").click(function(){!k.is(":checked")||kr.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&nu.is(":checked")?!k.is(":checked")&&kr.is(":checked")&&nu.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&k.attr("checked",!0):k.attr("checked",!1)});var d=n("#is_archive"),tu=n("#is_tax"),iu=n("#is_category"),ru=n("#is_tag"),uu=n("#is_author"),fu=n("#is_date"),eu=n("#is_posttype_archive"),ou=n("#is_tax, #is_category, #is_tag, #is_author, #is_date, #is_posttype_archive");return d.click(function(){d.is(":checked")&&ou.attr("checked",!0)}),ou.click(function(){!d.is(":checked")||tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")?!d.is(":checked")&&tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")&&d.attr("checked",!0):d.attr("checked",!1)}),n("#stats_month").change(function(){bi=n(this).val();n.post(cr,{action:"load_item_stats",id:lr,sm:bi}).done(function(t){n("#total_hits").text(t.total.hits);n("#total_clicks").text(t.total.clicks);b=[t.hits,t.clicks];o&&(o.destroy(),o=n.jqplot("graph",b,dt))})}),!1})})(jQuery) \ No newline at end of file +var sam=sam||{};(function(n){var t,i=samEditorOptions.media,r=samEditorOptions.strings;sam.media=t={buttonId:"#banner-media",adUrl:"#ad_img",adImgId:"#ad_img_id",adName:"#title",adDesc:"#item_description",adAlt:"#ad_alt",init:function(){n(this.buttonId).on("click",this.openMediaDialog)},openMediaDialog:function(n){if(n.preventDefault(),this._frame){this._frame.open();return}this._frame=t.frame=wp.media({title:i.title,button:{text:i.button},multiple:!1,library:{type:"image"}});this._frame.on("ready",function(){});this._frame.state("library").on("select",function(){var n=this.get("selection").single();t.handleMediaAttachment(n)});this._frame.open()},handleMediaAttachment:function(t){var i=t.toJSON();n(this.adUrl).val(i.url);n(this.adImgId).val(i.id);""==n(this.adName).val()&&""!=i.title&&n(this.adName).val(i.title);""==n(this.adDesc).val()&&""!=i.caption&&n(this.adDesc).val(i.caption);""==n(this.adAlt).val()&&""!=i.alt&&n(this.adAlt).val(i.alt)}};n(document).ready(function(){function ar(t,i,r,u,f,e){var o=r.val();i.w2grid({name:t,show:{selectColumn:!0,toolbar:!0,footer:!0},multiSelect:!0,columns:f,url:e,limit:1e4,onSelect:function(n){n.onComplete=function(){for(var f,e="",t=this.getSelection(),i,n=0;n<\/div>').appendTo(hr);n("#ad_img").val(gi.adUrl+i[0].name);n("#files").html(""+r.file+" "+i[0].name+" "+r.uploaded+"<\/p>").addClass("updated").delay(3e3).fadeOut(1e3,function(){n(this).remove()})},Error:function(t,i){n('<\/div>').appendTo(hr);n("#files").html("Error("+i.code+"): "+i.message+"<\/p>").addClass("error").delay(3e3).fadeOut(1e3,function(){n(this).remove()})}}});uf.init();n("#adv_nick").combogrid({url:w+"?action=load_combo_data",datatype:"json",munit:"px",alternate:!0,colModel:i.comboGrid,select:function(t,i){return n("#adv_nick").val(i.item.slug),n("#adv_name").val(i.item.title),n("#adv_mail").val(i.item.email),!1}});n("#add-file-button").click(function(){var t=u.url+n("select#files_list option:selected").val();return n("#ad_img").val(t),!1});e("ctt-grid",fi,su,"slug",i.customTaxes,kt.cTax);e("x-ctt-grid",ei,hu,"slug",i.customTaxes,kt.cTax);e("cust-grid",pi,du,"slug",i.customs,kt.customs);e("x-cust-grid",wi,gu,"slug",i.customs,kt.customs);nr=w+"?action=load_posts&cstr="+samEditorOptions.data.custList+"&sp="+nf+"&spg="+tf+"&limit=10000";ar("posts-grid",oi,cu,"id",i.posts,nr);ar("x-posts-grid",si,au,"id",i.posts,nr);n("#tabs").tabs({activate:function(t,i){var r=i.newPanel[0].id;r=="tabs-1"&&w2ui["posts-grid"]&&oi.w2render("posts-grid");r=="tabs-2"&&(vt.is(":visible")&&w2ui["ctt-grid"]&&fi.w2render("ctt-grid"),rt.is(":visible")&&w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid"),g.is(":visible")&&w2ui["x-posts-grid"]&&si.w2render("x-posts-grid"),at.is(":visible")&&w2ui["cats-grid"]&&hi.w2render("cats-grid"),tt.is(":visible")&&w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid"),yt.is(":visible")&&w2ui["auth-grid"]&&li.w2render("auth-grid"),ft.is(":visible")&&w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid"),pt.is(":visible")&&w2ui["tags-grid"]&&vi.w2render("tags-grid"),ot.is(":visible")&&w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid"),wt.is(":visible")&&w2ui["cust-grid"]&&pi.w2render("cust-grid"),ht.is(":visible")&&w2ui["xcust-grid"]&&wi.w2render("x-cust-grid"));r=="tabs-3"&&ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid");r=="tabs-5"&&o&&(o.destroy(),o=n.jqplot("graph",b,dt))}});n(window).resize(function(){o&&(o.destroy(),o=n.jqplot("graph",b,dt))});n("#code_mode_false").click(function(){ur.show("blind",{direction:"vertical"},500);fr.hide("blind",{direction:"vertical"},500)});n("#code_mode_true").click(function(){ur.hide("blind",{direction:"vertical"},500);fr.show("blind",{direction:"vertical"},500)});2==n("input:radio[name=view_type]:checked").val()&&(f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)),f.attr("disabled",!0));n("input:radio[name=view_type]").click(function(){var t=n("input:radio[name=view_type]:checked").val();switch(t){case"0":s.is(":hidden")&&s.show("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"1":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"2":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":hidden")&&(h.show("blind",{direction:"vertical"},500,function(){w2ui["posts-grid"]&&oi.w2render("posts-grid")}),f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)));f.attr("disabled",!0)}});vr=n.ajax({url:w,data:{action:"load_authors",level:3},type:"POST"});vr.done(function(n){tr=n;e("auth-grid",li,pu,"slug",i.authors,tr);e("x-auth-grid",ai,wu,"slug",i.authors,tr)});yr=n.ajax({url:w,data:{action:"load_users",subscriber:encodeURI(u.subscriber),contributor:encodeURI(u.contributor),author:encodeURI(u.author),editor:encodeURI(u.editor),admin:encodeURI(u.admin),sadmin:encodeURI(u.superAdmin)},type:"POST"});yr.done(function(n){pr=n;e("users-grid",lt,lu,"slug",i.users,pr)});wr=n.ajax({url:w,data:{action:"load_cats",level:3},type:"POST"});wr.done(function(n){ir=n;e("cats-grid",hi,vu,"slug",i.cats,ir);e("x-cats-grid",ci,yu,"slug",i.cats,ir)});br=n.ajax({url:w,data:{action:"load_tags",level:3},type:"POST"});br.done(function(n){rr=n;e("tags-grid",vi,bu,"slug",i.tags,rr);e("x-tags-grid",yi,ku,"slug",i.tags,rr)});f.click(function(){f.is(":checked")?2==n("input:radio[name=view_type]:checked").val()?f.attr("checked",!1):g.show("blind",{direction:"vertical"},500,function(){w2ui["x-posts-grid"]&&si.w2render("x-posts-grid")}):g.hide("blind",{direction:"vertical"},500)});n("input:radio[name=ad_users]").click(function(){var t=n("input:radio[name=ad_users]:checked").val();t=="0"?bt.is(":visible")&&bt.hide("blind",{direction:"vertical"},500):bt.is(":hidden")&&bt.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")})});er.click(function(){er.is(":checked")?or.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")}):or.hide("blind",{direction:"vertical"},500)});sr.click(function(){sr.is(":checked")?ct.show("blind",{direction:"vertical"},500,function(){w2ui["users-grid"]&<.w2render("users-grid")}):ct.hide("blind",{direction:"vertical"},500)});n("#ad_swf").click(function(){n("#ad_swf").is(":checked")?n("#swf-params").show("blind",{direction:"vertical"},500):n("#swf-params").hide("blind",{direction:"vertical"},500)});nt.is(":checked")&&c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500));nt.click(function(){nt.is(":checked")?(at.show("blind",{direction:"vertical"},500,function(){w2ui["cats-grid"]&&hi.w2render("cats-grid")}),ni.show("blind",{direction:"vertical"},500),c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500))):(at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))});c.click(function(){c.is(":checked")?(tt.show("blind",{direction:"vertical"},500,function(){w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid")}),nt.is(":checked")&&(nt.attr("checked",!1),at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))):tt.hide("blind",{direction:"vertical"},500)});it.is(":checked")&&l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500));it.click(function(){it.is(":checked")?(vt.show("blind",{direction:"vertical"},500,function(){w2ui["ctt-grid"]&&fi.w2render("ctt-grid")}),ti.show("blind",{direction:"vertical"},500),l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500))):(vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))});l.click(function(){l.is(":checked")?(rt.show("blind",{direction:"vertical"},500,function(){w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid")}),it.is(":checked")&&(it.attr("checked",!1),vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))):rt.hide("blind",{direction:"vertical"},500)});ut.is(":checked")&&a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500));ut.click(function(){ut.is(":checked")?(yt.show("blind",{direction:"vertical"},500,function(){w2ui["auth-grid"]&&li.w2render("auth-grid")}),ii.show("blind",{direction:"vertical"},500),a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500))):(yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))});a.click(function(){a.is(":checked")?(ft.show("blind",{direction:"vertical"},500,function(){w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid")}),ut.is(":checked")&&(ut.attr("checked",!1),yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))):ft.hide("blind",{direction:"vertical"},500)});et.is(":checked")&&v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500));et.click(function(){et.is(":checked")?(pt.show("blind",{direction:"vertical"},500,function(){w2ui["tags-grid"]&&vi.w2render("tags-grid")}),ri.show("blind",{direction:"vertical"},500),v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500))):(pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))});v.click(function(){v.is(":checked")?(ot.show("blind",{direction:"vertical"},500,function(){w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid")}),et.is(":checked")&&(et.attr("checked",!1),pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))):ot.hide("blind",{direction:"vertical"},500)});st.is(":checked")&&y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500));st.click(function(){st.is(":checked")?(wt.show("blind",{direction:"vertical"},500,function(){w2ui["cust-grid"]&&pi.w2render("cust-grid")}),ui.show("blind",{direction:"vertical"},500),y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500))):(wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))});y.click(function(){y.is(":checked")?(ht.show("blind",{direction:"vertical"},500,function(){w2ui["x-cust-grid"]&&wi.w2render("x-cust-grid")}),st.is(":checked")&&(st.attr("checked",!1),wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))):ht.hide("blind",{direction:"vertical"},500)});n("#ad_start_date, #ad_end_date").datepicker({dateFormat:"yy-mm-dd",showButtonPanel:!0});n("#ad_schedule").click(function(){n("#ad_schedule").is(":checked")?n("#rc-sc").show("blind",{direction:"vertical"},500):n("#rc-sc").hide("blind",{direction:"vertical"},500)});n("#limit_hits").click(function(){n("#limit_hits").is(":checked")?n("#rc-hl").show("blind",{direction:"vertical"},500):n("#rc-hl").hide("blind",{direction:"vertical"},500)});n("#limit_clicks").click(function(){n("#limit_clicks").is(":checked")?n("#rc-cl").show("blind",{direction:"vertical"},500):n("#rc-cl").hide("blind",{direction:"vertical"},500)});p=samEditorOptions.ads;p.pointer="ads";(p.enabled||""==gt.val())&>.pointer({content:""+p.title+"<\/h3>"+p.content+"<\/p>",position:"top",close:function(){n.ajax({url:ajaxurl,data:{action:"close_pointer",pointer:p.pointer},async:!0})}}).pointer("open");var k=n("#is_singular"),kr=n("#is_single"),dr=n("#is_page"),gr=n("#is_attachment"),nu=n("#is_posttype");k.click(function(){k.is(":checked")&&n("#is_single, #is_page, #is_attachment, #is_posttype").attr("checked",!0)});n("#is_single, #is_page, #is_attachment, #is_posttype").click(function(){!k.is(":checked")||kr.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&nu.is(":checked")?!k.is(":checked")&&kr.is(":checked")&&nu.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&k.attr("checked",!0):k.attr("checked",!1)});var d=n("#is_archive"),tu=n("#is_tax"),iu=n("#is_category"),ru=n("#is_tag"),uu=n("#is_author"),fu=n("#is_date"),eu=n("#is_posttype_archive"),ou=n("#is_tax, #is_category, #is_tag, #is_author, #is_date, #is_posttype_archive");return d.click(function(){d.is(":checked")&&ou.attr("checked",!0)}),ou.click(function(){!d.is(":checked")||tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")?!d.is(":checked")&&tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")&&d.attr("checked",!0):d.attr("checked",!1)}),n("#stats_month").change(function(){bi=n(this).val();n.post(cr,{action:"load_item_stats",id:lr,sm:bi}).done(function(t){n("#total_hits").text(t.total.hits);n("#total_clicks").text(t.total.clicks);b=[t.hits,t.clicks];o&&(o.destroy(),o=n.jqplot("graph",b,dt))})}),!1})})(jQuery) \ No newline at end of file diff --git a/js/sam-layout.js b/js/sam-layout.js index 028272d..876c68e 100644 --- a/js/sam-layout.js +++ b/js/sam-layout.js @@ -19,8 +19,8 @@ wc: samAjax.clauses, level: samAjax.level }, - type: 'POST', - crossDomain: true + type: 'POST'/*, + crossDomain: true*/ }).done(function(data) { $(el).replaceWith(data.ad); $.post(samAjax.ajaxurl, { diff --git a/js/sam-layout.min.js b/js/sam-layout.min.js index aa627e2..62deb23 100644 --- a/js/sam-layout.min.js +++ b/js/sam-layout.min.js @@ -1 +1 @@ -(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST",crossDomain:!0}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file +(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST"}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file diff --git a/js/w2ui.js b/js/w2ui.js index 6edd7fd..6e4bc6d 100644 --- a/js/w2ui.js +++ b/js/w2ui.js @@ -1,6938 +1,8478 @@ +/* w2ui 1.4.1 (c) http://w2ui.com, vitmalina@gmail.com */ var w2ui = w2ui || {}; var w2obj = w2obj || {}; // expose object to be able to overwrite default functions /************************************************ - * Library: Web 2.0 UI for jQuery - * - Following objects are defines - * - w2ui - object that will contain all widgets - * - w2obj - object with widget prototypes - * - w2utils - basic utilities - * - $().w2render - common render - * - $().w2destroy - common destroy - * - $().w2marker - marker plugin - * - $().w2tag - tag plugin - * - $().w2overlay - overlay plugin - * - $().w2menu - menu plugin - * - w2utils.event - generic event object - * - w2utils.keyboard - object for keyboard navigation - * - Dependencies: jQuery - * - * == NICE TO HAVE == - * - date has problems in FF new Date('yyyy-mm-dd') breaks - * - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter - * - overlay should be displayed where more space (on top or on bottom) - * - write and article how to replace certain framework functions - * - format date and time is buggy - * - onComplete should pass widget as context (this) - * - ************************************************/ +* Library: Web 2.0 UI for jQuery +* - Following objects are defines +* - w2ui - object that will contain all widgets +* - w2obj - object with widget prototypes +* - w2utils - basic utilities +* - $().w2render - common render +* - $().w2destroy - common destroy +* - $().w2marker - marker plugin +* - $().w2tag - tag plugin +* - $().w2overlay - overlay plugin +* - $().w2menu - menu plugin +* - w2utils.event - generic event object +* - w2utils.keyboard - object for keyboard navigation +* - Dependencies: jQuery +* +* == NICE TO HAVE == +* - date has problems in FF new Date('yyyy-mm-dd') breaks +* - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter +* - overlay should be displayed where more space (on top or on bottom) +* - write and article how to replace certain framework functions +* - format date and time is buggy +* - onComplete should pass widget as context (this) +* - add maxHeight for the w2menu +* - user localization from another lib (make it generic), https://github.com/jquery/globalize#readme +* - hidden and disabled in menus +* - isTime should support seconds +* - TEST On IOS +* +************************************************/ var w2utils = (function ($) { - var tmp = {}; // for some temp variables - var obj = { - settings : { - "locale" : "en-us", - "date_format" : "m/d/yyyy", - "date_display" : "Mon d, yyyy", - "time_format" : "hh:mi pm", - "currency" : "^[\$\€\£\¥]?[-]?[0-9]*[\.]?[0-9]+$", - "currencySymbol": "$", - "float" : "^[-]?[0-9]*[\.]?[0-9]+$", - "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], - "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], - "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], - "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], - "RESTfull" : false, - "phrases" : {} // empty object for english phrases - }, - isInt : isInt, - isFloat : isFloat, - isMoney : isMoney, - isHex : isHex, - isAlphaNumeric : isAlphaNumeric, - isEmail : isEmail, - isDate : isDate, - isTime : isTime, - age : age, - date : date, - size : size, - formatNumber : formatNumber, - formatDate : formatDate, - formatTime : formatTime, - formatDateTime : formatDateTime, - stripTags : stripTags, - encodeTags : encodeTags, - escapeId : escapeId, - base64encode : base64encode, - base64decode : base64decode, - transition : transition, - lock : lock, - unlock : unlock, - lang : lang, - locale : locale, - getSize : getSize, - scrollBarSize : scrollBarSize - } - return obj; - - function isInt (val) { - var re = /^[-]?[0-9]+$/; - return re.test(val); - } - - function isFloat (val) { - var re = new RegExp(w2utils.settings["float"]); - return re.test(val); - } - - function isMoney (val) { - var re = new RegExp(w2utils.settings.currency); - return re.test(val); - } - - function isHex (val) { - var re = /^[a-fA-F0-9]+$/; - return re.test(val); - } - - function isAlphaNumeric (val) { - var re = /^[a-zA-Z0-9_-]+$/; - return re.test(val); - } - - function isEmail (val) { - var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; - return email.test(val); - } - - function isDate (val, format, retDate) { - if (!val) return false; - if (!format) format = w2utils.settings.date_format; - // format date - var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); - var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); - var dt = 'Invalid Date'; - var month, day, year; - if (tmp2 == 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - if (tmp2 == 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - dt = new Date(month + '/' + day + '/' + year); - // do checks - if (typeof month == 'undefined') return false; - if (dt == 'Invalid Date') return false; - if ((dt.getMonth()+1 != month) || (dt.getDate() != day) || (dt.getFullYear() != year)) return false; - if (retDate === true) return dt; else return true; - } - - function isTime (val) { - // Both formats 10:20pm and 22:20 - if (String(val) == 'undefined') return false; - var max; - // -- process american foramt - val = val.toUpperCase(); - if (val.indexOf('PM') >= 0 || val.indexOf('AM') >= 0) max = 12; else max = 23; - val = $.trim(val.replace('AM', '')); - val = $.trim(val.replace('PM', '')); - // --- - var tmp = val.split(':'); - if (tmp.length != 2) { return false; } - if (tmp[0] == '' || parseInt(tmp[0]) < 0 || parseInt(tmp[0]) > max || !this.isInt(tmp[0])) { return false; } - if (tmp[1] == '' || parseInt(tmp[1]) < 0 || parseInt(tmp[1]) > 59 || !this.isInt(tmp[1])) { return false; } - return true; - } - - function age (timeStr) { - if (timeStr == '' || typeof timeStr == 'undefined' || timeStr == null) return ''; - if (w2utils.isInt(timeStr)) timeStr = Number(timeStr); // for unix timestamps - - var d1 = new Date(timeStr); - if (w2utils.isInt(timeStr)) d1 = new Date(Number(timeStr)); // for unix timestamps - var tmp = String(timeStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(timeStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Time') return ''; - - var d2 = new Date(); - var sec = (d2.getTime() - d1.getTime()) / 1000; - var amount = ''; - var type = ''; - - if (sec < 60) { - amount = Math.floor(sec); - type = 'sec'; - if (sec < 0) { amount = 0; type = 'sec' } - } else if (sec < 60*60) { - amount = Math.floor(sec/60); - type = 'min'; - } else if (sec < 24*60*60) { - amount = Math.floor(sec/60/60); - type = 'hour'; - } else if (sec < 30*24*60*60) { - amount = Math.floor(sec/24/60/60); - type = 'day'; - } else if (sec < 12*30*24*60*60) { - amount = Math.floor(sec/30/24/60/60*10)/10; - type = 'month'; - } else if (sec >= 12*30*24*60*60) { - amount = Math.floor(sec/12/30/24/60/60*10)/10; - type = 'year'; - } - return amount + ' ' + type + (amount > 1 ? 's' : ''); - } - - function date (dateStr) { - var months = w2utils.settings.shortmonths; - if (dateStr == '' || typeof dateStr == 'undefined' || dateStr == null) return ''; - if (w2utils.isInt(dateStr)) dateStr = Number(dateStr); // for unix timestamps - - var d1 = new Date(dateStr); - if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Date') return ''; - - var d2 = new Date(); // today - var d3 = new Date(); - d3.setTime(d3.getTime() - 86400000); // yesterday - - var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear(); - var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear(); - var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear(); - - var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var dsp = dd1; - if (dd1 == dd2) dsp = time; - if (dd1 == dd3) dsp = w2utils.lang('Yesterday'); - - return ''+ dsp +''; - } - - function size (sizeStr) { - if (!w2utils.isFloat(sizeStr) || sizeStr == '') return ''; - sizeStr = parseFloat(sizeStr); - if (sizeStr == 0) return 0; - var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB']; - var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) ); - return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i == 0 ? 0 : 1) + ' ' + sizes[i]; - } - - function formatNumber (val) { - var ret = ''; - // check if this is a number - if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) { - ret = String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); - } - return ret; - } - - function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.date_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) dt = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) dt = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (dt == 'Invalid Date') return ''; - - var year = dt.getFullYear(); - var month = dt.getMonth(); - var date = dt.getDate(); - return format.toLowerCase() - .replace('month', w2utils.settings.fullmonths[month]) - .replace('mon', w2utils.settings.shortmonths[month]) - .replace(/yyyy/g, year) - .replace(/yyy/g, year) - .replace(/yy/g, String(year).substr(2)) - .replace(/(^|[^a-z$])y/g, '$1'+year) // only y's that are not preceeded by a letter - .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1)) - .replace(/dd/g, (date < 10 ? '0' : '') + date) - .replace(/(^|[^a-z$])m/g, '$1'+ (month + 1)) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter - } - - - function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.time_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - if (dt == 'Invalid Date') return ''; - - var type = 'am'; - var hour = dt.getHours(); - var h24 = dt.getHours(); - var min = dt.getMinutes(); - var sec = dt.getSeconds(); - if (min < 10) min = '0' + min; - if (sec < 10) sec = '0' + sec; - if (format.indexOf('am') != -1 || format.indexOf('pm') != -1) { - if (hour >= 12) type = 'pm'; - if (hour > 12) hour = hour - 12; - } - return format.toLowerCase() - .replace('am', type) - .replace('pm', type) - .replace('hh', hour) - .replace('h24', h24) - .replace('mm', min) - .replace('mi', min) - .replace('ss', sec) - .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter - } - - function formatDateTime(dateStr, format) { - var fmt; - if (typeof format != 'string') { - var fmt = [this.settings.date_format, this.settings.time_format]; - } else { - var fmt = format.split('|'); - } - return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]); - } - - function stripTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = $.trim(String(html).replace(/(<([^>]+)>)/ig, "")); - break; - case 'object': - for (var a in html) html[a] = this.stripTags(html[a]); - break; - } - return html; - } - - function encodeTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/\|\/? {}\\])/g, '\\$1'); - } - - function base64encode (input) { - var output = ""; - var chr1, chr2, chr3, enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = utf8_encode(input); - - while (i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); + var tmp = {}; // for some temp variables + var obj = { + version : '1.4.1', + settings : { + "locale" : "en-us", + "date_format" : "m/d/yyyy", + "date_display" : "Mon d, yyyy", + "time_format" : "hh:mi pm", + "currencyPrefix" : "$", + "currencySuffix" : "", + "currencyPrecision" : 2, + "groupSymbol" : ",", + "decimalSymbol" : ".", + "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], + "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], + "dataType" : 'HTTP', // can be HTTP, RESTFULL, JSON (case sensative) + "phrases" : {} // empty object for english phrases + }, + isInt : isInt, + isFloat : isFloat, + isMoney : isMoney, + isHex : isHex, + isAlphaNumeric : isAlphaNumeric, + isEmail : isEmail, + isDate : isDate, + isTime : isTime, + age : age, + date : date, + size : size, + formatNumber : formatNumber, + formatDate : formatDate, + formatTime : formatTime, + formatDateTime : formatDateTime, + stripTags : stripTags, + encodeTags : encodeTags, + escapeId : escapeId, + base64encode : base64encode, + base64decode : base64decode, + transition : transition, + lock : lock, + unlock : unlock, + lang : lang, + locale : locale, + getSize : getSize, + scrollBarSize : scrollBarSize, + checkName : checkName, + checkUniqueId : checkUniqueId, + parseRoute : parseRoute, + // some internal variables + isIOS : ((navigator.userAgent.toLowerCase().indexOf('iphone') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipod') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipad') != -1) + ? true : false), + isIE : ((navigator.userAgent.toLowerCase().indexOf('msie') != -1 || + navigator.userAgent.toLowerCase().indexOf('trident') != -1 ) + ? true : false) + }; + return obj; + + function isInt (val) { + var re = /^[-+]?[0-9]+$/; + return re.test(val); } - function utf8_encode (string) { - var string = String(string).replace(/\r\n/g,"\n"); - var utftext = ""; - - for (var n = 0; n < string.length; n++) { - var c = string.charCodeAt(n); - if (c < 128) { - utftext += String.fromCharCode(c); - } - else if((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } - else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - } - return utftext; + function isFloat (val) { + if (typeof val == 'string') val = val.replace(w2utils.settings.decimalSymbol, '.'); + return (typeof val === 'number' || (typeof val === 'string' && val !== '')) && !isNaN(Number(val)); } - return output; - } - - function base64decode (input) { - var output = ""; - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - - while (i < input.length) { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - output = output + String.fromCharCode(chr1); - if (enc3 != 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 != 64) { - output = output + String.fromCharCode(chr3); - } - } - output = utf8_decode(output); - - function utf8_decode (utftext) { - var string = ""; - var i = 0; - var c = 0, c1 = 0, c2 = 0; - - while ( i < utftext.length ) { - c = utftext.charCodeAt(i); - if (c < 128) { - string += String.fromCharCode(c); - i++; - } - else if((c > 191) && (c < 224)) { - c2 = utftext.charCodeAt(i+1); - string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); - i += 2; + function isMoney (val) { + var se = w2utils.settings; + var re = new RegExp('^'+ (se.currencyPrefix ? '\\' + se.currencyPrefix + '?' : '') +'[-+]?[0-9]*[\\'+ w2utils.settings.decimalSymbol +']?[0-9]+'+ (se.currencySuffix ? '\\' + se.currencySuffix + '?' : '') +'$', 'i'); + if (typeof val === 'string') { + val = val.replace(new RegExp(se.groupSymbol, 'g'), ''); } - else { - c2 = utftext.charCodeAt(i+1); - c3 = utftext.charCodeAt(i+2); - string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); - i += 3; - } - } - - return string; + if (typeof val === 'object' || val === '') return false; + return re.test(val); } - return output; - } - - function transition (div_old, div_new, type, callBack) { - var width = $(div_old).width(); - var height = $(div_old).height(); - var time = 0.5; - - if (!div_old || !div_new) { - console.log('ERROR: Cannot do transition when one of the divs is null'); - return; + function isHex (val) { + var re = /^[a-fA-F0-9]+$/; + return re.test(val); } - div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;'; - div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden'); - div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden'); - - switch (type) { - case 'slide-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - }, 1); - break; - - case 'slide-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)'); - }, 1); - break; - - case 'slide-down': - // init divs - div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - }, 1); - break; - - case 'slide-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - }, 1); - break; - - case 'flip-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('-transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)'); - }, 1); - break; - - case 'flip-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)'); - }, 1); - break; - - case 'flip-down': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)'); - }, 1); - break; - - case 'flip-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)'); - }, 1); - break; - - case 'pop-in': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +';'; - }, 1); - break; - - case 'pop-out': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;'; - }, 1); - break; - - default: - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time +'s'); - }, 1); - break; + function isAlphaNumeric (val) { + var re = /^[a-zA-Z0-9_-]+$/; + return re.test(val); } - setTimeout(function () { - if (type == 'slide-down') { - $(div_old).css('z-index', '1019'); - $(div_new).css('z-index', '1020'); - } - if (div_new) { - $(div_new).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - } - if (div_old) { - $(div_old).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - if (div_old.parentNode) $(div_old.parentNode).css({ - '-webkit-perspective': '', - '-moz-perspective': '', - '-ms-perspective': '', - '-o-perspective': '' - }); - } - if (typeof callBack == 'function') callBack(); - }, time * 1000); - - function cross(property, value, none_webkit_value) { - var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR - if (!isWebkit && typeof none_webkit_value != 'undefined') value = none_webkit_value; - return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+ - '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';'; - } - } - - function lock (box, msg, showSpinner) { - if (!msg && msg != 0) msg = ''; - w2utils.unlock(box); - $(box).find('>:first-child').before( - ''+ - '' - ); - setTimeout(function () { - var lock = $(box).find('.w2ui-lock'); - var mess = $(box).find('.w2ui-lock-msg'); - lock.data('old_opacity', lock.css('opacity')).css('opacity', '0').show(); - mess.data('old_opacity', mess.css('opacity')).css('opacity', '0').show(); - setTimeout(function () { - var lock = $(box).find('.w2ui-lock'); - var mess = $(box).find('.w2ui-lock-msg'); - var left = ($(box).width() - w2utils.getSize(mess, 'width')) / 2; - var top = ($(box).height() * 0.9 - w2utils.getSize(mess, 'height')) / 2; - lock.css({ - opacity : lock.data('old_opacity'), - left : '0px', - top : '0px', - width : '100%', - height : '100%' - }); - if (!msg) mess.css({ 'background-color': 'transparent', 'border': '0px' }); - if (showSpinner === true) msg = '' + msg; - mess.html(msg).css({ - opacity : mess.data('old_opacity'), - left : left + 'px', - top : top + 'px' - }); - }, 10); - }, 10); - // hide all tags (do not hide overlays as the form can be in overlay) - $().w2tag(); - } - - function unlock (box) { - $(box).find('.w2ui-lock').remove(); - $(box).find('.w2ui-lock-msg').remove(); - } - - function getSize (el, type) { - var bwidth = { - left: parseInt($(el).css('border-left-width')) || 0, - right: parseInt($(el).css('border-right-width')) || 0, - top: parseInt($(el).css('border-top-width')) || 0, - bottom: parseInt($(el).css('border-bottom-width')) || 0 - } - var mwidth = { - left: parseInt($(el).css('margin-left')) || 0, - right: parseInt($(el).css('margin-right')) || 0, - top: parseInt($(el).css('margin-top')) || 0, - bottom: parseInt($(el).css('margin-bottom')) || 0 - } - var pwidth = { - left: parseInt($(el).css('padding-left')) || 0, - right: parseInt($(el).css('padding-right')) || 0, - top: parseInt($(el).css('padding-top')) || 0, - bottom: parseInt($(el).css('padding-bottom')) || 0 - } - switch (type) { - case 'top': return bwidth.top + mwidth.top + pwidth.top; - case 'bottom': return bwidth.bottom + mwidth.bottom + pwidth.bottom; - case 'left': return bwidth.left + mwidth.left + pwidth.left; - case 'right': return bwidth.right + mwidth.right + pwidth.right; - case 'width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right + parseInt($(el).width()); - case 'height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom + parseInt($(el).height()); - case '+width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right; - case '+height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom; + function isEmail (val) { + var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; + return email.test(val); } - return 0; - } - - function lang (phrase) { - var translation = this.settings.phrases[phrase]; - if (typeof translation == 'undefined') return phrase; else return translation; - } - - function locale (locale) { - if (!locale) locale = 'en-us'; - if (locale.length == 5) locale = 'locale/'+ locale +'.json'; - // load from the file - $.ajax({ - url : locale, - type : "GET", - dataType: "JSON", - async : false, - cache : false, - success : function (data, status, xhr) { - w2utils.settings = $.extend(true, w2utils.settings, data); - }, - error : function (xhr, status, msg) { - console.log('ERROR: Cannot load locale '+ locale); - } - }); - } - - function scrollBarSize () { - if (tmp.scrollBarSize) return tmp.scrollBarSize; - var html = ''+ - ' 1'+ - ''; - $('body').append(html); - tmp.scrollBarSize = 100 - $('#_scrollbar_width > div').width(); - $('#_scrollbar_width').remove(); - if (String(navigator.userAgent).indexOf('MSIE') >= 0) tmp.scrollBarSize = tmp.scrollBarSize / 2; // need this for IE9+ - return tmp.scrollBarSize; - } -})(jQuery); + function isDate (val, format, retDate) { + if (!val) return false; -/*********************************************************** - * Generic Event Object - * --- This object is reused across all other - * --- widgets in w2ui. - * - *********************************************************/ + var dt = 'Invalid Date'; + var month, day, year; -w2utils.event = { + if (format == null) format = w2utils.settings.date_format; - on: function (eventData, handler) { - if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; - eventData = jQuery.extend({ type: null, execute: 'before', target: null, onComplete: null }, eventData); - - if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return; } - if (typeof handler == 'undefined') { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return; } - this.handlers.push({ event: eventData, handler: handler }); - }, - - off: function (eventData, handler) { - if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; - eventData = jQuery.extend({}, { type: null, execute: 'before', target: null, onComplete: null }, eventData); - - if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return; } - if (typeof handler == 'undefined') { handler = null; } - // remove handlers - var newHandlers = []; - for (var h in this.handlers) { - var t = this.handlers[h]; - if ( (t.event.type == eventData.type || eventData.type == '*') - && (t.event.target == eventData.target || eventData.target == null) - && (t.handler == handler || handler == null)) { - // match - } else { - newHandlers.push(t); - } - } - this.handlers = newHandlers; - }, - - trigger: function (eventData) { - var eventData = jQuery.extend({ type: null, phase: 'before', target: null, isStopped: false, isCancelled: false }, eventData, { - preventDefault : function () { this.isCancelled = true; }, - stopPropagation : function () { this.isStopped = true; }, - }); - if (typeof eventData.target == 'undefined') eventData.target = null; - // process events in REVERSE order - for (var h = this.handlers.length-1; h >= 0; h--) { - var item = this.handlers[h]; - if ( (item.event.type == eventData.type || item.event.type == '*') - && (item.event.target == eventData.target || item.event.target == null) - && (item.event.execute == eventData.phase || item.event.execute == '*' || item.event.phase == '*') ) { - eventData = jQuery.extend({}, item.event, eventData); - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(item.handler); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - item.handler.call(this, eventData.target, eventData); // old way for back compatibility + if (typeof val.getUTCFullYear === 'function' && typeof val.getUTCMonth === 'function' && typeof val.getUTCDate === 'function') { + year = val.getUTCFullYear(); + month = val.getUTCMonth(); + day = val.getUTCDate(); + } else if (typeof val.getFullYear === 'function' && typeof val.getMonth === 'function' && typeof val.getDate === 'function') { + year = val.getFullYear(); + month = val.getMonth(); + day = val.getDate(); } else { - item.handler.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true - } - } - // main object events - var funName = 'on' + eventData.type.substr(0,1).toUpperCase() + eventData.type.substr(1); - if (eventData.phase == 'before' && typeof this[funName] == 'function') { - var fun = this[funName]; - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(fun); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - fun.call(this, eventData.target, eventData); // old way for back compatibility - } else { - fun.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true - } - // item object events - if (typeof eventData.object != 'undefined' && eventData.object != null && eventData.phase == 'before' - && typeof eventData.object[funName] == 'function') { - var fun = eventData.object[funName]; - // check handler arguments - var args = []; - var tmp = RegExp(/\((.*?)\)/).exec(fun); - if (tmp) args = tmp[1].split(/\s*,\s*/); - if (args.length == 2) { - fun.call(this, eventData.target, eventData); // old way for back compatibility - } else { - fun.call(this, eventData); // new way - } - if (eventData.isStopped === true || eventData.stop === true) return eventData; + val = String(val); + // convert month formats + if (RegExp('mon', 'ig').test(format)) { + format = format.replace(/month/ig, 'm').replace(/mon/ig, 'm').replace(/dd/ig, 'd').replace(/[, ]/ig, '/').replace(/\/\//g, '/').toLowerCase(); + val = val.replace(/[, ]/ig, '/').replace(/\/\//g, '/').toLowerCase(); + for (var m = 0, len = w2utils.settings.fullmonths.length; m < len; m++) { + var t = w2utils.settings.fullmonths[m]; + val = val.replace(RegExp(t, 'ig'), (parseInt(m) + 1)).replace(RegExp(t.substr(0, 3), 'ig'), (parseInt(m) + 1)); + } + } + // format date + var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); + var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); + if (tmp2 === 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } + if (tmp2 === 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } + if (tmp2 === 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } + if (tmp2 === 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } + if (tmp2 === 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } + if (tmp2 === 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } + if (tmp2 === 'mm/dd/yy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } + if (tmp2 === 'm/d/yy') { month = tmp[0]; day = tmp[1]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'dd/mm/yy') { month = tmp[1]; day = tmp[0]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'd/m/yy') { month = tmp[1]; day = tmp[0]; year = parseInt(tmp[2]) + 1900; } + if (tmp2 === 'yy/dd/mm') { month = tmp[2]; day = tmp[1]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/d/m') { month = tmp[2]; day = tmp[1]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/mm/dd') { month = tmp[1]; day = tmp[2]; year = parseInt(tmp[0]) + 1900; } + if (tmp2 === 'yy/m/d') { month = tmp[1]; day = tmp[2]; year = parseInt(tmp[0]) + 1900; } + } + if (!isInt(year)) return false; + if (!isInt(month)) return false; + if (!isInt(day)) return false; + year = +year; + month = +month; + day = +day; + dt = new Date(year, month - 1, day); + // do checks + if (month == null) return false; + if (dt === 'Invalid Date') return false; + if ((dt.getMonth() + 1 !== month) || (dt.getDate() !== day) || (dt.getFullYear() !== year)) return false; + if (retDate === true) return dt; else return true; } - // execute onComplete - if (eventData.phase == 'after' && eventData.onComplete != null) eventData.onComplete.call(this, eventData); - - return eventData; - } -}; - -/*********************************************************** - * Common Keyboard Handler. Supported in - * - grid - * - sidebar - * - popup - * - *********************************************************/ -w2utils.keyboard = (function (obj) { - // private scope - var w2ui_name = null; - - obj.active = active; - obj.clear = clear; - obj.register = register; - - init(); - return obj; - - function init() { - jQuery(document).on('keydown', keydown); - jQuery(document).on('mousedown', mousedown); - } - - function keydown (event) { - var tag = event.target.tagName; - if (jQuery.inArray(tag, ['INPUT', 'SELECT', 'TEXTAREA']) != -1) return; - if (jQuery(event.target).prop('contenteditable') == 'true') return; - if (!w2ui_name) return; - // pass to appropriate widget - if (w2ui[w2ui_name] && typeof w2ui[w2ui_name].keydown == 'function') { - w2ui[w2ui_name].keydown.call(w2ui[w2ui_name], event); + function isTime (val, retTime) { + // Both formats 10:20pm and 22:20 + if (val == null) return false; + var max, pm; + // -- process american format + val = String(val); + val = val.toUpperCase(); + pm = val.indexOf('PM') >= 0; + var ampm = (pm || val.indexOf('AM') >= 0); + if (ampm) max = 12; else max = 24; + val = val.replace('AM', '').replace('PM', ''); + val = $.trim(val); + // --- + var tmp = val.split(':'); + var h = parseInt(tmp[0] || 0), m = parseInt(tmp[1] || 0); + // accept edge case: 3PM is a good timestamp, but 3 (without AM or PM) is NOT: + if ((!ampm || tmp.length !== 1) && tmp.length !== 2) { return false; } + if (tmp[0] === '' || h < 0 || h > max || !this.isInt(tmp[0]) || tmp[0].length > 2) { return false; } + if (tmp.length === 2 && (tmp[1] === '' || m < 0 || m > 59 || !this.isInt(tmp[1]) || tmp[1].length !== 2)) { return false; } + // check the edge cases: 12:01AM is ok, as is 12:01PM, but 24:01 is NOT ok while 24:00 is (midnight; equivalent to 00:00). + // meanwhile, there is 00:00 which is ok, but 0AM nor 0PM are okay, while 0:01AM and 0:00AM are. + if (!ampm && max === h && m !== 0) { return false; } + if (ampm && tmp.length === 1 && h === 0) { return false; } + + if (retTime === true) { + if (pm) h += 12; + return { + hours: h, + minutes: m + }; + } + return true; } - } - function mousedown (event) { - var tag = event.target.tagName; - var obj = jQuery(event.target).parents('.w2ui-reset'); - if (obj.length > 0) { - w2ui_name = obj.attr('name'); + function age (dateStr) { + if (dateStr === '' || dateStr == null) return ''; + var d1 = new Date(dateStr); + if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps + if (d1 === 'Invalid Date') return ''; + + var d2 = new Date(); + var sec = (d2.getTime() - d1.getTime()) / 1000; + var amount = ''; + var type = ''; + if (sec < 0) { + amount = 'future'; + type = ''; + } else if (sec < 60) { + amount = Math.floor(sec); + type = 'sec'; + if (sec < 0) { amount = 0; type = 'sec'; } + } else if (sec < 60*60) { + amount = Math.floor(sec/60); + type = 'min'; + } else if (sec < 24*60*60) { + amount = Math.floor(sec/60/60); + type = 'hour'; + } else if (sec < 30*24*60*60) { + amount = Math.floor(sec/24/60/60); + type = 'day'; + } else if (sec < 365.25*24*60*60) { + amount = Math.floor(sec/365.25/24/60/60*10)/10; + type = 'month'; + } else if (sec >= 365.25*24*60*60) { + amount = Math.floor(sec/365.25/24/60/60*10)/10; + type = 'year'; + } + return amount + ' ' + type + (amount > 1 ? 's' : ''); } - } - - function active (new_w2ui_name) { - if (typeof new_w2ui_name == 'undefined') return w2ui_name; - w2ui_name = new_w2ui_name; - } - function clear () { - w2ui_name = null; - } + function date (dateStr) { + if (dateStr === '' || dateStr == null) return ''; + var d1 = new Date(dateStr); + if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps + if (d1 === 'Invalid Date') return ''; - function register () { - } - -})({}); + var months = w2utils.settings.shortmonths; + var d2 = new Date(); // today + var d3 = new Date(); + d3.setTime(d3.getTime() - 86400000); // yesterday -/*********************************************************** - * Commonly used plugins - * --- used primarily in grid and form - * - *********************************************************/ + var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear(); + var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear(); + var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear(); -(function ($) { + var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); + var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); + var dsp = dd1; + if (dd1 === dd2) dsp = time; + if (dd1 === dd3) dsp = w2utils.lang('Yesterday'); - $.fn.w2render = function (name) { - if ($(this).length > 0) { - if (typeof name == 'string' && w2ui[name]) w2ui[name].render($(this)[0]); - if (typeof name == 'object') name.render($(this)[0]); - } - } - - $.fn.w2destroy = function (name) { - if (!name && this.length > 0) name = this.attr('name'); - if (typeof name == 'string' && w2ui[name]) w2ui[name].destroy(); - if (typeof name == 'object') name.destroy(); - } - - $.fn.w2marker = function (str) { - if (str == '' || typeof str == 'undefined') { // remove marker - return $(this).each(function (index, el) { - el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark - }); - } else { // add marker - return $(this).each(function (index, el) { - if (typeof str == 'string') str = [str]; - el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark - for (var s in str) { - var tmp = str[s]; - if (typeof tmp != 'string') tmp = String(tmp); - // escape regex special chars - tmp = tmp.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, '&').replace(//g, '<'); - var regex = new RegExp(tmp + '(?!([^<]+)?>)', "gi"); // only outside tags - el.innerHTML = el.innerHTML.replace(regex, function (matched) { // mark new - return '' + matched + ''; - }); - } - }); - } - } - - // -- w2tag - appears on the right side from element, there can be multiple on screen at a time - - $.fn.w2tag = function (text, options) { - if (!$.isPlainObject(options)) options = {}; - if (!$.isPlainObject(options.css)) options.css = {}; - if (typeof options['class'] == 'undefined') options['class'] = ''; - // remove all tags - if ($(this).length == 0) { - $('.w2ui-tag').each(function (index, elem) { - var opt = $(elem).data('options'); - if (typeof opt == 'undefined') opt = {}; - $($(elem).data('taged-el')).removeClass( opt['class'] ); - clearInterval($(elem).data('timer')); - $(elem).remove(); - }); - return; - } - return $(this).each(function (index, el) { - // show or hide tag - var tagOrigID = el.id; - var tagID = w2utils.escapeId(el.id); - if (text == '' || text == null || typeof text == 'undefined') { - $('#w2ui-tag-'+tagID).css('opacity', 0); - setTimeout(function () { - // remmove element - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - }, 300); - } else { - // remove elements - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - // insert - $('body').append(''); - - var timer = setInterval(function () { - // monitor if destroyed - if ($(el).length == 0 || ($(el).offset().left == 0 && $(el).offset().top == 0)) { - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - tmp_hide(); - return; - } - // monitor if moved - if ($('#w2ui-tag-'+tagID).data('position') != ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) { - $('#w2ui-tag-'+tagID).css({ - '-webkit-transition': '.2s', - '-moz-transition': '.2s', - '-ms-transition': '.2s', - '-o-transition': '.2s', - left: ($(el).offset().left + el.offsetWidth) + 'px', - top: $(el).offset().top + 'px' - }).data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top); - } - }, 100); - setTimeout(function () { - if (!$(el).offset()) return; - $('#w2ui-tag-'+tagID).css({ - opacity: '1', - left: ($(el).offset().left + el.offsetWidth) + 'px', - top: $(el).offset().top + 'px' - }).html(' '+ text +' ') - .data('text', text) - .data('taged-el', el) - .data('options', options) - .data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) - .data('timer', timer); - $(el).off('keypress', tmp_hide).on('keypress', tmp_hide).off('change', tmp_hide).on('change', tmp_hide) - .css(options.css).addClass(options['class']); - if (typeof options.onShow == 'function') options.onShow(); - }, 1); - var originalCSS = ''; - if ($(el).length > 0) originalCSS = $(el)[0].style.cssText; - // bind event to hide it - function tmp_hide() { - if ($('#w2ui-tag-'+tagID).length <= 0) return; - clearInterval($('#w2ui-tag-'+tagID).data('timer')); - $('#w2ui-tag-'+tagID).remove(); - $(el).off('keypress', tmp_hide).removeClass(options['class']); - if ($(el).length > 0) $(el)[0].style.cssText = originalCSS; - if (typeof options.onHide == 'function') options.onHide(); - } - } - }); - } - - // w2overlay - appears under the element, there can be only one at a time - - $.fn.w2overlay = function (html, options) { - if (!$.isPlainObject(options)) options = {}; - if (!$.isPlainObject(options.css)) options.css = {}; - if (this.length == 0 || html == '' || typeof html == 'undefined') { hide(); return $(this); } - if ($('#w2ui-overlay').length > 0) $(document).click(); - $('body').append(''+ - ' '+ - ''); - - // init - var obj = this; - var div = $('#w2ui-overlay div'); - div.css(options.css).html(html); - if (typeof options['class'] != 'undefined') div.addClass(options['class']); - if (typeof options.top == 'undefined') options.top = 0; - if (typeof options.left == 'undefined') options.left = 0; - if (typeof options.width == 'undefined') options.width = 100; - if (typeof options.height == 'undefined') options.height = 0; - - // pickup bg color of first div - var bc = div.css('background-color'); - var div = $('#w2ui-overlay'); - if (typeof bc != 'undefined' && bc != 'rgba(0, 0, 0, 0)' && bc != 'transparent') div.css('background-color', bc); - - div.css({ - display : 'none', - left : ($(obj).offset().left + options.left) + 'px', - top : ($(obj).offset().top + w2utils.getSize($(obj), 'height') + 3 + options.top) + 'px', - 'min-width' : (options.width ? options.width : 'auto'), - 'min-height' : (options.height ? options.height : 'auto') - }) - .fadeIn('fast') - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }); - - // click anywhere else hides the drop down - function hide () { - var result; - if (typeof options.onHide == 'function') result = options.onHide(); - if (result === false) return; - $('#w2ui-overlay').remove(); - $(document).off('click', hide); + return ''+ dsp +''; } - // need time to display - setTimeout(fixSize, 0); - return $(this); - - function fixSize () { - $(document).on('click', hide); - // if goes over the screen, limit height and width - if ( $('#w2ui-overlay > div').length > 0) { - var h = $('#w2ui-overlay > div').height(); - var w = $('#w2ui-overlay> div').width(); - // $(window).height() - has a problem in FF20 - var max = window.innerHeight - $('#w2ui-overlay > div').offset().top - 7; - if (h > max) $('#w2ui-overlay> div').height(max).width(w + w2utils.scrollBarSize()).css({ 'overflow-y': 'auto' }); - // check width - w = $('#w2ui-overlay> div').width(); - max = window.innerWidth - $('#w2ui-overlay > div').offset().left - 7; - if (w > max) $('#w2ui-overlay> div').width(max).css({ 'overflow-x': 'auto' }); - // onShow event - if (typeof options.onShow == 'function') options.onShow(); - } + function size (sizeStr) { + if (!w2utils.isFloat(sizeStr) || sizeStr === '') return ''; + sizeStr = parseFloat(sizeStr); + if (sizeStr === 0) return 0; + var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB']; + var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) ); + return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i === 0 ? 0 : 1) + ' ' + sizes[i]; } - } - $.fn.w2menu = function (menu, options) { - if (typeof options.select == 'undefined' && typeof options.onSelect == 'function') options.select = options.onSelect; - if (typeof options.select != 'function') { - console.log('ERROR: options.select is required to be a function, not '+ typeof options.select + ' in $().w2menu(menu, options)'); - return $(this); - } - if (!$.isArray(menu)) { - console.log('ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)'); - return $(this); - } - // since only one overlay can exist at a time - $.fn.w2menuHandler = function (event, index) { - options.select(menu[index], event, index); - } - return $(this).w2overlay(getMenuHTML(), options); - - function getMenuHTML () { - var menu_html = ''; - for (var f = 0; f < menu.length; f++) { - var mitem = menu[f]; - if (typeof mitem == 'string') { - var tmp = mitem.split('|'); - // 1 - id, 2 - text, 3 - image, 4 - icon - mitem = { id: tmp[0], text: tmp[0], img: null, icon: null }; - if (tmp[1]) mitem.text = tmp[1]; - if (tmp[2]) mitem.img = tmp[2]; - if (tmp[3]) mitem.icon = tmp[3]; - } else { - if (typeof mitem.text != 'undefined' && typeof mitem.id == 'undefined') mitem.id = mitem.text; - if (typeof mitem.text == 'undefined' && typeof mitem.id != 'undefined') mitem.text = mitem.id; - if (typeof mitem.caption != 'undefined') mitem.text = mitem.caption; - if (typeof mitem.img == 'undefined') mitem.img = null; - if (typeof mitem.icon == 'undefined') mitem.icon = null; + function formatNumber (val, groupSymbol, decimalSymbol) { + var ret = ''; + if (groupSymbol == null) groupSymbol = w2utils.settings.groupSymbol || ','; + if (decimalSymbol == null) decimalSymbol = w2utils.settings.decimalSymbol || '.'; + // check if this is a number + if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) { + tmp = String(val).split('.'); + ret = String(tmp[0]).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + groupSymbol); + if (tmp[1] != null) ret += w2utils.settings.decimalSymbol + tmp[1]; } - var img = ' '; - if (mitem.img) img = ''; - if (mitem.icon) img = ''; - menu_html += - ''+ - img + - ' '+ mitem.text +''+ - ''; - } - menu_html += ""; - return menu_html; + return ret; } - } -})(jQuery); - -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2grid - grid widget - * - $().w2grid - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2toolbar, w2fields, w2alert, w2confirm - * - * == NICE TO HAVE == - * - global search apply types and drop downs - * - editable fields (list) - better inline editing - * - frozen columns - * - column autosize based on largest content - * - save grid state into localStorage and restore - * - easy bubbles in the grid - * - possibly add context menu similar to sidebar's - * - Merged cells - * - More than 2 layers of header groups - * - for search fields one should be able to pass w2field options - * - add enum to advanced search fields - * - be able to attach events in advanced search dialog - * - reorder columns/records - * - hidden searches could not be clearned by the user - * - search-logic -> searchLogic - * - ************************************************************************/ -(function ($) { - var w2grid = function(options) { - - // public properties - this.name = null; - this.box = null; // HTML element that hold this element - this.header = ''; - this.url = ''; - this.columns = []; // { field, caption, size, attr, render, hidden, gridMinWidth, [editable: {type, inTag, outTag, style, items}] } - this.columnGroups = []; // { span: int, caption: 'string', master: true/false } - this.records = []; // { recid: int(requied), field1: 'value1', ... fieldN: 'valueN', style: 'string', editable: true/false, summary: true/false, changed: true/false, changes: object } - this.summary = []; // arry of summary records, same structure as records array - this.searches = []; // { type, caption, field, inTag, outTag, default, items, hidden } - this.searchData = []; - this.sortData = []; - this.postData = {}; - this.toolbar = {}; // if not empty object; then it is toolbar object - - this.show = { - header : false, - toolbar : false, - footer : false, - columnHeaders : true, - lineNumbers : false, - expandColumn : false, - selectColumn : false, - emptyRecords : true, - toolbarReload : true, - toolbarColumns : true, - toolbarSearch : true, - toolbarAdd : false, - toolbarEdit : false, - toolbarDelete : false, - toolbarSave : false, - selectionBorder : true, - recordTitles : true + function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String + var months = w2utils.settings.shortmonths; + var fullMonths = w2utils.settings.fullmonths; + if (!format) format = this.settings.date_format; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + + var dt = new Date(dateStr); + if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps + if (dt === 'Invalid Date') return ''; + + var year = dt.getFullYear(); + var month = dt.getMonth(); + var date = dt.getDate(); + return format.toLowerCase() + .replace('month', w2utils.settings.fullmonths[month]) + .replace('mon', w2utils.settings.shortmonths[month]) + .replace(/yyyy/g, year) + .replace(/yyy/g, year) + .replace(/yy/g, year > 2000 ? 100 + parseInt(String(year).substr(2)) : String(year).substr(2)) + .replace(/(^|[^a-z$])y/g, '$1' + year) // only y's that are not preceeded by a letter + .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1)) + .replace(/dd/g, (date < 10 ? '0' : '') + date) + .replace(/th/g, (date == 1 ? 'st' : 'th')) + .replace(/th/g, (date == 2 ? 'nd' : 'th')) + .replace(/th/g, (date == 3 ? 'rd' : 'th')) + .replace(/(^|[^a-z$])m/g, '$1' + (month + 1)) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter } - this.autoLoad = true; // for infinite scroll - this.fixedBody = true; // if false; then grid grows with data - this.recordHeight = 24; - this.keyboard = true; - this.selectType = 'row'; // can be row|cell - this.multiSearch = true; - this.multiSelect = true; - this.multiSort = true; - this.markSearchResults = true; - - this.total = 0; // server total - this.buffered = 0; // number of records in the records array - this.limit = 100; - this.offset = 0; // how many records to skip (for infinite scroll) when pulling from server - this.style = ''; - this.ranges = []; - - // events - this.onAdd = null; - this.onEdit = null; - this.onRequest = null; // called on any server event - this.onLoad = null; - this.onDelete = null; - this.onDeleted = null - this.onSave = null; - this.onSaved = null; - this.onSelect = null; - this.onUnselect = null; - this.onClick = null; - this.onDblClick = null; - this.onColumnClick = null; - this.onColumnResize = null; - this.onSort = null; - this.onSearch = null; - this.onChange = null; // called when editable record is changed - this.onExpand = null; - this.onCollapse = null; - this.onError = null; - this.onKeydown = null; - this.onToolbar = null; // all events from toolbar - this.onColumnOnOff = null; - this.onCopy = null; - this.onPaste = null; - this.onSelectionExtend = null; - this.onEditField = null; - this.onRender = null; - this.onRefresh = null; - this.onReload = null; - this.onResize = null; - this.onDestroy = null; - - // internal - this.last = { - field : 'all', - caption : w2utils.lang('All Fields'), - logic : 'OR', - search : '', - searchIds : [], - multi : false, - scrollTop : 0, - scrollLeft : 0, - selected : [], - sortData : null, - sortCount : 0, - xhr : null, - range_start : null, - range_end : null, - sel_ind : null, - sel_col : null, - sel_type : null + function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String + var months = w2utils.settings.shortmonths; + var fullMonths = w2utils.settings.fullmonths; + if (!format) format = this.settings.time_format; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + + var dt = new Date(dateStr); + if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps + if (w2utils.isTime(dateStr)) { + var tmp = w2utils.isTime(dateStr, true); + dt = new Date(); + dt.setHours(tmp.hours); + dt.setMinutes(tmp.minutes); + } + if (dt === 'Invalid Date') return ''; + + var type = 'am'; + var hour = dt.getHours(); + var h24 = dt.getHours(); + var min = dt.getMinutes(); + var sec = dt.getSeconds(); + if (min < 10) min = '0' + min; + if (sec < 10) sec = '0' + sec; + if (format.indexOf('am') !== -1 || format.indexOf('pm') !== -1) { + if (hour >= 12) type = 'pm'; + if (hour > 12) hour = hour - 12; + } + return format.toLowerCase() + .replace('am', type) + .replace('pm', type) + .replace('hhh', (hour < 10 ? '0' + hour : hour)) + .replace('hh24', (h24 < 10 ? '0' + h24 : h24)) + .replace('h24', h24) + .replace('hh', hour) + .replace('mm', min) + .replace('mi', min) + .replace('ss', sec) + .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter + .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter } - this.isIOS = (navigator.userAgent.toLowerCase().indexOf('iphone') != -1 || - navigator.userAgent.toLowerCase().indexOf('ipod') != -1 || - navigator.userAgent.toLowerCase().indexOf('ipad') != -1) ? true : false; - - $.extend(true, this, w2obj.grid, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2grid = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // remember items - var columns = method.columns; - var columnGroups= method.columnGroups; - var records = method.records; - var searches = method.searches; - var searchData = method.searchData; - var sortData = method.sortData; - var postData = method.postData; - var toolbar = method.toolbar; - // extend items - var object = new w2grid(method); - $.extend(object, { postData: {}, records: [], columns: [], searches: [], toolbar: {}, sortData: [], searchData: [], handlers: [] }); - if (object.onExpand != null) object.show.expandColumn = true; - $.extend(true, object.toolbar, toolbar); - // reassign variables - for (var p in columns) object.columns[p] = $.extend(true, {}, columns[p]); - for (var p in columnGroups) object.columnGroups[p] = $.extend(true, {}, columnGroups[p]); - for (var p in searches) object.searches[p] = $.extend(true, {}, searches[p]); - for (var p in searchData) object.searchData[p] = $.extend(true, {}, searchData[p]); - for (var p in sortData) object.sortData[p] = $.extend(true, {}, sortData[p]); - object.postData = $.extend(true, {}, postData); - - // check if there are records without recid - for (var r in records) { - if (records[r].recid == null || typeof records[r].recid == 'undefined') { - console.log('ERROR: Cannot add records without recid. (obj: '+ object.name +')'); - return; + function formatDateTime(dateStr, format) { + var fmt; + if (dateStr === '' || dateStr == null || (typeof dateStr == 'object' && !dateStr.getMonth)) return ''; + if (typeof format !== 'string') { + fmt = [this.settings.date_format, this.settings.time_format]; + } else { + fmt = format.split('|'); } - object.records[r] = $.extend(true, {}, records[r]); - } - if (object.records.length > 0) object.buffered = object.records.length; - // add searches - for (var c in object.columns) { - var col = object.columns[c]; - if (typeof col.searchable == 'undefined' || object.getSearch(col.field) != null) continue; - var stype = col.searchable; - var attr = ''; - if (col.searchable === true) { stype = 'text'; attr = 'size="20"'; } - object.addSearch({ field: col.field, caption: col.caption, type: stype, attr: attr }); - } - // init toolbar - object.initToolbar(); - // render if necessary - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2grid'); + return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]); } - } - - // ==================================================== - // -- Implementation of core functionality - - w2grid.prototype = { - // ---- - // properties that need to be in prototype - - msgDelete : w2utils.lang('Are you sure you want to delete selected records?'), - msgNotJSON : w2utils.lang('Returned data is not in valid JSON format.'), - msgRefresh : w2utils.lang('Refreshing...'), - - // for easy button overwrite - buttons: { - 'reload' : { type: 'button', id: 'reload', img: 'icon-reload', hint: w2utils.lang('Reload data in the list') }, - 'columns' : { type: 'drop', id: 'column-on-off', img: 'icon-columns', hint: w2utils.lang('Show/hide columns'), arrow: false, html: '' }, - 'search' : { type: 'html', id: 'search', - html: '' - }, - 'search-go' : { type: 'check', id: 'search-advanced', caption: w2utils.lang('Search...'), hint: w2utils.lang('Open Search Fields') }, - 'add' : { type: 'button', id: 'add', caption: w2utils.lang('Add New'), hint: w2utils.lang('Add new record'), img: 'icon-add' }, - 'edit' : { type: 'button', id: 'edit', caption: w2utils.lang('Edit'), hint: w2utils.lang('Edit selected record'), img: 'icon-edit', disabled: true }, - 'delete' : { type: 'button', id: 'delete', caption: w2utils.lang('Delete'), hint: w2utils.lang('Delete selected records'), img: 'icon-delete', disabled: true }, - 'save' : { type: 'button', id: 'save', caption: w2utils.lang('Save'), hint: w2utils.lang('Save changed records'), img: 'icon-save' } - }, - - add: function (record) { - if (!$.isArray(record)) record = [record]; - var added = 0; - for (var o in record) { - if (record[o].recid == null || typeof record[o].recid == 'undefined') { - console.log('ERROR: Cannot add record without recid. (obj: '+ this.name +')'); - continue; - } - this.records.push(record[o]); - added++; - } - this.buffered = this.records.length; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - this.localSearch(); - } - this.refresh(); // ?? should it be reload? - return added; - }, - find: function (obj, returnIndex) { - if (typeof obj == 'undefined' || obj == null) obj = {}; - var recs = []; - for (var i=0; i]+)>)/ig, "")); + break; + case 'object': + for (var a in html) html[a] = this.stripTags(html[a]); + break; } - if (match && returnIndex !== true) recs.push(this.records[i]); - if (match && returnIndex === true) recs.push(i); - } - return recs; - }, + return html; + } - set: function (recid, record, noRefresh) { // does not delete existing, but overrides on top of it - if (typeof recid == 'object') { - noRefresh = record; - record = recid; - recid = null; - } - // update all records - if (recid == null) { - for (var r in this.records) { - $.extend(true, this.records[r], record); // recid is the whole record - } - if (noRefresh !== true) this.refresh(); - } else { // find record to update - var ind = this.get(recid, true); - if (ind == null) return false; - $.extend(true, this.records[ind], record); - // refresh only that record - if (noRefresh !== true) { - var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); - if (tr.length != 0) { - var line = tr.attr('line'); - // if it is searched, find index in search array - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (this.searchData.length > 0 && !url) for (var s in this.last.searchIds) if (this.last.searchIds[s] == ind) ind = s; - $(tr).replaceWith(this.getRecordHTML(ind, line)); - } + function encodeTags (html) { + if (html === null) return html; + switch (typeof html) { + case 'number': + break; + case 'string': + html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/\|\/? {}\\])/g, '\\$1'); + } - remove: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.records.length-1; r >= 0; r--) { - if (this.records[r].recid == arguments[a]) { this.records.splice(r, 1); removed++; } + function base64encode (input) { + var output = ""; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + input = utf8_encode(input); + + while (i < input.length) { + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); } - } - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.buffered = this.records.length; - this.localSort(); - this.localSearch(); - } - this.refresh(); - return removed; - }, - addColumn: function (before, columns) { - var added = 0; - if (arguments.length == 1) { - columns = before; - before = this.columns.length; - } else { - if (typeof before == 'string') before = this.getColumn(before, true); - if (before === null) before = this.columns.length; - } - if (!$.isArray(columns)) columns = [columns]; - for (var o in columns) { - this.columns.splice(before, 0, columns[o]); - before++; - added++; - } - this.initColumnOnOff(); - this.refresh(); - return added; - }, + function utf8_encode (string) { + var string = String(string).replace(/\r\n/g,"\n"); + var utftext = ""; - removeColumn: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a]) { this.columns.splice(r, 1); removed++; } + for (var n = 0; n < string.length; n++) { + var c = string.charCodeAt(n); + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + } + return utftext; } - } - this.initColumnOnOff(); - this.refresh(); - return removed; - }, - getColumn: function (field, returnIndex) { - for (var i=0; i= 0; r--) { - if (this.columns[r].field == arguments[a]) { - this.columns[r].hidden = !this.columns[r].hidden; - effected++; - } + function base64decode (input) { + var output = ""; + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + enc1 = keyStr.indexOf(input.charAt(i++)); + enc2 = keyStr.indexOf(input.charAt(i++)); + enc3 = keyStr.indexOf(input.charAt(i++)); + enc4 = keyStr.indexOf(input.charAt(i++)); + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + output = output + String.fromCharCode(chr1); + if (enc3 !== 64) { + output = output + String.fromCharCode(chr2); + } + if (enc4 !== 64) { + output = output + String.fromCharCode(chr3); + } } - } - this.refresh(); - return effected; - }, + output = utf8_decode(output); - showColumn: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a] && this.columns[r].hidden !== false) { - this.columns[r].hidden = false; - shown++; - } - } - } - this.refresh(); - return shown; - }, + function utf8_decode (utftext) { + var string = ""; + var i = 0; + var c = 0, c2, c3; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + if (c < 128) { + string += String.fromCharCode(c); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + } - hideColumn: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.columns.length-1; r >= 0; r--) { - if (this.columns[r].field == arguments[a] && this.columns[r].hidden !== true) { - this.columns[r].hidden = true; - hidden++; - } + return string; } - } - this.refresh(); - return hidden; - }, - addSearch: function (before, search) { - var added = 0; - if (arguments.length == 1) { - search = before; - before = this.searches.length; - } else { - if (typeof before == 'string') before = this.getSearch(before, true); - if (before === null) before = this.searches.length; - } - if (!$.isArray(search)) search = [search]; - for (var o in search) { - this.searches.splice(before, 0, search[o]); - before++; - added++; - } - this.searchClose(); - return added; - }, + return output; + } - removeSearch: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a]) { this.searches.splice(r, 1); removed++; } - } - } - this.searchClose(); - return removed; - }, + function transition (div_old, div_new, type, callBack) { + var width = $(div_old).width(); + var height = $(div_old).height(); + var time = 0.5; - getSearch: function (field, returnIndex) { - for (var i=0; i= 0; r--) { - if (this.searches[r].field == arguments[a]) { - this.searches[r].hidden = !this.searches[r].hidden; - effected++; - } - } - } - this.searchClose(); - return effected; - }, + div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;'; + div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden'); + div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden'); + + switch (type) { + case 'slide-left': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); + }, 1); + break; - showSearch: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== false) { - this.searches[r].hidden = false; - shown++; - } - } - } - this.searchClose(); - return shown; - }, + case 'slide-right': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)'); + }, 1); + break; - hideSearch: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - for (var r = this.searches.length-1; r >= 0; r--) { - if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== true) { - this.searches[r].hidden = true; - hidden++; - } - } - } - this.searchClose(); - return hidden; - }, + case 'slide-down': + // init divs + div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); + }, 1); + break; - getSearchData: function (field) { - for (var s in this.searchData) { - if (this.searchData[s].field == field) return this.searchData[s]; - } - return null; - }, + case 'slide-up': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + }, 1); + break; - localSort: function (silent) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - console.log('ERROR: grid.localSort can only be used on local data source, grid.url should be empty.'); - return; - } - if ($.isEmptyObject(this.sortData)) return; - var time = (new Date()).getTime(); - var obj = this; - this.records.sort(function (a, b) { - var ret = 0; - for (var s in obj.sortData) { - var aa = a[obj.sortData[s].field]; - var bb = b[obj.sortData[s].field]; - if (String(obj.sortData[s].field).indexOf('.') != -1) { - aa = obj.parseField(a, obj.sortData[s].field); - bb = obj.parseField(b, obj.sortData[s].field); - } - if (typeof aa == 'string') aa = $.trim(aa.toLowerCase()); - if (typeof bb == 'string') bb = $.trim(bb.toLowerCase()); - if (aa > bb) ret = (obj.sortData[s].direction == 'asc' ? 1 : -1); - if (aa < bb) ret = (obj.sortData[s].direction == 'asc' ? -1 : 1); - if (typeof aa != 'object' && typeof bb == 'object') ret = -1; - if (typeof bb != 'object' && typeof aa == 'object') ret = 1; - if (ret != 0) break; - } - return ret; - }); - time = (new Date()).getTime() - time; - if (silent !== true) setTimeout(function () { obj.status('Sorting took ' + time/1000 + ' sec'); }, 10); - return time; - }, + case 'flip-left': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)'); + }, 1); + break; - localSearch: function (silent) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - console.log('ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.'); - return; - } - var time = (new Date()).getTime(); - var obj = this; - this.total = this.records.length; - // mark all records as shown - this.last.searchIds = []; - // hide records that did not match - if (this.searchData.length > 0 && !url) { - this.total = 0; - for (var r in this.records) { - var rec = this.records[r]; - var fl = 0; - for (var s in this.searchData) { - var sdata = this.searchData[s]; - var search = this.getSearch(sdata.field); - if (sdata == null) continue; - if (search == null) search = { field: sdata.field, type: sdata.type }; - var val1 = String(obj.parseField(rec, search.field)).toLowerCase(); - if (typeof sdata.value != 'undefined') { - if (!$.isArray(sdata.value)) { - var val2 = String(sdata.value).toLowerCase(); - } else { - var val2 = sdata.value[0]; - var val3 = sdata.value[1]; - } - } - switch (sdata.operator) { - case 'is': - if (rec[search.field] == sdata.value) fl++; // do not hide record - if (search.type == 'date') { - var tmp = new Date(Number(val1)); // create date - val1 = (new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate())).getTime(); // drop time - val2 = Number(val2); - var val3 = Number(val1) + 86400000; // 1 day - if (val2 >= val1 && val2 <= val3) fl++; - } + case 'flip-right': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)'); + }, 1); break; - case 'between': - if (search.type == 'int' && parseInt(rec[search.field]) >= parseInt(val2) && parseInt(rec[search.field]) <= parseInt(val3)) fl++; - if (search.type == 'float' && parseFloat(rec[search.field]) >= parseFloat(val2) && parseFloat(rec[search.field]) <= parseFloat(val3)) fl++; - if (search.type == 'date') { - var tmp = new Date(Number(val3)); // create date - val3 = (new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate())).getTime(); // drop time - var val3 = Number(val3) + 86400000; // 1 day - if (val1 >= val2 && val1 < val3) fl++; - } + + case 'flip-down': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)'); + }, 1); break; - case 'in': - if (sdata.value.indexOf(val1) !== -1) fl++; + + case 'flip-up': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)'); + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)'); + }, 1); break; - case 'begins with': - if (val1.indexOf(val2) == 0) fl++; // do not hide record + + case 'pop-in': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time+'s') +';'; + }, 1); break; - case 'contains': - if (val1.indexOf(val2) >= 0) fl++; // do not hide record + + case 'pop-out': + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;'; + }, 1); break; - case 'ends with': - if (val1.indexOf(val2) == val1.length - val2.length) fl++; // do not hide record + + default: + // init divs + div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); + div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; + $(div_new).show(); + // -- need a timing function because otherwise not working + window.setTimeout(function() { + div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;'; + div_old.style.cssText += cross('transition', time +'s'); + }, 1); break; - } - } - if ((this.last.logic == 'OR' && fl != 0) || (this.last.logic == 'AND' && fl == this.searchData.length)) this.last.searchIds.push(parseInt(r)); } - this.total = this.last.searchIds.length; - } - this.buffered = this.total; - time = (new Date()).getTime() - time; - if (silent !== true) setTimeout(function () { obj.status('Search took ' + time/1000 + ' sec'); }, 10); - return time; - }, - getRangeData: function (range, extra) { - var rec1 = this.get(range[0].recid, true); - var rec2 = this.get(range[1].recid, true); - var col1 = range[0].column; - var col2 = range[1].column; - - var res = []; - if (col1 == col2) { // one row - for (var r = rec1; r <= rec2; r++) { - var record = this.records[r]; - var dt = record[this.columns[col1].field] || null; - if (extra !== true) { - res.push(dt); - } else { - res.push({ data: dt, column: col1, index: r, record: record }); - } - } - } else if (rec1 == rec2) { // one line - var record = this.records[rec1]; - for (var i = col1; i <= col2; i++) { - var dt = record[this.columns[i].field] || null; - if (extra !== true) { - res.push(dt); - } else { - res.push({ data: dt, column: i, index: rec1, record: record }); - } - } - } else { - for (var r = rec1; r <= rec2; r++) { - var record = this.records[r]; - res.push([]); - for (var i = col1; i <= col2; i++) { - var dt = record[this.columns[i].field]; - if (extra !== true) { - res[res.length-1].push(dt); - } else { - res[res.length-1].push({ data: dt, column: i, index: r, record: record }); + setTimeout(function () { + if (type === 'slide-down') { + $(div_old).css('z-index', '1019'); + $(div_new).css('z-index', '1020'); } - } - } - } - return res; - }, - - addRange: function (ranges) { - var added = 0; - if (this.selectType == 'row') return added; - if (!$.isArray(ranges)) ranges = [ranges]; - // if it is selection - for (var r in ranges) { - if (typeof ranges[r] != 'object') ranges[r] = { name: 'selection' }; - if (ranges[r].name == 'selection') { - if (this.show.selectionBorder === false) continue; - var sel = this.getSelection(); - if (sel.length == 0) { - this.removeRange(ranges[r].name); - continue; - } else { - var first = sel[0]; - var last = sel[sel.length-1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - } - } else { // other range - var first = ranges[r].range[0]; - var last = ranges[r].range[1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - } - if (first) { - var rg = { - name: ranges[r].name, - range: [{ recid: first.recid, column: first.column }, { recid: last.recid, column: last.column }], - style: ranges[r].style || '' - }; - // add range - var ind = false; - for (var t in this.ranges) if (this.ranges[t].name == ranges[r].name) { ind = r; break; } - if (ind !== false) { - this.ranges[ind] = rg; - } else { - this.ranges.push(rg); - } - added++ - } - } - this.refreshRanges(); - return added; - }, + if (div_new) { + $(div_new).css({ + 'opacity': '1', + '-webkit-transition': '', + '-moz-transition': '', + '-ms-transition': '', + '-o-transition': '', + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '', + '-webkit-backface-visibility': '', + '-moz-backface-visibility': '', + '-ms-backface-visibility': '', + '-o-backface-visibility': '' + }); + } + if (div_old) { + $(div_old).css({ + 'opacity': '1', + '-webkit-transition': '', + '-moz-transition': '', + '-ms-transition': '', + '-o-transition': '', + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '', + '-webkit-backface-visibility': '', + '-moz-backface-visibility': '', + '-ms-backface-visibility': '', + '-o-backface-visibility': '' + }); + if (div_old.parentNode) $(div_old.parentNode).css({ + '-webkit-perspective': '', + '-moz-perspective': '', + '-ms-perspective': '', + '-o-perspective': '' + }); + } + if (typeof callBack === 'function') callBack(); + }, time * 1000); - removeRange: function () { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var name = arguments[a]; - $('#grid_'+ this.name +'_'+ name).remove(); - for (var r = this.ranges.length-1; r >= 0; r--) { - if (this.ranges[r].name == name) { - this.ranges.splice(r, 1); - removed++; - } + function cross(property, value, none_webkit_value) { + var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR + if (!isWebkit && typeof none_webkit_value !== 'undefined') value = none_webkit_value; + return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+ + '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';'; } - } - return removed; - }, + } - refreshRanges: function () { - var obj = this; - var time = (new Date()).getTime(); - var rec = $('#grid_'+ this.name +'_records'); - for (var r in this.ranges) { - var rg = this.ranges[r]; - var first = rg.range[0]; - var last = rg.range[1]; - var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); - var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); - if ($('#grid_'+ this.name +'_'+ rg.name).length == 0) { - rec.append(''+ - (rg.name == 'selection' ? '' : '')+ - ''); + function lock (box, msg, spinner) { + var options = {}; + if (typeof msg === 'object') { + options = msg; } else { - $('#grid_'+ this.name +'_'+ rg.name).attr('style', rg.style); - } - if (td1.length > 0 && td2.length > 0) { - $('#grid_'+ this.name +'_'+ rg.name).css({ - left : (td1.position().left - 1 + rec.scrollLeft()) + 'px', - top : (td1.position().top - 1 + rec.scrollTop()) + 'px', - width : (td2.position().left - td1.position().left + td2.width() + 3) + 'px', - height : (td2.position().top - td1.position().top + td2.height() + 3) + 'px' - }); - } - } - - // add resizer events - $(this.box).find('#grid_'+ this.name +'_resizer').off('mousedown').on('mousedown', mouseStart); - //$(this.box).find('#grid_'+ this.name +'_resizer').off('selectstart').on('selectstart', function () { return false; }); // fixes chrome cursror bug - - var eventData = { phase: 'before', type: 'selectionExtend', target: obj.name, originalRange: null, newRange: null }; - - function mouseStart (event) { - var sel = obj.getSelection(); - obj.last.move = { - type : 'expand', - x : event.screenX, - y : event.screenY, - divX : 0, - divY : 0, - recid : sel[0].recid, - column : sel[0].column, - originalRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }], - newRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }] - }; - $(document).off('mousemove', mouseMove).on('mousemove', mouseMove); - $(document).off('mouseup', mouseStop).on('mouseup', mouseStop); - } - - function mouseMove (event) { - var mv = obj.last.move; - if (!mv || mv.type != 'expand') return; - mv.divX = (event.screenX - mv.x); - mv.divY = (event.screenY - mv.y); - // find new cell - var recid, column; - var tmp = event.originalEvent.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); - tmp = $(tmp).parents('tr')[0]; - recid = $(tmp).attr('recid'); - // new range - if (mv.newRange[1].recid == recid && mv.newRange[1].column == column) return; - var prevNewRange = $.extend({}, mv.newRange); - mv.newRange = [{ recid: mv.recid, column: mv.column }, { recid: recid, column: column }]; - // event before - eventData = obj.trigger($.extend(eventData, { originalRange: mv.originalRange, newRange : mv.newRange })); - if (eventData.isCancelled === true) { - mv.newRange = prevNewRange; - eventData.newRange = prevNewRange; - return; + options.msg = msg; + options.spinner = spinner; + } + if (!options.msg && options.msg !== 0) options.msg = ''; + w2utils.unlock(box); + $(box).prepend( + ''+ + '' + ); + var $lock = $(box).find('.w2ui-lock'); + var mess = $(box).find('.w2ui-lock-msg'); + if (!options.msg) mess.css({ 'background-color': 'transparent', 'border': '0px' }); + if (options.spinner === true) options.msg = '' + options.msg; + if (options.opacity != null) $lock.css('opacity', options.opacity); + if (typeof $lock.fadeIn == 'function') { + $lock.fadeIn(200); + mess.html(options.msg).fadeIn(200); } else { - // default behavior - obj.removeRange('grid-selection-expand'); - obj.addRange({ - name : 'grid-selection-expand', - range : eventData.newRange, - style : 'background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);' - }); + $lock.show(); + mess.html(options.msg).show(0); } - } - - function mouseStop (event) { - // default behavior - obj.removeRange('grid-selection-expand'); - delete obj.last.move; - $(document).off('mousemove', mouseMove); - $(document).off('mouseup', mouseStop); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - - return (new Date()).getTime() - time; - }, + // hide all tags (do not hide overlays as the form can be in overlay) + $().w2tag(); + } - select: function () { - var selected = 0; - for (var a = 0; a < arguments.length; a++) { - var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; - var record = this.get(recid); - var index = this.get(recid, true); - if (record == null) continue; - if (this.selectType == 'row') { - if (record.selected === true) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid }); - if (eventData.isCancelled === true) continue; - // default action - record.selected = true; - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).addClass('w2ui-selected').data('selected', 'yes'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', true); - selected++; - } else { - var col = arguments[a].column; - if (!w2utils.isInt(col)) { // select all columns - var cols = []; - for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } - return this.select.apply(this, cols); - } - var s = record.selectedColumns; - if ($.isArray(s) && s.indexOf(col) != -1) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, column: col }); - if (eventData.isCancelled === true) continue; - // default action - if (!$.isArray(s)) record.selectedColumns = []; - record.selected = true; - record.selectedColumns.push(col); - record.selectedColumns.sort(function(a, b) { return a-b }); // sort function must be for numerical sort - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').addClass('w2ui-selected'); - selected++; - if (record.selected) { - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).data('selected', 'yes'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', true); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - this.status(); - this.addRange('selection'); - return selected; - }, + function unlock (box) { + $(box).find('.w2ui-lock').remove(); + $(box).find('.w2ui-lock-msg').remove(); + } - unselect: function () { - var unselected = 0; - for (var a = 0; a < arguments.length; a++) { - var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; - var record = this.get(recid); - var index = this.get(record.recid, true); - if (record == null) continue; - if (this.selectType == 'row') { - if (record.selected !== true) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid }); - if (eventData.isCancelled === true) continue; - // default action - record.selected = false - var el = $('#grid_'+this.name +'_rec_'+ w2utils.escapeId(record.recid)); - el.removeClass('w2ui-selected').removeData('selected'); - if (el.length != 0) el[0].style.cssText = 'height: '+ this.recordHeight +'px; ' + el.attr('custom_style'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop("checked", false); - unselected++; - } else { - var col = arguments[a].column; - if (!w2utils.isInt(col)) { // unselect all columns - var cols = []; - for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } - return this.unselect.apply(this, cols); - } - var s = record.selectedColumns; - if (!$.isArray(s) || s.indexOf(col) == -1) continue; - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, column: col }); - if (eventData.isCancelled === true) continue; - // default action - s.splice(s.indexOf(col), 1); - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').removeClass('w2ui-selected'); - unselected++; - if (s.length == 0) { - record.selected = false; - $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).removeData('selected'); - $('#grid_'+ this.name +'_cell_'+ index +'_select_check').prop('checked', false); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - // show number of selected - this.status(); - this.addRange('selection'); - return unselected; - }, + function getSize (el, type) { + var $el = $(el); + var bwidth = { + left : parseInt($el.css('border-left-width')) || 0, + right : parseInt($el.css('border-right-width')) || 0, + top : parseInt($el.css('border-top-width')) || 0, + bottom : parseInt($el.css('border-bottom-width')) || 0 + }; + var mwidth = { + left : parseInt($el.css('margin-left')) || 0, + right : parseInt($el.css('margin-right')) || 0, + top : parseInt($el.css('margin-top')) || 0, + bottom : parseInt($el.css('margin-bottom')) || 0 + }; + var pwidth = { + left : parseInt($el.css('padding-left')) || 0, + right : parseInt($el.css('padding-right')) || 0, + top : parseInt($el.css('padding-top')) || 0, + bottom : parseInt($el.css('padding-bottom')) || 0 + }; + switch (type) { + case 'top' : return bwidth.top + mwidth.top + pwidth.top; + case 'bottom' : return bwidth.bottom + mwidth.bottom + pwidth.bottom; + case 'left' : return bwidth.left + mwidth.left + pwidth.left; + case 'right' : return bwidth.right + mwidth.right + pwidth.right; + case 'width' : return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right + parseInt($el.width()); + case 'height' : return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom + parseInt($el.height()); + case '+width' : return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right; + case '+height' : return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom; + } + return 0; + } - selectAll: function () { - if (this.multiSelect === false) return; - // event before - var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, all: true }); - if (eventData.isCancelled === true) return; - // default action - var cols = []; - for (var c in this.columns) cols.push(parseInt(c)); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - if (this.searchData.length == 0) { - // not searched - this.set({ selected: true }); - if (this.selectType == 'row') { - this.set({ selected: true }); - } else { - this.set({ selected: true, selectedColumns: cols.slice() }); // .slice makes copy of the array - } - } else { - // local search applied - for (var i=0; i'+ + ' 1'+ + ''; + $('body').append(html); + tmp.scrollBarSize = 100 - $('#_scrollbar_width > div').width(); + $('#_scrollbar_width').remove(); + if (String(navigator.userAgent).indexOf('MSIE') >= 0) tmp.scrollBarSize = tmp.scrollBarSize / 2; // need this for IE9+ + return tmp.scrollBarSize; + } + + + function checkName (params, component) { // was w2checkNameParam + if (!params || typeof params.name === 'undefined') { + console.log('ERROR: The parameter "name" is required but not supplied in $().'+ component +'().'); + return false; } - } else { // remote data source - if (this.selectType == 'row') { - this.set({ selected: true }); - } else { - this.set({ selected: true, selectedColumns: cols.slice() }); + if (typeof w2ui[params.name] !== 'undefined') { + console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ params.name +').'); + return false; } - this.refresh(); - } - var sel = this.getSelection(); - if (sel.length == 1) this.toolbar.enable('edit'); else this.toolbar.disable('edit'); - if (sel.length >= 1) this.toolbar.enable('delete'); else this.toolbar.disable('delete'); - this.addRange('selection'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - selectNone: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, all: true }); - if (eventData.isCancelled === true) return; - // default action - this.last.selected = []; - for (var i in this.records) { - var rec = this.records[i]; - if (rec.selected === true) { - rec.selected = false; - var tmp = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(rec.recid)); - tmp.removeClass('w2ui-selected').removeData('selected'); - $('#grid_'+ this.name +'_cell_'+ i +'_select_check').prop("checked", false); - if (this.selectType != 'row') { - var cols = rec.selectedColumns; - for (var c in cols) tmp.find(' > td[col='+ cols[c] +']').removeClass('w2ui-selected'); - rec.selectedColumns = []; - } + if (!w2utils.isAlphaNumeric(params.name)) { + console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); + return false; } - } - this.toolbar.disable('edit', 'delete'); - this.removeRange('selection'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + return true; + } - getSelection: function (returnIndex) { - if (this.selectType == 'row') { - var sel = this.find({ selected: true }, true); - var ret = []; - for (var s in sel) { - if (returnIndex === true) { - ret.push(sel[s]); - } else { - ret.push(this.records[sel[s]].recid); - } - } - return ret; - } else { - var sel = this.find({ selected: true }, true); - var ret = []; - for (var s in sel) { - var rec = this.records[sel[s]]; - for (var c in rec.selectedColumns) { - ret.push({ recid: rec.recid, index: parseInt(sel[s]), column: rec.selectedColumns[c] }); - } + function checkUniqueId (id, items, itemsDecription, objName) { // was w2checkUniqueId + if (!$.isArray(items)) items = [items]; + for (var i = 0; i < items.length; i++) { + if (items[i].id === id) { + console.log('ERROR: The parameter "id='+ id +'" is not unique within the current '+ itemsDecription +'. (obj: '+ objName +')'); + return false; + } } - return ret; - } - }, + return true; + } - search: function (field, value) { - var obj = this; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - var searchData = []; - var last_multi = this.last.multi; - var last_logic = this.last.logic; - var last_field = this.last.field; - var last_search = this.last.search; - // 1: search() - advanced search (reads from popup) - if (arguments.length == 0) { - last_search = ''; - // advanced search - for (var s in this.searches) { - var search = this.searches[s]; - var operator = $('#grid_'+ this.name + '_operator_'+s).val(); - var value1 = $('#grid_'+ this.name + '_field_'+s).val(); - var value2 = $('#grid_'+ this.name + '_field2_'+s).val(); - if ((value1 != '' && value1 != null) || (typeof value2 != 'undefined' && value2 != '')) { - var tmp = { - field : search.field, - type : search.type, - operator : operator - } - if (operator == 'between') { - $.extend(tmp, { value: [value1, value2] }); - } else if (operator == 'in') { - $.extend(tmp, { value: value1.split(',') }); + function parseRoute(route) { + var keys = []; + var path = route + .replace(/\/\(/g, '(?:/') + .replace(/\+/g, '__plus__') + .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional) { + keys.push({ name: key, optional: !! optional }); + slash = slash || ''; + return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); + }) + .replace(/([\/.])/g, '\\$1') + .replace(/__plus__/g, '(.+)') + .replace(/\*/g, '(.*)'); + return { + path : new RegExp('^' + path + '$', 'i'), + keys : keys + }; + } +})(jQuery); + +/*********************************************************** +* Generic Event Object +* --- This object is reused across all other +* --- widgets in w2ui. +* +*********************************************************/ + +w2utils.event = { + + on: function (eventData, handler) { + if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; + eventData = jQuery.extend({ type: null, execute: 'before', target: null, onComplete: null }, eventData); + + if (!eventData.type) { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return; } + if (!handler) { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return; } + if (!jQuery.isArray(this.handlers)) this.handlers = []; + this.handlers.push({ event: eventData, handler: handler }); + }, + + off: function (eventData, handler) { + if (!jQuery.isPlainObject(eventData)) eventData = { type: eventData }; + eventData = jQuery.extend({}, { type: null, execute: 'before', target: null, onComplete: null }, eventData); + + if (!eventData.type) { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return; } + if (!handler) { handler = null; } + // remove handlers + var newHandlers = []; + for (var h = 0, len = this.handlers.length; h < len; h++) { + var t = this.handlers[h]; + if ((t.event.type === eventData.type || eventData.type === '*') && + (t.event.target === eventData.target || eventData.target === null) && + (t.handler === handler || handler === null)) + { + // match } else { - $.extend(tmp, { value: value1 }); - } - // conver date to unix time - try { - if (search.type == 'date' && operator == 'between') { - tmp.value[0] = w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); - tmp.value[1] = w2utils.isDate(value2, w2utils.settings.date_format, true).getTime(); - } - if (search.type == 'date' && operator == 'is') { - tmp.value = w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); - } - } catch (e) { - - } - searchData.push(tmp); - } + newHandlers.push(t); + } } - if (searchData.length > 0 && !url) { - last_multi = true; - last_logic = 'AND'; - } else { - last_multi = true; - last_logic = 'AND'; + this.handlers = newHandlers; + }, + + trigger: function (eventData) { + var eventData = jQuery.extend({ type: null, phase: 'before', target: null }, eventData, { + isStopped: false, isCancelled: false, + preventDefault : function () { this.isCancelled = true; }, + stopPropagation : function () { this.isStopped = true; } + }); + if (eventData.phase === 'before') eventData.onComplete = null; + var args, fun, tmp; + if (eventData.target == null) eventData.target = null; + if (!jQuery.isArray(this.handlers)) this.handlers = []; + // process events in REVERSE order + for (var h = this.handlers.length-1; h >= 0; h--) { + var item = this.handlers[h]; + if ((item.event.type === eventData.type || item.event.type === '*') && + (item.event.target === eventData.target || item.event.target === null) && + (item.event.execute === eventData.phase || item.event.execute === '*' || item.event.phase === '*')) + { + eventData = jQuery.extend({}, item.event, eventData); + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(item.handler); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + item.handler.call(this, eventData.target, eventData); // old way for back compatibility + } else { + item.handler.call(this, eventData); // new way + } + if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true + } } - } - // 2: search(field, value) - regular search - if (typeof field == 'string') { - last_field = field; - last_search = value; - last_multi = false; - last_logic = 'OR'; - // loop through all searches and see if it applies - if (typeof value != 'undefined') { - if (field.toLowerCase() == 'all') { - // if there are search fields loop thru them - if (this.searches.length > 0) { - for (var s in this.searches) { - var search = this.searches[s]; - if (search.type == 'text' || (search.type == 'int' && w2utils.isInt(value)) || (search.type == 'float' && w2utils.isFloat(value)) - || (search.type == 'money' && w2utils.isMoney(value)) || (search.type == 'hex' && w2utils.isHex(value)) - || (search.type == 'date' && w2utils.isDate(value)) || (search.type == 'alphaNumeric' && w2utils.isAlphaNumeric(value)) ) { - var tmp = { - field : search.field, - type : search.type, - operator : (search.type == 'text' ? 'contains' : 'is'), - value : value - }; - searchData.push(tmp); - } - // range in global search box - if (search.type == 'int' && String(value).indexOf('-') != -1) { - var t = String(value).split('-'); - var tmp = { - field : search.field, - type : search.type, - operator : 'between', - value : [t[0], t[1]] - }; - searchData.push(tmp); - } - } + // main object events + var funName = 'on' + eventData.type.substr(0,1).toUpperCase() + eventData.type.substr(1); + if (eventData.phase === 'before' && typeof this[funName] === 'function') { + fun = this[funName]; + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(fun); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + fun.call(this, eventData.target, eventData); // old way for back compatibility } else { - // no search fields, loop thru columns - for (var c in this.columns) { - var tmp = { - field : this.columns[c].field, - type : 'text', - operator : 'contains', - value : value - }; - searchData.push(tmp); - } + fun.call(this, eventData); // new way } - } else { - var search = this.getSearch(field); - if (search == null) search = { field: field, type: 'text' }; - if (search.field == field) this.last.caption = search.caption; - if (value != '') { - var op = 'contains'; - var val = value; - if (w2utils.isInt(value)) { - op = 'is'; - val = value; - } - if (search.type == 'int' && value != '') { - if (String(value).indexOf('-') != -1) { - var tmp = value.split('-'); - if (tmp.length == 2) { - op = 'between'; - val = [parseInt(tmp[0]), parseInt(tmp[1])]; - } - } - if (String(value).indexOf(',') != -1) { - var tmp = value.split(','); - op = 'in'; - val = []; - for (var t in tmp) val.push(tmp[t]); - } - } - var tmp = { - field : search.field, - type : search.type, - operator : op, - value : val - } - searchData.push(tmp); - } - } - } - } - // 3: search([ { field, value, [operator,] [type] }, { field, value, [operator,] [type] } ], logic) - submit whole structure - if ($.isArray(field)) { - var logic = 'AND'; - if (typeof value == 'string') { - logic = value.toUpperCase(); - if (logic != 'OR' && logic != 'AND') logic = 'AND'; - } - last_search = ''; - last_multi = true; - last_logic = logic; - for (var f in field) { - var data = field[f]; - var search = this.getSearch(data.field); - if (search == null) search = { type: 'text', operator: 'contains' }; - // merge current field and search if any - searchData.push($.extend(true, {}, search, data)); + if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true } - } - // event before - var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: searchData, - searchField: (field ? field : 'multi'), searchValue: (value ? value : 'multi') }); - if (eventData.isCancelled === true) return; - // default action - this.searchData = eventData.searchData; - this.last.field = last_field; - this.last.search = last_search; - this.last.multi = last_multi; - this.last.logic = last_logic; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - // -- clear all search field - this.searchClose(); - this.set({ expanded: false }); - // apply search - if (url) { - this.last.xhr_offset = 0; - this.reload(); - } else { - // local search - this.localSearch(); - this.refresh(); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - searchOpen: function () { - if (!this.box) return; - if (this.searches.length == 0) return; - var obj = this; - // show search - $('#tb_'+ this.name +'_toolbar_item_search-advanced').w2overlay( - this.getSearchesHTML(), + // item object events + if (eventData.object != null && eventData.phase === 'before' && + typeof eventData.object[funName] === 'function') { - left: -10, - 'class': 'w2ui-grid-searches', - onShow: function () { - if (obj.last.logic == 'OR') obj.searchData = []; - obj.initSearches(); - $('#w2ui-overlay .w2ui-grid-searches').data('grid-name', obj.name); - var sfields = $('#w2ui-overlay .w2ui-grid-searches *[rel=search]'); - if (sfields.length > 0) sfields[0].focus(); - } + fun = eventData.object[funName]; + // check handler arguments + args = []; + tmp = RegExp(/\((.*?)\)/).exec(fun); + if (tmp) args = tmp[1].split(/\s*,\s*/); + if (args.length === 2) { + fun.call(this, eventData.target, eventData); // old way for back compatibility + } else { + fun.call(this, eventData); // new way + } + if (eventData.isStopped === true || eventData.stop === true) return eventData; } - ); - }, + // execute onComplete + if (eventData.phase === 'after' && typeof eventData.onComplete === 'function') eventData.onComplete.call(this, eventData); - searchClose: function () { - if (!this.box) return; - if (this.searches.length == 0) return; - if (this.toolbar) this.toolbar.uncheck('search-advanced') - // hide search - if ($('#w2ui-overlay .w2ui-grid-searches').length > 0) $().w2overlay(); - }, + return eventData; + } +}; - searchShowFields: function (el) { - if (typeof el == 'undefined') el = $('#grid_'+ this.name +'_search_all'); - var html = ''; - for (var s = -1; s < this.searches.length; s++) { - var search = this.searches[s]; - if (s == -1) { - if (!this.multiSearch) continue; - search = { - type : 'text', - field : 'all', - caption : w2utils.lang('All Fields') - } - } else { - if (this.searches[s].hidden === true) continue; - } - html += ''+ - ''+ - ''+ search.caption +''+ - ''; - } - html += ""; - $(el).w2overlay(html, { left: -15, top: 7 }); - }, +/*********************************************************** +* Common Keyboard Handler. Supported in +* - grid +* - sidebar +* - popup +* +*********************************************************/ - searchReset: function (noRefresh) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: [] }); - if (eventData.isCancelled === true) return; - // default action - this.searchData = []; - this.last.search = ''; - this.last.logic = 'OR'; - if (this.last.multi) { - if (!this.multiSearch) { - this.last.field = this.searches[0].field; - this.last.caption = this.searches[0].caption; - } else { - this.last.field = 'all'; - this.last.caption = w2utils.lang('All Fields'); - } - } - this.last.multi = false; - this.last.xhr_offset = 0; - // reset scrolling position - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - // -- clear all search field - this.searchClose(); - // apply search - if (!noRefresh) this.reload(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - clear: function (noRefresh) { - this.offset = 0; - this.total = 0; - this.buffered = 0; - this.records = []; - this.summary = []; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.range_start = null; - this.last.range_end = null; - this.last.xhr_offset = 0; - if (!noRefresh) this.refresh(); - }, - - reset: function (noRefresh) { - // reset last remembered state - this.offset = 0; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - this.last.selected = []; - this.last.range_start = null; - this.last.range_end = null; - this.last.xhr_offset = 0; - this.searchReset(noRefresh); - // initial sort - if (this.last.sortData != null ) this.sortData = this.last.sortData; - // select none without refresh - this.set({ selected: false, expanded: false }, true); - // refresh - if (!noRefresh) this.refresh(); - }, +w2utils.keyboard = (function (obj) { + // private scope + var w2ui_name = null; - skip: function (offset) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - this.offset = parseInt(offset); - if (this.offset < 0 || !w2utils.isInt(this.offset)) this.offset = 0; - if (this.offset > this.total) this.offset = this.total - this.limit; - // console.log('last', this.last); - this.records = []; - this.buffered = 0; - this.last.xhr_offset = 0; - this.last.pull_more = true; - this.last.scrollTop = 0; - this.last.scrollLeft = 0; - $('#grid_'+ this.name +'_records').prop('scrollTop', 0); - this.initColumnOnOff(); - this.reload(); - } else { - console.log('ERROR: grid.skip() can only be called when you have remote data source.'); - } - }, + obj.active = active; + obj.clear = clear; - load: function (url, callBack) { - if (typeof url == 'undefined') { - console.log('ERROR: You need to provide url argument when calling .load() method of "'+ this.name +'" object.'); - return; - } - // default action - this.request('get-records', {}, url, callBack); - }, + init(); + return obj; - reload: function (callBack) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - if (this.last.xhr_offset > 0 && this.last.xhr_offset < this.buffered) this.last.xhr_offset = this.buffered; - this.request('get-records', {}, null, callBack); - } else { - this.localSearch(); - this.refresh(); - if (typeof callBack == 'function') callBack(); - } - }, + function init() { + jQuery(document).on('keydown', keydown); + jQuery(document).on('mousedown', mousedown); + } - request: function (cmd, add_params, url, callBack) { - if (typeof add_params == 'undefined') add_params = {}; - if (typeof url == 'undefined' || url == '' || url == null) url = this.url; - if (url == '' || url == null) return; - // build parameters list - var params = {}; - if (!w2utils.isInt(this.offset)) this.offset = 0; - if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0; - // add list params - params['cmd'] = cmd; - params['name'] = this.name; - params['limit'] = this.limit; - params['offset'] = parseInt(this.offset) + this.last.xhr_offset; - params['selected'] = this.getSelection(); - params['search'] = this.searchData; - params['search-logic'] = this.last.logic; - params['sort'] = (this.sortData.length != 0 ? this.sortData : ''); - // append other params - $.extend(params, this.postData); - $.extend(params, add_params); - // event before - if (cmd == 'get-records') { - var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: url, postData: params }); - if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack(); return false; } - } else { - var eventData = { url: this.url, postData: params }; - } - // call server to get data - var obj = this; - this.lock(this.msgRefresh, true); - if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; - var xhr_type = 'GET'; - var url = (typeof eventData.url != 'object' ? eventData.url : eventData.url.get); - if (params.cmd == 'save-records') { - if (typeof eventData.url == 'object') url = eventData.url.save; - xhr_type = 'PUT'; // so far it is always update - } - if (params.cmd == 'delete-records') { - if (typeof eventData.url == 'object') url = eventData.url.remove; - xhr_type = 'DELETE'; - } - if (!w2utils.settings.RESTfull) xhr_type = 'POST'; - this.last.xhr_cmd = params.cmd; - this.last.xhr_start = (new Date()).getTime(); - this.last.xhr = $.ajax({ - type : xhr_type, - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - complete : function (xhr, status) { - obj.requestComplete(status, cmd, callBack); + function keydown (event) { + var tag = event.target.tagName; + if (jQuery.inArray(tag, ['INPUT', 'SELECT', 'TEXTAREA']) !== -1) return; + if (jQuery(event.target).prop('contenteditable') === 'true') return; + if (!w2ui_name) return; + // pass to appropriate widget + if (w2ui[w2ui_name] && typeof w2ui[w2ui_name].keydown === 'function') { + w2ui[w2ui_name].keydown.call(w2ui[w2ui_name], event); } - }); - if (cmd == 'get-records') { - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, + } - requestComplete: function(status, cmd, callBack) { - var obj = this; - this.unlock(); - setTimeout(function () { obj.status(w2utils.lang('Server Response') + ' ' + ((new Date()).getTime() - obj.last.xhr_start)/1000 +' ' + w2utils.lang('sec')); }, 10); - this.last.pull_more = false; - this.last.pull_refresh = true; - - // event before - var event_name = 'load'; - if (this.last.xhr_cmd == 'save-records') event_name = 'saved'; - if (this.last.xhr_cmd == 'delete-records') event_name = 'deleted'; - var eventData = this.trigger({ phase: 'before', target: this.name, type: event_name, xhr: this.last.xhr, status: status }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // parse server response - var responseText = this.last.xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } - } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : this.msgNotJSON, - responseText : responseText - } - } - if (data['status'] == 'error') { - obj.error(data['message']); - } else { - if (cmd == 'get-records') { - if (this.last.xhr_offset == 0) { - this.records = []; - this.summary = []; - //data.xhr_status=data.status; - delete data.status; - $.extend(true, this, data); - this.buffered = this.records.length; - } else { - var records = data.records; - delete data.records; - //data.xhr_status=data.status; - delete data.status; - $.extend(true, this, data); - for (var r in records) { - this.records.push(records[r]); - } - this.buffered = this.records.length; - } - } - if (cmd == 'delete-records') { - this.reload(); - return; - } - } + function mousedown (event) { + var tag = event.target.tagName; + var obj = jQuery(event.target).parents('.w2ui-reset'); + if (obj.length > 0) { + var name = obj.attr('name'); + if (w2ui[name] && w2ui[name].keyboard) w2ui_name = name; } - } else { - obj.error('AJAX Error. See console for more details.'); - } - // event after - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - this.localSearch(); - } - this.total = parseInt(this.total); - this.trigger($.extend(eventData, { phase: 'after' })); - // do not refresh if loading on infinite scroll - if (this.last.xhr_offset == 0) this.refresh(); else this.scroll(); - // call back - if (typeof callBack == 'function') callBack(); - }, - - error: function (msg) { - var obj = this; - // let the management of the error outside of the grid - var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // need a time out because message might be already up) - setTimeout(function () { w2alert(msg, 'Error'); }, 1); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + } - getChanges: function () { - var changes = []; - var tmp = this.find({ changed: true }); - for (var t in tmp) { - changes.push($.extend(true, { recid: tmp[t].recid }, tmp[t].changes)); - } - return changes; - }, + function active (new_w2ui_name) { + if (typeof new_w2ui_name !== 'undefined') w2ui_name = new_w2ui_name; + return w2ui_name; + } - mergeChanges: function () { - var changed = this.getChanges(); - for (var c in changed) { - var record = this.get(changed[c].recid); - for (var s in changed[c]) { - if (s == 'recid') continue; // do not allow to change recid - try { eval('record.' + s + ' = changed[c][s]'); } catch (e) {} - delete record.changed; - delete record.changes; - } - } - $(this.box).find('.w2ui-editable input').removeClass('changed'); - this.refresh(); - }, + function clear () { + w2ui_name = null; + } - // =================================================== - // -- Action Handlers - - save: function () { - var obj = this; - var changed = this.getChanges(); - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'save', changed: changed }); - if (eventData.isCancelled === true) return false; - var url = (typeof this.url != 'object' ? this.url : this.url.save); - if (url) { - this.request('save-records', { 'changed' : eventData.changed }, null, - function () { // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - ); - } else { - this.mergeChanges(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, +})({}); - editField: function (recid, column, value, event) { - //console.log('edit field', recid, column); - var obj = this; - var index = obj.get(recid, true); - var rec = obj.records[index]; - var col = obj.columns[column]; - var edit = col.editable; - if (!rec || !col || !edit) return; - // event before - var eventData = obj.trigger({ phase: 'before', type: 'editField', target: obj.name, recid: recid, column: column, value: value, - index: index, originalEvent: event }); - if (eventData.isCancelled === true) return; - value = eventData.value; - // default behaviour - this.selectNone(); - this.select({ recid: recid, column: column }); - // create input element - var tr = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(recid)); - var el = tr.find('[col='+ column +'] > div'); - if (edit.type == 'enum') console.log('ERROR: Grid\'s inline editing does not support enum field type.'); - if (edit.type == 'list' || edit.type == 'select') console.log('ERROR: Grid\'s inline editing does not support list/select field type.'); - if (typeof edit.inTag == 'undefined') edit.inTag = ''; - if (typeof edit.outTag == 'undefined') edit.outTag = ''; - if (typeof edit.style == 'undefined') edit.style = ''; - if (typeof edit.items == 'undefined') edit.items = []; - var val = (rec.changed && rec.changes[col.field] ? w2utils.stripTags(rec.changes[col.field]) : w2utils.stripTags(rec[col.field])); - if (val == null || typeof val == 'undefined') val = ''; - if (typeof value != 'undefined' && value != null) val = value; - var addStyle = (typeof col.style != 'undefined' ? col.style + ';' : ''); - if ($.inArray(col.render, ['number', 'int', 'float', 'money', 'percent']) != -1) addStyle += 'text-align: right;'; - el.addClass('w2ui-editable') - .html('' + edit.outTag); - el.find('input') - .w2field(edit.type) - .on('blur', function (event) { - if (obj.parseField(rec, col.field) != this.value) { - // change event - var eventData2 = obj.trigger({ phase: 'before', type: 'change', target: obj.name, input_id: this.id, recid: recid, column: column, - value_new: this.value, value_previous: (rec.changes ? rec.changes[col.field] : obj.parseField(rec, col.field)), - value_original: obj.parseField(rec, col.field) }); - if (eventData2.isCancelled === true) { - // dont save new value - } else { - // default action - rec.changed = true; - rec.changes = rec.changes || {}; - rec.changes[col.field] = eventData2.value_new; - // event after - obj.trigger($.extend(eventData2, { phase: 'after' })); - } - } else { - if (rec.changes) delete rec.changes[col.field]; - if ($.isEmptyObject(rec.changes)) delete rec.changes; - } - // refresh record - $(tr).replaceWith(obj.getRecordHTML(index, tr.attr('line'))); - }) - .on('keydown', function (event) { - var cancel = false; - switch (event.keyCode) { - case 9: // tab - cancel = true; - var next = event.shiftKey ? prevCell(column) : nextCell(column); - if (next != column) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: recid, column: next }); - } else { - obj.editField(recid, next, null, event); - } - }, 1); - } - break; - - case 13: // enter - cancel = true; - var next = event.shiftKey ? prevRow(index) : nextRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 38: // up arrow - cancel = true; - var next = prevRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 40: // down arrow - cancel = true; - var next = nextRow(index); - if (next != index) { - this.blur(); - setTimeout(function () { - if (obj.selectType != 'row') { - obj.selectNone(); - obj.select({ recid: obj.records[next].recid, column: column }); - } else { - obj.editField(obj.records[next].recid, column, null, event); - } - }, 1); - } - break; - - case 27: // escape - var old = (rec.changed && rec.changes[col.field]) ? rec.changes[col.field] : obj.parseField(rec, col.field); - this.value = typeof old != 'undefined' ? old : ''; - this.blur(); - setTimeout(function () { obj.select({ recid: recid, column: column }) }, 1); - break; - } - if (cancel) if (event.preventDefault) event.preventDefault(); - // -- functions - function nextCell (check) { - var newCheck = check + 1; - if (obj.columns.length == newCheck) return check; - if (obj.columns[newCheck].hidden) return nextCell(newCheck); - return newCheck; - } - function prevCell (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - if (obj.columns[newCheck].hidden) return prevCell(newCheck); - return newCheck; - } - function nextRow (check) { - var newCheck = check + 1; - if (obj.records.length == newCheck) return check; - return newCheck; - } - function prevRow (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - return newCheck; - } - }); - // unselect - if (typeof value == 'undefined' || value == null) { - el.find('input').focus(); - } else { - el.find('input').val('').focus().val(value); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, +/*********************************************************** +* Commonly used plugins +* --- used primarily in grid and form +* +*********************************************************/ - delete: function (force) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'delete', force: force }); - if (eventData.isCancelled === true) return false; - force = eventData.force; - // default action - var recs = this.getSelection(); - if (recs.length == 0) return; - if (this.msgDelete != '' && !force) { - w2confirm(obj.msgDelete, w2utils.lang('Delete Confirmation'), function (result) { - if (result == 'Yes') w2ui[obj.name].delete(true); - }); - return; - } - // call delete script - var url = (typeof this.url != 'object' ? this.url : this.url.remove); - if (url) { - this.request('delete-records'); - } else { - if (typeof recs[0] != 'object') { - this.remove.apply(this, recs); - } else { - // clear cells - for (var r in recs) { - var fld = this.columns[recs[r].column].field; - var ind = this.get(recs[r].recid, true); - if (ind != null && fld != 'recid') { - this.records[ind][fld] = ''; - if (this.records[ind].changed) this.records[ind].changes[fld] = ''; - } - } - this.refresh(); - } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, +(function ($) { - click: function (recid, event) { - var time = (new Date()).getTime(); - var column = null; - if (typeof recid == 'object') { - column = recid.column; - recid = recid.recid; - } - if (w2utils.isInt(recid)) recid = parseInt(recid); - if (typeof event == 'undefined') event = {}; - // check for double click - if (time - parseInt(this.last.click_time) < 250 && event.type == 'click') { - this.dblClick(recid, event); - return; - } - this.last.click_time = time; - // column user clicked on - if (column == null && event.target) { - var tmp = event.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'click', recid: recid, column: column, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // if it is subgrid unselect top grid - var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).parents('tr'); - if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var grid = parent.parents('.w2ui-grid').attr('name'); - w2ui[grid].selectNone(); - // all subgrids - parent.parents('.w2ui-grid').find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { - var grid = $(el).attr('name'); - if (w2ui[grid]) w2ui[grid].selectNone(); - }); - } - // unselect all subgrids - $(this.box).find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { - var grid = $(el).attr('name'); - if (w2ui[grid]) w2ui[grid].selectNone(); - }); - // default action - var obj = this; - var sel = this.getSelection(); - $('#grid_'+ this.name +'_check_all').prop("checked", false); - var ind = this.get(recid, true); - var record = this.records[ind]; - var selectColumns = []; - obj.last.sel_ind = ind; - obj.last.sel_col = column; - obj.last.sel_recid = recid; - obj.last.sel_type = 'click'; - // multi select with shif key - if (event.shiftKey && sel.length > 0) { - if (sel[0].recid) { - var start = this.get(sel[0].recid, true); - var end = this.get(recid, true); - if (column > sel[0].column) { - var t1 = sel[0].column; - var t2 = column; - } else { - var t1 = column; - var t2 = sel[0].column; - } - for (var c = t1; c <= t2; c++) selectColumns.push(c); - } else { - var start = this.get(sel[0], true); - var end = this.get(recid, true); - } - var sel_add = [] - if (start > end) { var tmp = start; start = end; end = tmp; } - var url = (typeof this.url != 'object' ? this.url : this.url.get); - for (var i = start; i <= end; i++) { - if (this.searchData.length > 0 && !url && $.inArray(i, this.last.searchIds) == -1) continue; - if (this.selectType == 'row') { - sel_add.push(this.records[i].recid); - } else { - for (var sc in selectColumns) sel_add.push({ recid: this.records[i].recid, column: selectColumns[sc] }); - } - //sel.push(this.records[i].recid); + $.fn.w2render = function (name) { + if ($(this).length > 0) { + if (typeof name === 'string' && w2ui[name]) w2ui[name].render($(this)[0]); + if (typeof name === 'object') name.render($(this)[0]); } - this.select.apply(this, sel_add); - } else { - // clear other if necessary - if (((!event.ctrlKey && !event.shiftKey && !event.metaKey) || !this.multiSelect) && !this.showSelectColumn) { - var flag = record.selected; - if (this.selectType != 'row' && $.inArray(column, record.selectedColumns) == -1) flag = false; - if (sel.length > 300) this.selectNone(); else this.unselect.apply(this, sel); - if (flag === true) { - this.unselect({ recid: recid, column: column }); - //sel = []; - } else { - this.select({ recid: recid, column: column }); - //sel = [{ recid: recid, column: [column] }]; - } - } else { - var flag = record.selected; - if (this.selectType != 'row' && $.inArray(column, record.selectedColumns) == -1) flag = false; - if (flag === true) { - this.unselect({ recid: recid, column: column }); - //sel.splice($.inArray(record.recid, sel), 1); - } else { - this.select({ recid: record.recid, column: column }); - //sel.push(record.recid); - } - setTimeout(function () { if (window.getSelection) window.getSelection().removeAllRanges(); }, 10); - } - } - this.status(); - obj.last.selected = this.getSelection(); - obj.initResize(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }; - columnClick: function (field, event) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'columnClick', target: this.name, field: field, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behaviour - this.sort(field, null, (event && (event.ctrlKey || event.metaKey) ? true : false) ); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + $.fn.w2destroy = function (name) { + if (!name && this.length > 0) name = this.attr('name'); + if (typeof name === 'string' && w2ui[name]) w2ui[name].destroy(); + if (typeof name === 'object') name.destroy(); + }; - keydown: function (event) { - // this method is called from w2utils - var obj = this; - if (obj.keyboard !== true) return; - // trigger event - var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behavior - var sel = obj.getSelection(); - if (sel.length == 0) return; - var records = $('#grid_'+ obj.name +'_records'); - var recid = sel[0]; - var columns = []; - var recid2 = sel[sel.length-1]; - if (typeof recid == 'object') { - recid = sel[0].recid; - columns = []; - var ii = 0; - while (true) { - if (!sel[ii] || sel[ii].recid != recid) break; - columns.push(sel[ii].column); - ii++; + $.fn.w2marker = function (str) { + if (str === '' || str == null) { // remove marker + return $(this).each(function (index, el) { + el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark + }); + } else { // add marker + return $(this).each(function (index, el) { + if (typeof str === 'string') str = [str]; + el.innerHTML = el.innerHTML.replace(/\(.*)\<\/span\>/ig, '$1'); // unmark + for (var s in str) { + var tmp = str[s]; + if (typeof tmp !== 'string') tmp = String(tmp); + // escape regex special chars + tmp = tmp.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, '&').replace(//g, '<'); + var regex = new RegExp(tmp + '(?!([^<]+)?>)', "gi"); // only outside tags + el.innerHTML = el.innerHTML.replace(regex, replaceValue); + } + function replaceValue(matched) { // mark new + return '' + matched + ''; + } + }); + } + }; + + // -- w2tag - appears on the right side from element, there can be multiple on screen at a time + + $.fn.w2tag = function (text, options) { + if (!$.isPlainObject(options)) options = {}; + if (!$.isPlainObject(options.css)) options.css = {}; + if (typeof options['class'] === 'undefined') options['class'] = ''; + // remove all tags + if ($(this).length === 0) { + $('.w2ui-tag').each(function (index, elem) { + var opt = $(elem).data('options'); + if (opt == null) opt = {}; + $($(elem).data('taged-el')).removeClass( opt['class'] ); + clearInterval($(elem).data('timer')); + $(elem).remove(); + }); + return; } - recid2 = sel[sel.length-1].recid; - } - var ind = obj.get(recid, true); - var ind2 = obj.get(recid2, true); - var rec = obj.get(recid); - var recEL = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)); - var cancel = false; - switch (event.keyCode) { - case 8: // backspace - case 46: // delete - obj.delete(); - cancel = true; - event.stopPropagation(); - break; - - case 27: // escape - var sel = obj.getSelection(); - obj.selectNone(); - if (sel.length > 0) { - if (typeof sel[0] == 'object') { - obj.select({ recid: sel[0].recid, column: sel[0].column }); + return $(this).each(function (index, el) { + // show or hide tag + var tagOrigID = el.id; + var tagID = w2utils.escapeId(el.id); + if (text === '' || text == null) { + $('#w2ui-tag-'+tagID).css('opacity', 0); + setTimeout(function () { + // remmove element + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + $('#w2ui-tag-'+tagID).remove(); + }, 300); } else { - obj.select(sel[0]); - } - } - cancel = true; - break; - - case 13: // enter - case 32: // spacebar - if (columns.length == 0) columns.push(0); - obj.editField(recid, columns[0], null, event); - cancel = true; - break; - - case 65: // cmd + A - if (!event.metaKey && !event.ctrlKey) break; - obj.selectAll(); - cancel = true; - break; - - case 70: // cmd + F - if (!event.metaKey && !event.ctrlKey) break; - $('#grid_'+ obj.name + '_search_all').focus(); - cancel = true; - break; - - case 13: // enter - if (this.selectType == 'row') { - if (recEL.length <= 0 || obj.show.expandColumn !== true) break; - obj.toggle(recid, event); - cancel = true; - } else { // same as spacebar - if (columns.length == 0) columns.push(0); - obj.editField(recid, columns[0], null, event); - cancel = true; - } - break; - - case 37: // left - // check if this is subgrid - var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)).parents('tr'); - if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.prev().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].set(recid, { expanded: false }); - w2ui[grid].collapse(recid); - w2ui[grid].click(recid); - cancel = true; - break; - } - if (this.selectType == 'row') { - if (recEL.length <= 0 || rec.expanded !== true ) break; - obj.set(recid, { expanded: false }, true); - obj.collapse(recid, event); - } else { - var prev = prevCell(columns[0]); - if (prev != columns[0]) { - if (event.shiftKey) { - if (tmpUnselect()) return; - var tmp = []; - var newSel = []; - var unSel = []; - if (columns.indexOf(this.last.sel_col) == 0 && columns.length > 1) { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - unSel.push({ recid: sel[i].recid, column: columns[columns.length-1] }); - } - } else { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - newSel.push({ recid: sel[i].recid, column: prev }); - } - } - obj.unselect.apply(obj, unSel); - obj.select.apply(obj, newSel); - } else { - obj.click({ recid: recid, column: prev }, event); - } + // remove elements + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + $('#w2ui-tag-'+tagID).remove(); + // insert + $('body').append( + ''); + + var timer = setInterval(function () { + // monitor if destroyed + if ($(el).length === 0 || ($(el).offset().left === 0 && $(el).offset().top === 0)) { + clearInterval($('#w2ui-tag-'+tagID).data('timer')); + tmp_hide(); + return; + } + // monitor if moved + if ($('#w2ui-tag-'+tagID).data('position') !== ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) { + $('#w2ui-tag-'+tagID).css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s', + left: ($(el).offset().left + el.offsetWidth) + 'px', + top: $(el).offset().top + 'px' + }).data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top); + } + }, 100); + setTimeout(function () { + if (!$(el).offset()) return; + $('#w2ui-tag-'+tagID).css({ + opacity: '1', + left: ($(el).offset().left + el.offsetWidth) + 'px', + top: $(el).offset().top + 'px' + }).html(' '+ text +' ') + .data('text', text) + .data('taged-el', el) + .data('options', options) + .data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) + .data('timer', timer); + $(el).off('keypress', tmp_hide).on('keypress', tmp_hide).off('change', tmp_hide).on('change', tmp_hide) + .css(options.css).addClass(options['class']); + if (typeof options.onShow === 'function') options.onShow(); + }, 1); + var originalCSS = ''; + if ($(el).length > 0) originalCSS = $(el)[0].style.cssText; + // bind event to hide it + function tmp_hide() { + $tag = $('#w2ui-tag-'+tagID); + if ($tag.length <= 0) return; + clearInterval($tag.data('timer')); + $tag.remove(); + $(el).off('keypress', tmp_hide).removeClass(options['class']); + if ($(el).length > 0) $(el)[0].style.cssText = originalCSS; + if (typeof options.onHide === 'function') options.onHide(); + } + } + }); + }; + + // w2overlay - appears under the element, there can be only one at a time + + $.fn.w2overlay = function (html, options) { + var obj = this; + var name = ''; + var defaults = { + name : null, // it not null, then allows multiple concurent overlays + html : '', // html text to display + align : 'none', // can be none, left, right, both + left : 0, // offset left + top : 0, // offset top + tipLeft : 30, // tip offset left + width : 0, // fixed width + height : 0, // fixed height + maxWidth : null, // max width if any + maxHeight : null, // max height if any + style : '', // additional style for main div + 'class' : '', // additional class name for main div + onShow : null, // event on show + onHide : null, // event on hide + openAbove : false, // show abover control + tmp : {} + }; + if (arguments.length == 1) { + if (typeof html == 'object') { + options = html; } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=1; s 1) { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - unSel.push({ recid: sel[i].recid, column: columns[0] }); - } - } else { - for (var i in sel) { - if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); - newSel.push({ recid: sel[i].recid, column: next }); - } - } - obj.unselect.apply(obj, unSel); - obj.select.apply(obj, newSel); - } else { - obj.click({ recid: recid, column: next }, event); - } + options = { html: html }; + } + } + if (arguments.length == 2) options.html = html; + if (!$.isPlainObject(options)) options = {}; + options = $.extend({}, defaults, options); + if (options.name) name = '-' + options.name; + // if empty then hide + var tmp_hide; + if (this.length === 0 || options.html === '' || options.html == null) { + if ($('#w2ui-overlay'+ name).length > 0) { + tmp_hide = $('#w2ui-overlay'+ name)[0].hide; + if (typeof tmp_hide === 'function') tmp_hide(); } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=0; s 0 && w2ui[subgrid.attr('name')]) { - obj.selectNone(); - var grid = subgrid.attr('name'); - var recs = w2ui[grid].records; - w2utils.keyboard.active(grid); - w2ui[grid].click(recs[recs.length-1].recid); - cancel = true; - break; - } + $('#w2ui-overlay'+ name).remove(); } - if (event.shiftKey) { // expand selection - if (tmpUnselect()) return; - if (obj.selectType == 'row') { - if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { - obj.unselect(obj.records[ind2].recid); - } else { - obj.select(obj.records[prev].recid); - } - } else { - if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { - prev = ind2; - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); - obj.unselect.apply(obj, tmp); - } else { - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); - obj.select.apply(obj, tmp); - } - } - } else { // move selected record - obj.selectNone(); - obj.click({ recid: obj.records[prev].recid, column: columns[0] }, event); + return $(this); + } + if ($('#w2ui-overlay'+ name).length > 0) { + tmp_hide = $('#w2ui-overlay'+ name)[0].hide; + $(document).off('click', tmp_hide); + if (typeof tmp_hide === 'function') tmp_hide(); + } + $('body').append( + ''+ + ' '+ + ' '+ + '' + ); + // init + var div1 = $('#w2ui-overlay'+ name); + var div2 = div1.find(' > div'); + div2.html(options.html); + // pick bg color of first div + var bc = div2.css('background-color'); + if (bc != null && bc !== 'rgba(0, 0, 0, 0)' && bc !== 'transparent') div1.css('background-color', bc); + + div1.data('element', obj.length > 0 ? obj[0] : null) + .data('options', options) + .data('position', $(obj).offset().left + 'x' + $(obj).offset().top) + .fadeIn('fast').on('mousedown', function (event) { + $('#w2ui-overlay'+ name).data('keepOpen', true); + if (['INPUT', 'TEXTAREA', 'SELECT'].indexOf(event.target.tagName) === -1) event.preventDefault(); + }); + div1[0].hide = hide; + div1[0].resize = resize; + + // need time to display + resize(); + setTimeout(function () { + resize(); + $(document).off('click', hide).on('click', hide); + if (typeof options.onShow === 'function') options.onShow(); + }, 10); + + monitor(); + return $(this); + + // monitor position + function monitor() { + var tmp = $('#w2ui-overlay'+ name); + if (tmp.data('element') !== obj[0]) return; // it if it different overlay + if (tmp.length === 0) return; + var pos = $(obj).offset().left + 'x' + $(obj).offset().top; + if (tmp.data('position') !== pos) { + hide(); + } else { + setTimeout(monitor, 250); } - obj.scrollIntoView(prev); - if (event.preventDefault) event.preventDefault(); - } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=1; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.prev().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].click(recid); - cancel = true; - break; - } - } - break; - - case 40: // down - if (recEL.length <= 0) break; - // jump into subgrid - if (obj.records[ind2].expanded) { - var subgrid = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind2].recid) +'_expanded_row').find('.w2ui-grid'); - if (subgrid.length > 0 && w2ui[subgrid.attr('name')]) { - obj.selectNone(); - var grid = subgrid.attr('name'); - var recs = w2ui[grid].records; - w2utils.keyboard.active(grid); - w2ui[grid].click(recs[0].recid); - cancel = true; - break; - } - } - // move to the next record - var next = nextRow(ind2); - if (next != null) { - if (event.shiftKey) { // expand selection - if (tmpUnselect()) return; - if (obj.selectType == 'row') { - if (this.last.sel_ind < next && this.last.sel_ind != ind) { - obj.unselect(obj.records[ind].recid); - } else { - obj.select(obj.records[next].recid); - } - } else { - if (this.last.sel_ind < next && this.last.sel_ind != ind) { - next = ind; - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); - obj.unselect.apply(obj, tmp); + var result; + if (typeof options.onHide === 'function') result = options.onHide(); + if (result === false) return; + div1.remove(); + $(document).off('click', hide); + clearInterval(div1.data('timer')); + } + + function resize () { + var div1 = $('#w2ui-overlay'+ name); + var div2 = div1.find(' > div'); + // if goes over the screen, limit height and width + if (div1.length > 0) { + div2.height('auto').width('auto'); + // width/height + var overflowX = false; + var overflowY = false; + var h = div2.height(); + var w = div2.width(); + if (options.width && options.width < w) w = options.width; + if (w < 30) w = 30; + // if content of specific height + if (options.tmp.contentHeight) { + h = options.tmp.contentHeight; + div2.height(h); + setTimeout(function () { + if (div2.height() > div2.find('div.menu > table').height()) { + div2.find('div.menu').css('overflow-y', 'hidden'); + } + }, 1); + setTimeout(function () { div2.find('div.menu').css('overflow-y', 'auto'); }, 10); + } + if (options.tmp.contentWidth) { + w = options.tmp.contentWidth; + div2.width(w); + setTimeout(function () { + if (div2.width() > div2.find('div.menu > table').width()) { + div2.find('div.menu').css('overflow-x', 'hidden'); + } + }, 1); + setTimeout(function () { div2.find('div.menu').css('overflow-y', 'auto'); }, 10); + } + // alignment + switch (options.align) { + case 'both': + options.left = 17; + if (options.width === 0) options.width = w2utils.getSize($(obj), 'width'); + break; + case 'left': + options.left = 17; + break; + case 'right': + options.tipLeft = w - 45; + options.left = w2utils.getSize($(obj), 'width') - w + 10; + break; + } + // adjust position + var tmp = (w - 17) / 2; + var boxLeft = options.left; + var boxWidth = options.width; + var tipLeft = options.tipLeft; + if (w === 30 && !boxWidth) boxWidth = 30; else boxWidth = (options.width ? options.width : 'auto'); + if (tmp < 25) { + boxLeft = 25 - tmp; + tipLeft = Math.floor(tmp); + } + // Y coord + div1.css({ + top : (obj.offset().top + w2utils.getSize(obj, 'height') + options.top + 7) + 'px', + left : ((obj.offset().left > 25 ? obj.offset().left : 25) + boxLeft) + 'px', + 'min-width' : boxWidth, + 'min-height': (options.height ? options.height : 'auto') + }); + // $(window).height() - has a problem in FF20 + var maxHeight = window.innerHeight + $(document).scrollTop() - div2.offset().top - 7; + var maxWidth = window.innerWidth + $(document).scrollLeft() - div2.offset().left - 7; + if ((maxHeight > -50 && maxHeight < 210) || options.openAbove === true) { + // show on top + maxHeight = div2.offset().top - $(document).scrollTop() - 7; + if (options.maxHeight && maxHeight > options.maxHeight) maxHeight = options.maxHeight; + if (h > maxHeight) { + overflowY = true; + div2.height(maxHeight).width(w).css({ 'overflow-y': 'auto' }); + h = maxHeight; + } + div1.css('top', ($(obj).offset().top - h - 24 + options.top) + 'px'); + div1.find('>style').html( + '#w2ui-overlay'+ name +':before { display: none; margin-left: '+ parseInt(tipLeft) +'px; }'+ + '#w2ui-overlay'+ name +':after { display: block; margin-left: '+ parseInt(tipLeft) +'px; }' + ); } else { - var tmp = []; - for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); - obj.select.apply(obj, tmp); - } - } - } else { // move selected record - obj.selectNone(); - obj.click({ recid: obj.records[next].recid, column: columns[0] }, event); - } - obj.scrollIntoView(next); - cancel = true; - } else { - // if selected more then one, then select first - if (!event.shiftKey) { - for (var s=0; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { - var recid = parent.next().attr('recid'); - var grid = parent.parents('.w2ui-grid').attr('name'); - obj.selectNone(); - w2utils.keyboard.active(grid); - w2ui[grid].click(recid); - cancel = true; - break; - } - } - break; - - case 86: // v - paste - if (event.ctrlKey || event.metaKey) { - $('body').append(''); - $('#_tmp_copy_data').focus(); - setTimeout(function () { - obj.paste($('#_tmp_copy_data').val()); - $('#_tmp_copy_data').remove(); - }, 50); // need timer to allow paste - } - break; - - case 88: // x - cut - if (event.ctrlKey || event.metaKey) { - setTimeout(function () { obj.delete(true); }, 100); - } - case 67: // c - copy - if (event.ctrlKey || event.metaKey) { - var text = obj.copy(); - $('body').append(''+ text +''); - $('#_tmp_copy_data').focus().select(); - setTimeout(function () { $('#_tmp_copy_data').remove(); }, 50); - } - break; - } - var tmp = [187, 189]; // =- - for (var i=48; i<=90; i++) tmp.push(i); // 0-9,a-z,A-Z - if (tmp.indexOf(event.keyCode) != -1 && !event.ctrlKey && !event.metaKey && !cancel) { - if (columns.length == 0) columns.push(0); - var tmp = String.fromCharCode(event.keyCode); - if (event.keyCode == 187) tmp = '='; - if (event.keyCode == 189) tmp = '-'; - if (!event.shiftKey) tmp = tmp.toLowerCase(); - obj.editField(recid, columns[0], tmp, event); - cancel = true; - } - if (cancel) { // cancel default behaviour - if (event.preventDefault) event.preventDefault(); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - - function nextRow (ind) { - if ((ind + 1 < obj.records.length && obj.last.searchIds.length == 0) // if there are more records - || (obj.last.searchIds.length > 0 && ind < obj.last.searchIds[obj.last.searchIds.length-1])) { - ind++; - if (obj.last.searchIds.length > 0) { - while (true) { - if ($.inArray(ind, obj.last.searchIds) != -1 || ind > obj.records.length) break; - ind++; + // show under + if (options.maxHeight && maxHeight > options.maxHeight) maxHeight = options.maxHeight; + if (h > maxHeight) { + overflowY = true; + div2.height(maxHeight).width(w).css({ 'overflow-y': 'auto' }); + } + div1.find('>style').html( + '#w2ui-overlay'+ name +':before { display: block; margin-left: '+ parseInt(tipLeft) +'px; }'+ + '#w2ui-overlay'+ name +':after { display: none; margin-left: '+ parseInt(tipLeft) +'px; }' + ); + } + // check width + w = div2.width(); + maxWidth = window.innerWidth + $(document).scrollLeft() - div2.offset().left - 7; + if (options.maxWidth && maxWidth > options.maxWidth) maxWidth = options.maxWidth; + if (w > maxWidth && options.align !== 'both') { + options.align = 'right'; + setTimeout(function () { resize(); }, 1); + } + // check scroll bar + if (overflowY && overflowX) div2.width(w + w2utils.scrollBarSize() + 2); } - } - return ind; - } else { - return null; } - } - - function prevRow (ind) { - if ((ind > 0 && obj.last.searchIds.length == 0) // if there are more records - || (obj.last.searchIds.length > 0 && ind > obj.last.searchIds[0])) { - ind--; - if (obj.last.searchIds.length > 0) { - while (true) { - if ($.inArray(ind, obj.last.searchIds) != -1 || ind < 0) break; - ind--; + }; + + $.fn.w2menu = function (menu, options) { + /* + ITEM STRUCTURE + item : { + id : null, + text : '', + style : '', + img : '', + icon : '', + count : '', + hidden : false, + disabled : false + ... } - } - return ind; - } else { - return null; - } - } - - function nextCell (check) { - var newCheck = check + 1; - if (obj.columns.length == newCheck) return check; - if (obj.columns[newCheck].hidden) return findNext(newCheck); - return newCheck; - } - - function prevCell (check) { - var newCheck = check - 1; - if (newCheck < 0) return check; - if (obj.columns[newCheck].hidden) return findPrev(newCheck); - return newCheck; - } - - function tmpUnselect () { - if (obj.last.sel_type != 'click') return false; - if (obj.selectType != 'row') { - obj.last.sel_type = 'key'; - if (sel.length > 1) { - for (var s in sel) { - if (sel[s].recid == obj.last.sel_recid && sel[s].column == obj.last.sel_col) { - sel.splice(s, 1); - break; - } + */ + var defaults = { + index : null, // current selected + items : [], + render : null, + msgNoItems : 'No items', + onSelect : null, + tmp : {} + }; + var obj = this; + var name = ''; + if (menu === 'refresh') { + // if not show - call blur + if ($('#w2ui-overlay'+ name).length > 0) { + options = $.extend($.fn.w2menuOptions, options); + var scrTop = $('#w2ui-overlay'+ name +' div.menu').scrollTop(); + $('#w2ui-overlay'+ name +' div.menu').html(getMenuHTML()); + $('#w2ui-overlay'+ name +' div.menu').scrollTop(scrTop); + mresize(); + } else { + $(this).w2menu(options); } - obj.unselect.apply(obj, sel); - return true; - } - return false; } else { - obj.last.sel_type = 'key'; - if (sel.length > 1) { - sel.splice(sel.indexOf(obj.records[obj.last.sel_ind].recid), 1); - obj.unselect.apply(obj, sel); - return true; - } - return false; + if (arguments.length === 1) options = menu; else options.items = menu; + if (typeof options !== 'object') options = {}; + options = $.extend({}, defaults, options); + $.fn.w2menuOptions = options; + if (options.name) name = '-' + options.name; + if (typeof options.select === 'function' && typeof options.onSelect !== 'function') options.onSelect = options.select; + if (typeof options.onRender === 'function' && typeof options.render !== 'function') options.render = options.onRender; + // since only one overlay can exist at a time + $.fn.w2menuHandler = function (event, index) { + if (typeof options.onSelect === 'function') { + // need time so that menu first hides + setTimeout(function () { + options.onSelect({ + index : index, + item : options.items[index], + originalEvent: event + }); + }, 10); + } + // do not uncomment (enum in grid search will not work) + // setTimeout(function () { $(document).click(); }, 50); + }; + var html = ''; + if (options.search) { + html += + ''+ + ' '+ + ' '+ + ''; + options.style += ';background-color: #ECECEC'; + options.index = 0; + for (var i in options.items) options.items[i].hidden = false; + } + html += '' + + getMenuHTML() + + ''; + var ret = $(this).w2overlay(html, options); + setTimeout(function () { + $('#w2ui-overlay'+ name +' #menu-search') + .on('keyup', change) + .on('keydown', function (event) { + // cancel tab key + if (event.keyCode === 9) { event.stopPropagation(); event.preventDefault(); } + }); + if (options.search) { + if (['text', 'password'].indexOf($(obj)[0].type) != -1 || $(obj)[0].tagName == 'texarea') return; + $('#w2ui-overlay'+ name +' #menu-search').focus(); + } + }, 200); + mresize(); + return ret; } - } - }, - - scrollIntoView: function (ind) { - if (typeof ind == 'undefined') { - var sel = this.getSelection(); - if (sel.length == 0) return; - ind = this.get(sel[0], true); - } - var records = $('#grid_'+ this.name +'_records'); - if (records.length == 0) return; - // if all records in view - var len = this.last.searchIds.length; - if (records.height() > this.recordHeight * (len > 0 ? len : this.records.length)) return; - if (len > 0) ind = this.last.searchIds.indexOf(ind); // if seach is applied - // scroll to correct one - var t1 = Math.floor(records[0].scrollTop / this.recordHeight); - var t2 = t1 + Math.floor(records.height() / this.recordHeight); - if (ind == t1) records.animate({ 'scrollTop': records.scrollTop() - records.height() / 1.3 }); - if (ind == t2) records.animate({ 'scrollTop': records.scrollTop() + records.height() / 1.3 }); - if (ind < t1 || ind > t2) records.animate({ 'scrollTop': (ind - 1) * this.recordHeight }); - }, - - dblClick: function (recid, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // find columns - var column = null; - if (typeof recid == 'object') { - column = recid.column; - recid = recid.recid; - } - if (typeof event == 'undefined') event = {}; - // column user clicked on - if (column == null && event.target) { - var tmp = event.target; - if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; - column = parseInt($(tmp).attr('col')); - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'dblClick', recid: recid, column: column, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - this.selectNone(); - var col = this.columns[column]; - if (col && $.isPlainObject(col.editable)) { - this.editField(recid, column, null, event); - } else { - this.select({ recid: recid, column: column }); - this.last.selected = this.getSelection(); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - toggle: function (recid) { - var rec = this.get(recid); - if (rec.expanded === true) return this.collapse(recid); else return this.expand(recid); - }, - - expand: function (recid) { - var rec = this.get(recid); - var obj = this; - var id = w2utils.escapeId(recid); - if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length > 0) return false; - if (rec.expanded == 'none') return false; - // insert expand row - var tmp = 1 + (this.show.selectColumn ? 1 : 0); - var addClass = ''; // ($('#grid_'+this.name +'_rec_'+ w2utils.escapeId(recid)).hasClass('w2ui-odd') ? 'w2ui-odd' : 'w2ui-even'); - $('#grid_'+ this.name +'_rec_'+ id).after( - ''+ - (this.show.lineNumbers ? '' : '') + - ' '+ - ' '+ - ' '+ - ' '+ - ''); - // event before - var eventData = this.trigger({ phase: 'before', type: 'expand', target: this.name, recid: recid, - box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded', ready: ready }); - if (eventData.isCancelled === true) { - $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').remove(); - return false; - } - // default action - $('#grid_'+ this.name +'_rec_'+ id).attr('expanded', 'yes').addClass('w2ui-expanded'); - $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').show(); - $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html(''); - rec.expanded = true; - // check if height of expaned row > 5 then remove spinner - setTimeout(ready, 300); - function ready() { - var div1 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded'); - var div2 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row .w2ui-expanded1 > div'); - if (div1.height() < 5) return; - div1.css('opacity', 1); - div2.show().css('opacity', 1); - $('#grid_'+ obj.name +'_cell_'+ obj.get(recid, true) +'_expand div').html('-'); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resizeRecords(); - return true; - }, - - collapse: function (recid) { - var rec = this.get(recid); - var obj = this; - var id = w2utils.escapeId(recid); - if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length == 0) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'collapse', target: this.name, recid: recid, - box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded' }); - if (eventData.isCancelled === true) return false; - // default action - $('#grid_'+ this.name +'_rec_'+ id).removeAttr('expanded').removeClass('w2ui-expanded'); - $('#grid_'+ this.name +'_rec_'+ id +'_expanded').css('opacity', 0); - $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html('+'); - setTimeout(function () { - $('#grid_'+ obj.name +'_rec_'+ id +'_expanded').height('0px'); - setTimeout(function () { - $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row').remove(); - delete rec.expanded; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resizeRecords(); - }, 300); - }, 200); - return true; - }, - sort: function (field, direction, multiField) { // if no params - clears sort - // event before - var eventData = this.trigger({ phase: 'before', type: 'sort', target: this.name, field: field, direction: direction, multiField: multiField }); - if (eventData.isCancelled === true) return false; - // check if needed to quit - if (typeof field != 'undefined') { - // default action - var sortIndex = this.sortData.length; - for (var s in this.sortData) { - if (this.sortData[s].field == field) { sortIndex = s; break; } - } - if (typeof direction == 'undefined' || direction == null) { - if (typeof this.sortData[sortIndex] == 'undefined') { - direction = 'asc'; - } else { - switch (String(this.sortData[sortIndex].direction)) { - case 'asc' : direction = 'desc'; break; - case 'desc' : direction = 'asc'; break; - default : direction = 'asc'; break; - } - } + function mresize() { + setTimeout(function () { + // show selected + $('#w2ui-overlay'+ name +' tr.w2ui-selected').removeClass('w2ui-selected'); + var cur = $('#w2ui-overlay'+ name +' tr[index='+ options.index +']'); + var scrTop = $('#w2ui-overlay'+ name +' div.menu').scrollTop(); + cur.addClass('w2ui-selected'); + if (options.tmp) options.tmp.contentHeight = $('#w2ui-overlay'+ name +' table').height() + (options.search ? 50 : 10); + if (options.tmp) options.tmp.contentWidth = $('#w2ui-overlay'+ name +' table').width(); + if ($('#w2ui-overlay'+ name).length > 0) $('#w2ui-overlay'+ name)[0].resize(); + // scroll into view + if (cur.length > 0) { + var top = cur[0].offsetTop - 5; // 5 is margin top + var el = $('#w2ui-overlay'+ name +' div.menu'); + var height = el.height(); + $('#w2ui-overlay'+ name +' div.menu').scrollTop(scrTop); + if (top < scrTop || top + cur.height() > scrTop + height) { + $('#w2ui-overlay'+ name +' div.menu').animate({ 'scrollTop': top - (height - cur.height() * 2) / 2 }, 200, 'linear'); + } + } + }, 1); } - if (this.multiSort === false) { this.sortData = []; sortIndex = 0; } - if (multiField != true) { this.sortData = []; sortIndex = 0; } - // set new sort - if (typeof this.sortData[sortIndex] == 'undefined') this.sortData[sortIndex] = {}; - this.sortData[sortIndex].field = field; - this.sortData[sortIndex].direction = direction; - } else { - this.sortData = []; - } - // if local - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (!url) { - this.localSort(); - if (this.searchData.length > 0) this.localSearch(true); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - } else { - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.last.xhr_offset = 0; - this.reload(); - } - }, - copy: function () { - var sel = this.getSelection(); - if (sel.length == 0) return ''; - var text = ''; - if (typeof sel[0] == 'object') { // cell copy - // find min/max column - var minCol = sel[0].column; - var maxCol = sel[0].column; - var recs = []; - for (var s in sel) { - if (sel[s].column < minCol) minCol = sel[s].column; - if (sel[s].column > maxCol) maxCol = sel[s].column; - if (recs.indexOf(sel[s].index) == -1) recs.push(sel[s].index); - } - recs.sort(); - for (var r in recs) { - var ind = recs[r]; - for (var c = minCol; c <= maxCol; c++) { - var col = this.columns[c]; - if (col.hidden === true) continue; - text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; - } - text = text.substr(0, text.length-1); // remove last \t - text += '\n'; - } - } else { // row copy - for (var s in sel) { - var ind = this.get(sel[s], true); - for (var c in this.columns) { - var col = this.columns[c]; - if (col.hidden === true) continue; - text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; - } - text = text.substr(0, text.length-1); // remove last \t - text += '\n'; + function change(event) { + var search = this.value; + var key = event.keyCode; + var cancel = false; + switch (key) { + case 13: // enter + $('#w2ui-overlay'+ name).remove(); + $.fn.w2menuHandler(event, options.index); + break; + case 9: // tab + case 27: // escape + $('#w2ui-overlay'+ name).remove(); + $.fn.w2menuHandler(event, -1); + break; + case 38: // up + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index--; + while (options.index > 0 && options.items[options.index].hidden) options.index--; + if (options.index === 0 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } + if (options.index < 0) options.index = 0; + cancel = true; + break; + case 40: // down + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index++; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (options.index === options.items.length-1 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index--; + } + if (options.index >= options.items.length) options.index = options.items.length - 1; + cancel = true; + break; + } + // filter + if (!cancel) { + var shown = 0; + for (var i in options.items) { + var item = options.items[i]; + var prefix = ''; + var suffix = ''; + if (['is', 'begins with'].indexOf(options.match) !== -1) prefix = '^'; + if (['is', 'ends with'].indexOf(options.match) !== -1) suffix = '$'; + try { + var re = new RegExp(prefix + search + suffix, 'i'); + if (re.test(item.text) || item.text === '...') item.hidden = false; else item.hidden = true; + } catch (e) {} + // do not show selected items + if (obj.type === 'enum' && $.inArray(item.id, ids) !== -1) item.hidden = true; + if (item.hidden !== true) shown++; + } + options.index = 0; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (shown <= 0) options.index = -1; + } + $(obj).w2menu('refresh', options); + mresize(); } - } - text = text.substr(0, text.length - 1); - // before event - var eventData = this.trigger({ phase: 'before', type: 'copy', target: this.name, text: text }); - if (eventData.isCancelled === true) return ''; - text = eventData.text; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return text; - }, - paste: function (text) { - var sel = this.getSelection(); - var ind = this.get(sel[0].recid, true); - var col = sel[0].column; - // before event - var eventData = this.trigger({ phase: 'before', type: 'paste', target: this.name, text: text, index: ind, column: col }); - if (eventData.isCancelled === true) return; - text = eventData.text; - // default action - if (this.selectType == 'row' || sel.length == 0) { - console.log('ERROR: You can paste only if grid.selectType = \'cell\' and when at least one cell selected.'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return; - } - var newSel = []; - var text = text.split('\n'); - for (var t in text) { - var tmp = text[t].split('\t'); - var cnt = 0; - var rec = this.records[ind]; - var cols = []; - for (var dt in tmp) { - if (!this.columns[col + cnt]) continue; - var field = this.columns[col + cnt].field; - rec.changed = true; - rec.changes = rec.changes || {}; - rec.changes[field] = tmp[dt]; - cols.push(col + cnt); - cnt++; + function getMenuHTML () { + if (options.spinner) { + return ''+ + ' '+ + ' '+ w2utils.lang('Loading...') +''+ + ''; + } + var count = 0; + var menu_html = ''; + var img = null, icon = null; + for (var f = 0; f < options.items.length; f++) { + var mitem = options.items[f]; + if (typeof mitem === 'string') { + mitem = { id: mitem, text: mitem }; + } else { + if (mitem.text != null && mitem.id == null) mitem.id = mitem.text; + if (mitem.text == null && mitem.id != null) mitem.text = mitem.id; + if (mitem.caption != null) mitem.text = mitem.caption; + img = mitem.img; + icon = mitem.icon; + if (img == null) img = null; + if (icon == null) icon = null; + } + if (mitem.hidden !== true) { + var imgd = ''; + var txt = mitem.text; + if (typeof options.render === 'function') txt = options.render(mitem, options); + if (img) imgd = ''; + if (icon) imgd = ''; + // render only if non-empty + if (typeof txt !== 'undefined' && txt !== '' && !(/^-+$/.test(txt))) { + var bg = (count % 2 === 0 ? 'w2ui-item-even' : 'w2ui-item-odd'); + if (options.altRows !== true) bg = ''; + var colspan = 1; + if (imgd == '') colspan++; + if (mitem.count == null) colspan++; + menu_html += + ''+ + imgd + + ' '+ txt +''+ + ' '+ (mitem.count != null ? '' + mitem.count + '' : '') + '' + + ''; + count++; + } else { + // horizontal line + menu_html += ''; + } + } + options.items[f] = mitem; + } + if (count === 0) { + menu_html += ''+ options.msgNoItems +''; + } + menu_html += ""; + return menu_html; } - for (var c in cols) newSel.push({ recid: rec.recid, column: cols[c] }); - ind++; - } - this.selectNone(); - this.select.apply(this, newSel); - this.refresh(); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }; +})(jQuery); - // ================================================== - // --- Common functions - - resize: function () { - var obj = this; - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // make sure the box is right - if (!this.box || $(this.box).attr('name') != this.name) return; - // determine new width and height - $(this.box).find('> div') - .css('width', $(this.box).width()) - .css('height', $(this.box).height()); - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // resize - obj.resizeBoxes(); - obj.resizeRecords(); - // init editable - // $('#grid_'+ obj.name + '_records .w2ui-editable input').each(function (index, el) { - // var column = obj.columns[$(el).attr('column')]; - // if (column && column.editable) $(el).w2field(column.editable); - // }); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, - refresh: function () { - var obj = this; - var time = (new Date()).getTime(); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (this.total <= 0 && !url && this.searchData.length == 0) { - this.total = this.records.length; - this.buffered = this.total; - } - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - this.toolbar.disable('edit', 'delete'); - if (!this.box) return; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh' }); - if (eventData.isCancelled === true) return false; - // -- header - if (this.show.header) { - $('#grid_'+ this.name +'_header').html(this.header +' ').show(); - } else { - $('#grid_'+ this.name +'_header').hide(); - } - // -- toolbar - if (this.show.toolbar) { - // if select-collumn is checked - no toolbar refresh - if (this.toolbar && this.toolbar.get('column-on-off') && this.toolbar.get('column-on-off').checked) { - // no action - } else { - $('#grid_'+ this.name +'_toolbar').show(); - // refresh toolbar only once - if (typeof this.toolbar == 'object') { - this.toolbar.refresh(); - var tmp = $('#grid_'+ obj.name +'_search_all'); - tmp.val(this.last.search); - } - } - } else { - $('#grid_'+ this.name +'_toolbar').hide(); - } - // -- make sure search is closed - this.searchClose(); - // search placeholder - var searchEl = $('#grid_'+ obj.name +'_search_all'); - if (this.searches.length == 0) { - this.last.field = 'all'; - } - if (!this.multiSearch && this.last.field == 'all' && this.searches.length > 0) { - this.last.field = this.searches[0].field; - this.last.caption = this.searches[0].caption; - } - for (var s in this.searches) { - if (this.searches[s].field == this.last.field) this.last.caption = this.searches[s].caption; - } - if (this.last.multi) { - searchEl.attr('placeholder', '[' + w2utils.lang('Multiple Fields') + ']'); - } else { - searchEl.attr('placeholder', this.last.caption); - } - - // focus search if last searched - if (this._focus_when_refreshed === true) { - clearTimeout(obj._focus_timer); - obj._focus_timer = setTimeout(function () { - if (searchEl.length > 0) { searchEl[0].focus(); } - delete obj._focus_when_refreshed; - delete obj._focus_timer; - }, 600); // need time to render - } - - // -- separate summary - var tmp = this.find({ summary: true }, true); - if (tmp.length > 0) { - for (var t in tmp) this.summary.push(this.records[tmp[t]]); - for (var t=tmp.length-1; t>=0; t--) this.records.splice(tmp[t], 1); - this.total = this.total - tmp.length; - this.buffered = this.buffered - tmp.length; - } - - // -- body - var bodyHTML = ''; - bodyHTML += ''+ - this.getRecordsHTML() + - ''+ - ''+ - ' '+ this.getColumnsHTML() +''+ - ''; // Columns need to be after to be able to overlap - $('#grid_'+ this.name +'_body').html(bodyHTML); - // show summary records - if (this.summary.length > 0) { - $('#grid_'+ this.name +'_summary').html(this.getSummaryHTML()).show(); - } else { - $('#grid_'+ this.name +'_summary').hide(); - } - // -- footer - if (this.show.footer) { - $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()).show(); - } else { - $('#grid_'+ this.name +'_footer').hide(); - } - // select last selected record - if (this.last.selected.length > 0) for (var s in this.last.selected) { - if (this.get(this.last.selected[s]) != null) { - this.select(this.get(this.last.selected[s]).recid); - } - } - // show/hide clear search link - if (this.searchData.length > 0) { - $('#grid_'+ this.name +'_searchClear').show(); - } else { - $('#grid_'+ this.name +'_searchClear').hide(); - } - // all selected? - $('#grid_'+ this.name +'_check_all').prop('checked', true); - if ($('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length != 0 && - $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]').length == $('#grid_'+ this.name +'_records').find('.grid_select_check[type=checkbox]:checked').length) { - $('#grid_'+ this.name +'_check_all').prop('checked', true); - } else { - $('#grid_'+ this.name +'_check_all').prop("checked", false); - } - // show number of selected - this.status(); - // collapse all records - var rows = obj.find({ expanded: true }, true); - for (var r in rows) obj.records[rows[r]].expanded = false; - // mark selection - setTimeout(function () { - var str = $.trim($('#grid_'+ obj.name +'_search_all').val()); - if (str != '') $(obj.box).find('.w2ui-grid-data > div').w2marker(str); - }, 50); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - obj.addRange('selection'); - setTimeout(function () { obj.resize(); obj.scroll(); }, 1); // allow to render first - return (new Date()).getTime() - time; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2grid - grid widget +* - $().w2grid - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2toolbar, w2fields, w2alert, w2confirm +* +* == NICE TO HAVE == +* - frozen columns +* - add colspans +* - allow this.total to be unknown (-1) +* - column autosize based on largest content +* - easy bubbles in the grid +* - More than 2 layers of header groups +* - reorder columns/records +* - hidden searches could not be clearned by the user +* - problem with .set() and arrays, array get extended too, but should be replaced +* - move events into prototype +* - add grid.focus() +* - add showExtra, KickIn Infinite scroll when so many records +* - after edit stay on the same record option +* - allow render: function to be filters +* +************************************************************************/ - render: function (box) { - var obj = this; - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-grid') - .html(''); - } - this.box = box; - } - if (!this.box) return; - if (this.last.sortData == null) this.last.sortData = this.sortData; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: box }); - if (eventData.isCancelled === true) return false; - // insert Elements - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-grid') - .html(''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''); - if (this.selectType != 'row') $(this.box).addClass('w2ui-ss'); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // init toolbar - this.initToolbar(); - if (this.toolbar != null) this.toolbar.render($('#grid_'+ this.name +'_toolbar')[0]); - // init footer - $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()); - // refresh - this.refresh(); // show empty grid (need it) - this.reload(); - - // init mouse events for mouse selection - $(this.box).on('mousedown', mouseStart); - $(this.box).on('selectstart', function () { return false; }); // fixes chrome cursror bug - - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // attach to resize event - if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event - this.tmp_resize = function (event) { w2ui[obj.name].resize(); } - $(window).off('resize', this.tmp_resize).on('resize', this.tmp_resize); - } - return (new Date()).getTime() - time; - - function mouseStart (event) { - if (obj.last.move && obj.last.move.type == 'expand') return; - obj.last.move = { - x : event.screenX, - y : event.screenY, - divX : 0, - divY : 0, - recid : $(event.target).parents('tr').attr('recid'), - column : (event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')), - type : 'select', - start : true +(function ($) { + var w2grid = function(options) { + + // public properties + this.name = null; + this.box = null; // HTML element that hold this element + this.header = ''; + this.url = ''; + this.routeData = {}; // data for dynamic routes + this.columns = []; // { field, caption, size, attr, render, hidden, gridMinWidth, editable } + this.columnGroups = []; // { span: int, caption: 'string', master: true/false } + this.records = []; // { recid: int(requied), field1: 'value1', ... fieldN: 'valueN', style: 'string', editable: true/false, summary: true/false, changes: object } + this.summary = []; // arry of summary records, same structure as records array + this.searches = []; // { type, caption, field, inTag, outTag, hidden } + this.searchData = []; + this.sortData = []; + this.postData = {}; + this.toolbar = {}; // if not empty object; then it is toolbar object + + this.show = { + header : false, + toolbar : false, + footer : false, + columnHeaders : true, + lineNumbers : false, + expandColumn : false, + selectColumn : false, + emptyRecords : true, + toolbarReload : true, + toolbarColumns : true, + toolbarSearch : true, + toolbarAdd : false, + toolbarEdit : false, + toolbarDelete : false, + toolbarSave : false, + selectionBorder : true, + recordTitles : true, + skipRecords : true }; - $(document).on('mousemove', mouseMove); - $(document).on('mouseup', mouseStop); - } - - function mouseMove (event) { - if (!obj.last.move || obj.last.move.type != 'select') return; - obj.last.move.divX = (event.screenX - obj.last.move.x); - obj.last.move.divY = (event.screenY - obj.last.move.y); - if (Math.abs(obj.last.move.divX) <= 1 && Math.abs(obj.last.move.divY) <= 1) return; // only if moved more then 1px - if (obj.last.move.start && obj.last.move.recid) { - obj.selectNone(); - obj.last.move.start = false; - } - var newSel= []; - var recid = (event.target.tagName == 'TR' ? $(event.target).attr('recid') : $(event.target).parents('tr').attr('recid')); - if (typeof recid == 'undefined') return; - var ind1 = obj.get(obj.last.move.recid, true); - var ind2 = obj.get(recid, true); - var col1 = parseInt(obj.last.move.column); - var col2 = parseInt(event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')); - if (ind1 > ind2) { var tmp = ind1; ind1 = ind2; ind2 = tmp; } - // check if need to refresh - var tmp = 'ind1:'+ ind1 +',ind2;'+ ind2 +',col1:'+ col1 +',col2:'+ col2; - if (obj.last.move.range == tmp) return; - obj.last.move.range = tmp; - for (var i = ind1; i <= ind2; i++) { - if (obj.last.searchIds.length > 0 && obj.last.searchIds.indexOf(i) == -1) continue; - if (obj.selectType != 'row') { - if (col1 > col2) { var tmp = col1; col1 = col2; col2 = tmp; } - var tmp = []; - for (var c = col1; c <= col2; c++) { - if (obj.columns[c].hidden) continue; - newSel.push({ recid: obj.records[i].recid, column: parseInt(c) }); - } - } else { - newSel.push(obj.records[i].recid); - } - } - if (obj.selectType != 'row') { - var sel = obj.getSelection(); - // add more items - var tmp = []; - for (var ns in newSel) { - var flag = false; - for (var s in sel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; - if (!flag) tmp.push({ recid: newSel[ns].recid, column: newSel[ns].column }); - } - obj.select.apply(obj, tmp); - // remove items - var tmp = []; - for (var s in sel) { - var flag = false; - for (var ns in newSel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; - if (!flag) tmp.push({ recid: sel[s].recid, column: sel[s].column }); - } - obj.unselect.apply(obj, tmp); - } else { - if (obj.multiSelect) { - var sel = obj.getSelection(); - for (var ns in newSel) if (sel.indexOf(newSel[ns]) == -1) obj.select(newSel[ns]); // add more items - for (var s in sel) if (newSel.indexOf(sel[s]) == -1) obj.unselect(sel[s]); // remove items - } - } - } - - function mouseStop (event) { - if (!obj.last.move || obj.last.move.type != 'select') return; - delete obj.last.move; - $(document).off('mousemove', mouseMove); - $(document).off('mouseup', mouseStop); - } - }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); - if (eventData.isCancelled === true) return false; - // remove events - $(window).off('resize', this.tmp_resize); - // clean up - if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); - if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-grid') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - // =========================================== - // --- Internal Functions - - initColumnOnOff: function () { - if (!this.show.toolbarColumns) return; - var obj = this; - var col_html = ''+ - ''; - for (var c in this.columns) { - var col = this.columns[c]; - col_html += ''+ - ''+ - ' '+ - ''+ - ''+ - ' '+ - (this.columns[c].caption == '' ? '- column '+ (c+1) +' -' : this.columns[c].caption) + - ''+ - ''+ - ''; - } - col_html += ''; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url) { - col_html += - ''+ - ' '+ - ' '+ w2utils.lang('Skip') +' '+ w2utils.lang('Records')+ - ' '+ - ''; - } - col_html += ''+ - ' '+ w2utils.lang('Toggle Line Numbers') +''+ - ''+ - ''+ - ' '+ w2utils.lang('Reset Column Size') + ''+ - ''; - col_html += ""; - this.toolbar.get('column-on-off').html = col_html; - }, + this.autoLoad = true; // for infinite scroll + this.fixedBody = true; // if false; then grid grows with data + this.recordHeight = 24; + this.keyboard = true; + this.selectType = 'row'; // can be row|cell + this.multiSearch = true; + this.multiSelect = true; + this.multiSort = true; + this.reorderColumns = false; + this.reorderRows = false; + this.markSearch = true; + + this.total = 0; // server total + this.limit = 100; + this.offset = 0; // how many records to skip (for infinite scroll) when pulling from server + this.style = ''; + this.ranges = []; + this.menu = []; + this.method = null; // if defined, then overwrited ajax method + this.recid = null; + this.parser = null; + + // events + this.onAdd = null; + this.onEdit = null; + this.onRequest = null; // called on any server event + this.onLoad = null; + this.onDelete = null; + this.onDeleted = null; + this.onSubmit = null; + this.onSave = null; + this.onSelect = null; + this.onUnselect = null; + this.onClick = null; + this.onDblClick = null; + this.onContextMenu = null; + this.onMenuClick = null; // when context menu item selected + this.onColumnClick = null; + this.onColumnResize = null; + this.onSort = null; + this.onSearch = null; + this.onChange = null; // called when editable record is changed + this.onRestore = null; // called when editable record is restored + this.onExpand = null; + this.onCollapse = null; + this.onError = null; + this.onKeydown = null; + this.onToolbar = null; // all events from toolbar + this.onColumnOnOff = null; + this.onCopy = null; + this.onPaste = null; + this.onSelectionExtend = null; + this.onEditField = null; + this.onRender = null; + this.onRefresh = null; + this.onReload = null; + this.onResize = null; + this.onDestroy = null; + this.onStateSave = null; + this.onStateRestore = null; + + // internal + this.last = { + field : 'all', + caption : w2utils.lang('All Fields'), + logic : 'OR', + search : '', + searchIds : [], + selection : { + indexes : [], + columns : {} + }, + multi : false, + scrollTop : 0, + scrollLeft : 0, + sortData : null, + sortCount : 0, + xhr : null, + range_start : null, + range_end : null, + sel_ind : null, + sel_col : null, + sel_type : null, + edit_col : null + }; - columnOnOff: function (el, event, field, value) { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'columnOnOff', checkbox: el, field: field, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // regular processing - var obj = this; - // collapse expanded rows - for (var r in this.records) { - if (this.records[r].expanded === true) this.records[r].expanded = false - } - // show/hide - var hide = true; - if (field == 'line-numbers') { - this.show.lineNumbers = !this.show.lineNumbers; - this.refresh(); - } else if (field == 'skip') { - if (!w2utils.isInt(value)) value = 0; - obj.skip(value); - } else if (field == 'resize') { - // restore sizes - for (var c in this.columns) { - if (typeof this.columns[c].sizeOriginal != 'undefined') { - this.columns[c].size = this.columns[c].sizeOriginal; - } - } - this.initResize(); - this.resize(); - } else { - var col = this.getColumn(field); - if (col.hidden) { - $(el).prop('checked', true); - this.showColumn(col.field); + $.extend(true, this, w2obj.grid, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2grid = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2grid')) return; + // remember items + var columns = method.columns; + var columnGroups = method.columnGroups; + var records = method.records; + var searches = method.searches; + var searchData = method.searchData; + var sortData = method.sortData; + var postData = method.postData; + var toolbar = method.toolbar; + // extend items + var object = new w2grid(method); + $.extend(object, { postData: {}, records: [], columns: [], searches: [], toolbar: {}, sortData: [], searchData: [], handlers: [] }); + if (object.onExpand != null) object.show.expandColumn = true; + $.extend(true, object.toolbar, toolbar); + // reassign variables + for (var p in columns) object.columns[p] = $.extend(true, {}, columns[p]); + for (var p in columnGroups) object.columnGroups[p] = $.extend(true, {}, columnGroups[p]); + for (var p in searches) object.searches[p] = $.extend(true, {}, searches[p]); + for (var p in searchData) object.searchData[p] = $.extend(true, {}, searchData[p]); + for (var p in sortData) object.sortData[p] = $.extend(true, {}, sortData[p]); + object.postData = $.extend(true, {}, postData); + + // check if there are records without recid + for (var r in records) { + if (records[r].recid == null || typeof records[r].recid == 'undefined') { + console.log('ERROR: Cannot add records without recid. (obj: '+ object.name +')'); + return; + } + object.records[r] = $.extend(true, {}, records[r]); + } + // add searches + for (var c in object.columns) { + var col = object.columns[c]; + if (typeof col.searchable == 'undefined' || object.getSearch(col.field) != null) continue; + var stype = col.searchable; + var attr = ''; + if (col.searchable === true) { stype = 'text'; attr = 'size="20"'; } + object.addSearch({ field: col.field, caption: col.caption, type: stype, attr: attr }); + } + // init toolbar + object.initToolbar(); + // render if necessary + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - $(el).prop('checked', false); - this.hideColumn(col.field); + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2grid'); } - hide = false; - } - this.initColumnOnOff(); - if (hide) { - setTimeout(function () { - $().w2overlay(); - obj.toolbar.uncheck('column-on-off'); - }, 100); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, - - initToolbar: function () { - // -- if toolbar is true - if (typeof this.toolbar['render'] == 'undefined') { - var tmp_items = this.toolbar.items; - this.toolbar.items = []; - this.toolbar = $().w2toolbar($.extend(true, {}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - - // ============================================= - // ------ Toolbar Generic buttons + } - if (this.show.toolbarReload) { - this.toolbar.items.push($.extend(true, {}, this.buttons['reload'])); - } - if (this.show.toolbarColumns) { - this.toolbar.items.push($.extend(true, {}, this.buttons['columns'])); - this.initColumnOnOff(); - } - if (this.show.toolbarReload || this.show.toolbarColumn) { - this.toolbar.items.push({ type: 'break', id: 'break0' }); - } - if (this.show.toolbarSearch) { - var html = - ''+ - ''+ - ' '+ this.buttons['search'].html +''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''+ - ''; - this.toolbar.items.push({ type: 'html', id: 'search', html: html }); - if (this.multiSearch && this.searches.length > 0) { - this.toolbar.items.push($.extend(true, {}, this.buttons['search-go'])); - } - } - if (this.show.toolbarSearch && (this.show.toolbarAdd || this.show.toolbarEdit || this.show.toolbarDelete || this.show.toolbarSave)) { - this.toolbar.items.push({ type: 'break', id: 'break1' }); - } - if (this.show.toolbarAdd) { - this.toolbar.items.push($.extend(true, {}, this.buttons['add'])); - } - if (this.show.toolbarEdit) { - this.toolbar.items.push($.extend(true, {}, this.buttons['edit'])); - } - if (this.show.toolbarDelete) { - this.toolbar.items.push($.extend(true, {}, this.buttons['delete'])); - } - if (this.show.toolbarSave) { - if (this.show.toolbarAdd || this.show.toolbarDelete || this.show.toolbarEdit) { - this.toolbar.items.push({ type: 'break', id: 'break2' }); - } - this.toolbar.items.push($.extend(true, {}, this.buttons['save'])); - } - // add original buttons - for (var i in tmp_items) this.toolbar.items.push(tmp_items[i]); - - // ============================================= - // ------ Toolbar onClick processing - - var obj = this; - this.toolbar.on('click', function (event) { - var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); - if (eventData.isCancelled === true) return false; - var id = event.target; - switch (id) { - case 'reload': - var eventData2 = obj.trigger({ phase: 'before', type: 'reload', target: obj.name }); - if (eventData2.isCancelled === true) return false; - var url = (typeof obj.url != 'object' ? obj.url : obj.url.get); - if (url) { - obj.clear(true); - } else { - obj.last.scrollTop = 0; - obj.last.scrollLeft = 0; - obj.last.range_start= null; - obj.last.range_end = null; - } - obj.reload(); - obj.trigger($.extend(eventData2, { phase: 'after' })); - break; - case 'column-on-off': - for (var c in obj.columns) { - if (obj.columns[c].hidden) { - $("#grid_"+ obj.name +"_column_"+ c + "_check").prop("checked", false); + // ==================================================== + // -- Implementation of core functionality + + w2grid.prototype = { + // ---- + // properties that need to be in prototype + + msgDelete : 'Are you sure you want to delete selected records?', + msgNotJSON : 'Returned data is not in valid JSON format.', + msgAJAXerror : 'AJAX error. See console for more details.', + msgRefresh : 'Refreshing...', + + // for easy button overwrite + buttons: { + 'reload' : { type: 'button', id: 'w2ui-reload', icon: 'w2ui-icon-reload', hint: 'Reload data in the list' }, + 'columns' : { type: 'drop', id: 'w2ui-column-on-off', icon: 'w2ui-icon-columns', hint: 'Show/hide columns', arrow: false, html: '' }, + 'search' : { type: 'html', id: 'w2ui-search', + html: '' + }, + 'search-go': { type: 'check', id: 'w2ui-search-advanced', caption: 'Search...', hint: 'Open Search Fields' }, + 'add' : { type: 'button', id: 'w2ui-add', caption: 'Add New', hint: 'Add new record', icon: 'w2ui-icon-plus' }, + 'edit' : { type: 'button', id: 'w2ui-edit', caption: 'Edit', hint: 'Edit selected record', icon: 'w2ui-icon-pencil', disabled: true }, + 'delete' : { type: 'button', id: 'w2ui-delete', caption: 'Delete', hint: 'Delete selected records', icon: 'w2ui-icon-cross', disabled: true }, + 'save' : { type: 'button', id: 'w2ui-save', caption: 'Save', hint: 'Save changed records', icon: 'w2ui-icon-check' } + }, + + add: function (record) { + if (!$.isArray(record)) record = [record]; + var added = 0; + for (var o in record) { + if (!this.recid && typeof record[o].recid == 'undefined') record[o].recid = record[o][this.recid]; + if (record[o].recid == null || typeof record[o].recid == 'undefined') { + console.log('ERROR: Cannot add record without recid. (obj: '+ this.name +')'); + continue; + } + this.records.push(record[o]); + added++; + } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.total = this.records.length; + this.localSort(); + this.localSearch(); + } + this.refresh(); // ?? should it be reload? + return added; + }, + + find: function (obj, returnIndex) { + if (typeof obj == 'undefined' || obj == null) obj = {}; + var recs = []; + var hasDots = false; + // check if property is nested - needed for speed + for (var o in obj) if (String(o).indexOf('.') != -1) hasDots = true; + // look for an item + for (var i = 0; i < this.records.length; i++) { + var match = true; + for (var o in obj) { + var val = this.records[i][o]; + if (hasDots && String(o).indexOf('.') != -1) val = this.parseField(this.records[i], o); + if (obj[o] != val) match = false; + } + if (match && returnIndex !== true) recs.push(this.records[i].recid); + if (match && returnIndex === true) recs.push(i); + } + return recs; + }, + + set: function (recid, record, noRefresh) { // does not delete existing, but overrides on top of it + if (typeof recid == 'object') { + noRefresh = record; + record = recid; + recid = null; + } + // update all records + if (recid == null) { + for (var r in this.records) { + $.extend(true, this.records[r], record); // recid is the whole record + } + if (noRefresh !== true) this.refresh(); + } else { // find record to update + var ind = this.get(recid, true); + if (ind == null) return false; + var isSummary = (this.records[ind] && this.records[ind].recid == recid ? false : true); + if (isSummary) { + $.extend(true, this.summary[ind], record); } else { - $("#grid_"+ obj.name +"_column_"+ c + "_check").prop('checked', true); - } - } - obj.initResize(); - obj.resize(); - break; - case 'search-advanced': - var tb = this; - var it = this.get(id); - if (it.checked) { - obj.searchClose(); - setTimeout(function () { tb.uncheck(id); }, 1); - } else { - obj.searchOpen(); - event.originalEvent.stopPropagation(); - function tmp_close() { tb.uncheck(id); $(document).off('click', 'body', tmp_close); } - $(document).on('click', 'body', tmp_close); - } - break; - case 'add': - // events - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'add', recid: null }); - obj.trigger($.extend(eventData, { phase: 'after' })); - break; - case 'edit': - var sel = obj.getSelection(); - var recid = null; - if (sel.length == 1) recid = sel[0]; - // events - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'edit', recid: recid }); - obj.trigger($.extend(eventData, { phase: 'after' })); - break; - case 'delete': - obj.delete(); - break; - case 'save': - obj.save(); - break; - } - // no default action - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - } - return; - }, - - initSearches: function () { - var obj = this; - // init searches - for (var s in this.searches) { - var search = this.searches[s]; - var sdata = this.getSearchData(search.field); - // init types - switch (String(search.type).toLowerCase()) { - case 'alphaNumeric': - case 'text': - $('#grid_'+ this.name +'_operator_'+s).val('begins with'); - break; - - case 'int': - case 'float': - case 'hex': - case 'money': - case 'date': - $('#grid_'+ this.name +'_field_'+s).w2field('clear').w2field(search.type); - $('#grid_'+ this.name +'_field2_'+s).w2field('clear').w2field(search.type); - break; - - case 'list': - // build options - var options = '--'; - for (var i in search.items) { - if ($.isPlainObject(search.items[i])) { - var val = search.items[i].id; - var txt = search.items[i].text; - if (typeof val == 'undefined' && typeof search.items[i].value != 'undefined') val = search.items[i].value; - if (typeof txt == 'undefined' && typeof search.items[i].caption != 'undefined') txt = search.items[i].caption; - if (val == null) val = ''; - options += ''+ txt +''; - } else { - options += ''+ search.items[i] +''; - } - } - $('#grid_'+ this.name +'_field_'+s).html(options); - break; - } - if (sdata != null) { - $('#grid_'+ this.name +'_operator_'+ s).val(sdata.operator).trigger('change'); - if (!$.isArray(sdata.value)) { - if (typeof sdata.value != 'udefined') $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); - } else { - if (sdata.operator == 'in') { - $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); - } else { - $('#grid_'+ this.name +'_field_'+ s).val(sdata.value[0]).trigger('change'); - $('#grid_'+ this.name +'_field2_'+ s).val(sdata.value[1]).trigger('change'); + $.extend(true, this.records[ind], record); + } + if (noRefresh !== true) this.refreshRow(recid); // refresh only that record } - } - } - } - // add on change event - $('#w2ui-overlay .w2ui-grid-searches *[rel=search]').on('keypress', function (evnt) { - if (evnt.keyCode == 13) { obj.search(); } - }); - }, - - initResize: function () { - var obj = this; - //if (obj.resizing === true) return; - $(this.box).find('.w2ui-resizer') - .off('click') - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); - }) - .off('mousedown') - .on('mousedown', function (event) { - if (!event) event = window.event; - if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } - obj.resizing = true; - obj.last.tmp = { - x : event.screenX, - y : event.screenY, - gx : event.screenX, - gy : event.screenY, - col : parseInt($(this).attr('name')) - }; - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); - // fix sizes - for (var c in obj.columns) { - if (typeof obj.columns[c].sizeOriginal == 'undefined') obj.columns[c].sizeOriginal = obj.columns[c].size; - obj.columns[c].size = obj.columns[c].sizeCalculated; - } - var eventData = { phase: 'before', type: 'columnResize', target: obj.name, column: obj.last.tmp.col, field: obj.columns[obj.last.tmp.col].field }; - eventData = obj.trigger($.extend(eventData, { resizeBy: 0, originalEvent: event })); - // set move event - var mouseMove = function (event) { - if (obj.resizing != true) return; - if (!event) event = window.event; - // event before - eventData = obj.trigger($.extend(eventData, { resizeBy: (event.screenX - obj.last.tmp.gx), originalEvent: event })); - if (eventData.isCancelled === true) { eventData.isCancelled = false; return; } - // default action - obj.last.tmp.x = (event.screenX - obj.last.tmp.x); - obj.last.tmp.y = (event.screenY - obj.last.tmp.y); - obj.columns[obj.last.tmp.col].size = (parseInt(obj.columns[obj.last.tmp.col].size) + obj.last.tmp.x) + 'px'; - obj.resizeRecords(); - // reset - obj.last.tmp.x = event.screenX; - obj.last.tmp.y = event.screenY; - } - var mouseUp = function (event) { - delete obj.resizing; - $(document).off('mousemove', 'body'); - $(document).off('mouseup', 'body'); - obj.resizeRecords(); - // event before - obj.trigger($.extend(eventData, { phase: 'after', originalEvent: event })); - } - $(document).on('mousemove', 'body', mouseMove); - $(document).on('mouseup', 'body', mouseUp); - }) - .each(function (index, el) { - var td = $(el).parent(); - $(el).css({ - "height" : '25px', - "margin-left" : (td.width() - 3) + 'px' - }) - }); - }, - - resizeBoxes: function () { - // elements - var main = $(this.box).find('> div'); - var header = $('#grid_'+ this.name +'_header'); - var toolbar = $('#grid_'+ this.name +'_toolbar'); - var summary = $('#grid_'+ this.name +'_summary'); - var footer = $('#grid_'+ this.name +'_footer'); - var body = $('#grid_'+ this.name +'_body'); - var columns = $('#grid_'+ this.name +'_columns'); - var records = $('#grid_'+ this.name +'_records'); - - if (this.show.header) { - header.css({ - top: '0px', - left: '0px', - right: '0px' - }); - } + return true; + }, - if (this.show.toolbar) { - toolbar.css({ - top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - } - if (this.show.footer) { - footer.css({ - bottom: '0px', - left: '0px', - right: '0px' - }); - } - if (this.summary.length > 0) { - summary.css({ - bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - } - body.css({ - top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) + (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) ) + 'px', - bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) + (this.summary.length > 0 ? w2utils.getSize(summary, 'height') : 0) ) + 'px', - left: '0px', - right: '0px' - }); - }, + get: function (recid, returnIndex) { + // search records + for (var i = 0; i < this.records.length; i++) { + if (this.records[i].recid == recid) { + if (returnIndex === true) return i; else return this.records[i]; + } + } + // search summary + for (var i = 0; i < this.summary.length; i++) { + if (this.summary[i].recid == recid) { + if (returnIndex === true) return i; else return this.summary[i]; + } + } + return null; + }, - resizeRecords: function () { - var obj = this; - // remove empty records - $(this.box).find('.w2ui-empty-record').remove(); - // -- Calculate Column size in PX - var box = $(this.box); - var grid = $(this.box).find('> div'); - var header = $('#grid_'+ this.name +'_header'); - var toolbar = $('#grid_'+ this.name +'_toolbar'); - var summary = $('#grid_'+ this.name +'_summary'); - var footer = $('#grid_'+ this.name +'_footer'); - var body = $('#grid_'+ this.name +'_body'); - var columns = $('#grid_'+ this.name +'_columns'); - var records = $('#grid_'+ this.name +'_records'); - - // body might be expanded by data - if (!this.fixedBody) { - // allow it to render records, then resize - setTimeout(function () { - var calculatedHeight = w2utils.getSize(columns, 'height') - + w2utils.getSize($('#grid_'+ obj.name +'_records table'), 'height'); - obj.height = calculatedHeight - + w2utils.getSize(grid, '+height') - + (obj.show.header ? w2utils.getSize(header, 'height') : 0) - + (obj.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) - + (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) - + (obj.show.footer ? w2utils.getSize(footer, 'height') : 0); - grid.css('height', obj.height); - body.css('height', calculatedHeight); - box.css('height', w2utils.getSize(grid, 'height') + w2utils.getSize(box, '+height')); - }, 1); - } else { - // fixed body height - var calculatedHeight = grid.height() - - (this.show.header ? w2utils.getSize(header, 'height') : 0) - - (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) - - (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) - - (this.show.footer ? w2utils.getSize(footer, 'height') : 0); - body.css('height', calculatedHeight); - } - - // check overflow - var bodyOverflowX = false; - var bodyOverflowY = false; - if (body.width() < $(records).find('>table').width()) bodyOverflowX = true; - if (body.height() - columns.height() < $(records).find('>table').height() + (bodyOverflowX ? w2utils.scrollBarSize() : 0)) bodyOverflowY = true; - if (!this.fixedBody) { bodyOverflowY = false; bodyOverflowX = false; } - if (bodyOverflowX || bodyOverflowY) { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); - records.css({ - top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', - "-webkit-overflow-scrolling": "touch", - "overflow-x": (bodyOverflowX ? 'auto' : 'hidden'), - "overflow-y": (bodyOverflowY ? 'auto' : 'hidden') }); - } else { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').hide(); - records.css({ - top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', - overflow: 'hidden' - }); - if (records.length > 0) { this.last.scrollTop = 0; this.last.scrollLeft = 0; } // if no scrollbars, always show top - } - if (this.show.emptyRecords && !bodyOverflowY) { - var max = Math.floor(records.height() / this.recordHeight) + 1; - if (this.fixedBody) { - for (var di = this.buffered; di <= max; di++) { - var html = ''; - html += ''; - if (this.show.lineNumbers) html += ''; - if (this.show.selectColumn) html += ''; - if (this.show.expandColumn) html += ''; - var j = 0; - while (true && this.columns.length > 0) { - var col = this.columns[j]; - if (col.hidden) { j++; if (typeof this.columns[j] == 'undefined') break; else continue; } - html += ''; - j++; - if (typeof this.columns[j] == 'undefined') break; - } - html += ''; - html += ''; - $('#grid_'+ this.name +'_records > table').append(html); - } - } - } - if (body.length > 0) { - var width_max = parseInt(body.width()) - - (bodyOverflowY ? w2utils.scrollBarSize() : 0) - - (this.show.lineNumbers ? 34 : 0) - - (this.show.selectColumn ? 26 : 0) - - (this.show.expandColumn ? 26 : 0); - var width_box = width_max; - var percent = 0; - // gridMinWidth processiong - var restart = false; - for (var i=0; i width_box && col.hidden !== true) { - col.hidden = true; - restart = true; - } - if (col.gridMinWidth < width_box && col.hidden === true) { - col.hidden = false; - restart = true; - } - } - } - if (restart === true) { - this.refresh(); - return; - } - // assign PX column s - for (var i=0; i 0) { - for (var i=0; i= 0; r--) { + if (this.records[r].recid == arguments[a]) { this.records.splice(r, 1); removed++; } + } + } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + this.localSearch(); + } + this.refresh(); + return removed; + }, + + addColumn: function (before, columns) { + var added = 0; + if (arguments.length == 1) { + columns = before; + before = this.columns.length; } else { - // make it 1px smaller, so margin of error can be calculated correctly - this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.size) / 100) - 1 + 'px'; + if (typeof before == 'string') before = this.getColumn(before, true); + if (before === null) before = this.columns.length; } - } - } - } - // fix margin of error that is due percentage calculations - var width_cols = 0; - for (var i=0; i parseInt(col.max)) col.sizeCalculated = col.max + 'px'; - width_cols += parseInt(col.sizeCalculated); - } - var width_diff = parseInt(width_box) - parseInt(width_cols); - if (width_diff > 0 && percent > 0) { - var i = 0; - while (true) { - var col = this.columns[i]; - if (typeof col == 'undefined') { i = 0; continue; } - if (col.hidden || col.sizeType == 'px') { i++; continue; } - col.sizeCalculated = (parseInt(col.sizeCalculated) + 1) + 'px'; - width_diff--; - if (width_diff == 0) break; - i++; - } - } else if (width_diff > 0) { - columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); - } - // resize columns - columns.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-head-last')) { - $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - // if there are column groups - hide first row (needed for sizing) - if (columns.find('> table > tbody > tr').length == 3) { - columns.find('> table > tbody > tr:nth-child(1) td').html('').css({ - 'height' : '0px', - 'border' : '0px', - 'padding' : '0px', - 'margin' : '0px' - }); - } - // resize records - records.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-grid-data-last')) { - $(el).css('width', (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - // resize summary - summary.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { - var ind = $(el).attr('col'); - if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); - // last column - if ($(el).hasClass('w2ui-grid-data-last')) { - $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); - } - }); - this.initResize(); - this.refreshRanges(); - // apply last scroll if any - if (this.last.scrollTop != '' && records.length > 0) { - columns.prop('scrollLeft', this.last.scrollLeft); - records.prop('scrollTop', this.last.scrollTop); - records.prop('scrollLeft', this.last.scrollLeft); - } - }, + if (!$.isArray(columns)) columns = [columns]; + for (var o in columns) { + this.columns.splice(before, 0, columns[o]); + before++; + added++; + } + this.refresh(); + return added; + }, + + removeColumn: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + if (this.columns[r].field == arguments[a]) { this.columns.splice(r, 1); removed++; } + } + } + this.refresh(); + return removed; + }, + + getColumn: function (field, returnIndex) { + for (var i = 0; i < this.columns.length; i++) { + if (this.columns[i].field == field) { + if (returnIndex === true) return i; else return this.columns[i]; + } + } + return null; + }, + + toggleColumn: function () { + var effected = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.field == arguments[a]) { + col.hidden = !col.hidden; + effected++; + } + } + } + this.refresh(); + return effected; + }, + + showColumn: function () { + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.gridMinWidth) delete col.gridMinWidth; + if (col.field == arguments[a] && col.hidden !== false) { + col.hidden = false; + shown++; + } + } + } + this.refresh(); + return shown; + }, + + hideColumn: function () { + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.columns.length-1; r >= 0; r--) { + var col = this.columns[r]; + if (col.field == arguments[a] && col.hidden !== true) { + col.hidden = true; + hidden++; + } + } + } + this.refresh(); + return hidden; + }, + + addSearch: function (before, search) { + var added = 0; + if (arguments.length == 1) { + search = before; + before = this.searches.length; + } else { + if (typeof before == 'string') before = this.getSearch(before, true); + if (before === null) before = this.searches.length; + } + if (!$.isArray(search)) search = [search]; + for (var o in search) { + this.searches.splice(before, 0, search[o]); + before++; + added++; + } + this.searchClose(); + return added; + }, + + removeSearch: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a]) { this.searches.splice(r, 1); removed++; } + } + } + this.searchClose(); + return removed; + }, + + getSearch: function (field, returnIndex) { + for (var i = 0; i < this.searches.length; i++) { + if (this.searches[i].field == field) { + if (returnIndex === true) return i; else return this.searches[i]; + } + } + return null; + }, + + toggleSearch: function () { + var effected = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a]) { + this.searches[r].hidden = !this.searches[r].hidden; + effected++; + } + } + } + this.searchClose(); + return effected; + }, + + showSearch: function () { + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== false) { + this.searches[r].hidden = false; + shown++; + } + } + } + this.searchClose(); + return shown; + }, + + hideSearch: function () { + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + for (var r = this.searches.length-1; r >= 0; r--) { + if (this.searches[r].field == arguments[a] && this.searches[r].hidden !== true) { + this.searches[r].hidden = true; + hidden++; + } + } + } + this.searchClose(); + return hidden; + }, + + getSearchData: function (field) { + for (var s in this.searchData) { + if (this.searchData[s].field == field) return this.searchData[s]; + } + return null; + }, + + localSort: function (silent) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + console.log('ERROR: grid.localSort can only be used on local data source, grid.url should be empty.'); + return; + } + if ($.isEmptyObject(this.sortData)) return; + var time = (new Date()).getTime(); + var obj = this; + // process date fields + obj.prepareData(); + // process sortData + for (var s in this.sortData) { + var column = this.getColumn(this.sortData[s].field); + if (!column) return; + if (typeof column.render == 'string') { + if (['date', 'age'].indexOf(column.render.split(':')[0]) != -1) { + this.sortData[s]['field_'] = column.field + '_'; + } + if (['time'].indexOf(column.render.split(':')[0]) != -1) { + this.sortData[s]['field_'] = column.field + '_'; + } + } + } + // process sort + this.records.sort(function (a, b) { + var ret = 0; + for (var s in obj.sortData) { + var fld = obj.sortData[s].field; + if (obj.sortData[s].field_) fld = obj.sortData[s].field_; + var aa = a[fld]; + var bb = b[fld]; + if (String(fld).indexOf('.') != -1) { + aa = obj.parseField(a, fld); + bb = obj.parseField(b, fld); + } + if (typeof aa == 'string') aa = $.trim(aa.toLowerCase()); + if (typeof bb == 'string') bb = $.trim(bb.toLowerCase()); + if (aa > bb) ret = (obj.sortData[s].direction == 'asc' ? 1 : -1); + if (aa < bb) ret = (obj.sortData[s].direction == 'asc' ? -1 : 1); + if (typeof aa != 'object' && typeof bb == 'object') ret = -1; + if (typeof bb != 'object' && typeof aa == 'object') ret = 1; + if (aa == null && bb != null) ret = 1; // all nuls and undefined on bottom + if (aa != null && bb == null) ret = -1; + if (ret != 0) break; + } + return ret; + }); + time = (new Date()).getTime() - time; + if (silent !== true) setTimeout(function () { obj.status(w2utils.lang('Sorting took') + ' ' + time/1000 + ' ' + w2utils.lang('sec')); }, 10); + return time; + }, + + localSearch: function (silent) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + console.log('ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.'); + return; + } + var time = (new Date()).getTime(); + var obj = this; + this.total = this.records.length; + // mark all records as shown + this.last.searchIds = []; + // prepare date/time fields + this.prepareData(); + // hide records that did not match + if (this.searchData.length > 0 && !url) { + this.total = 0; + for (var r in this.records) { + var rec = this.records[r]; + var fl = 0; + for (var s in this.searchData) { + var sdata = this.searchData[s]; + var search = this.getSearch(sdata.field); + if (sdata == null) continue; + if (search == null) search = { field: sdata.field, type: sdata.type }; + var val1 = String(obj.parseField(rec, search.field)).toLowerCase(); + if (typeof sdata.value != 'undefined') { + if (!$.isArray(sdata.value)) { + var val2 = String(sdata.value).toLowerCase(); + } else { + var val2 = sdata.value[0]; + var val3 = sdata.value[1]; + } + } + switch (sdata.operator) { + case 'is': + if (rec[search.field] == sdata.value) fl++; // do not hide record + if (search.type == 'date') { + var val1 = w2utils.formatDate(rec[search.field + '_'], 'yyyy-mm-dd'); + var val2 = w2utils.formatDate(val2, 'yyyy-mm-dd'); + if (val1 == val2) fl++; + } + if (search.type == 'time') { + var val1 = w2utils.formatTime(rec[search.field + '_'], 'h24:mi'); + var val2 = w2utils.formatTime(val2, 'h24:mi'); + if (val1 == val2) fl++; + } + break; + case 'between': + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1) { + if (parseFloat(rec[search.field]) >= parseFloat(val2) && parseFloat(rec[search.field]) <= parseFloat(val3)) fl++; + } + if (search.type == 'date') { + var val1 = rec[search.field + '_']; + var val2 = w2utils.isDate(val2, w2utils.settings.date_format, true); + var val3 = w2utils.isDate(val3, w2utils.settings.date_format, true); + if (val3 != null) val3 = new Date(val3.getTime() + 86400000); // 1 day + if (val1 >= val2 && val1 < val3) fl++; + } + if (search.type == 'time') { + var val1 = rec[search.field + '_']; + var val2 = w2utils.isTime(val2, true); + var val3 = w2utils.isTime(val3, true); + val2 = (new Date()).setHours(val2.hours, val2.minutes, val2.seconds ? val2.seconds : 0, 0); + val3 = (new Date()).setHours(val3.hours, val3.minutes, val3.seconds ? val3.seconds : 0, 0); + if (val1 >= val2 && val1 < val3) fl++; + } + break; + case 'in': + var tmp = sdata.value; + if (sdata.svalue) tmp = sdata.svalue; + if (tmp.indexOf(val1) !== -1) fl++; + break; + case 'not in': + var tmp = sdata.value; + if (sdata.svalue) tmp = sdata.svalue; + if (tmp.indexOf(val1) == -1) fl++; + break; + case 'begins': + case 'begins with': // need for back compatib. + if (val1.indexOf(val2) == 0) fl++; // do not hide record + break; + case 'contains': + if (val1.indexOf(val2) >= 0) fl++; // do not hide record + break; + case 'ends': + case 'ends with': // need for back compatib. + if (val1.indexOf(val2) == val1.length - val2.length) fl++; // do not hide record + break; + } + } + if ((this.last.logic == 'OR' && fl != 0) || (this.last.logic == 'AND' && fl == this.searchData.length)) this.last.searchIds.push(parseInt(r)); + } + this.total = this.last.searchIds.length; + } + time = (new Date()).getTime() - time; + if (silent !== true) setTimeout(function () { obj.status(w2utils.lang('Search took') + ' ' + time/1000 + ' ' + w2utils.lang('sec')); }, 10); + return time; + }, + + getRangeData: function (range, extra) { + var rec1 = this.get(range[0].recid, true); + var rec2 = this.get(range[1].recid, true); + var col1 = range[0].column; + var col2 = range[1].column; + + var res = []; + if (col1 == col2) { // one row + for (var r = rec1; r <= rec2; r++) { + var record = this.records[r]; + var dt = record[this.columns[col1].field] || null; + if (extra !== true) { + res.push(dt); + } else { + res.push({ data: dt, column: col1, index: r, record: record }); + } + } + } else if (rec1 == rec2) { // one line + var record = this.records[rec1]; + for (var i = col1; i <= col2; i++) { + var dt = record[this.columns[i].field] || null; + if (extra !== true) { + res.push(dt); + } else { + res.push({ data: dt, column: i, index: rec1, record: record }); + } + } + } else { + for (var r = rec1; r <= rec2; r++) { + var record = this.records[r]; + res.push([]); + for (var i = col1; i <= col2; i++) { + var dt = record[this.columns[i].field]; + if (extra !== true) { + res[res.length-1].push(dt); + } else { + res[res.length-1].push({ data: dt, column: i, index: r, record: record }); + } + } + } + } + return res; + }, + + addRange: function (ranges) { + var added = 0; + if (this.selectType == 'row') return added; + if (!$.isArray(ranges)) ranges = [ranges]; + // if it is selection + for (var r in ranges) { + if (typeof ranges[r] != 'object') ranges[r] = { name: 'selection' }; + if (ranges[r].name == 'selection') { + if (this.show.selectionBorder === false) continue; + var sel = this.getSelection(); + if (sel.length == 0) { + this.removeRange(ranges[r].name); + continue; + } else { + var first = sel[0]; + var last = sel[sel.length-1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + } + } else { // other range + var first = ranges[r].range[0]; + var last = ranges[r].range[1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + } + if (first) { + var rg = { + name: ranges[r].name, + range: [{ recid: first.recid, column: first.column }, { recid: last.recid, column: last.column }], + style: ranges[r].style || '' + }; + // add range + var ind = false; + for (var t in this.ranges) if (this.ranges[t].name == ranges[r].name) { ind = r; break; } + if (ind !== false) { + this.ranges[ind] = rg; + } else { + this.ranges.push(rg); + } + added++ + } + } + this.refreshRanges(); + return added; + }, + + removeRange: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var name = arguments[a]; + $('#grid_'+ this.name +'_'+ name).remove(); + for (var r = this.ranges.length-1; r >= 0; r--) { + if (this.ranges[r].name == name) { + this.ranges.splice(r, 1); + removed++; + } + } + } + return removed; + }, + + refreshRanges: function () { + var obj = this; + var time = (new Date()).getTime(); + var rec = $('#grid_'+ this.name +'_records'); + for (var r in this.ranges) { + var rg = this.ranges[r]; + var first = rg.range[0]; + var last = rg.range[1]; + var td1 = $('#grid_'+ this.name +'_rec_'+ first.recid + ' td[col='+ first.column +']'); + var td2 = $('#grid_'+ this.name +'_rec_'+ last.recid + ' td[col='+ last.column +']'); + if ($('#grid_'+ this.name +'_'+ rg.name).length == 0) { + rec.append(''+ + (rg.name == 'selection' ? '' : '')+ + ''); + } else { + $('#grid_'+ this.name +'_'+ rg.name).attr('style', rg.style); + } + if (td1.length > 0 && td2.length > 0) { + $('#grid_'+ this.name +'_'+ rg.name).css({ + left : (td1.position().left - 1 + rec.scrollLeft()) + 'px', + top : (td1.position().top - 1 + rec.scrollTop()) + 'px', + width : (td2.position().left - td1.position().left + td2.width() + 3) + 'px', + height : (td2.position().top - td1.position().top + td2.height() + 3) + 'px' + }); + } + } + + // add resizer events + $(this.box).find('#grid_'+ this.name +'_resizer').off('mousedown').on('mousedown', mouseStart); + //$(this.box).find('#grid_'+ this.name +'_resizer').off('selectstart').on('selectstart', function () { return false; }); // fixes chrome cursror bug + + var eventData = { phase: 'before', type: 'selectionExtend', target: obj.name, originalRange: null, newRange: null }; + + function mouseStart (event) { + var sel = obj.getSelection(); + obj.last.move = { + type : 'expand', + x : event.screenX, + y : event.screenY, + divX : 0, + divY : 0, + recid : sel[0].recid, + column : sel[0].column, + originalRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }], + newRange : [{ recid: sel[0].recid, column: sel[0].column }, { recid: sel[sel.length-1].recid, column: sel[sel.length-1].column }] + }; + $(document).off('mousemove', mouseMove).on('mousemove', mouseMove); + $(document).off('mouseup', mouseStop).on('mouseup', mouseStop); + } + + function mouseMove (event) { + var mv = obj.last.move; + if (!mv || mv.type != 'expand') return; + mv.divX = (event.screenX - mv.x); + mv.divY = (event.screenY - mv.y); + // find new cell + var recid, column; + var tmp = event.originalEvent.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); + tmp = $(tmp).parents('tr')[0]; + recid = $(tmp).attr('recid'); + // new range + if (mv.newRange[1].recid == recid && mv.newRange[1].column == column) return; + var prevNewRange = $.extend({}, mv.newRange); + mv.newRange = [{ recid: mv.recid, column: mv.column }, { recid: recid, column: column }]; + // event before + eventData = obj.trigger($.extend(eventData, { originalRange: mv.originalRange, newRange : mv.newRange })); + if (eventData.isCancelled === true) { + mv.newRange = prevNewRange; + eventData.newRange = prevNewRange; + return; + } else { + // default behavior + obj.removeRange('grid-selection-expand'); + obj.addRange({ + name : 'grid-selection-expand', + range : eventData.newRange, + style : 'background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);' + }); + } + } + + function mouseStop (event) { + // default behavior + obj.removeRange('grid-selection-expand'); + delete obj.last.move; + $(document).off('mousemove', mouseMove); + $(document).off('mouseup', mouseStop); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + + return (new Date()).getTime() - time; + }, + + select: function () { + var selected = 0; + var sel = this.last.selection; + if (!this.multiSelect) this.selectNone(); + for (var a = 0; a < arguments.length; a++) { + var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; + var record = this.get(recid); + if (record == null) continue; + var index = this.get(recid, true); + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (this.selectType == 'row') { + if (sel.indexes.indexOf(index) >= 0) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, index: index }); + if (eventData.isCancelled === true) continue; + // default action + sel.indexes.push(index); + sel.indexes.sort(function(a, b) { return a-b }); + recEl.addClass('w2ui-selected').data('selected', 'yes'); + recEl.find('.w2ui-grid-select-check').prop("checked", true); + selected++; + } else { + var col = arguments[a].column; + if (!w2utils.isInt(col)) { // select all columns + var cols = []; + for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } + if (!this.multiSelect) cols = cols.splice(0, 1); + return this.select.apply(this, cols); + } + var s = sel.columns[index] || []; + if ($.isArray(s) && s.indexOf(col) != -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, recid: recid, index: index, column: col }); + if (eventData.isCancelled === true) continue; + // default action + if (sel.indexes.indexOf(index) == -1) { + sel.indexes.push(index); + sel.indexes.sort(function(a, b) { return a-b }); + } + s.push(col); + s.sort(function(a, b) { return a-b }); // sort function must be for numerical sort + recEl.find(' > td[col='+ col +']').addClass('w2ui-selected'); + selected++; + recEl.data('selected', 'yes'); + recEl.find('.w2ui-grid-select-check').prop("checked", true); + // save back to selection object + sel.columns[index] = s; + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + // all selected? + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + this.status(); + this.addRange('selection'); + return selected; + }, + + unselect: function () { + var unselected = 0; + var sel = this.last.selection; + for (var a = 0; a < arguments.length; a++) { + var recid = typeof arguments[a] == 'object' ? arguments[a].recid : arguments[a]; + var record = this.get(recid); + if (record == null) continue; + var index = this.get(record.recid, true); + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (this.selectType == 'row') { + if (sel.indexes.indexOf(index) == -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, index: index }); + if (eventData.isCancelled === true) continue; + // default action + sel.indexes.splice(sel.indexes.indexOf(index), 1); + recEl.removeClass('w2ui-selected').removeData('selected'); + if (recEl.length != 0) recEl[0].style.cssText = 'height: '+ this.recordHeight +'px; ' + recEl.attr('custom_style'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + unselected++; + } else { + var col = arguments[a].column; + if (!w2utils.isInt(col)) { // unselect all columns + var cols = []; + for (var c in this.columns) { if (this.columns[c].hidden) continue; cols.push({ recid: recid, column: parseInt(c) }); } + return this.unselect.apply(this, cols); + } + var s = sel.columns[index]; + if (!$.isArray(s) || s.indexOf(col) == -1) continue; + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, recid: recid, column: col }); + if (eventData.isCancelled === true) continue; + // default action + s.splice(s.indexOf(col), 1); + $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid) + ' > td[col='+ col +']').removeClass('w2ui-selected'); + unselected++; + if (s.length == 0) { + delete sel.columns[index]; + sel.indexes.splice(sel.indexes.indexOf(index), 1); + recEl.removeData('selected'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + // all selected? + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + // show number of selected + this.status(); + this.addRange('selection'); + return unselected; + }, + + selectAll: function () { + if (this.multiSelect === false) return; + // event before + var eventData = this.trigger({ phase: 'before', type: 'select', target: this.name, all: true }); + if (eventData.isCancelled === true) return; + // default action + var url = (typeof this.url != 'object' ? this.url : this.url.get); + var sel = this.last.selection; + var cols = []; + for (var c in this.columns) cols.push(parseInt(c)); + // if local data source and searched + sel.indexes = []; + if (!url && this.searchData.length !== 0) { + // local search applied + for (var i = 0; i < this.last.searchIds.length; i++) { + sel.indexes.push(this.last.searchIds[i]); + if (this.selectType != 'row') sel.columns[this.last.searchIds[i]] = cols.slice(); // .slice makes copy of the array + } + } else { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + for (var i = 0; i < buffered; i++) { + sel.indexes.push(i); + if (this.selectType != 'row') sel.columns[i] = cols.slice(); // .slice makes copy of the array + } + } + this.refresh(); + // enable/disable toolbar buttons + var sel = this.getSelection(); + if (sel.length == 1) this.toolbar.enable('w2ui-edit'); else this.toolbar.disable('w2ui-edit'); + if (sel.length >= 1) this.toolbar.enable('w2ui-delete'); else this.toolbar.disable('w2ui-delete'); + this.addRange('selection'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + selectNone: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'unselect', target: this.name, all: true }); + if (eventData.isCancelled === true) return; + // default action + var sel = this.last.selection; + for (var s in sel.indexes) { + var index = sel.indexes[s]; + var rec = this.records[index]; + var recid = rec ? rec.recid : null; + var recEl = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + recEl.removeClass('w2ui-selected').removeData('selected'); + recEl.find('.w2ui-grid-select-check').prop("checked", false); + // for not rows + if (this.selectType != 'row') { + var cols = sel.columns[index]; + for (var c in cols) recEl.find(' > td[col='+ cols[c] +']').removeClass('w2ui-selected'); + } + } + sel.indexes = []; + sel.columns = {}; + this.toolbar.disable('w2ui-edit', 'w2ui-delete'); + this.removeRange('selection'); + $('#grid_'+ this.name +'_check_all').prop('checked', false); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + getSelection: function (returnIndex) { + var ret = []; + var sel = this.last.selection; + if (this.selectType == 'row') { + for (var s in sel.indexes) { + if (!this.records[sel.indexes[s]]) continue; + if (returnIndex === true) ret.push(sel.indexes[s]); else ret.push(this.records[sel.indexes[s]].recid); + } + return ret; + } else { + for (var s in sel.indexes) { + var cols = sel.columns[sel.indexes[s]]; + if (!this.records[sel.indexes[s]]) continue; + for (var c in cols) { + ret.push({ recid: this.records[sel.indexes[s]].recid, index: parseInt(sel.indexes[s]), column: cols[c] }); + } + } + return ret; + } + }, + + search: function (field, value) { + var obj = this; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + var searchData = []; + var last_multi = this.last.multi; + var last_logic = this.last.logic; + var last_field = this.last.field; + var last_search = this.last.search; + // 1: search() - advanced search (reads from popup) + if (arguments.length == 0) { + last_search = ''; + // advanced search + for (var s in this.searches) { + var search = this.searches[s]; + var operator = $('#grid_'+ this.name + '_operator_'+s).val(); + var field1 = $('#grid_'+ this.name + '_field_'+s); + var field2 = $('#grid_'+ this.name + '_field2_'+s); + var value1 = field1.val(); + var value2 = field2.val(); + var svalue = null; + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1) { + var fld1 = field1.data('w2field'); + var fld2 = field2.data('w2field'); + if (fld1) value1 = fld1.clean(value1); + if (fld2) value2 = fld2.clean(value2); + } + if (['list', 'enum'].indexOf(search.type) != -1) { + value1 = field1.data('selected') || {}; + if ($.isArray(value1)) { + svalue = []; + for (var v in value1) { + svalue.push(w2utils.isFloat(value1[v].id) ? parseFloat(value1[v].id) : String(value1[v].id).toLowerCase()); + delete value1[v].hidden; + } + } else { + value1 = value1.id || ''; + } + } + if ((value1 != '' && value1 != null) || (typeof value2 != 'undefined' && value2 != '')) { + var tmp = { + field : search.field, + type : search.type, + operator : operator + } + if (operator == 'between') { + $.extend(tmp, { value: [value1, value2] }); + } else if (operator == 'in' && typeof value1 == 'string') { + $.extend(tmp, { value: value1.split(',') }); + } else if (operator == 'not in' && typeof value1 == 'string') { + $.extend(tmp, { value: value1.split(',') }); + } else { + $.extend(tmp, { value: value1 }); + } + if (svalue) $.extend(tmp, { svalue: svalue }); + // conver date to unix time + try { + if (search.type == 'date' && operator == 'between') { + tmp.value[0] = value1; // w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); + tmp.value[1] = value2; // w2utils.isDate(value2, w2utils.settings.date_format, true).getTime(); + } + if (search.type == 'date' && operator == 'is') { + tmp.value = value1; // w2utils.isDate(value1, w2utils.settings.date_format, true).getTime(); + } + } catch (e) { + + } + searchData.push(tmp); + } + } + if (searchData.length > 0 && !url) { + last_multi = true; + last_logic = 'AND'; + } else { + last_multi = true; + last_logic = 'AND'; + } + } + // 2: search(field, value) - regular search + if (typeof field == 'string') { + last_field = field; + last_search = value; + last_multi = false; + last_logic = 'OR'; + // loop through all searches and see if it applies + if (typeof value != 'undefined') { + if (field.toLowerCase() == 'all') { + // if there are search fields loop thru them + if (this.searches.length > 0) { + for (var s in this.searches) { + var search = this.searches[s]; + if (search.type == 'text' || (search.type == 'alphanumeric' && w2utils.isAlphaNumeric(value)) + || (search.type == 'int' && w2utils.isInt(value)) || (search.type == 'float' && w2utils.isFloat(value)) + || (search.type == 'percent' && w2utils.isFloat(value)) || (search.type == 'hex' && w2utils.isHex(value)) + || (search.type == 'currency' && w2utils.isMoney(value)) || (search.type == 'money' && w2utils.isMoney(value)) + || (search.type == 'date' && w2utils.isDate(value)) ) { + var tmp = { + field : search.field, + type : search.type, + operator : (search.type == 'text' ? 'contains' : 'is'), + value : value + }; + searchData.push(tmp); + } + // range in global search box + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(search.type) != -1 && String(value).indexOf('-') != -1) { + var t = String(value).split('-'); + var tmp = { + field : search.field, + type : search.type, + operator : 'between', + value : [t[0], t[1]] + }; + searchData.push(tmp); + } + } + } else { + // no search fields, loop thru columns + for (var c in this.columns) { + var tmp = { + field : this.columns[c].field, + type : 'text', + operator : 'contains', + value : value + }; + searchData.push(tmp); + } + } + } else { + var el = $('#grid_'+ this.name +'_search_all'); + var search = this.getSearch(field); + if (search == null) search = { field: field, type: 'text' }; + if (search.field == field) this.last.caption = search.caption; + if (search.type == 'list') { + var tmp = el.data('selected'); + if (tmp && !$.isEmptyObject(tmp)) value = tmp.id; + } + if (value != '') { + var op = 'contains'; + var val = value; + if (['date', 'time', 'list'].indexOf(search.type) != -1) op = 'is'; + if (search.type == 'int' && value != '') { + op = 'is'; + if (String(value).indexOf('-') != -1) { + var tmp = value.split('-'); + if (tmp.length == 2) { + op = 'between'; + val = [parseInt(tmp[0]), parseInt(tmp[1])]; + } + } + if (String(value).indexOf(',') != -1) { + var tmp = value.split(','); + op = 'in'; + val = []; + for (var t in tmp) val.push(tmp[t]); + } + } + var tmp = { + field : search.field, + type : search.type, + operator : op, + value : val + } + searchData.push(tmp); + } + } + } + } + // 3: search([ { field, value, [operator,] [type] }, { field, value, [operator,] [type] } ], logic) - submit whole structure + if ($.isArray(field)) { + var logic = 'AND'; + if (typeof value == 'string') { + logic = value.toUpperCase(); + if (logic != 'OR' && logic != 'AND') logic = 'AND'; + } + last_search = ''; + last_multi = true; + last_logic = logic; + for (var f in field) { + var data = field[f]; + var search = this.getSearch(data.field); + if (search == null) search = { type: 'text', operator: 'contains' }; + // merge current field and search if any + searchData.push($.extend(true, {}, search, data)); + } + } + // event before + var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: searchData, + searchField: (field ? field : 'multi'), searchValue: (value ? value : 'multi') }); + if (eventData.isCancelled === true) return; + // default action + this.searchData = eventData.searchData; + this.last.field = last_field; + this.last.search = last_search; + this.last.multi = last_multi; + this.last.logic = last_logic; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + // -- clear all search field + this.searchClose(); + this.set({ expanded: false }, true); + // apply search + if (url) { + this.last.xhr_offset = 0; + this.reload(); + } else { + // local search + this.localSearch(); + this.refresh(); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + searchOpen: function () { + if (!this.box) return; + if (this.searches.length == 0) return; + var obj = this; + // show search + $('#tb_'+ this.name +'_toolbar_item_w2ui-search-advanced').w2overlay( + this.getSearchesHTML(), { + name : 'searches-'+ this.name, + left : -10, + 'class' : 'w2ui-grid-searches', + onShow : function () { + if (obj.last.logic == 'OR') obj.searchData = []; + obj.initSearches(); + $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches').data('grid-name', obj.name); + var sfields = $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches *[rel=search]'); + if (sfields.length > 0) sfields[0].focus(); + } + } + ); + }, + + searchClose: function () { + if (!this.box) return; + if (this.searches.length == 0) return; + if (this.toolbar) this.toolbar.uncheck('w2ui-search-advanced') + // hide search + if ($('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches').length > 0) { + $().w2overlay('', { name: 'searches-'+ this.name }); + } + }, + + searchShowFields: function () { + var el = $('#grid_'+ this.name +'_search_all'); + var html = ''; + for (var s = -1; s < this.searches.length; s++) { + var search = this.searches[s]; + if (s == -1) { + if (!this.multiSearch) continue; + search = { field: 'all', caption: w2utils.lang('All Fields') }; + } else { + if (this.searches[s].hidden === true) continue; + } + html += ''+ + ' '+ + ' '+ search.caption +''+ + ''; + } + html += ""; + // need timer otherwise does nto show with list type + setTimeout(function () { + $(el).w2overlay(html, { left: -10 }); + }, 1); + }, + + initAllField: function (field, value) { + var el = $('#grid_'+ this.name +'_search_all'); + var search = this.getSearch(field); + if (field == 'all') { + search = { field: 'all', caption: w2utils.lang('All Fields') }; + el.w2field('clear'); + el.change().focus(); + } else { + var st = search.type; + if (['enum', 'select'].indexOf(st) != -1) st = 'list'; + el.w2field(st, $.extend({}, search.options, { suffix: '', autoFormat: false, selected: value })); + if (['list', 'enum'].indexOf(search.type) != -1) { + this.last.search = ''; + this.last.item = ''; + el.val(''); + } + // set focus + setTimeout(function () { + el.focus(); /* do not do el.change() as it will refresh grid and pull from server */ + }, 1); + } + // update field + if (this.last.search != '') { + this.search(search.field, this.last.search); + } else { + this.last.field = search.field; + this.last.caption = search.caption; + } + el.attr('placeholder', search.caption); + $().w2overlay(); + }, + + searchReset: function (noRefresh) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'search', target: this.name, searchData: [] }); + if (eventData.isCancelled === true) return; + // default action + this.searchData = []; + this.last.search = ''; + this.last.logic = 'OR'; + // --- do not reset to All Fields (I think) + // if (this.last.multi) { + // if (!this.multiSearch) { + // this.last.field = this.searches[0].field; + // this.last.caption = this.searches[0].caption; + // } else { + // this.last.field = 'all'; + // this.last.caption = w2utils.lang('All Fields'); + // } + // } + this.last.multi = false; + this.last.xhr_offset = 0; + // reset scrolling position + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + // -- clear all search field + this.searchClose(); + $('#grid_'+ this.name +'_search_all').val(''); + // apply search + if (!noRefresh) this.reload(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + clear: function (noRefresh) { + // this.offset = 0; // clear should not reset offset + // this.total = 0; // clear should not reset total + this.records = []; + this.summary = []; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.range_start = null; + this.last.range_end = null; + // this.last.xhr_offset = 0; // clear should not reset offset + if (!noRefresh) this.refresh(); + }, + + reset: function (noRefresh) { + // reset last remembered state + this.offset = 0; + this.total = 0; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.selection.indexes = []; + this.last.selection.columns = {}; + this.last.range_start = null; + this.last.range_end = null; + this.last.xhr_offset = 0; + this.searchReset(noRefresh); + // initial sort + if (this.last.sortData != null ) this.sortData = this.last.sortData; + // select none without refresh + this.set({ expanded: false }, true); + // refresh + if (!noRefresh) this.refresh(); + }, + + skip: function (offset) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + this.offset = parseInt(offset); + if (this.offset > this.total) this.offset = this.total - this.limit; + if (this.offset < 0 || !w2utils.isInt(this.offset)) this.offset = 0; + this.records = []; + this.last.xhr_offset = 0; + this.last.pull_more = true; + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + $('#grid_'+ this.name +'_records').prop('scrollTop', 0); + this.reload(); + } else { + console.log('ERROR: grid.skip() can only be called when you have remote data source.'); + } + }, + + load: function (url, callBack) { + if (typeof url == 'undefined') { + console.log('ERROR: You need to provide url argument when calling .load() method of "'+ this.name +'" object.'); + return; + } + // default action + this.request('get-records', {}, url, callBack); + }, + + reload: function (callBack) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url) { + this.clear(true); + this.request('get-records', {}, null, callBack); + } else { + this.last.scrollTop = 0; + this.last.scrollLeft = 0; + this.last.range_start = null; + this.last.range_end = null; + this.localSearch(); + this.refresh(); + if (typeof callBack == 'function') callBack({ status: 'success' }); + } + }, + + request: function (cmd, add_params, url, callBack) { + if (typeof add_params == 'undefined') add_params = {}; + if (typeof url == 'undefined' || url == '' || url == null) url = this.url; + if (url == '' || url == null) return; + // build parameters list + var params = {}; + if (!w2utils.isInt(this.offset)) this.offset = 0; + if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0; + // add list params + params['cmd'] = cmd; + params['selected'] = this.getSelection(); + params['limit'] = this.limit; + params['offset'] = parseInt(this.offset) + this.last.xhr_offset; + params['search'] = this.searchData; + params['searchLogic'] = this.last.logic; + params['sort'] = this.sortData; + if (this.searchData.length == 0) { + delete params['search']; + delete params['searchLogic']; + } + if (this.sortData.length == 0) { + delete params['sort']; + } + // append other params + $.extend(params, this.postData); + $.extend(params, add_params); + // event before + if (cmd == 'get-records') { + var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: url, postData: params }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + } else { + var eventData = { url: url, postData: params }; + } + // call server to get data + var obj = this; + if (this.last.xhr_offset == 0) { + this.lock(this.msgRefresh, true); + } else { + var more = $('#grid_'+ this.name +'_rec_more'); + if (this.autoLoad === true) { + more.show().find('td').html(''); + } else { + more.find('td').html(''+ w2utils.lang('Load') + ' ' + obj.limit + ' ' + w2utils.lang('More') + '...'); + } + } + if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; + // URL + var url = (typeof eventData.url != 'object' ? eventData.url : eventData.url.get); + if (params.cmd == 'save-records' && typeof eventData.url == 'object') url = eventData.url.save; + if (params.cmd == 'delete-records' && typeof eventData.url == 'object') url = eventData.url.remove; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + // ajax ptions + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text' // expected data type from server + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = (typeof ajaxOptions.data == 'object' ? String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']') : ajaxOptions.data); + } + if (w2utils.settings.dataType == 'RESTFULL') { + ajaxOptions.type = 'GET'; + if (params.cmd == 'save-records') ajaxOptions.type = 'PUT'; // so far it is always update + if (params.cmd == 'delete-records') ajaxOptions.type = 'DELETE'; + ajaxOptions.data = (typeof ajaxOptions.data == 'object' ? String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']') : ajaxOptions.data); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + if (this.method) ajaxOptions.type = this.method; + + this.last.xhr_cmd = params.cmd; + this.last.xhr_start = (new Date()).getTime(); + this.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.requestComplete(status, cmd, callBack); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', total: 5, records: [{ recid: 1, field: 'value' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + obj.requestComplete('error', cmd, callBack); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + if (cmd == 'get-records') { + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, + + requestComplete: function(status, cmd, callBack) { + var obj = this; + this.unlock(); + setTimeout(function () { obj.status(w2utils.lang('Server Response') + ' ' + ((new Date()).getTime() - obj.last.xhr_start)/1000 +' ' + w2utils.lang('sec')); }, 10); + this.last.pull_more = false; + this.last.pull_refresh = true; + + // event before + var event_name = 'load'; + if (this.last.xhr_cmd == 'save-records') event_name = 'save'; + if (this.last.xhr_cmd == 'delete-records') event_name = 'deleted'; + var eventData = this.trigger({ phase: 'before', target: this.name, type: event_name, xhr: this.last.xhr, status: status }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + // parse server response + var data; + var responseText = this.last.xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + if (typeof obj.parser == 'function') { + data = obj.parser(responseText); + if (typeof data != 'object') { + console.log('ERROR: Your parser did not return proper object'); + } + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + } + // convert recids + if (obj.recid) { + for (var r in data.records) { + data.records[r]['recid'] = data.records[r][obj.recid]; + } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : this.msgNotJSON, + responseText : responseText + }; + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + if (cmd == 'get-records') { + if (this.last.xhr_offset == 0) { + this.records = []; + this.summary = []; + //data.xhr_status=data.status; + delete data.status; + $.extend(true, this, data); + } else { + var records = data.records; + delete data.records; + //data.xhr_status=data.status; + delete data.status; + $.extend(true, this, data); + for (var r in records) { + this.records.push(records[r]); + } + } + } + if (cmd == 'delete-records') { + // reset() also triggers reload + this.reset(); // unselect old selections + return; + } + } + } + } else { + data = { + status : 'error', + message : this.msgAJAXerror, + responseText : responseText + }; + obj.error(this.msgAJAXerror); + } + // event after + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + this.localSearch(); + } + this.total = parseInt(this.total); + this.trigger($.extend(eventData, { phase: 'after' })); + // do not refresh if loading on infinite scroll + if (this.last.xhr_offset == 0) this.refresh(); else this.scroll(); + // call back + if (typeof callBack == 'function') callBack(data); + }, + + error: function (msg) { + var obj = this; + // let the management of the error outside of the grid + var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + w2alert(msg, 'Error'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + getChanges: function () { + var changes = []; + for (var r in this.records) { + var rec = this.records[r]; + if (typeof rec['changes'] != 'undefined') { + changes.push($.extend(true, { recid: rec.recid }, rec.changes)); + } + } + return changes; + }, + + mergeChanges: function () { + var changes = this.getChanges(); + for (var c in changes) { + var record = this.get(changes[c].recid); + for (var s in changes[c]) { + if (s == 'recid') continue; // do not allow to change recid + try { eval('record.' + s + ' = changes[c][s]'); } catch (e) {} + delete record.changes; + } + } + this.refresh(); + }, + + // =================================================== + // -- Action Handlers + + save: function () { + var obj = this; + var changes = this.getChanges(); + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'submit', changes: changes }); + if (eventData.isCancelled === true) return; + var url = (typeof this.url != 'object' ? this.url : this.url.save); + if (url) { + this.request('save-records', { 'changes' : eventData.changes }, null, + function (data) { + if (data.status !== 'error') { + // only merge changes, if save was successful + obj.mergeChanges(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + ); + } else { + this.mergeChanges(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, + + editField: function (recid, column, value, event) { + var obj = this; + var index = obj.get(recid, true); + var rec = obj.records[index]; + var col = obj.columns[column]; + var edit = col ? col.editable : null; + if (!rec || !col || !edit || rec.editable === false) return; + if (['enum', 'file'].indexOf(edit.type) != -1) { + console.log('ERROR: input types "enum" and "file" are not supported in inline editing.'); + return; + } + // event before + var eventData = obj.trigger({ phase: 'before', type: 'editField', target: obj.name, recid: recid, column: column, value: value, + index: index, originalEvent: event }); + if (eventData.isCancelled === true) return; + value = eventData.value; + // default behaviour + this.selectNone(); + this.select({ recid: recid, column: column }); + this.last.edit_col = column; + if (['checkbox', 'check'].indexOf(edit.type) != -1) return; + // create input element + var tr = $('#grid_'+ obj.name +'_rec_'+ w2utils.escapeId(recid)); + var el = tr.find('[col='+ column +'] > div'); + if (typeof edit.inTag == 'undefined') edit.inTag = ''; + if (typeof edit.outTag == 'undefined') edit.outTag = ''; + if (typeof edit.style == 'undefined') edit.style = ''; + if (typeof edit.items == 'undefined') edit.items = []; + var val = (rec.changes && typeof rec.changes[col.field] != 'undefined' ? w2utils.stripTags(rec.changes[col.field]) : w2utils.stripTags(rec[col.field])); + if (val == null || typeof val == 'undefined') val = ''; + if (typeof value != 'undefined' && value != null) val = value; + var addStyle = (typeof col.style != 'undefined' ? col.style + ';' : ''); + if (typeof col.render == 'string' && ['number', 'int', 'float', 'money', 'percent'].indexOf(col.render.split(':')[0]) != -1) { + addStyle += 'text-align: right;'; + } + // mormalize items + if (edit.items.length > 0 && !$.isPlainObject(edit.items[0])) { + edit.items = w2obj.field.prototype.normMenu(edit.items); + } + if (edit.type == 'select') { + var html = ''; + for (var i in edit.items) { + html += ''+ edit.items[i].text +''; + } + el.addClass('w2ui-editable') + .html(''+ html +'' + edit.outTag); + el.find('select').focus() + .on('change', function (event) { + delete obj.last.move; + }) + .on('blur', function (event) { + obj.editChange.call(obj, this, index, column, event); + }); + } else { + el.addClass('w2ui-editable') + .html('' + edit.outTag); + if (value == null) el.find('input').val(val != 'object' ? val : ''); + // init w2field + var input = el.find('input').get(0); + $(input).w2field(edit.type, $.extend(edit, { selected: val })) + // add blur listener + setTimeout(function () { + var tmp = input; + if (edit.type == 'list') { + tmp = $($(input).data('w2field').helpers.focus).find('input'); + if (val != 'object' && val != '') tmp.val(val).css({ opacity: 1 }).prev().css({ opacity: 1 }); + } + $(tmp).on('blur', function (event) { + obj.editChange.call(obj, input, index, column, event); + }); + }, 10); + if (value != null) $(input).val(val != 'object' ? val : ''); + } + setTimeout(function () { + el.find('input, select') + .on('click', function (event) { + event.stopPropagation(); + }) + .on('keydown', function (event) { + var cancel = false; + switch (event.keyCode) { + case 9: // tab + cancel = true; + var next_rec = recid; + var next_col = event.shiftKey ? obj.prevCell(column, true) : obj.nextCell(column, true); + // next or prev row + if (next_col == null) { + var tmp = event.shiftKey ? obj.prevRow(index) : obj.nextRow(index); + if (tmp != null && tmp != index) { + next_rec = obj.records[tmp].recid; + // find first editable row + for (var c in obj.columns) { + var tmp = obj.columns[c].editable; + if (typeof tmp != 'undefined' && ['checkbox', 'check'].indexOf(tmp.type) == -1) { + next_col = parseInt(c); + if (!event.shiftKey) break; + } + } + } + + } + if (next_rec === false) next_rec = recid; + if (next_col == null) next_col = column; + // init new or same record + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: next_rec, column: next_col }); + } else { + obj.editField(next_rec, next_col, null, event); + } + }, 1); + break; + + case 13: // enter + this.blur(); + var next = event.shiftKey ? obj.prevRow(index) : obj.nextRow(index); + if (next != null && next != index) { + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 100); + } + break; + + case 38: // up arrow + if (!event.shiftKey) break; + cancel = true; + var next = obj.prevRow(index); + if (next != index) { + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 1); + } + break; + + case 40: // down arrow + if (!event.shiftKey) break; + cancel = true; + var next = obj.nextRow(index); + if (next != null && next != index) { + this.blur(); + setTimeout(function () { + if (obj.selectType != 'row') { + obj.selectNone(); + obj.select({ recid: obj.records[next].recid, column: column }); + } else { + obj.editField(obj.records[next].recid, column, null, event); + } + }, 1); + } + break; + + case 27: // escape + var old = obj.parseField(rec, col.field); + if (rec.changes && typeof rec.changes[col.field] != 'undefined') old = rec.changes[col.field]; + this.value = typeof old != 'undefined' ? old : ''; + this.blur(); + setTimeout(function () { obj.select({ recid: recid, column: column }) }, 1); + break; + } + if (cancel) if (event.preventDefault) event.preventDefault(); + }); + // focus and select + var tmp = el.find('input').focus(); + if (value != null) { + // set cursor to the end + tmp[0].setSelectionRange(tmp.val().length, tmp.val().length); + } else { + tmp.select(); + } + + }, 1); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + editChange: function (el, index, column, event) { + // all other fields + var summary = index < 0; + index = index < 0 ? -index - 1 : index; + var records = summary ? this.summary : this.records; + var rec = records[index]; + var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(rec.recid)); + var col = this.columns[column]; + var new_val = el.value; + var old_val = this.parseField(rec, col.field); + var tmp = $(el).data('w2field'); + if (tmp) { + new_val = tmp.clean(new_val); + if (tmp.type == 'list' && new_val != '') new_val = $(el).data('selected'); + } + if (el.type == 'checkbox') new_val = el.checked; + // change/restore event + var eventData = { + phase: 'before', type: 'change', target: this.name, input_id: el.id, recid: rec.recid, index: index, column: column, + value_new: new_val, value_previous: (rec.changes && rec.changes.hasOwnProperty(col.field) ? rec.changes[col.field]: old_val), value_original: old_val + }; + while (true) { + new_val = eventData.value_new; + if (( typeof old_val == 'undefined' || old_val === null ? '' : String(old_val)) !== String(new_val)) { + // change event + eventData = this.trigger($.extend(eventData, { type: 'change', phase: 'before' })); + if (eventData.isCancelled !== true) { + if (new_val !== eventData.value_new) { + // re-evaluate the type of change to be made + continue; + } + // default action + rec.changes = rec.changes || {}; + rec.changes[col.field] = eventData.value_new; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + // restore event + eventData = this.trigger($.extend(eventData, { type: 'restore', phase: 'before' })); + if (eventData.isCancelled !== true) { + if (new_val !== eventData.value_new) { + // re-evaluate the type of change to be made + continue; + } + // default action + if (rec.changes) delete rec.changes[col.field]; + if ($.isEmptyObject(rec.changes)) delete rec.changes; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + } + break; + } + // refresh cell + var cell = this.getCellHTML(index, column, summary); + if (!summary) { + if (rec.changes && typeof rec.changes[col.field] != 'undefined') { + $(tr).find('[col='+ column +']').addClass('w2ui-changed').html(cell); + } else { + $(tr).find('[col='+ column +']').removeClass('w2ui-changed').html(cell); + } + } + }, + + "delete": function (force) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'delete', force: force }); + if (eventData.isCancelled === true) return; + force = eventData.force; + // default action + var recs = this.getSelection(); + if (recs.length == 0) return; + if (this.msgDelete != '' && !force) { + w2confirm({ + title : w2utils.lang('Delete Confirmation'), + msg : obj.msgDelete, + btn_yes : { "class": 'btn-red' }, + callBack: function (result) { + if (result == 'Yes') w2ui[obj.name].delete(true); + } + }); + return; + } + // call delete script + var url = (typeof this.url != 'object' ? this.url : this.url.remove); + if (url) { + this.request('delete-records'); + } else { + this.selectNone(); + if (typeof recs[0] != 'object') { + this.remove.apply(this, recs); + } else { + // clear cells + for (var r in recs) { + var fld = this.columns[recs[r].column].field; + var ind = this.get(recs[r].recid, true); + if (ind != null && fld != 'recid') { + this.records[ind][fld] = ''; + if (this.records[ind].changes) delete this.records[ind].changes[fld]; + } + } + this.refresh(); + } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + click: function (recid, event) { + var time = (new Date()).getTime(); + var column = null; + if (this.last.cancelClick == true || (event && event.altKey)) return; + if (typeof recid == 'object') { + column = recid.column; + recid = recid.recid; + } + if (typeof event == 'undefined') event = {}; + // check for double click + if (time - parseInt(this.last.click_time) < 350 && event.type == 'click') { + this.dblClick(recid, event); + return; + } + this.last.click_time = time; + // column user clicked on + if (column == null && event.target) { + var tmp = event.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + if (typeof $(tmp).attr('col') != 'undefined') column = parseInt($(tmp).attr('col')); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'click', recid: recid, column: column, originalEvent: event }); + if (eventData.isCancelled === true) return; + // if it is subgrid unselect top grid + var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)).parents('tr'); + if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var grid = parent.parents('.w2ui-grid').attr('name'); + w2ui[grid].selectNone(); + // all subgrids + parent.parents('.w2ui-grid').find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { + var grid = $(el).attr('name'); + if (w2ui[grid]) w2ui[grid].selectNone(); + }); + } + // unselect all subgrids + $(this.box).find('.w2ui-expanded-row .w2ui-grid').each(function (index, el) { + var grid = $(el).attr('name'); + if (w2ui[grid]) w2ui[grid].selectNone(); + }); + // default action + var obj = this; + var sel = this.getSelection(); + $('#grid_'+ this.name +'_check_all').prop("checked", false); + var ind = this.get(recid, true); + var record = this.records[ind]; + var selectColumns = []; + obj.last.sel_ind = ind; + obj.last.sel_col = column; + obj.last.sel_recid = recid; + obj.last.sel_type = 'click'; + // multi select with shif key + if (event.shiftKey && sel.length > 0 && obj.multiSelect) { + if (sel[0].recid) { + var start = this.get(sel[0].recid, true); + var end = this.get(recid, true); + if (column > sel[0].column) { + var t1 = sel[0].column; + var t2 = column; + } else { + var t1 = column; + var t2 = sel[0].column; + } + for (var c = t1; c <= t2; c++) selectColumns.push(c); + } else { + var start = this.get(sel[0], true); + var end = this.get(recid, true); + } + var sel_add = [] + if (start > end) { var tmp = start; start = end; end = tmp; } + var url = (typeof this.url != 'object' ? this.url : this.url.get); + for (var i = start; i <= end; i++) { + if (this.searchData.length > 0 && !url && $.inArray(i, this.last.searchIds) == -1) continue; + if (this.selectType == 'row') { + sel_add.push(this.records[i].recid); + } else { + for (var sc in selectColumns) sel_add.push({ recid: this.records[i].recid, column: selectColumns[sc] }); + } + //sel.push(this.records[i].recid); + } + this.select.apply(this, sel_add); + } else { + var last = this.last.selection; + var flag = (last.indexes.indexOf(ind) != -1 ? true : false); + // clear other if necessary + if (((!event.ctrlKey && !event.shiftKey && !event.metaKey) || !this.multiSelect) && !this.showSelectColumn) { + if (this.selectType != 'row' && $.inArray(column, last.columns[ind]) == -1) flag = false; + if (sel.length > 300) this.selectNone(); else this.unselect.apply(this, sel); + if (flag === true) { + this.unselect({ recid: recid, column: column }); + } else { + this.select({ recid: recid, column: column }); + } + } else { + if (this.selectType != 'row' && $.inArray(column, last.columns[ind]) == -1) flag = false; + if (flag === true) { + this.unselect({ recid: recid, column: column }); + } else { + this.select({ recid: recid, column: column }); + } + } + } + this.status(); + obj.initResize(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - getSearchesHTML: function () { - var html = ''; - var showBtn = false; - for (var i = 0; i < this.searches.length; i++) { - var s = this.searches[i]; - if (s.hidden) continue; - var btn = ''; - if (showBtn == false) { - btn = ''; - showBtn = true; - } - if (typeof s.inTag == 'undefined') s.inTag = ''; - if (typeof s.outTag == 'undefined') s.outTag = ''; - if (typeof s.type == 'undefined') s.type = 'text'; - if (s.type == 'text') { - var operator = ''+ - ' '+ w2utils.lang('is') +''+ - ' '+ w2utils.lang('begins with') +''+ - ' '+ w2utils.lang('contains') +''+ - ' '+ w2utils.lang('ends with') +''+ - ''; - } - if (s.type == 'int' || s.type == 'float' || s.type == 'date') { - var operator = ''+ - ' '+ w2utils.lang('is') +''+ - (s.type == 'date' ? '' : ''+ w2utils.lang('in') +'')+ - ' '+ w2utils.lang('between') +''+ - ''; - } - if (s.type == 'list') { - var operator = 'is '; - } - html += ''+ - ' '+ btn +'' + - ' '+ s.caption +'' + - ' '+ operator +''+ - ' '; - - switch (s.type) { - case 'alphaNumeric': - case 'text': - html += ''; - break; - - case 'int': - case 'float': - case 'hex': - case 'money': - case 'date': - html += ''+ - ''+ - ' - '+ - ''; - break; - - case 'list': - html += ''; - break; + columnClick: function (field, event) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'columnClick', target: this.name, field: field, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behaviour + var column = this.getColumn(field); + if (column.sortable) this.sort(field, null, (event && (event.ctrlKey || event.metaKey) ? true : false) ); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - } - html += s.outTag + - ' ' + - ''; - } - html += ''+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''; - return html; - }, + keydown: function (event) { + // this method is called from w2utils + var obj = this; + if (obj.keyboard !== true) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behavior + var empty = false; + var records = $('#grid_'+ obj.name +'_records'); + var sel = obj.getSelection(); + if (sel.length == 0) empty = true; + var recid = sel[0] || null; + var columns = []; + var recid2 = sel[sel.length-1]; + if (typeof recid == 'object' && recid != null) { + recid = sel[0].recid; + columns = []; + var ii = 0; + while (true) { + if (!sel[ii] || sel[ii].recid != recid) break; + columns.push(sel[ii].column); + ii++; + } + recid2 = sel[sel.length-1].recid; + } + var ind = obj.get(recid, true); + var ind2 = obj.get(recid2, true); + var rec = obj.get(recid); + var recEL = $('#grid_'+ obj.name +'_rec_'+ (ind !== null ? w2utils.escapeId(obj.records[ind].recid) : 'none')); + var cancel = false; + var key = event.keyCode; + var shiftKey= event.shiftKey; + if (key == 9) { // tab key + if (event.shiftKey) key = 37; else key = 39; // replace with arrows + shiftKey = false; + cancel = true; + } + switch (key) { + case 8: // backspace + case 46: // delete + if (this.show.toolbarDelete) obj["delete"](); + cancel = true; + event.stopPropagation(); + break; - getColumnsHTML: function () { - var obj = this; - var html = ''; - if (this.show.columnHeaders) { - if (this.columnGroups.length > 0) { - html = getColumns(true) + getGroups() + getColumns(false); - } else { - html = getColumns(true); - } - } - return html; - - function getGroups () { - var html = ''; - // add empty group at the end - if (obj.columnGroups[obj.columnGroups.length-1].caption != '') obj.columnGroups.push({ caption: '' }); - - if (obj.show.lineNumbers) { - html += ''+ - ' '+ - ''; - } - if (obj.show.selectColumn) { - html += ''+ - ' '+ - ''; - } - if (obj.show.expandColumn) { - html += ''+ - ' '+ - ''; - } - var ii = 0; - for (var i=0; i'; - } - html += ''+ - resizer + - ' '+ - (col.caption == '' ? ' ' : col.caption) + - ' '+ - ''; - } else { - html += ''+ - ' '+ - (colg.caption == '' ? ' ' : colg.caption) + - ' '+ - ''; - } - ii += colg.span; - } - html += ''; - return html; - } - - function getColumns (master) { - var html = ''; - if (obj.show.lineNumbers) { - html += ''+ - ' #'+ - ''; - } - if (obj.show.selectColumn) { - html += ''+ - ' '+ - ' '+ - ' '+ - ''; - } - if (obj.show.expandColumn) { - html += ''+ - ' '+ - ''; - } - var ii = 0; - var id = 0; - for (var i=0; i'; - } - html += ''+ - resizer + - ' '+ - (col.caption == '' ? ' ' : col.caption) + - ' '+ - ''; - } - } - html += ' '; - html += ''; - return html; - } - }, + case 27: // escape + obj.selectNone(); + if (sel.length > 0 && typeof sel[0] == 'object') { + obj.select({ recid: sel[0].recid, column: sel[0].column }); + } + cancel = true; + break; + + case 65: // cmd + A + if (!event.metaKey && !event.ctrlKey) break; + obj.selectAll(); + cancel = true; + break; + + case 70: // cmd + F + if (!event.metaKey && !event.ctrlKey) break; + $('#grid_'+ obj.name + '_search_all').focus(); + cancel = true; + break; + + case 13: // enter + // if expandable columns - expand it + if (this.selectType == 'row' && obj.show.expandColumn === true) { + if (recEL.length <= 0) break; + obj.toggle(recid, event); + cancel = true; + } else { // or enter edit + for (var c in this.columns) { + if (this.columns[c].editable) { + columns.push(parseInt(c)); + break; + } + } + // edit last column that was edited + if (this.selectType == 'row' && this.last.edit_col) columns = [this.last.edit_col]; + if (columns.length > 0) { + obj.editField(recid, columns[0], null, event); + cancel = true; + } + } + break; + + case 37: // left + if (empty) break; + // check if this is subgrid + var parent = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind].recid)).parents('tr'); + if (parent.length > 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.prev().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].set(recid, { expanded: false }); + w2ui[grid].collapse(recid); + w2ui[grid].click(recid); + cancel = true; + break; + } + if (this.selectType == 'row') { + if (recEL.length <= 0 || rec.expanded !== true ) break; + obj.set(recid, { expanded: false }, true); + obj.collapse(recid, event); + } else { + var prev = obj.prevCell(columns[0]); + if (prev != null) { + if (shiftKey && obj.multiSelect) { + if (tmpUnselect()) return; + var tmp = []; + var newSel = []; + var unSel = []; + if (columns.indexOf(this.last.sel_col) == 0 && columns.length > 1) { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + unSel.push({ recid: sel[i].recid, column: columns[columns.length-1] }); + } + } else { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + newSel.push({ recid: sel[i].recid, column: prev }); + } + } + obj.unselect.apply(obj, unSel); + obj.select.apply(obj, newSel); + } else { + event.shiftKey = false; + obj.click({ recid: recid, column: prev }, event); + } + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=1; s 1) { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + unSel.push({ recid: sel[i].recid, column: columns[0] }); + } + } else { + for (var i in sel) { + if (tmp.indexOf(sel[i].recid) == -1) tmp.push(sel[i].recid); + newSel.push({ recid: sel[i].recid, column: next }); + } + } + obj.unselect.apply(obj, unSel); + obj.select.apply(obj, newSel); + } else { + obj.click({ recid: recid, column: next }, event); + } + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=0; s 0 && w2ui[subgrid.attr('name')]) { + obj.selectNone(); + var grid = subgrid.attr('name'); + var recs = w2ui[grid].records; + w2utils.keyboard.active(grid); + w2ui[grid].click(recs[recs.length-1].recid); + cancel = true; + break; + } + } + if (shiftKey && obj.multiSelect) { // expand selection + if (tmpUnselect()) return; + if (obj.selectType == 'row') { + if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { + obj.unselect(obj.records[ind2].recid); + } else { + obj.select(obj.records[prev].recid); + } + } else { + if (obj.last.sel_ind > prev && obj.last.sel_ind != ind2) { + prev = ind2; + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); + obj.unselect.apply(obj, tmp); + } else { + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[prev].recid, column: columns[c] }); + obj.select.apply(obj, tmp); + } + } + } else { // move selected record + obj.selectNone(); + obj.click({ recid: obj.records[prev].recid, column: columns[0] }, event); + } + obj.scrollIntoView(prev); + if (event.preventDefault) event.preventDefault(); + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=1; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.prev().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].click(recid); + cancel = true; + break; + } + } + break; + + case 40: // down + if (empty) selectTopRecord(); + if (recEL.length <= 0) break; + // jump into subgrid + if (obj.records[ind2].expanded) { + var subgrid = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(obj.records[ind2].recid) +'_expanded_row').find('.w2ui-grid'); + if (subgrid.length > 0 && w2ui[subgrid.attr('name')]) { + obj.selectNone(); + var grid = subgrid.attr('name'); + var recs = w2ui[grid].records; + w2utils.keyboard.active(grid); + w2ui[grid].click(recs[0].recid); + cancel = true; + break; + } + } + // move to the next record + var next = obj.nextRow(ind2); + if (next != null) { + if (shiftKey && obj.multiSelect) { // expand selection + if (tmpUnselect()) return; + if (obj.selectType == 'row') { + if (this.last.sel_ind < next && this.last.sel_ind != ind) { + obj.unselect(obj.records[ind].recid); + } else { + obj.select(obj.records[next].recid); + } + } else { + if (this.last.sel_ind < next && this.last.sel_ind != ind) { + next = ind; + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); + obj.unselect.apply(obj, tmp); + } else { + var tmp = []; + for (var c in columns) tmp.push({ recid: obj.records[next].recid, column: columns[c] }); + obj.select.apply(obj, tmp); + } + } + } else { // move selected record + obj.selectNone(); + obj.click({ recid: obj.records[next].recid, column: columns[0] }, event); + } + obj.scrollIntoView(next); + cancel = true; + } else { + // if selected more then one, then select first + if (!shiftKey) { + for (var s=0; s 0 && String(parent.attr('id')).indexOf('expanded_row') != -1) { + var recid = parent.next().attr('recid'); + var grid = parent.parents('.w2ui-grid').attr('name'); + obj.selectNone(); + w2utils.keyboard.active(grid); + w2ui[grid].click(recid); + cancel = true; + break; + } + } + break; + + // copy & paste + + case 17: // ctrl key + case 91: // cmd key + if (empty) break; + var text = obj.copy(); + $('body').append(''+ text +''); + $('#_tmp_copy_data').focus().select(); + // remove _tmp_copy_data textarea + $(document).on('keyup', tmp_key_down); + function tmp_key_down() { + $('#_tmp_copy_data').remove(); + $(document).off('keyup', tmp_key_down); + } + break; + + case 88: // x - cut + if (empty) break; + if (event.ctrlKey || event.metaKey) { + setTimeout(function () { obj["delete"](true); }, 100); + } + break; + } + var tmp = [187, 189, 32]; // =-spacebar + for (var i=48; i<=90; i++) tmp.push(i); // 0-9,a-z,A-Z + if (tmp.indexOf(key) != -1 && !event.ctrlKey && !event.metaKey && !cancel) { + if (columns.length == 0) columns.push(0); + var tmp = String.fromCharCode(key); + if (key == 187) tmp = '='; + if (key == 189) tmp = '-'; + if (!shiftKey) tmp = tmp.toLowerCase(); + obj.editField(recid, columns[0], tmp, event); + cancel = true; + } + if (cancel) { // cancel default behaviour + if (event.preventDefault) event.preventDefault(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + + function selectTopRecord() { + var ind = Math.floor((records[0].scrollTop + (records.height() / 2.1)) / obj.recordHeight); + if (!obj.records[ind]) ind = 0; + obj.select({ recid: obj.records[ind].recid, column: 0}); + } + + function tmpUnselect () { + if (obj.last.sel_type != 'click') return false; + if (obj.selectType != 'row') { + obj.last.sel_type = 'key'; + if (sel.length > 1) { + for (var s in sel) { + if (sel[s].recid == obj.last.sel_recid && sel[s].column == obj.last.sel_col) { + sel.splice(s, 1); + break; + } + } + obj.unselect.apply(obj, sel); + return true; + } + return false; + } else { + obj.last.sel_type = 'key'; + if (sel.length > 1) { + sel.splice(sel.indexOf(obj.records[obj.last.sel_ind].recid), 1); + obj.unselect.apply(obj, sel); + return true; + } + return false; + } + } + }, + + scrollIntoView: function (ind) { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + if (typeof ind == 'undefined') { + var sel = this.getSelection(); + if (sel.length == 0) return; + ind = this.get(sel[0], true); + } + var records = $('#grid_'+ this.name +'_records'); + if (buffered == 0) return; + // if all records in view + var len = this.last.searchIds.length; + if (records.height() > this.recordHeight * (len > 0 ? len : buffered)) return; + if (len > 0) ind = this.last.searchIds.indexOf(ind); // if seach is applied + // scroll to correct one + var t1 = Math.floor(records[0].scrollTop / this.recordHeight); + var t2 = t1 + Math.floor(records.height() / this.recordHeight); + if (ind == t1) records.animate({ 'scrollTop': records.scrollTop() - records.height() / 1.3 }, 250, 'linear'); + if (ind == t2) records.animate({ 'scrollTop': records.scrollTop() + records.height() / 1.3 }, 250, 'linear'); + if (ind < t1 || ind > t2) records.animate({ 'scrollTop': (ind - 1) * this.recordHeight }); + }, + + dblClick: function (recid, event) { + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // find columns + var column = null; + if (typeof recid == 'object') { + column = recid.column; + recid = recid.recid; + } + if (typeof event == 'undefined') event = {}; + // column user clicked on + if (column == null && event.target) { + var tmp = event.target; + if (tmp.tagName != 'TD') tmp = $(tmp).parents('td')[0]; + column = parseInt($(tmp).attr('col')); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'dblClick', recid: recid, column: column, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + this.selectNone(); + var col = this.columns[column]; + if (col && $.isPlainObject(col.editable)) { + this.editField(recid, column, null, event); + } else { + this.select({ recid: recid, column: column }); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + contextMenu: function (recid, event) { + var obj = this; + if (obj.last.userSelect == 'text') return; + if (typeof event == 'undefined') event = { offsetX: 0, offsetY: 0, target: $('#grid_'+ obj.name +'_rec_'+ recid)[0] }; + if (typeof event.offsetX === 'undefined') { + event.offsetX = event.layerX - event.target.offsetLeft; + event.offsetY = event.layerY - event.target.offsetTop; + } + if (w2utils.isFloat(recid)) recid = parseFloat(recid); + if (this.getSelection().indexOf(recid) == -1) obj.click(recid); + // need timeout to allow click to finish first + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: obj.name, originalEvent: event, recid: recid }); + if (eventData.isCancelled === true) return; + // default action + if (obj.menu.length > 0) { + $(obj.box).find(event.target) + .w2menu(obj.menu, { + left : event.offsetX, + onSelect: function (event) { + obj.menuClick(recid, parseInt(event.index), event.originalEvent); + } + } + ); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 150); // need timer 150 for FF + // cancel event + if (event.preventDefault) event.preventDefault(); + }, + + menuClick: function (recid, index, event) { + var obj = this; + // event before + var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: obj.name, originalEvent: event, + recid: recid, menuIndex: index, menuItem: obj.menu[index] }); + if (eventData.isCancelled === true) return; + // default action + // -- empty + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + toggle: function (recid) { + var rec = this.get(recid); + if (rec.expanded === true) return this.collapse(recid); else return this.expand(recid); + }, + + expand: function (recid) { + var rec = this.get(recid); + var obj = this; + var id = w2utils.escapeId(recid); + if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length > 0) return false; + if (rec.expanded == 'none') return false; + // insert expand row + var tmp = 1 + (this.show.selectColumn ? 1 : 0); + var addClass = ''; // ($('#grid_'+this.name +'_rec_'+ w2utils.escapeId(recid)).hasClass('w2ui-odd') ? 'w2ui-odd' : 'w2ui-even'); + $('#grid_'+ this.name +'_rec_'+ id).after( + ''+ + (this.show.lineNumbers ? '' : '') + + ' '+ + ' '+ + ' '+ + ' '+ + ''); + // event before + var eventData = this.trigger({ phase: 'before', type: 'expand', target: this.name, recid: recid, + box_id: 'grid_'+ this.name +'_rec_'+ recid +'_expanded', ready: ready }); + if (eventData.isCancelled === true) { + $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').remove(); + return; + } + // default action + $('#grid_'+ this.name +'_rec_'+ id).attr('expanded', 'yes').addClass('w2ui-expanded'); + $('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').show(); + $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html(''); + rec.expanded = true; + // check if height of expanded row > 5 then remove spinner + setTimeout(ready, 300); + function ready() { + var div1 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded'); + var div2 = $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row .w2ui-expanded1 > div'); + if (div1.height() < 5) return; + div1.css('opacity', 1); + div2.show().css('opacity', 1); + $('#grid_'+ obj.name +'_cell_'+ obj.get(recid, true) +'_expand div').html('-'); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.resizeRecords(); + return true; + }, + + collapse: function (recid) { + var rec = this.get(recid); + var obj = this; + var id = w2utils.escapeId(recid); + if ($('#grid_'+ this.name +'_rec_'+ id +'_expanded_row').length == 0) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'collapse', target: this.name, recid: recid, + box_id: 'grid_'+ this.name +'_rec_'+ id +'_expanded' }); + if (eventData.isCancelled === true) return; + // default action + $('#grid_'+ this.name +'_rec_'+ id).removeAttr('expanded').removeClass('w2ui-expanded'); + $('#grid_'+ this.name +'_rec_'+ id +'_expanded').css('opacity', 0); + $('#grid_'+ this.name +'_cell_'+ this.get(recid, true) +'_expand div').html('+'); + setTimeout(function () { + $('#grid_'+ obj.name +'_rec_'+ id +'_expanded').height('0px'); + setTimeout(function () { + $('#grid_'+ obj.name +'_rec_'+ id +'_expanded_row').remove(); + delete rec.expanded; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resizeRecords(); + }, 300); + }, 200); + return true; + }, + + sort: function (field, direction, multiField) { // if no params - clears sort + // event before + var eventData = this.trigger({ phase: 'before', type: 'sort', target: this.name, field: field, direction: direction, multiField: multiField }); + if (eventData.isCancelled === true) return; + // check if needed to quit + if (typeof field != 'undefined') { + // default action + var sortIndex = this.sortData.length; + for (var s in this.sortData) { + if (this.sortData[s].field == field) { sortIndex = s; break; } + } + if (typeof direction == 'undefined' || direction == null) { + if (typeof this.sortData[sortIndex] == 'undefined') { + direction = 'asc'; + } else { + switch (String(this.sortData[sortIndex].direction)) { + case 'asc' : direction = 'desc'; break; + case 'desc' : direction = 'asc'; break; + default : direction = 'asc'; break; + } + } + } + if (this.multiSort === false) { this.sortData = []; sortIndex = 0; } + if (multiField != true) { this.sortData = []; sortIndex = 0; } + // set new sort + if (typeof this.sortData[sortIndex] == 'undefined') this.sortData[sortIndex] = {}; + this.sortData[sortIndex].field = field; + this.sortData[sortIndex].direction = direction; + } else { + this.sortData = []; + } + this.selectNone(); + // if local + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (!url) { + this.localSort(); + if (this.searchData.length > 0) this.localSearch(true); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + } else { + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.last.xhr_offset = 0; + this.reload(); + } + }, + + copy: function () { + var sel = this.getSelection(); + if (sel.length == 0) return ''; + var text = ''; + if (typeof sel[0] == 'object') { // cell copy + // find min/max column + var minCol = sel[0].column; + var maxCol = sel[0].column; + var recs = []; + for (var s in sel) { + if (sel[s].column < minCol) minCol = sel[s].column; + if (sel[s].column > maxCol) maxCol = sel[s].column; + if (recs.indexOf(sel[s].index) == -1) recs.push(sel[s].index); + } + recs.sort(); + for (var r in recs) { + var ind = recs[r]; + for (var c = minCol; c <= maxCol; c++) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += w2utils.stripTags(this.getCellHTML(ind, c)) + '\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + } + } else { // row copy + // copy headers + for (var c in this.columns) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += '"' + w2utils.stripTags(col.caption ? col.caption : col.field) + '"\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + // copy selected text + for (var s in sel) { + var ind = this.get(sel[s], true); + for (var c in this.columns) { + var col = this.columns[c]; + if (col.hidden === true) continue; + text += '"' + w2utils.stripTags(this.getCellHTML(ind, c)) + '"\t'; + } + text = text.substr(0, text.length-1); // remove last \t + text += '\n'; + } + } + text = text.substr(0, text.length - 1); + // before event + var eventData = this.trigger({ phase: 'before', type: 'copy', target: this.name, text: text }); + if (eventData.isCancelled === true) return ''; + text = eventData.text; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return text; + }, + + paste: function (text) { + var sel = this.getSelection(); + var ind = this.get(sel[0].recid, true); + var col = sel[0].column; + // before event + var eventData = this.trigger({ phase: 'before', type: 'paste', target: this.name, text: text, index: ind, column: col }); + if (eventData.isCancelled === true) return; + text = eventData.text; + // default action + if (this.selectType == 'row' || sel.length == 0) { + console.log('ERROR: You can paste only if grid.selectType = \'cell\' and when at least one cell selected.'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return; + } + var newSel = []; + var text = text.split('\n'); + for (var t in text) { + var tmp = text[t].split('\t'); + var cnt = 0; + var rec = this.records[ind]; + var cols = []; + for (var dt in tmp) { + if (!this.columns[col + cnt]) continue; + var field = this.columns[col + cnt].field; + rec.changes = rec.changes || {}; + rec.changes[field] = tmp[dt]; + cols.push(col + cnt); + cnt++; + } + for (var c in cols) newSel.push({ recid: rec.recid, column: cols[c] }); + ind++; + } + this.selectNone(); + this.select.apply(this, newSel); + this.refresh(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // ================================================== + // --- Common functions + + resize: function () { + var obj = this; + var time = (new Date()).getTime(); + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // make sure the box is right + if (!this.box || $(this.box).attr('name') != this.name) return; + // determine new width and height + $(this.box).find('> div') + .css('width', $(this.box).width()) + .css('height', $(this.box).height()); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; + // resize + obj.resizeBoxes(); + obj.resizeRecords(); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, + + refreshCell: function (recid, field) { + var index = this.get(recid, true); + var isSummary = (this.records[index] && this.records[index].recid == recid ? false : true); + var col_ind = this.getColumn(field, true); + var rec = (isSummary ? this.summary[index] : this.records[index]); + var col = this.columns[col_ind]; + var cell = $('#grid_'+ this.name + '_rec_'+ recid +' [col='+ col_ind +']'); + // set cell html and changed flag + cell.html(this.getCellHTML(index, col_ind, isSummary)); + if (rec.changes && typeof rec.changes[col.field] != 'undefined') { + cell.addClass('w2ui-changed'); + } else { + cell.removeClass('w2ui-changed'); + } + }, + + refreshRow: function (recid) { + var tr = $('#grid_'+ this.name +'_rec_'+ w2utils.escapeId(recid)); + if (tr.length != 0) { + var ind = this.get(recid, true); + var line = tr.attr('line'); + var isSummary = (this.records[ind] && this.records[ind].recid == recid ? false : true); + // if it is searched, find index in search array + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (this.searchData.length > 0 && !url) for (var s in this.last.searchIds) if (this.last.searchIds[s] == ind) ind = s; + $(tr).replaceWith(this.getRecordHTML(ind, line, isSummary)); + if (isSummary) this.resize(); + } + }, + + refresh: function () { + var obj = this; + var time = (new Date()).getTime(); + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (this.total <= 0 && !url && this.searchData.length == 0) { + this.total = this.records.length; + } + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + this.toolbar.disable('w2ui-edit', 'w2ui-delete'); + if (!this.box) return; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh' }); + if (eventData.isCancelled === true) return; + // -- header + if (this.show.header) { + $('#grid_'+ this.name +'_header').html(this.header +' ').show(); + } else { + $('#grid_'+ this.name +'_header').hide(); + } + // -- toolbar + if (this.show.toolbar) { + // if select-collumn is checked - no toolbar refresh + if (this.toolbar && this.toolbar.get('w2ui-column-on-off') && this.toolbar.get('w2ui-column-on-off').checked) { + // no action + } else { + $('#grid_'+ this.name +'_toolbar').show(); + // refresh toolbar all but search field + if (typeof this.toolbar == 'object') { + var tmp = this.toolbar.items; + for (var t in tmp) { + if (tmp[t].id == 'w2ui-search' || tmp[t].type == 'break') continue; + this.toolbar.refresh(tmp[t].id); + } + } + } + } else { + $('#grid_'+ this.name +'_toolbar').hide(); + } + // -- make sure search is closed + this.searchClose(); + // search placeholder + var el = $('#grid_'+ obj.name +'_search_all'); + if (!this.multiSearch && this.last.field == 'all' && this.searches.length > 0) { + this.last.field = this.searches[0].field; + this.last.caption = this.searches[0].caption; + } + for (var s in this.searches) { + if (this.searches[s].field == this.last.field) this.last.caption = this.searches[s].caption; + } + if (this.last.multi) { + el.attr('placeholder', '[' + w2utils.lang('Multiple Fields') + ']'); + } else { + el.attr('placeholder', this.last.caption); + } + if (el.val() != this.last.search) { + var val = this.last.search; + var tmp = el.data('w2field'); + if (tmp) val = tmp.format(val); + el.val(val); + } + + // -- separate summary + var tmp = this.find({ summary: true }, true); + if (tmp.length > 0) { + for (var t in tmp) this.summary.push(this.records[tmp[t]]); + for (var t=tmp.length-1; t>=0; t--) this.records.splice(tmp[t], 1); + this.total = this.total - tmp.length; + } + + // -- body + var bodyHTML = ''; + bodyHTML += ''+ + this.getRecordsHTML() + + ''+ + ''+ + ' '+ this.getColumnsHTML() +''+ + ''; // Columns need to be after to be able to overlap + $('#grid_'+ this.name +'_body').html(bodyHTML); + // show summary records + if (this.summary.length > 0) { + $('#grid_'+ this.name +'_summary').html(this.getSummaryHTML()).show(); + } else { + $('#grid_'+ this.name +'_summary').hide(); + } + // -- footer + if (this.show.footer) { + $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()).show(); + } else { + $('#grid_'+ this.name +'_footer').hide(); + } + // show/hide clear search link + if (this.searchData.length > 0) { + $('#grid_'+ this.name +'_searchClear').show(); + } else { + $('#grid_'+ this.name +'_searchClear').hide(); + } + // all selected? + var sel = this.last.selection; + if (sel.indexes.length == this.records.length || (this.searchData.length !== 0 && sel.indexes.length == this.last.searchIds.length)) { + $('#grid_'+ this.name +'_check_all').prop('checked', true); + } else { + $('#grid_'+ this.name +'_check_all').prop('checked', false); + } + // show number of selected + this.status(); + // collapse all records + var rows = obj.find({ expanded: true }, true); + for (var r in rows) obj.records[rows[r]].expanded = false; + // mark selection + setTimeout(function () { + var str = $.trim($('#grid_'+ obj.name +'_search_all').val()); + if (str != '') $(obj.box).find('.w2ui-grid-data > div').w2marker(str); + }, 50); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + obj.addRange('selection'); + setTimeout(function () { obj.resize(); obj.scroll(); }, 1); // allow to render first + + if ( obj.reorderColumns && !obj.last.columnDrag ) { + obj.last.columnDrag = obj.initColumnDrag(); + } else if ( !obj.reorderColumns && obj.last.columnDrag ) { + obj.last.columnDrag.remove(); + } + + return (new Date()).getTime() - time; + }, + + render: function (box) { + var obj = this; + var time = (new Date()).getTime(); + //if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof box != 'undefined' && box != null) { + if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-grid') + .html(''); + } + this.box = box; + } + if (!this.box) return; + if (this.last.sortData == null) this.last.sortData = this.sortData; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: box }); + if (eventData.isCancelled === true) return; + // insert Elements + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-grid') + .html(''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''); + if (this.selectType != 'row') $(this.box).addClass('w2ui-ss'); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // init toolbar + this.initToolbar(); + if (this.toolbar != null) this.toolbar.render($('#grid_'+ this.name +'_toolbar')[0]); + // reinit search_all + if (this.last.field && this.last.field != 'all') { + var sd = this.searchData; + this.initAllField(this.last.field, (sd.length == 1 ? sd[0].value : null)); + } + // init footer + $('#grid_'+ this.name +'_footer').html(this.getFooterHTML()); + // refresh + if (!this.last.state) this.last.state = this.stateSave(true); // initial default state + this.stateRestore(); + if (this.url) this.refresh(); // show empty grid (need it) - should it be only for remote data source + this.reload(); + + // init mouse events for mouse selection + $(this.box).on('mousedown', mouseStart); + $(this.box).on('selectstart', function () { return false; }); // fixes chrome cursor bug + + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // attach to resize event + if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event + this.tmp_resize = function (event) { w2ui[obj.name].resize(); } + $(window).off('resize', this.tmp_resize).on('resize', this.tmp_resize); + } + return (new Date()).getTime() - time; + + function mouseStart (event) { + if (event.which != 1) return; // if not left mouse button + // restore css user-select + if (obj.last.userSelect == 'text') { + delete obj.last.userSelect; + $(obj.box).find('.w2ui-grid-body') + .css('user-select', 'none') + .css('-webkit-user-select', 'none') + .css('-moz-user-select', 'none') + .css('-ms-user-select', 'none'); + $(this.box).on('selectstart', function () { return false; }); + } + // regular record select + if ($(event.target).parents().hasClass('w2ui-head') || $(event.target).hasClass('w2ui-head')) return; + if (obj.last.move && obj.last.move.type == 'expand') return; + // if altKey - alow text selection + if (event.altKey) { + $(obj.box).off('selectstart'); + $(obj.box).find('.w2ui-grid-body') + .css('user-select', 'text') + .css('-webkit-user-select', 'text') + .css('-moz-user-select', 'text') + .css('-ms-user-select', 'text'); + obj.selectNone(); + obj.last.move = { type: 'text-select' }; + obj.last.userSelect = 'text'; + } else { + if (!obj.multiSelect) return; + obj.last.move = { + x : event.screenX, + y : event.screenY, + divX : 0, + divY : 0, + recid : $(event.target).parents('tr').attr('recid'), + column : (event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')), + type : 'select', + ghost : false, + start : true + }; + } + $(document).on('mousemove', mouseMove); + $(document).on('mouseup', mouseStop); + } + + function mouseMove (event) { + var mv = obj.last.move; + if (!mv || mv.type != 'select') return; + mv.divX = (event.screenX - mv.x); + mv.divY = (event.screenY - mv.y); + if (Math.abs(mv.divX) <= 1 && Math.abs(mv.divY) <= 1) return; // only if moved more then 1px + obj.last.cancelClick = true; + if (obj.reorderRows == true) { + if (!mv.ghost) { + var row = $('#grid_'+ obj.name + '_rec_'+ mv.recid); + var tmp = row.parents('table').find('tr:first-child').clone(); + mv.offsetY = event.offsetY; + mv.from = mv.recid; + mv.pos = row.position(); + mv.ghost = $(row).clone(true); + mv.ghost.removeAttr('id'); + row.find('td:first-child').replaceWith(''); + var recs = $(obj.box).find('.w2ui-grid-records'); + recs.append(''); + $('#grid_'+ obj.name + '_ghost').append(tmp).append(mv.ghost); + } + var recid = $(event.target).parents('tr').attr('recid'); + if (recid != mv.from) { + var row1 = $('#grid_'+ obj.name + '_rec_'+ mv.recid); + var row2 = $('#grid_'+ obj.name + '_rec_'+ recid); + if (event.screenY - mv.lastY < 0) row1.after(row2); else row2.after(row1); + mv.lastY = event.screenY; + mv.to = recid; + } + var ghost = $('#grid_'+ obj.name + '_ghost'); + var recs = $(obj.box).find('.w2ui-grid-records'); + ghost.css({ + top : mv.pos.top + mv.divY + recs.scrollTop(), // + mv.offsetY - obj.recordHeight / 2, + left : mv.pos.left + }); + return; + } + if (mv.start && mv.recid) { + obj.selectNone(); + mv.start = false; + } + var newSel= []; + var recid = (event.target.tagName == 'TR' ? $(event.target).attr('recid') : $(event.target).parents('tr').attr('recid')); + if (typeof recid == 'undefined') return; + var ind1 = obj.get(mv.recid, true); + // |:wolfmanx:| this happens when selection is started on summary row + if (ind1 === null) return; + var ind2 = obj.get(recid, true); + // this happens when selection is extended into summary row (a good place to implement scrolling) + if (ind2 === null) return; + var col1 = parseInt(mv.column); + var col2 = parseInt(event.target.tagName == 'TD' ? $(event.target).attr('col') : $(event.target).parents('td').attr('col')); + if (ind1 > ind2) { var tmp = ind1; ind1 = ind2; ind2 = tmp; } + // check if need to refresh + var tmp = 'ind1:'+ ind1 +',ind2;'+ ind2 +',col1:'+ col1 +',col2:'+ col2; + if (mv.range == tmp) return; + mv.range = tmp; + for (var i = ind1; i <= ind2; i++) { + if (obj.last.searchIds.length > 0 && obj.last.searchIds.indexOf(i) == -1) continue; + if (obj.selectType != 'row') { + if (col1 > col2) { var tmp = col1; col1 = col2; col2 = tmp; } + var tmp = []; + for (var c = col1; c <= col2; c++) { + if (obj.columns[c].hidden) continue; + newSel.push({ recid: obj.records[i].recid, column: parseInt(c) }); + } + } else { + newSel.push(obj.records[i].recid); + } + } + if (obj.selectType != 'row') { + var sel = obj.getSelection(); + // add more items + var tmp = []; + for (var ns in newSel) { + var flag = false; + for (var s in sel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; + if (!flag) tmp.push({ recid: newSel[ns].recid, column: newSel[ns].column }); + } + obj.select.apply(obj, tmp); + // remove items + var tmp = []; + for (var s in sel) { + var flag = false; + for (var ns in newSel) if (newSel[ns].recid == sel[s].recid && newSel[ns].column == sel[s].column) flag = true; + if (!flag) tmp.push({ recid: sel[s].recid, column: sel[s].column }); + } + obj.unselect.apply(obj, tmp); + } else { + if (obj.multiSelect) { + var sel = obj.getSelection(); + for (var ns in newSel) if (sel.indexOf(newSel[ns]) == -1) obj.select(newSel[ns]); // add more items + for (var s in sel) if (newSel.indexOf(sel[s]) == -1) obj.unselect(sel[s]); // remove items + } + } + } + + function mouseStop (event) { + var mv = obj.last.move; + setTimeout(function () { delete obj.last.cancelClick; }, 1); + if ($(event.target).parents().hasClass('.w2ui-head') || $(event.target).hasClass('.w2ui-head')) return; + if (mv && mv.type == 'select') { + if (obj.reorderRows == true) { + var ind1 = obj.get(mv.from, true); + var tmp = obj.records[ind1]; + obj.records.splice(ind1, 1); + var ind2 = obj.get(mv.to, true); + if (ind1 > ind2) obj.records.splice(ind2, 0, tmp); else obj.records.splice(ind2+1, 0, tmp); + $('#grid_'+ obj.name + '_ghost').remove(); + obj.refresh(); + } + } + delete obj.last.move; + $(document).off('mousemove', mouseMove); + $(document).off('mouseup', mouseStop); + } + }, + + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); + if (eventData.isCancelled === true) return; + // remove events + $(window).off('resize', this.tmp_resize); + // clean up + if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); + if ($(this.box).find('#grid_'+ this.name +'_body').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-grid') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // =========================================== + // --- Internal Functions + + initColumnOnOff: function () { + if (!this.show.toolbarColumns) return; + var obj = this; + var col_html = ''+ + ''+ + ''+ + ' '+ + ''+ + ''+ + ' '+ w2utils.lang('Line #') +''+ + ''; + for (var c in this.columns) { + var col = this.columns[c]; + var tmp = this.columns[c].caption; + if (col.hideable === false) continue; + if (!tmp && this.columns[c].hint) tmp = this.columns[c].hint; + if (!tmp) tmp = '- column '+ (parseInt(c) + 1) +' -'; + col_html += ''+ + ''+ + ' '+ + ''+ + ''+ + ' '+ tmp + ''+ + ''+ + ''; + } + col_html += ''; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && obj.show.skipRecords) { + col_html += + ''+ + ' '+ w2utils.lang('Skip') + + ' '+ w2utils.lang('Records')+ + ' '+ + ''; + } + col_html += ''+ + ' '+ w2utils.lang('Save Grid State') + ''+ + ''+ + ''+ + ' '+ w2utils.lang('Restore Default State') + ''+ + ''; + col_html += ""; + this.toolbar.get('w2ui-column-on-off').html = col_html; + }, + + /** + * + * @param box, grid object + * @returns {{remove: Function}} contains a closure around all events to ensure they are removed from the dom + */ + initColumnDrag: function ( box ) { + //throw error if using column groups + if ( this.columnGroups && this.columnGroups.length ) throw 'Draggable columns are not currently supported with column groups.'; + + var obj = this, + _dragData = {}; + _dragData.lastInt = null; + _dragData.pressed = false; + _dragData.timeout = null;_dragData.columnHead = null; + + //attach orginal event listener + $(obj.box).on('mousedown', dragColStart); + $(obj.box).on('mouseup', catchMouseup); + + function catchMouseup(){ + _dragData.pressed = false; + clearTimeout( _dragData.timeout ); + } + /** + * + * @param event, mousedown + * @returns {boolean} false, preventsDefault + */ + function dragColStart ( event ) { + if ( _dragData.timeout ) clearTimeout( _dragData.timeout ); + var self = this; + _dragData.pressed = true; + + _dragData.timeout = setTimeout(function(){ + if ( !_dragData.pressed ) return; + + var eventData, + columns, + selectedCol, + origColumn, + origColumnNumber, + invalidPreColumns = [ 'w2ui-col-number', 'w2ui-col-expand', 'w2ui-col-select' ], + invalidPostColumns = [ 'w2ui-head-last' ], + invalidColumns = invalidPreColumns.concat( invalidPostColumns ), + preColumnsSelector = '.w2ui-col-number, .w2ui-col-expand, .w2ui-col-select', + preColHeadersSelector = '.w2ui-head.w2ui-col-number, .w2ui-head.w2ui-col-expand, .w2ui-head.w2ui-col-select'; + + // do nothing if it is not a header + if ( !$( event.originalEvent.target ).parents().hasClass( 'w2ui-head' ) ) return; + + // do nothing if it is an invalid column + for ( var i = 0, l = invalidColumns.length; i < l; i++ ){ + if ( $( event.originalEvent.target ).parents().hasClass( invalidColumns[ i ] ) ) return; + } + + _dragData.numberPreColumnsPresent = $( obj.box ).find( preColHeadersSelector ).length; + + //start event for drag start + _dragData.columnHead = origColumn = $( event.originalEvent.target ).parents( '.w2ui-head' ); + origColumnNumber = parseInt( origColumn.attr( 'col' ), 10); + eventData = obj.trigger({ type: 'columnDragStart', phase: 'before', originalEvent: event, origColumnNumber: origColumnNumber, target: origColumn[0] }); + if ( eventData.isCancelled === true ) return false; + + columns = _dragData.columns = $( obj.box ).find( '.w2ui-head:not(.w2ui-head-last)' ); + + //add events + $( document ).on( 'mouseup', dragColEnd ); + $( document ).on( 'mousemove', dragColOver ); + + _dragData.originalPos = parseInt( $( event.originalEvent.target ).parent( '.w2ui-head' ).attr( 'col' ), 10 ); + //_dragData.columns.css({ overflow: 'visible' }).children( 'div' ).css({ overflow: 'visible' }); + + //configure and style ghost image + _dragData.ghost = $( self ).clone( true ); + + //hide other elements on ghost except the grid body + $( _dragData.ghost ).find( '[col]:not([col="' + _dragData.originalPos + '"]), .w2ui-toolbar, .w2ui-grid-header' ).remove(); + $( _dragData.ghost ).find( preColumnsSelector ).remove(); + $( _dragData.ghost ).find( '.w2ui-grid-body' ).css({ top: 0 }); + + selectedCol = $( _dragData.ghost ).find( '[col="' + _dragData.originalPos + '"]' ); + $( document.body ).append( _dragData.ghost ); + + $( _dragData.ghost ).css({ + width: 0, + height: 0, + margin: 0, + position: 'fixed', + zIndex: 999999, + opacity: 0 + }).addClass( '.w2ui-grid-ghost' ).animate({ + width: selectedCol.width(), + height: $(obj.box).find('.w2ui-grid-body:first').height(), + left : event.pageX, + top : event.pageY, + opacity: .8 + }, 0 ); + + //establish current offsets + _dragData.offsets = []; + for ( var i = 0, l = columns.length; i < l; i++ ) { + _dragData.offsets.push( $( columns[ i ] ).offset().left ); + } + + //conclude event + obj.trigger( $.extend( eventData, { phase: 'after' } ) ); + }, 150 );//end timeout wrapper + } + + function dragColOver ( event ) { + if ( !_dragData.pressed ) return; + + var cursorX = event.originalEvent.pageX, + cursorY = event.originalEvent.pageY, + offsets = _dragData.offsets, + lastWidth = $( '.w2ui-head:not(.w2ui-head-last)' ).width(); + + _dragData.targetInt = Math.max(_dragData.numberPreColumnsPresent,targetIntersection( cursorX, offsets, lastWidth )); + + markIntersection( _dragData.targetInt ); + trackGhost( cursorX, cursorY ); + } + + function dragColEnd ( event ) { + _dragData.pressed = false; + + var eventData, + target, + selected, + columnConfig, + targetColumn, + ghosts = $( '.w2ui-grid-ghost' ); + + //start event for drag start + eventData = obj.trigger({ type: 'columnDragEnd', phase: 'before', originalEvent: event, target: _dragData.columnHead[0] }); + if ( eventData.isCancelled === true ) return false; + + selected = obj.columns[ _dragData.originalPos ]; + columnConfig = obj.columns; + targetColumn = $( _dragData.columns[ Math.min(_dragData.lastInt, _dragData.columns.length - 1) ] ); + target = (_dragData.lastInt < _dragData.columns.length) ? parseInt(targetColumn.attr('col')) : columnConfig.length; + + if ( target !== _dragData.originalPos + 1 && target !== _dragData.originalPos && targetColumn && targetColumn.length ) { + $( _dragData.ghost ).animate({ + top: $( obj.box ).offset().top, + left: targetColumn.offset().left, + width: 0, + height: 0, + opacity:.2 + }, 300, function(){ + $( this ).remove(); + ghosts.remove(); + }); + + columnConfig.splice( target, 0, $.extend( {}, selected ) ); + columnConfig.splice( columnConfig.indexOf( selected ), 1); + + } else { + $( _dragData.ghost ).remove(); + ghosts.remove(); + } + + //_dragData.columns.css({ overflow: '' }).children( 'div' ).css({ overflow: '' }); + + $( document ).off( 'mouseup', dragColEnd ); + $( document ).off( 'mousemove', dragColOver ); + if ( _dragData.marker ) _dragData.marker.remove(); + _dragData = {}; + + obj.refresh(); + + //conclude event + obj.trigger( $.extend( eventData, { phase: 'after', targetColumnNumber: target - 1 } ) ); + } + + function markIntersection( intersection ){ + if ( !_dragData.marker && !_dragData.markerLeft ) { + _dragData.marker = $('' + + '' + + '' + + ''); + _dragData.markerLeft = $('' + + '' + + '' + + ''); + } + + if ( !_dragData.lastInt || _dragData.lastInt !== intersection ){ + _dragData.lastInt = intersection; + _dragData.marker.remove(); + _dragData.markerLeft.remove(); + $('.w2ui-head').removeClass('w2ui-col-intersection'); + + //if the current intersection is greater than the number of columns add the marker to the end of the last column only + if ( intersection >= _dragData.columns.length ) { + $( _dragData.columns[ _dragData.columns.length - 1 ] ).children( 'div:last' ).append( _dragData.marker.addClass( 'right' ).removeClass( 'left' ) ); + $( _dragData.columns[ _dragData.columns.length - 1 ] ).addClass('w2ui-col-intersection'); + } else if ( intersection <= _dragData.numberPreColumnsPresent ) { + //if the current intersection is on the column numbers place marker on first available column only + $( _dragData.columns[ _dragData.numberPreColumnsPresent ] ).prepend( _dragData.marker.addClass( 'left' ).removeClass( 'right' ) ).css({ position: 'relative' }); + $( _dragData.columns[ _dragData.numberPreColumnsPresent ] ).prev().addClass('w2ui-col-intersection'); + } else { + //otherwise prepend the marker to the targeted column and append it to the previous column + $( _dragData.columns[intersection] ).children( 'div:last' ).prepend( _dragData.marker.addClass( 'left' ).removeClass( 'right' ) ); + $( _dragData.columns[intersection] ).prev().children( 'div:last' ).append( _dragData.markerLeft.addClass( 'right' ).removeClass( 'left' ) ).css({ position: 'relative' }); + $( _dragData.columns[intersection - 1] ).addClass('w2ui-col-intersection'); + } + } + } - getRecordsHTML: function () { - // larget number works better with chrome, smaller with FF. - if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300; - var records = $('#grid_'+ this.name +'_records'); - var limit = Math.floor(records.height() / this.recordHeight) + this.show_extra + 1; - if (!this.fixedBody) limit = this.buffered; - // always need first record for resizing purposes - var html = '' + this.getRecordHTML(-1, 0); - // first empty row with height - html += ''+ - ' '+ - ''; - for (var i = 0; i < limit; i++) { - html += this.getRecordHTML(i, i+1); - } - html += ''+ - ' '+ - ''+ - ''+ - ' '+ - ''+ - ''; - this.last.range_start = 0; - this.last.range_end = limit; - return html; - }, + function targetIntersection( cursorX, offsets, lastWidth ){ + if ( cursorX <= offsets[0] ) { + return 0; + } else if ( cursorX >= offsets[offsets.length - 1] + lastWidth ) { + return offsets.length; + } else { + for ( var i = 0, l = offsets.length; i < l; i++ ) { + var thisOffset = offsets[ i ]; + var nextOffset = offsets[ i + 1 ] || offsets[ i ] + lastWidth; + var midpoint = ( nextOffset - offsets[ i ]) / 2 + offsets[ i ]; + + if ( cursorX > thisOffset && cursorX <= midpoint ) { + return i; + } else if ( cursorX > midpoint && cursorX <= nextOffset ) { + return i + 1; + } + } + return intersection; + } + } - getSummaryHTML: function () { - if (this.summary.length == 0) return; - var html = ''; - for (var i = 0; i < this.summary.length; i++) { - html += this.getRecordHTML(i, i+1, true); - } - html += ''; - return html; - }, + function trackGhost( cursorX, cursorY ){ + $( _dragData.ghost ).css({ + left: cursorX - 10, + top: cursorY - 10 + }); + } - scroll: function (event) { - var time = (new Date()).getTime(); - var obj = this; - var records = $('#grid_'+ this.name +'_records'); - if (this.records.length == 0 || records.length == 0 || records.height() == 0) return; - if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300; - // need this to enable scrolling when this.limit < then a screen can fit - if (records.height() < this.buffered * this.recordHeight && records.css('overflow-y') == 'hidden') { - if (this.total > 0) this.refresh(); - return; - } - // update footer - var t1 = Math.floor(records[0].scrollTop / this.recordHeight + 1); - var t2 = Math.floor(records[0].scrollTop / this.recordHeight + 1) + Math.round(records.height() / this.recordHeight); - if (t1 > this.buffered) t1 = this.buffered; - if (t2 > this.buffered) t2 = this.buffered; - var url = (typeof this.url != 'object' ? this.url : this.url.get); - $('#grid_'+ this.name + '_footer .w2ui-footer-right').html(w2utils.formatNumber(this.offset + t1) + '-' + w2utils.formatNumber(this.offset + t2) + ' ' + w2utils.lang('of') + ' ' + w2utils.formatNumber(this.total) + - (url ? ' ('+ w2utils.lang('buffered') + ' '+ w2utils.formatNumber(this.buffered) + (this.offset > 0 ? ', skip ' + w2utils.formatNumber(this.offset) : '') + ')' : '') - ); - // only for local data source, else no extra records loaded - if (!url && (!this.fixedBody || this.total <= 300)) return; - // regular processing - var start = Math.floor(records[0].scrollTop / this.recordHeight) - this.show_extra; - var end = start + Math.floor(records.height() / this.recordHeight) + this.show_extra * 2 + 1; - // var div = start - this.last.range_start; - if (start < 1) start = 1; - if (end > this.total) end = this.total; - var tr1 = records.find('#grid_'+ this.name +'_rec_top'); - var tr2 = records.find('#grid_'+ this.name +'_rec_bottom'); - // if row is expanded - if (String(tr1.next().prop('id')).indexOf('_expanded_row') != -1) tr1.next().remove(); - if (String(tr2.prev().prop('id')).indexOf('_expanded_row') != -1) tr2.prev().remove(); - var first = parseInt(tr1.next().attr('line')); - var last = parseInt(tr2.prev().attr('line')); - //$('#log').html('buffer: '+ this.buffered +' start-end: ' + start + '-'+ end + ' ===> first-last: ' + first + '-' + last); - if (first < start || first == 1 || this.last.pull_refresh) { // scroll down - //console.log('end', end, 'last', last, 'show_extre', this.show_extra, this.last.pull_refresh); - if (end <= last + this.show_extra - 2 && end != this.total) return; - this.last.pull_refresh = false; - // remove from top - while (true) { - var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); - if (tmp.attr('line') == 'bottom') break; - if (parseInt(tmp.attr('line')) < start) tmp.remove(); else break; - } - // add at bottom - var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); - var rec_start = tmp.attr('line'); - if (rec_start == 'top') rec_start = start; - for (var i = parseInt(rec_start) + 1; i <= end; i++) { - if (!this.records[i-1]) continue; - if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; - tr2.before(this.getRecordHTML(i-1, i)); - } - markSearch(); - setTimeout(function() { obj.refreshRanges(); }, 0); - } else { // scroll up - if (start >= first - this.show_extra + 2 && start > 1) return; - // remove from bottom - while (true) { - var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); - if (tmp.attr('line') == 'top') break; - if (parseInt(tmp.attr('line')) > end) tmp.remove(); else break; - } - // add at top - var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); - var rec_start = tmp.attr('line'); - if (rec_start == 'bottom') rec_start = end; - for (var i = parseInt(rec_start) - 1; i >= start; i--) { - if (!this.records[i-1]) continue; - if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; - tr1.after(this.getRecordHTML(i-1, i)); - } - markSearch(); - setTimeout(function() { obj.refreshRanges(); }, 0); - } - // first/last row size - var h1 = (start - 1) * obj.recordHeight; - var h2 = (this.buffered - end) * obj.recordHeight; - if (h2 < 0) h2 = 0; - tr1.css('height', h1 + 'px'); - tr2.css('height', h2 + 'px'); - obj.last.range_start = start; - obj.last.range_end = end; - // load more if needed - var s = Math.floor(records[0].scrollTop / this.recordHeight); - var e = s + Math.floor(records.height() / this.recordHeight); - if (e + 10 > this.buffered && this.last.pull_more !== true && this.buffered < this.total - this.offset) { - if (this.autoLoad === true) { - this.last.pull_more = true; - this.last.xhr_offset += this.limit; - this.request('get-records'); - } else { - var more = $('#grid_'+ this.name +'_rec_more'); - if (more.css('display') == 'none') { - more.show() - .on('click', function () { - $(this).find('td').html(''); - obj.last.pull_more = true; - obj.last.xhr_offset += obj.limit; - obj.request('get-records'); - }); - } - if (more.find('td').text().indexOf('Load') == -1) { - more.find('td').html('Load '+ obj.limit + ' More...'); - } - } - } - // check for grid end - if (this.buffered >= this.total - this.offset) $('#grid_'+ this.name +'_rec_more').hide(); - return; - - function markSearch() { - // mark search - if(obj.markSearchResults === false) return; - clearTimeout(obj.last.marker_timer); - obj.last.marker_timer = setTimeout(function () { - // mark all search strings - var str = []; - for (var s in obj.searchData) { - var tmp = obj.searchData[s]; - if ($.inArray(tmp.value, str) == -1) str.push(tmp.value); - } - if (str.length > 0) $(obj.box).find('.w2ui-grid-data > div').w2marker(str); - }, 50); - } - }, + //return an object to remove drag if it has ever been enabled + return { + remove: function(){ + $( obj.box ).off( 'mousedown', dragColStart ); + $( obj.box ).off( 'mouseup', catchMouseup ); + $( obj.box ).find( '.w2ui-head' ).removeAttr( 'draggable' ); + obj.last.columnDrag = false; + } + } + }, - getRecordHTML: function (ind, lineNum, summary) { - var rec_html = ''; - // first record needs for resize purposes - if (ind == -1) { - rec_html += ''; - if (this.show.lineNumbers) rec_html += ''; - if (this.show.selectColumn) rec_html += ''; - if (this.show.expandColumn) rec_html += ''; - for (var i in this.columns) { - if (this.columns[i].hidden) continue; - rec_html += ''; - } - rec_html += ''; - rec_html += ''; - return rec_html; - } - // regular record - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (summary !== true) { - if (this.searchData.length > 0 && !url) { - if (ind >= this.last.searchIds.length) return ''; - ind = this.last.searchIds[ind]; - record = this.records[ind]; - } else { - if (ind >= this.records.length) return ''; - record = this.records[ind]; - } - } else { - if (ind >= this.summary.length) return ''; - record = this.summary[ind]; - } - if (!record) return ''; - var id = w2utils.escapeId(record.recid); - var isRowSelected = false; - if (record.selected && this.selectType == 'row') isRowSelected = true; - // render TR - rec_html += ''; - if (this.show.lineNumbers) { - rec_html += ''+ - (summary !== true ? ''+ lineNum +'' : '') + - ''; - } - if (this.show.selectColumn) { - rec_html += - ''+ - (summary !== true ? - ' '+ - ' '+ - ' ' - : - '' ) + - ''; - } - if (this.show.expandColumn) { - var tmp_img = ''; - if (record.expanded === true) tmp_img = '-'; else tmp_img = '+'; - if (record.expanded == 'none') tmp_img = ''; - if (record.expanded == 'spinner') tmp_img = ''; - rec_html += - ''+ - (summary !== true ? - ' '+ - ' '+ tmp_img +' ' - : - '' ) + - ''; - } - var col_ind = 0; - while (true) { - var col = this.columns[col_ind]; - if (col.hidden) { col_ind++; if (typeof this.columns[col_ind] == 'undefined') break; else continue; } - var isChanged = record.changed && record.changes[col.field]; - var rec_cell = this.getCellHTML(ind, col_ind, summary); - var addStyle = ''; - if (typeof col.render == 'string') { - var tmp = col.render.toLowerCase().split(':'); - if ($.inArray(tmp[0], ['number', 'int', 'float', 'money', 'percent']) != -1) addStyle = 'text-align: right'; - if ($.inArray(tmp[0], ['date']) != -1) addStyle = 'text-align: right'; - } - var isCellSelected = false; - if (record.selected && $.inArray(col_ind, record.selectedColumns) != -1) isCellSelected = true; - rec_html += ''+ - rec_cell + - ''; - col_ind++; - if (typeof this.columns[col_ind] == 'undefined') break; - } - rec_html += ''; - rec_html += ''; - // if row is expanded (buggy) - // if (record.expanded === true && $('#grid_'+ this.name +'_rec_'+ record.recid +'_expanded_row').length == 0) { - // var tmp = 1 + (this.show.selectColumn ? 1 : 0); - // rec_html += - // ''+ - // (this.show.lineNumbers ? '' : '') + - // ' '+ - // ' '+ - // ' '+ - // ' '+ - // ''; - // } - return rec_html; - }, + columnOnOff: function (el, event, field) { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'columnOnOff', checkbox: el, field: field, originalEvent: event }); + if (eventData.isCancelled === true) return; + // regular processing + var obj = this; + // collapse expanded rows + for (var r in this.records) { + if (this.records[r].expanded === true) this.records[r].expanded = false + } + // show/hide + var hide = true; + if (field == 'line-numbers') { + this.show.lineNumbers = !this.show.lineNumbers; + this.refresh(); + } else { + var col = this.getColumn(field); + if (col.hidden) { + $(el).prop('checked', true); + this.showColumn(col.field); + } else { + $(el).prop('checked', false); + this.hideColumn(col.field); + } + hide = false; + } + if (hide) { + setTimeout(function () { + $().w2overlay('', { name: 'searches-'+ this.name }); + obj.toolbar.uncheck('column-on-off'); + }, 100); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - getCellHTML: function (ind, col_ind, summary) { - var col = this.columns[col_ind]; - var record = (summary !== true ? this.records[ind] : this.summary[ind]); - var data = this.parseField(record, col.field); - var isChanged = record.changed && typeof record.changes[col.field] != 'undefined'; - if (isChanged) data = record.changes[col.field]; - // various renderers - if (data == null || typeof data == 'undefined') data = ''; - if (typeof col.render != 'undefined') { - if (typeof col.render == 'function') { - data = col.render.call(this, record, ind, col_ind); - if (data.length >= 4 && data.substr(0, 4) != ''; - } - if (typeof col.render == 'object') data = '' + col.render[data] + ''; - if (typeof col.render == 'string') { - var tmp = col.render.toLowerCase().split(':'); - var prefix = ''; - var suffix = ''; - if ($.inArray(tmp[0], ['number', 'int', 'float', 'money', 'percent']) != -1) { - if (typeof tmp[1] == 'undefined' || !w2utils.isInt(tmp[1])) tmp[1] = 0; - if (tmp[1] > 20) tmp[1] = 20; - if (tmp[1] < 0) tmp[1] = 0; - if (tmp[0] == 'money') { tmp[1] = 2; prefix = w2utils.settings.currencySymbol; } - if (tmp[0] == 'percent') { suffix = '%'; if (tmp[1] !== '0') tmp[1] = 1; } - if (tmp[0] == 'int') { tmp[1] = 0; } - // format - data = '' + prefix + w2utils.formatNumber(Number(data).toFixed(tmp[1])) + suffix + ''; - } - if (tmp[0] == 'date') { - if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.date_display; - data = '' + prefix + w2utils.formatDate(data, tmp[1]) + suffix + ''; - } - if (tmp[0] == 'age') { - data = '' + prefix + w2utils.age(data) + suffix + ''; - } - } - } else { - if (!this.show.recordTitles) { - var data = ''+ data +''; - } else { - // title overwrite - var title = String(data).replace(/"/g, "''"); - if (typeof col.title != 'undefined') { - if (typeof col.title == 'function') title = col.title.call(this, record, ind, col_ind); - if (typeof col.title == 'string') title = col.title; - } - var data = ''+ data +''; - } - } - if (data == null || typeof data == 'undefined') data = ''; - return data; - }, + initToolbar: function () { + // -- if toolbar is true + if (typeof this.toolbar['render'] == 'undefined') { + var tmp_items = this.toolbar.items; + this.toolbar.items = []; + this.toolbar = $().w2toolbar($.extend(true, {}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - getFooterHTML: function () { - return ''+ - ' '+ - ' '+ - ' '+ - ''; - }, + // ============================================= + // ------ Toolbar Generic buttons - status: function (msg) { - if (typeof msg != 'undefined') { - $('#grid_'+ this.name +'_footer').find('.w2ui-footer-left').html(msg); - } else { - // show number of selected - var msgLeft = ''; - var sel = this.getSelection(); - if (sel.length > 0) { - msgLeft = String(sel.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' ' + w2utils.lang('selected'); - var tmp = sel[0]; - if (typeof tmp == 'object') tmp = tmp.recid + ', '+ w2utils.lang('Column') +': '+ tmp.column; - if (sel.length == 1) msgLeft = w2utils.lang('Record ID') + ': '+ tmp + ' '; - } - $('#grid_'+ this.name +'_footer .w2ui-footer-left').html(msgLeft); - // toolbar - if (sel.length == 1) this.toolbar.enable('edit'); else this.toolbar.disable('edit'); - if (sel.length >= 1) this.toolbar.enable('delete'); else this.toolbar.disable('delete'); - } - }, + if (this.show.toolbarReload) { + this.toolbar.items.push($.extend(true, {}, this.buttons['reload'])); + } + if (this.show.toolbarColumns) { + this.toolbar.items.push($.extend(true, {}, this.buttons['columns'])); + } + if (this.show.toolbarReload || this.show.toolbarColumn) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break0' }); + } + if (this.show.toolbarSearch) { + var html = + ''+ + ''+ + ' '+ this.buttons['search'].html +''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''+ + ''; + this.toolbar.items.push({ type: 'html', id: 'w2ui-search', html: html }); + if (this.multiSearch && this.searches.length > 0) { + this.toolbar.items.push($.extend(true, {}, this.buttons['search-go'])); + } + } + if (this.show.toolbarSearch && (this.show.toolbarAdd || this.show.toolbarEdit || this.show.toolbarDelete || this.show.toolbarSave)) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break1' }); + } + if (this.show.toolbarAdd) { + this.toolbar.items.push($.extend(true, {}, this.buttons['add'])); + } + if (this.show.toolbarEdit) { + this.toolbar.items.push($.extend(true, {}, this.buttons['edit'])); + } + if (this.show.toolbarDelete) { + this.toolbar.items.push($.extend(true, {}, this.buttons['delete'])); + } + if (this.show.toolbarSave) { + if (this.show.toolbarAdd || this.show.toolbarDelete || this.show.toolbarEdit) { + this.toolbar.items.push({ type: 'break', id: 'w2ui-break2' }); + } + this.toolbar.items.push($.extend(true, {}, this.buttons['save'])); + } + // add original buttons + for (var i in tmp_items) this.toolbar.items.push(tmp_items[i]); - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - setTimeout(function () { w2utils.lock(box, msg, showSpinner); }, 10); - }, + // ============================================= + // ------ Toolbar onClick processing - unlock: function () { - var box = this.box; - setTimeout(function () { w2utils.unlock(box); }, 25); // needed timer so if server fast, it will not flash - }, + var obj = this; + this.toolbar.on('click', function (event) { + var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); + if (eventData.isCancelled === true) return; + var id = event.target; + switch (id) { + case 'w2ui-reload': + var eventData2 = obj.trigger({ phase: 'before', type: 'reload', target: obj.name }); + if (eventData2.isCancelled === true) return false; + obj.reload(); + obj.trigger($.extend(eventData2, { phase: 'after' })); + break; + case 'w2ui-column-on-off': + obj.initColumnOnOff(); + obj.initResize(); + obj.resize(); + break; + case 'w2ui-search-advanced': + var tb = this; + var it = this.get(id); + if (it.checked) { + obj.searchClose(); + setTimeout(function () { tb.uncheck(id); }, 1); + } else { + obj.searchOpen(); + event.originalEvent.stopPropagation(); + function tmp_close() { + if ($('#w2ui-overlay-searches-'+ obj.name).data('keepOpen') === true) return; + tb.uncheck(id); + $(document).off('click', 'body', tmp_close); + } + $(document).on('click', 'body', tmp_close); + } + break; + case 'w2ui-add': + // events + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'add', recid: null }); + obj.trigger($.extend(eventData, { phase: 'after' })); + break; + case 'w2ui-edit': + var sel = obj.getSelection(); + var recid = null; + if (sel.length == 1) recid = sel[0]; + // events + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'edit', recid: recid }); + obj.trigger($.extend(eventData, { phase: 'after' })); + break; + case 'w2ui-delete': + obj["delete"](); + break; + case 'w2ui-save': + obj.save(); + break; + } + // no default action + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + } + return; + }, - parseField: function (obj, field) { - var val = ''; - try { // need this to make sure no error in fields - val = obj; - var tmp = String(field).split('.'); - for (var i in tmp) { - val = val[tmp[i]]; - } - } catch (event) { - val = ''; - } - return val; - } - } + initResize: function () { + var obj = this; + //if (obj.resizing === true) return; + $(this.box).find('.w2ui-resizer') + .off('click') + .on('click', function (event) { + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + if (event.preventDefault) event.preventDefault(); + }) + .off('mousedown') + .on('mousedown', function (event) { + if (!event) event = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + obj.resizing = true; + obj.last.tmp = { + x : event.screenX, + y : event.screenY, + gx : event.screenX, + gy : event.screenY, + col : parseInt($(this).attr('name')) + }; + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + if (event.preventDefault) event.preventDefault(); + // fix sizes + for (var c in obj.columns) { + if (typeof obj.columns[c].sizeOriginal == 'undefined') obj.columns[c].sizeOriginal = obj.columns[c].size; + obj.columns[c].size = obj.columns[c].sizeCalculated; + } + var eventData = { phase: 'before', type: 'columnResize', target: obj.name, column: obj.last.tmp.col, field: obj.columns[obj.last.tmp.col].field }; + eventData = obj.trigger($.extend(eventData, { resizeBy: 0, originalEvent: event })); + // set move event + var mouseMove = function (event) { + if (obj.resizing != true) return; + if (!event) event = window.event; + // event before + eventData = obj.trigger($.extend(eventData, { resizeBy: (event.screenX - obj.last.tmp.gx), originalEvent: event })); + if (eventData.isCancelled === true) { eventData.isCancelled = false; return; } + // default action + obj.last.tmp.x = (event.screenX - obj.last.tmp.x); + obj.last.tmp.y = (event.screenY - obj.last.tmp.y); + obj.columns[obj.last.tmp.col].size = (parseInt(obj.columns[obj.last.tmp.col].size) + obj.last.tmp.x) + 'px'; + obj.resizeRecords(); + // reset + obj.last.tmp.x = event.screenX; + obj.last.tmp.y = event.screenY; + } + var mouseUp = function (event) { + delete obj.resizing; + $(document).off('mousemove', 'body'); + $(document).off('mouseup', 'body'); + obj.resizeRecords(); + // event before + obj.trigger($.extend(eventData, { phase: 'after', originalEvent: event })); + } + $(document).on('mousemove', 'body', mouseMove); + $(document).on('mouseup', 'body', mouseUp); + }) + .each(function (index, el) { + var td = $(el).parent(); + $(el).css({ + "height" : '25px', + "margin-left" : (td.width() - 3) + 'px' + }) + }); + }, + + resizeBoxes: function () { + // elements + var main = $(this.box).find('> div'); + var header = $('#grid_'+ this.name +'_header'); + var toolbar = $('#grid_'+ this.name +'_toolbar'); + var summary = $('#grid_'+ this.name +'_summary'); + var footer = $('#grid_'+ this.name +'_footer'); + var body = $('#grid_'+ this.name +'_body'); + var columns = $('#grid_'+ this.name +'_columns'); + var records = $('#grid_'+ this.name +'_records'); + + if (this.show.header) { + header.css({ + top: '0px', + left: '0px', + right: '0px' + }); + } - $.extend(w2grid.prototype, w2utils.event); - w2obj.grid = w2grid; -})(jQuery); + if (this.show.toolbar) { + toolbar.css({ + top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + } + if (this.show.footer) { + footer.css({ + bottom: '0px', + left: '0px', + right: '0px' + }); + } + if (this.summary.length > 0) { + summary.css({ + bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + } + body.css({ + top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) + (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) ) + 'px', + bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) + (this.summary.length > 0 ? w2utils.getSize(summary, 'height') : 0) ) + 'px', + left: '0px', + right: '0px' + }); + }, -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2layout - layout widget - * - $().w2layout - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2toolbar, w2tabs - * - * == NICE TO HAVE == - * - onResize for the panel - * - problem with layout.html (see in 1.3) - * - add panel title - * - ************************************************************************/ + resizeRecords: function () { + var obj = this; + // remove empty records + $(this.box).find('.w2ui-empty-record').remove(); + // -- Calculate Column size in PX + var box = $(this.box); + var grid = $(this.box).find('> div'); + var header = $('#grid_'+ this.name +'_header'); + var toolbar = $('#grid_'+ this.name +'_toolbar'); + var summary = $('#grid_'+ this.name +'_summary'); + var footer = $('#grid_'+ this.name +'_footer'); + var body = $('#grid_'+ this.name +'_body'); + var columns = $('#grid_'+ this.name +'_columns'); + var records = $('#grid_'+ this.name +'_records'); + + // body might be expanded by data + if (!this.fixedBody) { + // allow it to render records, then resize + var calculatedHeight = w2utils.getSize(columns, 'height') + + w2utils.getSize($('#grid_'+ obj.name +'_records table'), 'height'); + obj.height = calculatedHeight + + w2utils.getSize(grid, '+height') + + (obj.show.header ? w2utils.getSize(header, 'height') : 0) + + (obj.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) + + (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) + + (obj.show.footer ? w2utils.getSize(footer, 'height') : 0); + grid.css('height', obj.height); + body.css('height', calculatedHeight); + box.css('height', w2utils.getSize(grid, 'height') + w2utils.getSize(box, '+height')); + } else { + // fixed body height + var calculatedHeight = grid.height() + - (this.show.header ? w2utils.getSize(header, 'height') : 0) + - (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) + - (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0) + - (this.show.footer ? w2utils.getSize(footer, 'height') : 0); + body.css('height', calculatedHeight); + } -(function ($) { - var w2layout = function (options) { - this.box = null // DOM Element that holds the element - this.name = null; // unique name for w2ui - this.panels = []; - this.tmp = {}; - - this.padding = 1; // panel padding - this.resizer = 4; // resizer width or height - this.style = ''; - - this.onShow = null; - this.onHide = null; - this.onResizing = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null - - $.extend(true, this, w2obj.layout, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2layout = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - var panels = method.panels; - var object = new w2layout(method); - $.extend(object, { handlers: [], panels: [] }); - // add defined panels panels - for (var p in panels) { - object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, panels[p]); - if ($.isPlainObject(object.panels[p].tabs) || $.isArray(object.panels[p].tabs)) initTabs(object, panels[p].type); - if ($.isPlainObject(object.panels[p].toolbar) || $.isArray(object.panels[p].toolbar)) initToolbar(object, panels[p].type); - } - // add all other panels - for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) { - if (object.get(p) != null) continue; - object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, { type: p, hidden: true, size: 50 }); - } - - if ($(this).length > 0) { - object.render($(this)[0]); - } - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2layout' ); - } + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + // check overflow + var bodyOverflowX = false; + var bodyOverflowY = false; + if (body.width() < $(records).find('>table').width()) bodyOverflowX = true; + if (body.height() - columns.height() < $(records).find('>table').height() + (bodyOverflowX ? w2utils.scrollBarSize() : 0)) bodyOverflowY = true; + if (!this.fixedBody) { bodyOverflowY = false; bodyOverflowX = false; } + if (bodyOverflowX || bodyOverflowY) { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); + records.css({ + top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', + "-webkit-overflow-scrolling": "touch", + "overflow-x": (bodyOverflowX ? 'auto' : 'hidden'), + "overflow-y": (bodyOverflowY ? 'auto' : 'hidden') }); + } else { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').hide(); + records.css({ + top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px', + overflow: 'hidden' + }); + if (records.length > 0) { this.last.scrollTop = 0; this.last.scrollLeft = 0; } // if no scrollbars, always show top + } + if (this.show.emptyRecords && !bodyOverflowY) { + var max = Math.floor(records.height() / this.recordHeight) + 1; + if (this.fixedBody) { + for (var di = buffered; di <= max; di++) { + var html = ''; + html += ''; + if (this.show.lineNumbers) html += ''; + if (this.show.selectColumn) html += ''; + if (this.show.expandColumn) html += ''; + var j = 0; + while (true && this.columns.length > 0) { + var col = this.columns[j]; + if (col.hidden) { j++; if (typeof this.columns[j] == 'undefined') break; else continue; } + html += ''; + j++; + if (typeof this.columns[j] == 'undefined') break; + } + html += ''; + html += ''; + $('#grid_'+ this.name +'_records > table').append(html); + } + } + } + if (body.length > 0) { + var width_max = parseInt(body.width()) + - (bodyOverflowY ? w2utils.scrollBarSize() : 0) + - (this.show.lineNumbers ? 34 : 0) + - (this.show.selectColumn ? 26 : 0) + - (this.show.expandColumn ? 26 : 0); + var width_box = width_max; + var percent = 0; + // gridMinWidth processiong + var restart = false; + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.gridMinWidth > 0) { + if (col.gridMinWidth > width_box && col.hidden !== true) { + col.hidden = true; + restart = true; + } + if (col.gridMinWidth < width_box && col.hidden === true) { + col.hidden = false; + restart = true; + } + } + } + if (restart === true) { + this.refresh(); + return; + } + // assign PX column s + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (String(col.size).substr(String(col.size).length-2).toLowerCase() == 'px') { + width_max -= parseFloat(col.size); + this.columns[i].sizeCalculated = col.size; + this.columns[i].sizeType = 'px'; + } else { + percent += parseFloat(col.size); + this.columns[i].sizeType = '%'; + delete col.sizeCorrected; + } + } + // if sum != 100% -- reassign proportionally + if (percent != 100 && percent > 0) { + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (col.sizeType == '%') { + col.sizeCorrected = Math.round(parseFloat(col.size) * 100 * 100 / percent) / 100 + '%'; + } + } + } + // calculate % columns + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (col.sizeType == '%') { + if (typeof this.columns[i].sizeCorrected != 'undefined') { + // make it 1px smaller, so margin of error can be calculated correctly + this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.sizeCorrected) / 100) - 1 + 'px'; + } else { + // make it 1px smaller, so margin of error can be calculated correctly + this.columns[i].sizeCalculated = Math.floor(width_max * parseFloat(col.size) / 100) - 1 + 'px'; + } + } + } + } + // fix margin of error that is due percentage calculations + var width_cols = 0; + for (var i = 0; i < this.columns.length; i++) { + var col = this.columns[i]; + if (col.hidden) continue; + if (typeof col.min == 'undefined') col.min = 20; + if (parseInt(col.sizeCalculated) < parseInt(col.min)) col.sizeCalculated = col.min + 'px'; + if (parseInt(col.sizeCalculated) > parseInt(col.max)) col.sizeCalculated = col.max + 'px'; + width_cols += parseInt(col.sizeCalculated); + } + var width_diff = parseInt(width_box) - parseInt(width_cols); + if (width_diff > 0 && percent > 0) { + var i = 0; + while (true) { + var col = this.columns[i]; + if (typeof col == 'undefined') { i = 0; continue; } + if (col.hidden || col.sizeType == 'px') { i++; continue; } + col.sizeCalculated = (parseInt(col.sizeCalculated) + 1) + 'px'; + width_diff--; + if (width_diff == 0) break; + i++; + } + } else if (width_diff > 0) { + columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show(); + } + // resize columns + columns.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-head-last')) { + $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + // if there are column groups - hide first row (needed for sizing) + if (columns.find('> table > tbody > tr').length == 3) { + columns.find('> table > tbody > tr:nth-child(1) td').html('').css({ + 'height' : '0px', + 'border' : '0px', + 'padding': '0px', + 'margin' : '0px' + }); + } + // resize records + records.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-grid-data-last')) { + $(el).css('width', (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + // resize summary + summary.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) { + var ind = $(el).attr('col'); + if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated); + // last column + if ($(el).hasClass('w2ui-grid-data-last')) { + $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px'); + } + }); + this.initResize(); + this.refreshRanges(); + // apply last scroll if any + if ((this.last.scrollTop || this.last.scrollLeft) && records.length > 0) { + columns.prop('scrollLeft', this.last.scrollLeft); + records.prop('scrollTop', this.last.scrollTop); + records.prop('scrollLeft', this.last.scrollLeft); + } + }, + + getSearchesHTML: function () { + var html = ''; + var showBtn = false; + for (var i = 0; i < this.searches.length; i++) { + var s = this.searches[i]; + s.type = String(s.type).toLowerCase(); + if (s.hidden) continue; + var btn = ''; + if (showBtn == false) { + btn = 'X'+ + ' '+ w2utils.lang('is') +''+ + ' '+ w2utils.lang('begins') +''+ + ' '+ w2utils.lang('contains') +''+ + ' '+ w2utils.lang('ends') +''+ + ''; + } + if (['int', 'float', 'money', 'currency', 'percent', 'date', 'time'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('is') +''+ + (['int'].indexOf(s.type) != -1 ? ''+ w2utils.lang('in') +'' : '') + + (['int'].indexOf(s.type) != -1 ? ''+ w2utils.lang('not in') +'' : '') + + ''+ w2utils.lang('between') +''+ + ''; + } + if (['select', 'list', 'hex'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('is') +''+ + ''; + } + if (['enum'].indexOf(s.type) != -1) { + var operator = ''+ + ' '+ w2utils.lang('in') +''+ + ' '+ w2utils.lang('not in') +''+ + ''; + } + html += ''+ + ' '+ btn +'' + + ' '+ s.caption +'' + + ' '+ operator +''+ + ' '; + + switch (s.type) { + case 'text': + case 'alphanumeric': + case 'hex': + case 'list': + case 'combo': + case 'enum': + html += ''; + break; + + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'date': + case 'time': + html += ''+ + ''+ + ' - '+ + ''; + break; + + case 'select': + html += ''; + break; - function initTabs(object, panel, tabs) { - var pan = object.get(panel); - if (pan != null && typeof tabs == 'undefined') tabs = pan.tabs; - if (pan == null || tabs == null) return false; - // instanciate tabs - if ($.isArray(tabs)) tabs = { tabs: tabs }; - $().w2destroy(object.name + '_' + panel + '_tabs'); // destroy if existed - pan.tabs = $().w2tabs($.extend({}, tabs, { owner: object, name: object.name + '_' + panel + '_tabs' })); - pan.show.tabs = true; - return true; - } + } + html += s.outTag + + ' ' + + ''; + } + html += ''+ + ' '+ + ' '+ + ' '+ w2utils.lang('Reset') + ''+ + ' '+ w2utils.lang('Search') + ''+ + ' '+ + ' '+ + ''; + return html; + }, + + initOperator: function (el, search_ind) { + var obj = this; + var search = obj.searches[search_ind]; + var range = $('#grid_'+ obj.name + '_range_'+ search_ind); + var fld1 = $('#grid_'+ obj.name +'_field_'+ search_ind); + var fld2 = fld1.parent().find('span input'); + if ($(el).val() == 'in' || $(el).val() == 'not in') { fld1.w2field('clear'); } else { fld1.w2field(search.type); } + if ($(el).val() == 'between') { range.show(); fld2.w2field(search.type); } else { range.hide(); } + }, + + initSearches: function () { + var obj = this; + // init searches + for (var s in this.searches) { + var search = this.searches[s]; + var sdata = this.getSearchData(search.field); + search.type = String(search.type).toLowerCase(); + if (typeof search.options != 'object') search.options = {}; + // init types + switch (search.type) { + case 'text': + case 'alphanumeric': + $('#grid_'+ this.name +'_operator_'+s).val('begins'); + if (['alphanumeric', 'hex'].indexOf(search.type) != -1) { + $('#grid_'+ this.name +'_field_' + s).w2field(search.type, search.options); + } + break; + + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'date': + case 'time': + if (sdata && sdata.type == 'int' && ['in', 'not in'].indexOf(sdata.operator) != -1) break; + $('#grid_'+ this.name +'_field_'+s).w2field(search.type, search.options); + $('#grid_'+ this.name +'_field2_'+s).w2field(search.type, search.options); + setTimeout(function () { // convert to date if it is number + $('#grid_'+ obj.name +'_field_'+s).keydown(); + $('#grid_'+ obj.name +'_field2_'+s).keydown(); + }, 1); + break; + + case 'hex': + break; + + case 'list': + case 'combo': + case 'enum': + var options = search.options; + if (search.type == 'list') options.selected = {}; + if (search.type == 'enum') options.selected = []; + if (sdata) options.selected = sdata.value; + $('#grid_'+ this.name +'_field_'+s).w2field(search.type, options); + if (search.type == 'combo') { + $('#grid_'+ this.name +'_operator_'+s).val('begins'); + } + break; + + case 'select': + // build options + var options = '--'; + for (var i in search.options.items) { + var si = search.options.items[i]; + if ($.isPlainObject(search.options.items[i])) { + var val = si.id; + var txt = si.text; + if (typeof val == 'undefined' && typeof si.value != 'undefined') val = si.value; + if (typeof txt == 'undefined' && typeof si.caption != 'undefined') txt = si.caption; + if (val == null) val = ''; + options += ''+ txt +''; + } else { + options += ''+ si +''; + } + } + $('#grid_'+ this.name +'_field_'+s).html(options); + break; + } + if (sdata != null) { + if (sdata.type == 'int' && ['in', 'not in'].indexOf(sdata.operator) != -1) { + $('#grid_'+ this.name +'_field_'+ s).w2field('clear').val(sdata.value); + } + $('#grid_'+ this.name +'_operator_'+ s).val(sdata.operator).trigger('change'); + if (!$.isArray(sdata.value)) { + if (typeof sdata.value != 'udefined') $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); + } else { + if (['in', 'not in'].indexOf(sdata.operator) != -1) { + $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change'); + } else { + $('#grid_'+ this.name +'_field_'+ s).val(sdata.value[0]).trigger('change'); + $('#grid_'+ this.name +'_field2_'+ s).val(sdata.value[1]).trigger('change'); + } + } + } + } + // add on change event + $('#w2ui-overlay-searches-'+ this.name +' .w2ui-grid-searches *[rel=search]').on('keypress', function (evnt) { + if (evnt.keyCode == 13) { + obj.search(); + $().w2overlay(); + } + }); + }, + + getColumnsHTML: function () { + var obj = this; + var html = ''; + if (this.show.columnHeaders) { + if (this.columnGroups.length > 0) { + html = getColumns(true) + getGroups() + getColumns(false); + } else { + html = getColumns(true); + } + } + return html; - function initToolbar(object, panel, toolbar) { - var pan = object.get(panel); - if (pan != null && typeof toolbar == 'undefined') toolbar = pan.toolbar; - if (pan == null || toolbar == null) return false; - // instanciate toolbar - if ($.isArray(toolbar)) toolbar = { items: toolbar }; - $().w2destroy(object.name + '_' + panel + '_toolbar'); // destroy if existed - pan.toolbar = $().w2toolbar($.extend({}, toolbar, { owner: object, name: object.name + '_' + panel + '_toolbar' })); - pan.show.toolbar = true; - return true; - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2layout.prototype = { - // default setting for a panel - panel: { - type : null, // left, right, top, bottom - size : 100, // width or height depending on panel name - minSize : 20, - hidden : false, - resizable : false, - overflow : 'auto', - style : '', - content : '', // can be String or Object with .render(box) method - tabs : null, - toolbar : null, - width : null, // read only - height : null, // read only - show : { - toolbar : false, - tabs : false - }, - onRefresh : null, - onShow : null, - onHide : null - }, + function getGroups () { + var html = ''; + // add empty group at the end + if (obj.columnGroups[obj.columnGroups.length-1].caption != '') obj.columnGroups.push({ caption: '' }); - // alias for content - html: function (panel, data, transition) { - return this.content(panel, data, transition); - }, + if (obj.show.lineNumbers) { + html += ''+ + ' '+ + ''; + } + if (obj.show.selectColumn) { + html += ''+ + ' '+ + ''; + } + if (obj.show.expandColumn) { + html += ''+ + ' '+ + ''; + } + var ii = 0; + for (var i=0; i'; + } + html += ''+ + resizer + + ' '+ + ' '+ + (!col.caption ? ' ' : col.caption) + + ' '+ + ''; + } else { + html += ''+ + ' '+ + (!colg.caption ? ' ' : colg.caption) + + ' '+ + ''; + } + ii += colg.span; + } + html += ''; + return html; + } - content: function (panel, data, transition) { - var obj = this; - var p = this.get(panel); - if (panel == 'css') { - $('#layout_'+ obj.name +'_panel_css').html(''); - return true; - } - if (p == null) return false; - if ($('#layout_'+ this.name + '_panel2_'+ p.type).length > 0) return false; - $('#layout_'+ this.name + '_panel_'+ p.type).scrollTop(0); - if (data == null || typeof data == 'undefined') { - return p.content; - } else { - if (data instanceof jQuery) { - console.log('ERROR: You can not pass jQuery object to w2layout.content() method'); - return false; - } - // remove foreign classes and styles - var tmp = $('#'+ 'layout_'+ this.name + '_panel_'+ panel + ' > .w2ui-panel-content'); - var panelTop = $(tmp).position().top; - tmp.attr('class', 'w2ui-panel-content'); - if (tmp.length > 0 && typeof p.style != 'undefined') tmp[0].style.cssText = p.style; - if (p.content == '') { - p.content = data; - if (!p.hidden) this.refresh(panel); - } else { - p.content = data; - if (!p.hidden) { - if (transition != null && transition != '' && typeof transition != 'undefined') { - // apply transition - var nm = 'layout_'+ this.name + '_panel_'+ p.type; - var div1 = $('#'+ nm + ' > .w2ui-panel-content'); - div1.after(''); - var div2 = $('#'+ nm + ' > .w2ui-panel-content.new-panel'); - div1.css('top', panelTop); - div2.css('top', panelTop); - if (typeof data == 'object') { - data.box = div2[0]; // do not do .render(box); - data.render(); - } else { - div2.html(data); - } - w2utils.transition(div1[0], div2[0], transition, function () { - div1.remove(); - div2.removeClass('new-panel'); - div2.css('overflow', p.overflow); - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - }); + function getColumns (master) { + var html = '', + reorderCols = (obj.reorderColumns && (!obj.columnGroups || !obj.columnGroups.length)) ? ' w2ui-reorder-cols-head ' : ''; + if (obj.show.lineNumbers) { + html += ''+ + ' #'+ + ''; + } + if (obj.show.selectColumn) { + html += ''+ + ' '+ + ' '+ + ' '+ + ''; + } + if (obj.show.expandColumn) { + html += ''+ + ' '+ + ''; + } + var ii = 0; + var id = 0; + for (var i=0; i'; + } + html += ''+ + resizer + + ' '+ + ' '+ + (!col.caption ? ' ' : col.caption) + + ' '+ + ''; + } + } + html += ' '; + html += ''; + return html; + } + }, + + getRecordsHTML: function () { + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + // larget number works better with chrome, smaller with FF. + if (buffered > 300) this.show_extra = 30; else this.show_extra = 300; + var records = $('#grid_'+ this.name +'_records'); + var limit = Math.floor(records.height() / this.recordHeight) + this.show_extra + 1; + if (!this.fixedBody || limit > buffered) limit = buffered; + // always need first record for resizing purposes + var html = '' + this.getRecordHTML(-1, 0); + // first empty row with height + html += ''+ + ' '+ + ''; + for (var i = 0; i < limit; i++) { + html += this.getRecordHTML(i, i+1); + } + html += ''+ + ' '+ + ''+ + ''+ + ' '+ + ''+ + ''; + this.last.range_start = 0; + this.last.range_end = limit; + return html; + }, + + getSummaryHTML: function () { + if (this.summary.length == 0) return; + var html = ''; + for (var i = 0; i < this.summary.length; i++) { + html += this.getRecordHTML(i, i+1, true); + } + html += ''; + return html; + }, + + scroll: function (event) { + var time = (new Date()).getTime(); + var obj = this; + var records = $('#grid_'+ this.name +'_records'); + var buffered = this.records.length; + if (this.searchData.length != 0 && !this.url) buffered = this.last.searchIds.length; + if (buffered == 0 || records.length == 0 || records.height() == 0) return; + if (buffered > 300) this.show_extra = 30; else this.show_extra = 300; + // need this to enable scrolling when this.limit < then a screen can fit + if (records.height() < buffered * this.recordHeight && records.css('overflow-y') == 'hidden') { + if (this.total > 0) this.refresh(); + return; + } + // update footer + var t1 = Math.round(records[0].scrollTop / this.recordHeight + 1); + var t2 = t1 + (Math.round(records.height() / this.recordHeight) - 1); + if (t1 > buffered) t1 = buffered; + if (t2 > buffered) t2 = buffered; + var url = (typeof this.url != 'object' ? this.url : this.url.get); + $('#grid_'+ this.name + '_footer .w2ui-footer-right').html(w2utils.formatNumber(this.offset + t1) + '-' + w2utils.formatNumber(this.offset + t2) + ' ' + w2utils.lang('of') + ' ' + w2utils.formatNumber(this.total) + + (url ? ' ('+ w2utils.lang('buffered') + ' '+ w2utils.formatNumber(buffered) + (this.offset > 0 ? ', skip ' + w2utils.formatNumber(this.offset) : '') + ')' : '') + ); + // only for local data source, else no extra records loaded + if (!url && (!this.fixedBody || this.total <= 300)) return; + // regular processing + var start = Math.floor(records[0].scrollTop / this.recordHeight) - this.show_extra; + var end = start + Math.floor(records.height() / this.recordHeight) + this.show_extra * 2 + 1; + // var div = start - this.last.range_start; + if (start < 1) start = 1; + if (end > this.total) end = this.total; + var tr1 = records.find('#grid_'+ this.name +'_rec_top'); + var tr2 = records.find('#grid_'+ this.name +'_rec_bottom'); + // if row is expanded + if (String(tr1.next().prop('id')).indexOf('_expanded_row') != -1) tr1.next().remove(); + if (this.total > end && String(tr2.prev().prop('id')).indexOf('_expanded_row') != -1) tr2.prev().remove(); + var first = parseInt(tr1.next().attr('line')); + var last = parseInt(tr2.prev().attr('line')); + //$('#log').html('buffer: '+ this.buffered +' start-end: ' + start + '-'+ end + ' ===> first-last: ' + first + '-' + last); + if (first < start || first == 1 || this.last.pull_refresh) { // scroll down + // console.log('end', end, 'last', last, 'show_extre', this.show_extra, this.last.pull_refresh); + if (end <= last + this.show_extra - 2 && end != this.total) return; + this.last.pull_refresh = false; + // remove from top + while (true) { + var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); + if (tmp.attr('line') == 'bottom') break; + if (parseInt(tmp.attr('line')) < start) tmp.remove(); else break; + } + // add at bottom + var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); + var rec_start = tmp.attr('line'); + if (rec_start == 'top') rec_start = start; + for (var i = parseInt(rec_start) + 1; i <= end; i++) { + if (!this.records[i-1]) continue; + if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; + tr2.before(this.getRecordHTML(i-1, i)); + } + markSearch(); + setTimeout(function() { obj.refreshRanges(); }, 0); + } else { // scroll up + if (start >= first - this.show_extra + 2 && start > 1) return; + // remove from bottom + while (true) { + var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev(); + if (tmp.attr('line') == 'top') break; + if (parseInt(tmp.attr('line')) > end) tmp.remove(); else break; + } + // add at top + var tmp = records.find('#grid_'+ this.name +'_rec_top').next(); + var rec_start = tmp.attr('line'); + if (rec_start == 'bottom') rec_start = end; + for (var i = parseInt(rec_start) - 1; i >= start; i--) { + if (!this.records[i-1]) continue; + if (this.records[i-1].expanded === true) this.records[i-1].expanded = false; + tr1.after(this.getRecordHTML(i-1, i)); + } + markSearch(); + setTimeout(function() { obj.refreshRanges(); }, 0); + } + // first/last row size + var h1 = (start - 1) * obj.recordHeight; + var h2 = (buffered - end) * obj.recordHeight; + if (h2 < 0) h2 = 0; + tr1.css('height', h1 + 'px'); + tr2.css('height', h2 + 'px'); + obj.last.range_start = start; + obj.last.range_end = end; + // load more if needed + var s = Math.floor(records[0].scrollTop / this.recordHeight); + var e = s + Math.floor(records.height() / this.recordHeight); + if (e + 10 > buffered && this.last.pull_more !== true && buffered < this.total - this.offset) { + if (this.autoLoad === true) { + this.last.pull_more = true; + this.last.xhr_offset += this.limit; + this.request('get-records'); + } else { + var more = $('#grid_'+ this.name +'_rec_more'); + if (more.css('display') == 'none') { + more.show() + .on('click', function () { + obj.last.pull_more = true; + obj.last.xhr_offset += obj.limit; + obj.request('get-records'); + // show spinner the last + $(this).find('td').html(''); + }); + } + if (more.find('td').text().indexOf('Load') == -1) { + more.find('td').html(''+ w2utils.lang('Load') + ' ' + obj.limit + ' ' + w2utils.lang('More') + '...'); + } + } + } + // check for grid end + if (buffered >= this.total - this.offset) $('#grid_'+ this.name +'_rec_more').hide(); + return; + + function markSearch() { + // mark search + if(obj.markSearch === false) return; + clearTimeout(obj.last.marker_timer); + obj.last.marker_timer = setTimeout(function () { + // mark all search strings + var str = []; + for (var s in obj.searchData) { + var tmp = obj.searchData[s]; + if ($.inArray(tmp.value, str) == -1) str.push(tmp.value); + } + if (str.length > 0) $(obj.box).find('.w2ui-grid-data > div').w2marker(str); + }, 50); + } + }, + + getRecordHTML: function (ind, lineNum, summary) { + var rec_html = ''; + var sel = this.last.selection; + var record; + // first record needs for resize purposes + if (ind == -1) { + rec_html += ''; + if (this.show.lineNumbers) rec_html += ''; + if (this.show.selectColumn) rec_html += ''; + if (this.show.expandColumn) rec_html += ''; + for (var i in this.columns) { + if (this.columns[i].hidden) continue; + rec_html += ''; + } + rec_html += ''; + rec_html += ''; + return rec_html; + } + // regular record + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (summary !== true) { + if (this.searchData.length > 0 && !url) { + if (ind >= this.last.searchIds.length) return ''; + ind = this.last.searchIds[ind]; + record = this.records[ind]; + } else { + if (ind >= this.records.length) return ''; + record = this.records[ind]; + } } else { - if (!p.hidden) this.refresh(panel); + if (ind >= this.summary.length) return ''; + record = this.summary[ind]; } - } - } - } - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - return true; - }, + if (!record) return ''; + var id = w2utils.escapeId(record.recid); + var isRowSelected = false; + if (sel.indexes.indexOf(ind) != -1) isRowSelected = true; + // render TR + rec_html += ''; + if (this.show.lineNumbers) { + rec_html += ''+ + (summary !== true ? ''+ lineNum +'' : '') + + ''; + } + if (this.show.selectColumn) { + rec_html += + ''+ + (summary !== true ? + ' '+ + ' '+ + ' ' + : + '' ) + + ''; + } + if (this.show.expandColumn) { + var tmp_img = ''; + if (record.expanded === true) tmp_img = '-'; else tmp_img = '+'; + if (record.expanded == 'none') tmp_img = ''; + if (record.expanded == 'spinner') tmp_img = ''; + rec_html += + ''+ + (summary !== true ? + ' '+ + ' '+ tmp_img +' ' + : + '' ) + + ''; + } + var col_ind = 0; + while (true) { + var col = this.columns[col_ind]; + if (col.hidden) { col_ind++; if (typeof this.columns[col_ind] == 'undefined') break; else continue; } + var isChanged = !summary && record.changes && typeof record.changes[col.field] != 'undefined'; + var rec_cell = this.getCellHTML(ind, col_ind, summary); + var addStyle = ''; + if (typeof col.render == 'string') { + var tmp = col.render.toLowerCase().split(':'); + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(tmp[0]) != -1) addStyle += 'text-align: right;'; + } + if (typeof record.style == 'object' && typeof record.style[col_ind] == 'string') { + addStyle += record.style[col_ind] + ';'; + } + var isCellSelected = false; + if (isRowSelected && $.inArray(col_ind, sel.columns[ind]) != -1) isCellSelected = true; + rec_html += ''+ + rec_cell + + ''; + col_ind++; + if (typeof this.columns[col_ind] == 'undefined') break; + } + rec_html += ''; + rec_html += ''; + return rec_html; + }, + + getCellHTML: function (ind, col_ind, summary) { + var col = this.columns[col_ind]; + var record = (summary !== true ? this.records[ind] : this.summary[ind]); + var data = this.getCellValue(ind, col_ind, summary); + var edit = col.editable; + // various renderers + if (typeof col.render != 'undefined') { + if (typeof col.render == 'function') { + data = $.trim(col.render.call(this, record, ind, col_ind)); + if (data.length < 4 || data.substr(0, 4).toLowerCase() != ''; + } + if (typeof col.render == 'object') data = '' + (col.render[data] || '') + ''; + if (typeof col.render == 'string') { + var tmp = col.render.toLowerCase().split(':'); + var prefix = ''; + var suffix = ''; + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(tmp[0]) != -1) { + if (typeof tmp[1] == 'undefined' || !w2utils.isInt(tmp[1])) tmp[1] = 0; + if (tmp[1] > 20) tmp[1] = 20; + if (tmp[1] < 0) tmp[1] = 0; + if (['money', 'currency'].indexOf(tmp[0]) != -1) { tmp[1] = w2utils.settings.currencyPrecision; prefix = w2utils.settings.currencyPrefix; suffix = w2utils.settings.currencySuffix } + if (tmp[0] == 'percent') { suffix = '%'; if (tmp[1] !== '0') tmp[1] = 1; } + if (tmp[0] == 'int') { tmp[1] = 0; } + // format + data = '' + (data !== '' ? prefix + w2utils.formatNumber(Number(data).toFixed(tmp[1])) + suffix : '') + ''; + } + if (tmp[0] == 'time') { + if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.time_format; + data = '' + prefix + w2utils.formatTime(data, tmp[1] == 'h12' ? 'hh:mi pm': 'h24:min') + suffix + ''; + } + if (tmp[0] == 'date') { + if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.date_display; + data = '' + prefix + w2utils.formatDate(data, tmp[1]) + suffix + ''; + } + if (tmp[0] == 'age') { + data = '' + prefix + w2utils.age(data) + suffix + ''; + } + if (tmp[0] == 'toggle') { + data = '' + prefix + (data ? 'Yes' : '') + suffix + ''; + } + } + } else { + // if editable checkbox + var addStyle = ''; + if (edit && ['checkbox', 'check'].indexOf(edit.type) != -1) { + var changeInd = summary ? -(ind + 1) : ind; + addStyle = 'text-align: center'; + data = ''; + } + if (!this.show.recordTitles) { + var data = ''+ data +''; + } else { + // title overwrite + var title = String(data).replace(/"/g, "''"); + if (typeof col.title != 'undefined') { + if (typeof col.title == 'function') title = col.title.call(this, record, ind, col_ind); + if (typeof col.title == 'string') title = col.title; + } + var data = ''+ data +''; + } + } + if (data == null || typeof data == 'undefined') data = ''; + return data; + }, + + getCellValue: function (ind, col_ind, summary) { + var col = this.columns[col_ind]; + var record = (summary !== true ? this.records[ind] : this.summary[ind]); + var data = this.parseField(record, col.field); + if (record.changes && typeof record.changes[col.field] != 'undefined') data = record.changes[col.field]; + if (data == null || typeof data == 'undefined') data = ''; + return data; + }, + + getFooterHTML: function () { + return ''+ + ' '+ + ' '+ + ' '+ + ''; + }, - load: function (panel, url, transition, onLoad) { - var obj = this; - if (panel == 'css') { - $.get(url, function (data, status, xhr) { - obj.content(panel, xhr.responseText); - if (onLoad) onLoad(); - }); - return true; - } - if (this.get(panel) != null) { - $.get(url, function (data, status, xhr) { - obj.content(panel, xhr.responseText, transition); - if (onLoad) onLoad(); - // IE Hack - if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100); - }); - return true; - } - return false; - }, + status: function (msg) { + if (typeof msg != 'undefined') { + $('#grid_'+ this.name +'_footer').find('.w2ui-footer-left').html(msg); + } else { + // show number of selected + var msgLeft = ''; + var sel = this.getSelection(); + if (sel.length > 0) { + msgLeft = String(sel.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' ' + w2utils.lang('selected'); + var tmp = sel[0]; + if (typeof tmp == 'object') tmp = tmp.recid + ', '+ w2utils.lang('Column') +': '+ tmp.column; + if (sel.length == 1) msgLeft = w2utils.lang('Record ID') + ': '+ tmp + ' '; + } + $('#grid_'+ this.name +'_footer .w2ui-footer-left').html(msgLeft); + // toolbar + if (sel.length == 1) this.toolbar.enable('w2ui-edit'); else this.toolbar.disable('w2ui-edit'); + if (sel.length >= 1) this.toolbar.enable('w2ui-delete'); else this.toolbar.disable('w2ui-delete'); + } + }, + + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + setTimeout(function () { w2utils.lock.apply(window, args); }, 10); + }, + + unlock: function () { + var box = this.box; + setTimeout(function () { w2utils.unlock(box); }, 25); // needed timer so if server fast, it will not flash + }, + + stateSave: function (returnOnly) { + if (!localStorage) return null; + var state = { + columns : [], + show : $.extend({}, this.show), + last : { + search : this.last.search, + multi : this.last.multi, + logic : this.last.logic, + caption : this.last.caption, + field : this.last.field, + scrollTop : this.last.scrollTop, + scrollLeft : this.last.scrollLeft + }, + sortData : [], + searchData : [] + }; + for (var i in this.columns) { + var col = this.columns[i]; + state.columns.push({ + field : col.field, + hidden : col.hidden, + size : col.size, + sizeCalculated : col.sizeCalculated, + sizeOriginal : col.sizeOriginal, + sizeType : col.sizeType + }); + } + for (var i in this.sortData) state.sortData.push($.extend({}, this.sortData[i])); + for (var i in this.searchData) state.searchData.push($.extend({}, this.searchData[i])); + // save into local storage + if (returnOnly !== true) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'stateSave', target: this.name, state: state }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + try { + var savedState = $.parseJSON(localStorage.w2ui || '{}'); + if (!savedState) savedState = {}; + if (!savedState.states) savedState.states = {}; + savedState.states[this.name] = state; + localStorage.w2ui = JSON.stringify(savedState); + } catch (e) { + delete localStorage.w2ui; + return null; + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + return state; + }, - sizeTo: function (panel, size) { - var obj = this; - var pan = obj.get(panel); - if (pan == null) return false; - // resize - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.35s', - '-moz-transition' : '.35s', - '-ms-transition' : '.35s', - '-o-transition' : '.35s' - }); - setTimeout(function () { - obj.set(panel, { size: size }); - }, 1); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.resize(); - }, 500); - return true; - }, + stateRestore: function (newState) { + var obj = this; + if (!newState) { + // read it from local storage + try { + if (!localStorage) return false; + var tmp = $.parseJSON(localStorage.w2ui || '{}'); + if (!tmp) tmp = {}; + if (!tmp.states) tmp.states = {}; + newState = tmp.states[this.name]; + } catch (e) { + delete localStorage.w2ui; + return null; + } + } + // event before + var eventData = this.trigger({ phase: 'before', type: 'stateRestore', target: this.name, state: newState }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + // default behavior + if ($.isPlainObject(newState)) { + $.extend(this.show, newState.show); + $.extend(this.last, newState.last); + var sTop = this.last.scrollTop; + var sLeft = this.last.scrollLeft; + for (var c in newState.columns) { + var tmp = newState.columns[c]; + var col = this.getColumn(tmp.field); + if (col) $.extend(col, tmp); + } + this.sortData.splice(0, this.sortData.length); + for (var c in newState.sortData) this.sortData.push(newState.sortData[c]); + this.searchData.splice(0, this.searchData.length); + for (var c in newState.searchData) this.searchData.push(newState.searchData[c]); + // apply sort and search + setTimeout(function () { + // needs timeout as records need to be populated + if (obj.sortData.length > 0) obj.localSort(); + if (obj.searchData.length > 0) obj.localSearch(); + obj.last.scrollTop = sTop; + obj.last.scrollLeft = sLeft; + obj.refresh(); + }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return true; + }, + + stateReset: function () { + this.stateRestore(this.last.state); + // remove from local storage + if (localStorage) { + try { + var tmp = $.parseJSON(localStorage.w2ui || '{}'); + if (tmp.states && tmp.states[this.name]) { + delete tmp.states[this.name]; + } + localStorage.w2ui = JSON.stringify(tmp); + } catch (e) { + delete localStorage.w2ui; + return null; + } + } + }, + + parseField: function (obj, field) { + var val = ''; + try { // need this to make sure no error in fields + val = obj; + var tmp = String(field).split('.'); + for (var i in tmp) { + val = val[tmp[i]]; + } + } catch (event) { + val = ''; + } + return val; + }, + + prepareData: function () { + // loops thru records and prepares date and time objects + for (var r in this.records) { + var rec = this.records[r]; + for (var c in this.columns) { + var column = this.columns[c]; + if (rec[column.field] == null || typeof column.render != 'string') continue; + // number + if (['number', 'int', 'float', 'money', 'currency', 'percent'].indexOf(column.render.split(':')[0]) != -1) { + if (typeof rec[column.field] != 'number') rec[column.field] = parseFloat(rec[column.field]); + } + // date + if (['date', 'age'].indexOf(column.render.split(':')[0]) != -1) { + if (!rec[column.field + '_']) { + var dt = rec[column.field]; + if (w2utils.isInt(dt)) dt = parseInt(dt); + rec[column.field + '_'] = new Date(dt); + } + } + // time + if (['time'].indexOf(column.render) != -1) { + if (w2utils.isTime(rec[column.field])) { // if string + var tmp = w2utils.isTime(rec[column.field], true); + var dt = new Date(); + dt.setHours(tmp.hours, tmp.minutes, (tmp.seconds ? tmp.seconds : 0), 0); // sets hours, min, sec, mills + if (!rec[column.field + '_']) rec[column.field + '_'] = dt; + } else { // if date object + var tmp = rec[column.field]; + if (w2utils.isInt(tmp)) tmp = parseInt(tmp); + var tmp = (tmp != null ? new Date(tmp) : new Date()); + var dt = new Date(); + dt.setHours(tmp.getHours(), tmp.getMinutes(), tmp.getSeconds(), 0); // sets hours, min, sec, mills + if (!rec[column.field + '_']) rec[column.field + '_'] = dt; + } + } + } + } + }, + + nextCell: function (col_ind, editable) { + var check = col_ind + 1; + if (this.columns.length == check) return null; + if (editable === true) { + var edit = this.columns[check].editable; + if (this.columns[check].hidden || typeof edit == 'undefined' + || (edit && ['checkbox', 'check'].indexOf(edit.type) != -1)) return this.nextCell(check, editable); + } + return check; + }, + + prevCell: function (col_ind, editable) { + var check = col_ind - 1; + if (check < 0) return null; + if (editable === true) { + var edit = this.columns[check].editable; + if (this.columns[check].hidden || typeof edit == 'undefined' + || (edit && ['checkbox', 'check'].indexOf(edit.type) != -1)) return this.prevCell(check, editable); + } + return check; + }, + + nextRow: function (ind) { + if ((ind + 1 < this.records.length && this.last.searchIds.length == 0) // if there are more records + || (this.last.searchIds.length > 0 && ind < this.last.searchIds[this.last.searchIds.length-1])) { + ind++; + if (this.last.searchIds.length > 0) { + while (true) { + if ($.inArray(ind, this.last.searchIds) != -1 || ind > this.records.length) break; + ind++; + } + } + return ind; + } else { + return null; + } + }, + + prevRow: function (ind) { + if ((ind > 0 && this.last.searchIds.length == 0) // if there are more records + || (this.last.searchIds.length > 0 && ind > this.last.searchIds[0])) { + ind--; + if (this.last.searchIds.length > 0) { + while (true) { + if ($.inArray(ind, this.last.searchIds) != -1 || ind < 0) break; + ind--; + } + } + return ind; + } else { + return null; + } + } + }; - show: function (panel, immediate) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', type: 'show', target: panel, object: this.get(panel), immediate: immediate }); - if (eventData.isCancelled === true) return false; - - var p = obj.get(panel); - if (p == null) return false; - p.hidden = false; - if (immediate === true) { - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '1' }); - if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show(); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - } else { - if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show(); - // resize - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.2s', - '-moz-transition' : '.2s', - '-ms-transition' : '.2s', - '-o-transition' : '.2s' - }); - setTimeout(function () { obj.resize(); }, 1); - // show - setTimeout(function() { - $('#layout_'+ obj.name +'_panel_'+ panel).css({ 'opacity': '1' }); - }, 250); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - }, 500); - } - return true; - }, + $.extend(w2grid.prototype, w2utils.event); + w2obj.grid = w2grid; +})(jQuery); - hide: function (panel, immediate) { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', type: 'hide', target: panel, object: this.get(panel), immediate: immediate }); - if (eventData.isCancelled === true) return false; - - var p = obj.get(panel); - if (p == null) return false; - p.hidden = true; - if (immediate === true) { - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - $('#layout_'+ obj.name +'_resizer_'+panel).hide(); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - } else { - $('#layout_'+ obj.name +'_resizer_'+panel).hide(); - // hide - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '.2s', - '-moz-transition' : '.2s', - '-ms-transition' : '.2s', - '-o-transition' : '.2s' - }); - $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); - setTimeout(function () { obj.resize(); }, 1); - // clean - setTimeout(function () { - $(obj.box).find(' > div .w2ui-panel').css({ - '-webkit-transition': '0s', - '-moz-transition' : '0s', - '-ms-transition' : '0s', - '-o-transition' : '0s' - }); - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.resize(); - }, 500); - } - return true; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2layout - layout widget +* - $().w2layout - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2toolbar, w2tabs +* +* == NICE TO HAVE == +* - onResize for the panel +* - add more panel title positions (left=rotated, right=rotated, bottom) +* - bug: resizer is visible (and onHover) when panel is hidden. +* - bug: when you assign content before previous transition completed. +* +************************************************************************/ - toggle: function (panel, immediate) { - var p = this.get(panel); - if (p == null) return false; - if (p.hidden) return this.show(panel, immediate); else return this.hide(panel, immediate); - }, +(function ($) { + var w2layout = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.panels = []; + this.tmp = {}; + + this.padding = 1; // panel padding + this.resizer = 4; // resizer width or height + this.style = ''; + + this.onShow = null; + this.onHide = null; + this.onResizing = null; + this.onResizerClick = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.layout, options); + }; + + /* @const */ var w2layout_panels = ['top', 'left', 'main', 'preview', 'right', 'bottom']; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2layout = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2layout')) return; + var panels = method.panels || []; + var object = new w2layout(method); + $.extend(object, { handlers: [], panels: [] }); + // add defined panels + for (var p = 0, len = panels.length; p < len; p++) { + object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, panels[p]); + if ($.isPlainObject(object.panels[p].tabs) || $.isArray(object.panels[p].tabs)) initTabs(object, panels[p].type); + if ($.isPlainObject(object.panels[p].toolbar) || $.isArray(object.panels[p].toolbar)) initToolbar(object, panels[p].type); + } + // add all other panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + if (object.get(p1) !== null) continue; + object.panels.push($.extend(true, {}, w2layout.prototype.panel, { type: p1, hidden: (p1 !== 'main'), size: 50 })); + } + if ($(this).length > 0) { + object.render($(this)[0]); + } + w2ui[object.name] = object; + return object; - set: function (panel, options) { - var obj = this.get(panel, true); - if (obj == null) return false; - $.extend(this.panels[obj], options); - this.refresh(panel); - this.resize(); // resize is needed when panel size is changed - return true; - }, + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; + } else { + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2layout' ); + } + + function initTabs(object, panel, tabs) { + var pan = object.get(panel); + if (pan !== null && typeof tabs == 'undefined') tabs = pan.tabs; + if (pan === null || tabs === null) return false; + // instanciate tabs + if ($.isArray(tabs)) tabs = { tabs: tabs }; + $().w2destroy(object.name + '_' + panel + '_tabs'); // destroy if existed + pan.tabs = $().w2tabs($.extend({}, tabs, { owner: object, name: object.name + '_' + panel + '_tabs' })); + pan.show.tabs = true; + return true; + } - get: function (panel, returnIndex) { - var obj = null; - for (var p in this.panels) { - if (this.panels[p].type == panel) { - if (returnIndex === true) return p; else return this.panels[p]; + function initToolbar(object, panel, toolbar) { + var pan = object.get(panel); + if (pan !== null && typeof toolbar == 'undefined') toolbar = pan.toolbar; + if (pan === null || toolbar === null) return false; + // instanciate toolbar + if ($.isArray(toolbar)) toolbar = { items: toolbar }; + $().w2destroy(object.name + '_' + panel + '_toolbar'); // destroy if existed + pan.toolbar = $().w2toolbar($.extend({}, toolbar, { owner: object, name: object.name + '_' + panel + '_toolbar' })); + pan.show.toolbar = true; + return true; } - } - return null; - }, + }; + + // ==================================================== + // -- Implementation of core functionality + + w2layout.prototype = { + // default setting for a panel + panel: { + type : null, // left, right, top, bottom + title : '', + size : 100, // width or height depending on panel name + minSize : 20, + maxSize : false, + hidden : false, + resizable : false, + overflow : 'auto', + style : '', + content : '', // can be String or Object with .render(box) method + tabs : null, + toolbar : null, + width : null, // read only + height : null, // read only + show : { + toolbar : false, + tabs : false + }, + onRefresh : null, + onShow : null, + onHide : null + }, + + // alias for content + html: function (panel, data, transition) { + return this.content(panel, data, transition); + }, + + content: function (panel, data, transition) { + var obj = this; + var p = this.get(panel); + // if it is CSS panel + if (panel == 'css') { + $('#layout_'+ obj.name +'_panel_css').html(''); + return true; + } + if (p === null) return false; + if (typeof data == 'undefined' || data === null) { + return p.content; + } else { + if (data instanceof jQuery) { + console.log('ERROR: You can not pass jQuery object to w2layout.content() method'); + return false; + } + var pname = '#layout_'+ this.name + '_panel_'+ p.type; + var current = $(pname + '> .w2ui-panel-content'); + var panelTop = 0; + if (current.length > 0) { + $(pname).scrollTop(0); + panelTop = $(current).position().top; + } + if (p.content === '') { + p.content = data; + this.refresh(panel); + } else { + p.content = data; + if (!p.hidden) { + if (transition !== null && transition !== '' && typeof transition != 'undefined') { + // apply transition + var div1 = $(pname + '> .w2ui-panel-content'); + div1.after(''); + var div2 = $(pname + '> .w2ui-panel-content.new-panel'); + div1.css('top', panelTop); + div2.css('top', panelTop); + if (typeof data == 'object') { + data.box = div2[0]; // do not do .render(box); + data.render(); + } else { + div2.html(data); + } + w2utils.transition(div1[0], div2[0], transition, function () { + div1.remove(); + div2.removeClass('new-panel'); + div2.css('overflow', p.overflow); + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + }); + } + } + this.refresh(panel); + } + } + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + return true; + }, - el: function (panel) { - var el = $('#layout_'+ this.name +'_panel_'+ panel +' .w2ui-panel-content'); - if (el.length != 1) return null; - return el[0]; - }, + load: function (panel, url, transition, onLoad) { + var obj = this; + if (panel == 'css') { + $.get(url, function (data, status, xhr) { // should always be $.get as it is template + obj.content(panel, xhr.responseText); + if (onLoad) onLoad(); + }); + return true; + } + if (this.get(panel) !== null) { + $.get(url, function (data, status, xhr) { // should always be $.get as it is template + obj.content(panel, xhr.responseText, transition); + if (onLoad) onLoad(); + // IE Hack + obj.resize(); + if (window.navigator.userAgent.indexOf('MSIE') != -1) setTimeout(function () { obj.resize(); }, 100); + }); + return true; + } + return false; + }, - hideToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.toolbar = false; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').hide(); - this.resize(); - }, + sizeTo: function (panel, size) { + var obj = this; + var pan = obj.get(panel); + if (pan === null) return false; + // resize + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + setTimeout(function () { + obj.set(panel, { size: size }); + }, 1); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.resize(); + }, 500); + return true; + }, - showToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.toolbar = true; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').show(); - this.resize(); - }, + show: function (panel, immediate) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', type: 'show', target: panel, object: this.get(panel), immediate: immediate }); + if (eventData.isCancelled === true) return; + + var p = obj.get(panel); + if (p === null) return false; + p.hidden = false; + if (immediate === true) { + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '1' }); + if (p.resizable) $('#layout_'+ obj.name +'_resizer_'+panel).show(); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + } else { + if (p.resizable) $('#layout_'+ obj.name +'_resizer_'+panel).show(); + // resize + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + setTimeout(function () { obj.resize(); }, 1); + // show + setTimeout(function() { + $('#layout_'+ obj.name +'_panel_'+ panel).css({ 'opacity': '1' }); + }, 250); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + }, 500); + } + return true; + }, - toggleToolbar: function (panel) { - var pan = this.get(panel); - if (!pan) return; - if (pan.show.toolbar) this.hideToolbar(panel); else this.showToolbar(panel); - }, + hide: function (panel, immediate) { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', type: 'hide', target: panel, object: this.get(panel), immediate: immediate }); + if (eventData.isCancelled === true) return; + + var p = obj.get(panel); + if (p === null) return false; + p.hidden = true; + if (immediate === true) { + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + $('#layout_'+ obj.name +'_resizer_'+panel).hide(); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + } else { + $('#layout_'+ obj.name +'_resizer_'+panel).hide(); + // hide + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '.2s', + '-moz-transition' : '.2s', + '-ms-transition' : '.2s', + '-o-transition' : '.2s' + }); + $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' }); + setTimeout(function () { obj.resize(); }, 1); + // clean + setTimeout(function () { + $(obj.box).find(' > div > .w2ui-panel').css({ + '-webkit-transition' : '0s', + '-moz-transition' : '0s', + '-ms-transition' : '0s', + '-o-transition' : '0s' + }); + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.resize(); + }, 500); + } + return true; + }, + + toggle: function (panel, immediate) { + var p = this.get(panel); + if (p === null) return false; + if (p.hidden) return this.show(panel, immediate); else return this.hide(panel, immediate); + }, + + set: function (panel, options) { + var obj = this.get(panel, true); + if (obj === null) return false; + $.extend(this.panels[obj], options); + if (typeof options['content'] != 'undefined') this.refresh(panel); // refresh only when content changed + this.resize(); // resize is needed when panel size is changed + return true; + }, - hideTabs: function (panel) { - var pan = this.get(panel); - if (!pan) return; - pan.show.tabs = false; - $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-tabs').hide(); - this.resize(); - }, + get: function (panel, returnIndex) { + for (var p in this.panels) { + if (this.panels[p].type == panel) { + if (returnIndex === true) return p; else return this.panels[p]; + } + } + return null; + }, + + el: function (panel) { + var el = $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-content'); + if (el.length != 1) return null; + return el[0]; + }, + + hideToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.toolbar = false; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-toolbar').hide(); + this.resize(); + }, + + showToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.toolbar = true; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-toolbar').show(); + this.resize(); + }, + + toggleToolbar: function (panel) { + var pan = this.get(panel); + if (!pan) return; + if (pan.show.toolbar) this.hideToolbar(panel); else this.showToolbar(panel); + }, + + hideTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.tabs = false; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-tabs').hide(); + this.resize(); + }, + + showTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + pan.show.tabs = true; + $('#layout_'+ this.name +'_panel_'+ panel +'> .w2ui-panel-tabs').show(); + this.resize(); + }, + + toggleTabs: function (panel) { + var pan = this.get(panel); + if (!pan) return; + if (pan.show.tabs) this.hideTabs(panel); else this.showTabs(panel); + }, + + render: function (box) { + var obj = this; + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + var time = (new Date()).getTime(); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'render', target: obj.name, box: box }); + if (eventData.isCancelled === true) return; + + if (typeof box != 'undefined' && box !== null) { + if ($(obj.box).find('#layout_'+ obj.name +'_panel_main').length > 0) { + $(obj.box) + .removeAttr('name') + .removeClass('w2ui-layout') + .html(''); + } + obj.box = box; + } + if (!obj.box) return false; + $(obj.box) + .attr('name', obj.name) + .addClass('w2ui-layout') + .html(''); + if ($(obj.box).length > 0) $(obj.box)[0].style.cssText += obj.style; + // create all panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + var pan = obj.get(p1); + var html = ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ''+ + ''; + $(obj.box).find(' > div').append(html); + // tabs are rendered in refresh() + } + $(obj.box).find(' > div') + .append(' .w2ui-panel-tabs').show(); - this.resize(); - }, + function resizeStart(type, evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + $(document).off('mousemove', obj.tmp.events.mouseMove).on('mousemove', obj.tmp.events.mouseMove); + $(document).off('mouseup', obj.tmp.events.mouseUp).on('mouseup', obj.tmp.events.mouseUp); + obj.tmp.resize = { + type : type, + x : evnt.screenX, + y : evnt.screenY, + diff_x : 0, + diff_y : 0, + value : 0 + }; + // lock all panels + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + obj.lock(p1, { opacity: 0 }); + } + if (type == 'left' || type == 'right') { + obj.tmp.resize.value = parseInt($('#layout_'+ obj.name +'_resizer_'+ type)[0].style.left); + } + if (type == 'top' || type == 'preview' || type == 'bottom') { + obj.tmp.resize.value = parseInt($('#layout_'+ obj.name +'_resizer_'+ type)[0].style.top); + } + } - toggleTabs: function (panel) { - var pan = this.get(panel); - if (!pan) return; - if (pan.show.tabs) this.hideTabs(panel); else this.showTabs(panel); - }, + function resizeStop(evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + $(document).off('mousemove', obj.tmp.events.mouseMove); + $(document).off('mouseup', obj.tmp.events.mouseUp); + if (typeof obj.tmp.resize == 'undefined') return; + // unlock all panels + for (var p1 in w2layout_panels) { + obj.unlock(w2layout_panels[p1]); + } + // set new size + if (obj.tmp.diff_x !== 0 || obj.tmp.resize.diff_y !== 0) { // only recalculate if changed + var ptop = obj.get('top'); + var pbottom = obj.get('bottom'); + var panel = obj.get(obj.tmp.resize.type); + var height = parseInt($(obj.box).height()); + var width = parseInt($(obj.box).width()); + var str = String(panel.size); + var ns, nd; + switch (obj.tmp.resize.type) { + case 'top': + ns = parseInt(panel.sizeCalculated) + obj.tmp.resize.diff_y; + nd = 0; + break; + case 'bottom': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_y; + nd = 0; + break; + case 'preview': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_y; + nd = (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) + + (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); + break; + case 'left': + ns = parseInt(panel.sizeCalculated) + obj.tmp.resize.diff_x; + nd = 0; + break; + case 'right': + ns = parseInt(panel.sizeCalculated) - obj.tmp.resize.diff_x; + nd = 0; + break; + } + // set size + if (str.substr(str.length-1) == '%') { + panel.size = Math.floor(ns * 100 / + (panel.type == 'left' || panel.type == 'right' ? width : height - nd) * 100) / 100 + '%'; + } else { + panel.size = ns; + } + obj.resize(); + } + $('#layout_'+ obj.name + '_resizer_'+ obj.tmp.resize.type).removeClass('active'); + delete obj.tmp.resize; + } - render: function (box) { - var obj = this; - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var time = (new Date()).getTime(); - // event before - var eventData = obj.trigger({ phase: 'before', type: 'render', target: obj.name, box: box }); - if (eventData.isCancelled === true) return false; - - if (typeof box != 'undefined' && box != null) { - if ($(obj.box).find('#layout_'+ obj.name +'_panel_main').length > 0) { - $(obj.box) - .removeAttr('name') - .removeClass('w2ui-layout') - .html(''); - } - obj.box = box; - } - if (!obj.box) return false; - $(obj.box) - .attr('name', obj.name) - .addClass('w2ui-layout') - .html(''); - if ($(obj.box).length > 0) $(obj.box)[0].style.cssText += obj.style; - // create all panels - var tmp = ['top', 'left', 'main', 'preview', 'right', 'bottom']; - for (var t in tmp) { - var pan = obj.get(tmp[t]); - var html = ''+ - ' '+ - ' '+ - ' '+ - ''+ - ''; - $(obj.box).find(' > div').append(html); - // tabs are rendered in refresh() - } - $(obj.box).find(' > div') - .append(' drag - if (obj.tmp.resizing == 'left' && (obj.get('left').minSize - obj.tmp.resize.div_x > obj.get('left').width)) { - obj.tmp.resize.div_x = obj.get('left').minSize - obj.get('left').width; - } - if (obj.tmp.resize.type == 'left' && (obj.get('main').minSize + obj.tmp.resize.div_x > obj.get('main').width)) { - obj.tmp.resize.div_x = obj.get('main').width - obj.get('main').minSize; - } - // right panel -> drag - if (obj.tmp.resize.type == 'right' && (obj.get('right').minSize + obj.tmp.resize.div_x > obj.get('right').width)) { - obj.tmp.resize.div_x = obj.get('right').width - obj.get('right').minSize; - } - if (obj.tmp.resize.type == 'right' && (obj.get('main').minSize - obj.tmp.resize.div_x > obj.get('main').width)) { - obj.tmp.resize.div_x = obj.get('main').minSize - obj.get('main').width; - } - // top panel -> drag - if (obj.tmp.resize.type == 'top' && (obj.get('top').minSize - obj.tmp.resize.div_y > obj.get('top').height)) { - obj.tmp.resize.div_y = obj.get('top').minSize - obj.get('top').height; - } - if (obj.tmp.resize.type == 'top' && (obj.get('main').minSize + obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').height - obj.get('main').minSize; - } - // bottom panel -> drag - if (obj.tmp.resize.type == 'bottom' && (obj.get('bottom').minSize + obj.tmp.resize.div_y > obj.get('bottom').height)) { - obj.tmp.resize.div_y = obj.get('bottom').height - obj.get('bottom').minSize; - } - if (obj.tmp.resize.type == 'bottom' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height; - } - // preview panel -> drag - if (obj.tmp.resize.type == 'preview' && (obj.get('preview').minSize + obj.tmp.resize.div_y > obj.get('preview').height)) { - obj.tmp.resize.div_y = obj.get('preview').height - obj.get('preview').minSize; - } - if (obj.tmp.resize.type == 'preview' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) { - obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height; - } - switch(obj.tmp.resize.type) { - case 'top': - case 'preview': - case 'bottom': - obj.tmp.resize.div_x = 0; - if (p.length > 0) p[0].style.top = (obj.tmp.resize.value + obj.tmp.resize.div_y) + 'px'; - break; - case 'left': - case 'right': - obj.tmp.resize.div_y = 0; - if (p.length > 0) p[0].style.left = (obj.tmp.resize.value + obj.tmp.resize.div_x) + 'px'; - break; - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - } - }, + function resizeMove(evnt) { + if (!obj.box) return; + if (!evnt) evnt = window.event; + if (typeof obj.tmp.resize == 'undefined') return; + var panel = obj.get(obj.tmp.resize.type); + // event before + var tmp = obj.tmp.resize; + var eventData = obj.trigger({ phase: 'before', type: 'resizing', target: obj.name, object: panel, originalEvent: evnt, + panel: tmp ? tmp.type : 'all', diff_x: tmp ? tmp.diff_x : 0, diff_y: tmp ? tmp.diff_y : 0 }); + if (eventData.isCancelled === true) return; + + var p = $('#layout_'+ obj.name + '_resizer_'+ tmp.type); + var resize_x = (evnt.screenX - tmp.x); + var resize_y = (evnt.screenY - tmp.y); + var mainPanel = obj.get('main'); + + if (!p.hasClass('active')) p.addClass('active'); + + switch (tmp.type) { + case 'left': + if (panel.minSize - resize_x > panel.width) { + resize_x = panel.minSize - panel.width; + } + if (panel.maxSize && (panel.width + resize_x > panel.maxSize)) { + resize_x = panel.maxSize - panel.width; + } + if (mainPanel.minSize + resize_x > mainPanel.width) { + resize_x = mainPanel.width - mainPanel.minSize; + } + break; + + case 'right': + if (panel.minSize + resize_x > panel.width) { + resize_x = panel.width - panel.minSize; + } + if (panel.maxSize && (panel.width - resize_x > panel.maxSize)) { + resize_x = panel.width - panel.maxSize; + } + if (mainPanel.minSize - resize_x > mainPanel.width) { + resize_x = mainPanel.minSize - mainPanel.width; + } + break; + + case 'top': + if (panel.minSize - resize_y > panel.height) { + resize_y = panel.minSize - panel.height; + } + if (panel.maxSize && (panel.height + resize_y > panel.maxSize)) { + resize_y = panel.maxSize - panel.height; + } + if (mainPanel.minSize + resize_y > mainPanel.height) { + resize_y = mainPanel.height - mainPanel.minSize; + } + break; + + case 'preview': + case 'bottom': + if (panel.minSize + resize_y > panel.height) { + resize_y = panel.height - panel.minSize; + } + if (panel.maxSize && (panel.height - resize_y > panel.maxSize)) { + resize_y = panel.height - panel.maxSize; + } + if (mainPanel.minSize - resize_y > mainPanel.height) { + resize_y = mainPanel.minSize - mainPanel.height; + } + break; + } + tmp.diff_x = resize_x; + tmp.diff_y = resize_y; + + switch (tmp.type) { + case 'top': + case 'preview': + case 'bottom': + tmp.diff_x = 0; + if (p.length > 0) p[0].style.top = (tmp.value + tmp.diff_y) + 'px'; + break; + + case 'left': + case 'right': + tmp.diff_y = 0; + if (p.length > 0) p[0].style.left = (tmp.value + tmp.diff_x) + 'px'; + break; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + }, - refresh: function (panel) { - var obj = this; - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (typeof panel == 'undefined') panel = null; - var time = (new Date()).getTime(); - // event before - var eventData = obj.trigger({ phase: 'before', type: 'refresh', target: (typeof panel != 'undefined' ? panel : obj.name), object: obj.get(panel) }); - if (eventData.isCancelled === true) return; - - // obj.unlock(panel); - if (panel != null && typeof panel != 'undefined') { - var p = obj.get(panel); - if (p == null) return; - // apply properties to the panel - var el = $('#layout_'+ obj.name +'_panel_'+ panel).css({ display: p.hidden ? 'none' : 'block' }); - el = el.find('.w2ui-panel-content'); - if (el.length > 0) el.css('overflow', p.overflow)[0].style.cssText += ';' + p.style; - if (p.resizable === true) { - $('#layout_'+ this.name +'_resizer_'+ panel).show(); - } else { - $('#layout_'+ this.name +'_resizer_'+ panel).hide(); - } - // insert content - if (typeof p.content == 'object' && p.content.render) { - p.content.box = $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content')[0]; - p.content.render(); // do not do .render(box); - } else { - $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content').html(p.content); - } - // if there are tabs and/or toolbar - render it - var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-tabs'); - if (p.show.tabs) { - if (tmp.find('[name='+ p.tabs.name +']').length == 0 && p.tabs != null) tmp.w2render(p.tabs); else p.tabs.refresh(); - } else { - tmp.html('').removeClass('w2ui-tabs').hide(); - } - var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-toolbar'); - if (p.show.toolbar) { - if (tmp.find('[name='+ p.toolbar.name +']').length == 0 && p.toolbar != null) tmp.w2render(p.toolbar); else p.toolbar.refresh(); - } else { - tmp.html('').removeClass('w2ui-toolbar').hide(); - } - } else { - if ($('#layout_' +obj.name +'_panel_main').length <= 0) { - obj.render(); - return; - } - obj.resize(); - // refresh all of them - for (var p in this.panels) { obj.refresh(this.panels[p].type); } - } - obj.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + refresh: function (panel) { + var obj = this; + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof panel == 'undefined') panel = null; + var time = (new Date()).getTime(); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'refresh', target: (typeof panel != 'undefined' ? panel : obj.name), object: obj.get(panel) }); + if (eventData.isCancelled === true) return; + // obj.unlock(panel); + if (typeof panel == 'string') { + var p = obj.get(panel); + if (p === null) return; + var pname = '#layout_'+ obj.name + '_panel_'+ p.type; + var rname = '#layout_'+ obj.name +'_resizer_'+ p.type; + // apply properties to the panel + $(pname).css({ display: p.hidden ? 'none' : 'block' }); + if (p.resizable) $(rname).show(); else $(rname).hide(); + // insert content + if (typeof p.content == 'object' && typeof p.content.render === 'function') { + p.content.box = $(pname +'> .w2ui-panel-content')[0]; + setTimeout(function () { + // need to remove unnecessary classes + if ($(pname +'> .w2ui-panel-content').length > 0) { + $(pname +'> .w2ui-panel-content') + .removeClass() + .addClass('w2ui-panel-content') + .css('overflow', p.overflow)[0].style.cssText += ';' + p.style; + } + p.content.render(); // do not do .render(box); + }, 1); + } else { + // need to remove unnecessary classes + if ($(pname +'> .w2ui-panel-content').length > 0) { + $(pname +'> .w2ui-panel-content') + .removeClass() + .addClass('w2ui-panel-content') + .html(p.content) + .css('overflow', p.overflow)[0].style.cssText += ';' + p.style; + } + } + // if there are tabs and/or toolbar - render it + var tmp = $(obj.box).find(pname +'> .w2ui-panel-tabs'); + if (p.show.tabs) { + if (tmp.find('[name='+ p.tabs.name +']').length === 0 && p.tabs !== null) tmp.w2render(p.tabs); else p.tabs.refresh(); + } else { + tmp.html('').removeClass('w2ui-tabs').hide(); + } + tmp = $(obj.box).find(pname +'> .w2ui-panel-toolbar'); + if (p.show.toolbar) { + if (tmp.find('[name='+ p.toolbar.name +']').length === 0 && p.toolbar !== null) tmp.w2render(p.toolbar); else p.toolbar.refresh(); + } else { + tmp.html('').removeClass('w2ui-toolbar').hide(); + } + // show title + tmp = $(obj.box).find(pname +'> .w2ui-panel-title'); + if (p.title) { + tmp.html(p.title).show(); + } else { + tmp.html('').hide(); + } + } else { + if ($('#layout_'+ obj.name +'_panel_main').length == 0) { + obj.render(); + return; + } + obj.resize(); + // refresh all of them + for (var p1 in this.panels) { obj.refresh(this.panels[p1].type); } + } + obj.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - resize: function () { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (!this.box) return false; - var time = (new Date()).getTime(); - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name, panel: this.tmp.resizing }); - if (eventData.isCancelled === true) return false; - if (this.padding < 0) this.padding = 0; - - // layout itself - var width = parseInt($(this.box).width()); - var height = parseInt($(this.box).height()); - $(this.box).find(' > div').css({ - width : width + 'px', - height : height + 'px' - }); - var obj = this; - // panels - var pmain = this.get('main'); - var pprev = this.get('preview'); - var pleft = this.get('left'); - var pright = this.get('right'); - var ptop = this.get('top'); - var pbottom = this.get('bottom'); - var smain = true; // main always on - var sprev = (pprev != null && pprev.hidden != true ? true : false); - var sleft = (pleft != null && pleft.hidden != true ? true : false); - var sright = (pright != null && pright.hidden != true ? true : false); - var stop = (ptop != null && ptop.hidden != true ? true : false); - var sbottom = (pbottom != null && pbottom.hidden != true ? true : false); - // calculate % - for (var p in { 'top':'', 'left':'', 'right':'', 'bottom':'', 'preview':'' }) { - var tmp = this.get(p); - var str = String(tmp.size); - if (tmp && str.substr(str.length-1) == '%') { - var tmph = height; - if (tmp.type == 'preview') { - tmph = tmph - - (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) - - (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); - } - tmp.sizeCalculated = parseInt((tmp.type == 'left' || tmp.type == 'right' ? width : tmph) * parseFloat(tmp.size) / 100); - } else { - tmp.sizeCalculated = parseInt(tmp.size); - } - if (tmp.sizeCalculated < parseInt(tmp.minSize)) tmp.sizeCalculated = parseInt(tmp.minSize); - } - // top if any - if (ptop != null && ptop.hidden != true) { - var l = 0; - var t = 0; - var w = width; - var h = ptop.sizeCalculated; - $('#layout_'+ this.name +'_panel_top').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - ptop.width = w; - ptop.height = h; - // resizer - if (ptop.resizable) { - t = ptop.sizeCalculated - (this.padding == 0 ? this.resizer : 0); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_top').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('top', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_top').hide(); - } - // left if any - if (pleft != null && pleft.hidden != true) { - var l = 0; - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = pleft.sizeCalculated; - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0); - var e = $('#layout_'+ this.name +'_panel_left'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_left').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pleft.width = w; - pleft.height = h; - // resizer - if (pleft.resizable) { - l = pleft.sizeCalculated - (this.padding == 0 ? this.resizer : 0); - w = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_left').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ew-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('left', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_left').hide(); - $('#layout_'+ this.name +'_resizer_left').hide(); - } - // right if any - if (pright != null && pright.hidden != true) { - var l = width - pright.sizeCalculated; - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = pright.sizeCalculated; - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0); - $('#layout_'+ this.name +'_panel_right').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pright.width = w; - pright.height = h; - // resizer - if (pright.resizable) { - l = l - this.padding; - w = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_right').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ew-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('right', event); - return false; - }); - } - } else { - $('#layout_'+ this.name +'_panel_right').hide(); - } - // bottom if any - if (pbottom != null && pbottom.hidden != true) { - var l = 0; - var t = height - pbottom.sizeCalculated; - var w = width; - var h = pbottom.sizeCalculated; - $('#layout_'+ this.name +'_panel_bottom').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pbottom.width = w; - pbottom.height = h; - // resizer - if (pbottom.resizable) { - t = t - (this.padding == 0 ? 0 : this.padding); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_bottom').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('bottom', event); - return false; + resize: function () { + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (!this.box) return false; + var time = (new Date()).getTime(); + // event before + var tmp = this.tmp.resize; + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name, + panel: tmp ? tmp.type : 'all', diff_x: tmp ? tmp.diff_x : 0, diff_y: tmp ? tmp.diff_y : 0 }); + if (eventData.isCancelled === true) return; + if (this.padding < 0) this.padding = 0; + + // layout itself + var width = parseInt($(this.box).width()); + var height = parseInt($(this.box).height()); + $(this.box).find(' > div').css({ + width : width + 'px', + height : height + 'px' }); - } - } else { - $('#layout_'+ this.name +'_panel_bottom').hide(); - } - // main - always there - var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); - var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); - var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - - (sright ? pright.sizeCalculated + this.padding: 0); - var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - - (sprev ? pprev.sizeCalculated + this.padding : 0); - var e = $('#layout_'+ this.name +'_panel_main'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_main').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }); - pmain.width = w; - pmain.height = h; - - // preview if any - if (pprev != null && pprev.hidden != true) { - var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); - var t = height - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - pprev.sizeCalculated; - var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - - (sright ? pright.sizeCalculated + this.padding : 0); - var h = pprev.sizeCalculated; - var e = $('#layout_'+ this.name +'_panel_preview'); - if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack - $('#layout_'+ this.name +'_panel_preview').css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px' - }).show(); - pprev.width = w; - pprev.height = h; - // resizer - if (pprev.resizable) { - t = t - (this.padding == 0 ? 0 : this.padding); - h = (this.resizer > this.padding ? this.resizer : this.padding); - $('#layout_'+ this.name +'_resizer_preview').show().css({ - 'display': 'block', - 'left': l + 'px', - 'top': t + 'px', - 'width': w + 'px', - 'height': h + 'px', - 'cursor': 'ns-resize' - }).bind('mousedown', function (event) { - w2ui[obj.name].tmp.events.resizeStart('preview', event); - return false; + var obj = this; + // panels + var pmain = this.get('main'); + var pprev = this.get('preview'); + var pleft = this.get('left'); + var pright = this.get('right'); + var ptop = this.get('top'); + var pbottom = this.get('bottom'); + var smain = true; // main always on + var sprev = (pprev !== null && pprev.hidden !== true ? true : false); + var sleft = (pleft !== null && pleft.hidden !== true ? true : false); + var sright = (pright !== null && pright.hidden !== true ? true : false); + var stop = (ptop !== null && ptop.hidden !== true ? true : false); + var sbottom = (pbottom !== null && pbottom.hidden !== true ? true : false); + var l, t, w, h, e; + // calculate % + for (var p in w2layout_panels) { + p = w2layout_panels[p]; + if (p === 'main') continue; + var tmp = this.get(p); + if (!tmp) continue; + var str = String(tmp.size || 0); + if (str.substr(str.length-1) == '%') { + var tmph = height; + if (tmp.type == 'preview') { + tmph = tmph - + (ptop && !ptop.hidden ? ptop.sizeCalculated : 0) - + (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0); + } + tmp.sizeCalculated = parseInt((tmp.type == 'left' || tmp.type == 'right' ? width : tmph) * parseFloat(tmp.size) / 100); + } else { + tmp.sizeCalculated = parseInt(tmp.size); + } + tmp.sizeCalculated = Math.max(tmp.sizeCalculated, parseInt(tmp.minSize)); + } + // top if any + if (ptop !== null && ptop.hidden !== true) { + l = 0; + t = 0; + w = width; + h = ptop.sizeCalculated; + $('#layout_'+ this.name +'_panel_top').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + ptop.width = w; + ptop.height = h; + // resizer + if (ptop.resizable) { + t = ptop.sizeCalculated - (this.padding === 0 ? this.resizer : 0); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_top').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'top', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('top', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_top').hide(); + } + // left if any + if (pleft !== null && pleft.hidden !== true) { + l = 0; + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = pleft.sizeCalculated; + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0); + e = $('#layout_'+ this.name +'_panel_left'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pleft.width = w; + pleft.height = h; + // resizer + if (pleft.resizable) { + l = pleft.sizeCalculated - (this.padding === 0 ? this.resizer : 0); + w = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_left').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ew-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'left', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('left', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_left').hide(); + $('#layout_'+ this.name +'_resizer_left').hide(); + } + // right if any + if (pright !== null && pright.hidden !== true) { + l = width - pright.sizeCalculated; + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = pright.sizeCalculated; + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0); + $('#layout_'+ this.name +'_panel_right').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pright.width = w; + pright.height = h; + // resizer + if (pright.resizable) { + l = l - this.padding; + w = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_right').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ew-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'right', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('right', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_right').hide(); + } + // bottom if any + if (pbottom !== null && pbottom.hidden !== true) { + l = 0; + t = height - pbottom.sizeCalculated; + w = width; + h = pbottom.sizeCalculated; + $('#layout_'+ this.name +'_panel_bottom').css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pbottom.width = w; + pbottom.height = h; + // resizer + if (pbottom.resizable) { + t = t - (this.padding === 0 ? 0 : this.padding); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_bottom').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'bottom', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('bottom', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_bottom').hide(); + } + // main - always there + l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); + t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0); + w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - + (sright ? pright.sizeCalculated + this.padding: 0); + h = height - (stop ? ptop.sizeCalculated + this.padding : 0) - + (sbottom ? pbottom.sizeCalculated + this.padding : 0) - + (sprev ? pprev.sizeCalculated + this.padding : 0); + e = $('#layout_'+ this.name +'_panel_main'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' }); - } - } else { - $('#layout_'+ this.name +'_panel_preview').hide(); - } - - // display tabs and toolbar if needed - for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) { - var pan = this.get(p); - var tmp = '#layout_'+ this.name +'_panel_'+ p +' > .w2ui-panel-'; - var height = 0; - if (pan.show.tabs) { - if (pan.tabs != null && w2ui[this.name +'_'+ p +'_tabs']) w2ui[this.name +'_'+ p +'_tabs'].resize(); - height += w2utils.getSize($(tmp + 'tabs').css({ display: 'block' }), 'height'); - } - if (pan.show.toolbar) { - if (pan.toolbar != null && w2ui[this.name +'_'+ p +'_toolbar']) w2ui[this.name +'_'+ p +'_toolbar'].resize(); - height += w2utils.getSize($(tmp + 'toolbar').css({ top: height + 'px', display: 'block' }), 'height'); - } - $(tmp + 'content').css({ display: 'block' }).css({ top: height + 'px' }); - } - // send resize to all objects - var obj = this; - clearTimeout(this._resize_timer); - this._resize_timer = setTimeout(function () { - for (var e in w2ui) { - if (typeof w2ui[e].resize == 'function') { - // sent to all none-layouts - if (w2ui[e].panels == 'undefined') w2ui[e].resize(); - // only send to nested layouts - var parent = $(w2ui[e].box).parents('.w2ui-layout'); - if (parent.length > 0 && parent.attr('name') == obj.name) w2ui[e].resize(); - } - } - }, 100); - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + pmain.width = w; + pmain.height = h; + + // preview if any + if (pprev !== null && pprev.hidden !== true) { + l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0); + t = height - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - pprev.sizeCalculated; + w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) - + (sright ? pright.sizeCalculated + this.padding : 0); + h = pprev.sizeCalculated; + e = $('#layout_'+ this.name +'_panel_preview'); + if (window.navigator.userAgent.indexOf('MSIE') != -1 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack + e.css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px' + }).show(); + pprev.width = w; + pprev.height = h; + // resizer + if (pprev.resizable) { + t = t - (this.padding === 0 ? 0 : this.padding); + h = (this.resizer > this.padding ? this.resizer : this.padding); + $('#layout_'+ this.name +'_resizer_preview').show().css({ + 'display': 'block', + 'left': l + 'px', + 'top': t + 'px', + 'width': w + 'px', + 'height': h + 'px', + 'cursor': 'ns-resize' + }).off('mousedown').on('mousedown', function (event) { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'resizerClick', target: 'preview', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + w2ui[obj.name].tmp.events.resizeStart('preview', event); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + return false; + }); + } + } else { + $('#layout_'+ this.name +'_panel_preview').hide(); + } - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - if (typeof w2ui[this.name] == 'undefined') return false; - // clean up - if ($(this.box).find('#layout_'+ this.name +'_panel_main').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-layout') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - - if (this.tmp.events && this.tmp.events.resize) $(window).off('resize', this.tmp.events.resize); - if (this.tmp.events && this.tmp.events.mousemove) $(document).off('mousemove', this.tmp.events.mousemove); - if (this.tmp.events && this.tmp.events.mouseup) $(document).off('mouseup', this.tmp.events.mouseup); - - return true; - }, + // display tabs and toolbar if needed + for (var p1 in w2layout_panels) { + p1 = w2layout_panels[p1]; + var pan = this.get(p1); + var tmp2 = '#layout_'+ this.name +'_panel_'+ p1 +' > .w2ui-panel-'; + var tabHeight = 0; + if (pan) { + if (pan.title) { + tabHeight += w2utils.getSize($(tmp2 + 'title').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + if (pan.show.tabs) { + if (pan.tabs !== null && w2ui[this.name +'_'+ p1 +'_tabs']) w2ui[this.name +'_'+ p1 +'_tabs'].resize(); + tabHeight += w2utils.getSize($(tmp2 + 'tabs').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + if (pan.show.toolbar) { + if (pan.toolbar !== null && w2ui[this.name +'_'+ p1 +'_toolbar']) w2ui[this.name +'_'+ p1 +'_toolbar'].resize(); + tabHeight += w2utils.getSize($(tmp2 + 'toolbar').css({ top: tabHeight + 'px', display: 'block' }), 'height'); + } + } + $(tmp2 + 'content').css({ display: 'block' }).css({ top: tabHeight + 'px' }); + } + // send resize to all objects + clearTimeout(this._resize_timer); + this._resize_timer = setTimeout(function () { + for (var e in w2ui) { + if (typeof w2ui[e].resize == 'function') { + // sent to all none-layouts + if (w2ui[e].panels == 'undefined') w2ui[e].resize(); + // only send to nested layouts + var parent = $(w2ui[e].box).parents('.w2ui-layout'); + if (parent.length > 0 && parent.attr('name') == obj.name) w2ui[e].resize(); + } + } + }, 100); + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - lock: function (panel, msg, showSpinner) { - if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) { - console.log('ERROR: First parameter needs to be the a valid panel name.'); - return; - } - var nm = '#layout_'+ this.name + '_panel_' + panel; - w2utils.lock(nm, msg, showSpinner); - }, + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + if (typeof w2ui[this.name] == 'undefined') return false; + // clean up + if ($(this.box).find('#layout_'+ this.name +'_panel_main').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-layout') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + if (this.tmp.events && this.tmp.events.resize) $(window).off('resize', this.tmp.events.resize); + return true; + }, - unlock: function (panel) { - if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) { - console.log('ERROR: First parameter needs to be the a valid panel name.'); - return; - } - var nm = '#layout_'+ this.name + '_panel_' + panel; - w2utils.unlock(nm); - } - } + lock: function (panel, msg, showSpinner) { + if (w2layout_panels.indexOf(panel) == -1) { + console.log('ERROR: First parameter needs to be the a valid panel name.'); + return; + } + var args = Array.prototype.slice.call(arguments, 0); + args[0] = '#layout_'+ this.name + '_panel_' + panel; + w2utils.lock.apply(window, args); + }, + + unlock: function (panel) { + if (w2layout_panels.indexOf(panel) == -1) { + console.log('ERROR: First parameter needs to be the a valid panel name.'); + return; + } + var nm = '#layout_'+ this.name + '_panel_' + panel; + w2utils.unlock(nm); + } + }; - $.extend(w2layout.prototype, w2utils.event); - w2obj.layout = w2layout; + $.extend(w2layout.prototype, w2utils.event); + w2obj.layout = w2layout; })(jQuery); /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2popup - popup widget - * - $().w2popup - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - when maximized, align the slide down message - * - bug: after transfer to another content, message does not work - * - transition should include title, body and buttons, not just body - * - add lock method() to lock popup content - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2popup - popup widget +* - $().w2popup - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - transition should include title, body and buttons, not just body +* +************************************************************************/ var w2popup = {}; (function ($) { - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2popup = function(method, options) { - if (typeof method == 'undefined') { - options = {}; - method = 'open'; - } - if ($.isPlainObject(method)) { - options = method; - method = 'open'; - } - method = method.toLowerCase(); - if (method == 'load' && typeof options == 'string') options = { url: options }; - if (method == 'open' && typeof options.url != 'undefined') method = 'load'; - if (typeof options == 'undefined') options = {}; - // load options from markup - var dlgOptions = {}; - if ($(this).length > 0 ) { - if ($(this).find('div[rel=title], div[rel=body], div[rel=buttons]').length > 0) { - if ($(this).find('div[rel=title]').length > 0) { - dlgOptions['title'] = $(this).find('div[rel=title]').html(); - } - if ($(this).find('div[rel=body]').length > 0) { - dlgOptions['body'] = $(this).find('div[rel=body]').html(); - dlgOptions['style'] = $(this).find('div[rel=body]')[0].style.cssText; - } - if ($(this).find('div[rel=buttons]').length > 0) { - dlgOptions['buttons'] = $(this).find('div[rel=buttons]').html(); - } - } else { - dlgOptions['title'] = ' '; - dlgOptions['body'] = $(this).html(); - } - if (parseInt($(this).css('width')) != 0) dlgOptions['width'] = parseInt($(this).css('width')); - if (parseInt($(this).css('height')) != 0) dlgOptions['height'] = parseInt($(this).css('height')); - } - // show popup - return w2popup[method]($.extend({}, dlgOptions, options)); - }; - - // ==================================================== - // -- Implementation of core functionality (SINGELTON) - - w2popup = { - defaults: { - title : '', - body : '', - buttons : '', - style : '', - color : '#000', - opacity : 0.4, - speed : 0.3, - modal : false, - maximized : false, - keyboard : true, // will close popup on esc if not modal - width : 500, - height : 300, - showClose : true, - showMax : false, - transition : null - }, - handlers : [], - onOpen : null, - onClose : null, - onMax : null, - onMin : null, - onKeydown : null, - - open: function (options) { - var obj = this; - // get old options and merge them - var old_options = $('#w2ui-popup').data('options'); - var options = $.extend({}, this.defaults, { body : '' }, old_options, options); - // if new - reset event handlers - if ($('#w2ui-popup').length == 0) { - w2popup.handlers = []; - w2popup.onMax = null; - w2popup.onMin = null; - w2popup.onOpen = null; - w2popup.onClose = null; - w2popup.onKeydown = null; - } - if (options.onOpen) w2popup.onOpen = options.onOpen; - if (options.onClose) w2popup.onClose = options.onClose; - if (options.onMax) w2popup.onMax = options.onMax; - if (options.onMin) w2popup.onMin = options.onMin; - if (options.onKeydown) w2popup.onKeydown = options.onKeydown; - - if (window.innerHeight == undefined) { - var width = document.documentElement.offsetWidth; - var height = document.documentElement.offsetHeight; - if (w2utils.engine == 'IE7') { width += 21; height += 4; } - } else { - var width = window.innerWidth; - var height = window.innerHeight; - } - if (parseInt(width) - 10 < parseInt(options.width)) options.width = parseInt(width) - 10; - if (parseInt(height) - 10 < parseInt(options.height)) options.height = parseInt(height) - 10; - var top = ((parseInt(height) - parseInt(options.height)) / 2) * 0.6; - var left = (parseInt(width) - parseInt(options.width)) / 2; - // check if message is already displayed - if ($('#w2ui-popup').length == 0) { - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: false }); - if (eventData.isCancelled === true) return; - // output message - w2popup.lockScreen(options); - var msg = ''; - if (options.title != '') { - msg +=''+ - (options.showClose ? 'Close' : '')+ - (options.showMax ? 'Max' : '') + - options.title + - ''; - } - msg += ''; - msg += ''+ options.body +''; - msg += ''; - msg += ''; - msg += ''; - msg += ''; - if (options.buttons != '') { - msg += ''+ options.buttons +''; - } - msg += ''; - $('body').append(msg); - // allow element to render - setTimeout(function () { - $('#w2ui-popup .w2ui-box2').hide(); - $('#w2ui-popup').css({ - '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform', - '-webkit-transform': 'scale(1)', - '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform', - '-moz-transform': 'scale(1)', - '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform', - '-ms-transform': 'scale(1)', - '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform', - '-o-transform': 'scale(1)', - 'opacity': '1' - }); - }, 1); - // clean transform - setTimeout(function () { - $('#w2ui-popup').css({ - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '' - }); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, options.speed * 1000); - } else { - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: true }); - if (eventData.isCancelled === true) return; - // check if size changed - if (typeof old_options == 'undefined' || old_options['width'] != options['width'] || old_options['height'] != options['height']) { - $('#w2ui-panel').remove(); - w2popup.resize(options.width, options.height); - } - // show new items - var body = $('#w2ui-popup .w2ui-box2 > .w2ui-msg-body').html(options.body); - if (body.length > 0) body[0].style.cssText = options.style; - $('#w2ui-popup .w2ui-msg-buttons').html(options.buttons); - $('#w2ui-popup .w2ui-msg-title').html( - (options.showClose ? 'Close' : '')+ - (options.showMax ? 'Max' : '') + - options.title); - // transition - var div_old = $('#w2ui-popup .w2ui-box1')[0]; - var div_new = $('#w2ui-popup .w2ui-box2')[0]; - w2utils.transition(div_old, div_new, options.transition); - div_new.className = 'w2ui-box1'; - div_old.className = 'w2ui-box2'; - $(div_new).addClass('w2ui-current-box'); - // remove max state - $('#w2ui-popup').data('prev-size', null); - // call event onChange - setTimeout(function () { - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - } - // save new options - options._last_w2ui_name = w2utils.keyboard.active(); - w2utils.keyboard.active(null); - $('#w2ui-popup').data('options', options); - // keyboard events - if (options.keyboard) $(document).on('keydown', this.keydown); - - // initialize move - var tmp = { resizing: false }; - $('#w2ui-popup .w2ui-msg-title') - .on('mousedown', function (event) { mvStart(event); }) - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - $('#w2ui-popup .w2ui-msg-body') - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - $('#w2ui-lock') - .on('mousemove', function (event) { mvMove(event); }) - .on('mouseup', function (event) { mvStop(event); }); - - // handlers - function mvStart(event) { - if (!event) event = window.event; - if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } - tmp.resizing = true; - tmp.tmp_x = event.screenX; - tmp.tmp_y = event.screenY; - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - if (event.preventDefault) event.preventDefault(); else return false; - } - - function mvMove(evnt) { - if (tmp.resizing != true) return; - if (!evnt) evnt = window.event; - tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x); - tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y); - $('#w2ui-popup').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-ms-transition': 'none', - '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-o-transition': 'none', - '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)' - }); - $('#w2ui-panel').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)', - '-ms-transition': 'none', - '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px', - '-o-transition': 'none', - '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)' - }); - } - - function mvStop(evnt) { - if (tmp.resizing != true) return; - if (!evnt) evnt = window.event; - tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x); - tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y); - $('#w2ui-popup').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d(0px, 0px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate(0px, 0px)', - '-ms-transition': 'none', - '-ms-transform': 'translate(0px, 0px)', - '-o-transition': 'none', - '-o-transform': 'translate(0px, 0px)', - 'left': (parseInt($('#w2ui-popup').css('left')) + parseInt(tmp.tmp_div_x)) + 'px', - 'top': (parseInt($('#w2ui-popup').css('top')) + parseInt(tmp.tmp_div_y)) + 'px' - }); - $('#w2ui-panel').css({ - '-webkit-transition': 'none', - '-webkit-transform': 'translate3d(0px, 0px, 0px)', - '-moz-transition': 'none', - '-moz-transform': 'translate(0px, 0px)', - '-ms-transition': 'none', - '-ms-transform': 'translate(0px, 0px)', - '-o-transition': 'none', - '-o-transform': 'translate(0px, 0px)', - 'left': (parseInt($('#w2ui-panel').css('left')) + parseInt(tmp.tmp_div_x)) + 'px', - 'top': (parseInt($('#w2ui-panel').css('top')) + parseInt(tmp.tmp_div_y)) + 'px' - }); - tmp.resizing = false; - } - return this; - }, - - keydown: function (event) { - var options = $('#w2ui-popup').data('options'); - if (!options.keyboard) return; - // trigger event - var eventData = w2popup.trigger({ phase: 'before', type: 'keydown', target: 'popup', options: options, object: w2popup, originalEvent: event }); - if (eventData.isCancelled === true) return; - // default behavior - switch (event.keyCode) { - case 27: - event.preventDefault(); - if ($('#w2ui-popup .w2ui-popup-message').length > 0) w2popup.message(); else w2popup.close(); - break; - } - // event after - w2popup.trigger($.extend(eventData, { phase: 'after'})); - }, - - close: function (options) { - var obj = this; - var options = $.extend({}, $('#w2ui-popup').data('options'), options); - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'close', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - $('#w2ui-popup, #w2ui-panel').css({ - '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform', - '-webkit-transform': 'scale(0.9)', - '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform', - '-moz-transform': 'scale(0.9)', - '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform', - '-ms-transform': 'scale(0.9)', - '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform', - '-o-transform': 'scale(0.9)', - 'opacity': '0' - }); - w2popup.unlockScreen(); - setTimeout(function () { - $('#w2ui-popup').remove(); - $('#w2ui-panel').remove(); - // event after - obj.trigger($.extend(eventData, { phase: 'after'})); - }, options.speed * 1000); - // restore active - w2utils.keyboard.active(options._last_w2ui_name); - // remove keyboard events - if (options.keyboard) $(document).off('keydown', this.keydown); - }, - - toggle: function () { - var options = $('#w2ui-popup').data('options'); - if (options.maximized === true) w2popup.min(); else w2popup.max(); - }, - - max: function () { - var obj = this; - var options = $('#w2ui-popup').data('options'); - if (options.maximized === true) return; - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'max', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - options.maximized = true; - options.prevSize = $('#w2ui-popup').css('width')+':'+$('#w2ui-popup').css('height'); - $('#w2ui-popup').data('options', options); - // do resize - w2popup.resize(10000, 10000, function () { - obj.trigger($.extend(eventData, { phase: 'after'})); - }); - }, - - min: function () { - var obj = this; - var options = $('#w2ui-popup').data('options'); - if (options.maximized !== true) return; - var size = options.prevSize.split(':'); - // trigger event - var eventData = this.trigger({ phase: 'before', type: 'min', target: 'popup', options: options }); - if (eventData.isCancelled === true) return; - // default behavior - options.maximized = false; - options.prevSize = null; - $('#w2ui-popup').data('options', options); - // do resize - w2popup.resize(size[0], size[1], function () { - obj.trigger($.extend(eventData, { phase: 'after'})); - }); - }, - - get: function () { - return $('#w2ui-popup').data('options'); - }, - - set: function (options) { - w2popup.open(options); - }, - - clear: function() { - $('#w2ui-popup .w2ui-msg-title').html(''); - $('#w2ui-popup .w2ui-msg-body').html(''); - $('#w2ui-popup .w2ui-msg-buttons').html(''); - }, - - reset: function () { - w2popup.open(w2popup.defaults); - }, + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2popup = function(method, options) { + if (typeof method === 'undefined') { + options = {}; + method = 'open'; + } + if ($.isPlainObject(method)) { + options = method; + method = 'open'; + } + method = method.toLowerCase(); + if (method === 'load' && typeof options === 'string') { + options = $.extend({ url: options }, arguments.length > 2 ? arguments[2] : {}); + } + if (method === 'open' && options.url != null) method = 'load'; + options = options || {}; + // load options from markup + var dlgOptions = {}; + if ($(this).length > 0) { + if ($(this).find('div[rel=title], div[rel=body], div[rel=buttons]').length > 0) { + if ($(this).find('div[rel=title]').length > 0) { + dlgOptions['title'] = $(this).find('div[rel=title]').html(); + } + if ($(this).find('div[rel=body]').length > 0) { + dlgOptions['body'] = $(this).find('div[rel=body]').html(); + dlgOptions['style'] = $(this).find('div[rel=body]')[0].style.cssText; + } + if ($(this).find('div[rel=buttons]').length > 0) { + dlgOptions['buttons'] = $(this).find('div[rel=buttons]').html(); + } + } else { + dlgOptions['title'] = ' '; + dlgOptions['body'] = $(this).html(); + } + if (parseInt($(this).css('width')) != 0) dlgOptions['width'] = parseInt($(this).css('width')); + if (parseInt($(this).css('height')) != 0) dlgOptions['height'] = parseInt($(this).css('height')); + } + // show popup + return w2popup[method]($.extend({}, dlgOptions, options)); + }; + + // ==================================================== + // -- Implementation of core functionality (SINGELTON) + + w2popup = { + defaults: { + title : '', + body : '', + buttons : '', + style : '', + color : '#000', + opacity : 0.4, + speed : 0.3, + modal : false, + maximized : false, + keyboard : true, // will close popup on esc if not modal + width : 500, + height : 300, + showClose : true, + showMax : false, + transition: null + }, + status : 'closed', // string that describes current status + handlers : [], + onOpen : null, + onClose : null, + onMax : null, + onMin : null, + onToggle : null, + onKeydown : null, + + open: function (options) { + var obj = this; + if (w2popup.status == 'closing') { + setTimeout(function () { obj.open.call(obj, options); }, 100); + return; + } + // get old options and merge them + var old_options = $('#w2ui-popup').data('options'); + var options = $.extend({}, this.defaults, old_options, { title: '', body : '', buttons: '' }, options, { maximized: false }); + // need timer because popup might not be open + setTimeout(function () { $('#w2ui-popup').data('options', options); }, 100); + // if new - reset event handlers + if ($('#w2ui-popup').length == 0) { + w2popup.handlers = []; + w2popup.onMax = null; + w2popup.onMin = null; + w2popup.onToggle = null; + w2popup.onOpen = null; + w2popup.onClose = null; + w2popup.onKeydown = null; + } + if (options.onOpen) w2popup.onOpen = options.onOpen; + if (options.onClose) w2popup.onClose = options.onClose; + if (options.onMax) w2popup.onMax = options.onMax; + if (options.onMin) w2popup.onMin = options.onMin; + if (options.onToggle) w2popup.onToggle = options.onToggle; + if (options.onKeydown) w2popup.onKeydown = options.onKeydown; + + if (window.innerHeight == undefined) { + var width = document.documentElement.offsetWidth; + var height = document.documentElement.offsetHeight; + if (w2utils.engine === 'IE7') { width += 21; height += 4; } + } else { + var width = window.innerWidth; + var height = window.innerHeight; + } + if (parseInt(width) - 10 < parseInt(options.width)) options.width = parseInt(width) - 10; + if (parseInt(height) - 10 < parseInt(options.height)) options.height = parseInt(height) - 10; + var top = parseInt(((parseInt(height) - parseInt(options.height)) / 2) * 0.6); + var left = parseInt((parseInt(width) - parseInt(options.width)) / 2); + // check if message is already displayed + if ($('#w2ui-popup').length == 0) { + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: false }); + if (eventData.isCancelled === true) return; + w2popup.status = 'opening'; + // output message + w2popup.lockScreen(options); + var btn = ''; + if (options.showClose) { + btn += 'Close'; + } + if (options.showMax) { + btn += 'Max'; + } + var msg=''+ + ' ' + btn + options.title + ''+ + ' '+ + ' ' + options.body + ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' ' + options.buttons + ''+ + ''; + $('body').append(msg); + // allow element to render + setTimeout(function () { + $('#w2ui-popup .w2ui-box2').hide(); + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's opacity, ' + options.speed + 's -webkit-transform', + '-webkit-transform': 'scale(1)', + '-moz-transition': options.speed + 's opacity, ' + options.speed + 's -moz-transform', + '-moz-transform': 'scale(1)', + '-ms-transition': options.speed + 's opacity, ' + options.speed + 's -ms-transform', + '-ms-transform': 'scale(1)', + '-o-transition': options.speed + 's opacity, ' + options.speed + 's -o-transform', + '-o-transform': 'scale(1)', + 'opacity': '1' + }); + }, 1); + // clean transform + setTimeout(function () { + $('#w2ui-popup').css({ + '-webkit-transform': '', + '-moz-transform': '', + '-ms-transform': '', + '-o-transform': '' + }); + // event after + w2popup.status = 'open'; + setTimeout(function () { + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 100); + }, options.speed * 1000); + } else { + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: true }); + if (eventData.isCancelled === true) return; + // check if size changed + w2popup.status = 'opening'; + if (typeof old_options == 'undefined' || old_options['width'] != options['width'] || old_options['height'] != options['height']) { + w2popup.resize(options.width, options.height); + } + if (typeof old_options != 'undefined') { + options.prevSize = options.width + ':' + options.height; + options.maximized = old_options.maximized; + } + // show new items + var body = $('#w2ui-popup .w2ui-box2 > .w2ui-msg-body').html(options.body); + if (body.length > 0) body[0].style.cssText = options.style; + if (options.buttons != '') { + $('#w2ui-popup .w2ui-msg-buttons').show().html(options.buttons); + $('#w2ui-popup .w2ui-msg-body').removeClass('w2ui-msg-no-buttons'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('bottom', ''); + } else { + $('#w2ui-popup .w2ui-msg-buttons').hide().html(''); + $('#w2ui-popup .w2ui-msg-body').addClass('w2ui-msg-no-buttons'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('bottom', '0px'); + } + if (options.title != '') { + $('#w2ui-popup .w2ui-msg-title').show().html( + (options.showClose ? 'Close' : '') + + (options.showMax ? 'Max' : '') + + options.title); + $('#w2ui-popup .w2ui-msg-body').removeClass('w2ui-msg-no-title'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('top', ''); + } else { + $('#w2ui-popup .w2ui-msg-title').hide().html(''); + $('#w2ui-popup .w2ui-msg-body').addClass('w2ui-msg-no-title'); + $('#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2').css('top', '0px'); + } + // transition + var div_old = $('#w2ui-popup .w2ui-box1')[0]; + var div_new = $('#w2ui-popup .w2ui-box2')[0]; + w2utils.transition(div_old, div_new, options.transition); + div_new.className = 'w2ui-box1'; + div_old.className = 'w2ui-box2'; + $(div_new).addClass('w2ui-current-box'); + // remove max state + $('#w2ui-popup').data('prev-size', null); + // call event onChange + setTimeout(function () { + w2popup.status = 'open'; + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 100); + } + // save new options + options._last_w2ui_name = w2utils.keyboard.active(); + w2utils.keyboard.active(null); + // keyboard events + if (options.keyboard) $(document).on('keydown', this.keydown); - load: function (options) { - if (String(options.url) == 'undefined') { - console.log('ERROR: The url parameter is empty.'); - return; - } - var tmp = String(options.url).split('#'); - var url = tmp[0]; - var selector = tmp[1]; - if (String(options) == 'undefined') options = {}; - // load url - var html = $('#w2ui-popup').data(url); - if (typeof html != 'undefined' && html != null) { - popup(html, selector); - } else { - $.get(url, function (data, status, obj) { - popup(obj.responseText, selector); - $('#w2ui-popup').data(url, obj.responseText); // remember for possible future purposes - }); - } - function popup(html, selector) { - delete options.url; - $('body').append(''+ html +''); - if (typeof selector != 'undefined' && $('#w2ui-tmp #'+selector).length > 0) { - $('#w2ui-tmp #'+ selector).w2popup(options); - } else { - $('#w2ui-tmp > div').w2popup(options); - } - // link styles - if ($('#w2ui-tmp > style').length > 0) { - var style = $('').append($('#w2ui-tmp > style').clone()).html(); - if ($('#w2ui-popup #div-style').length == 0) { - $('#w2ui-ppopup').append(''); - } - $('#w2ui-popup #div-style').html(style); - } - $('#w2ui-tmp').remove(); - } - }, + // initialize move + var tmp = { + resizing : false, + mvMove : mvMove, + mvStop : mvStop + }; + $('#w2ui-popup .w2ui-msg-title').on('mousedown', function (event) { mvStart(event); }) + + // handlers + function mvStart(evnt) { + if (!evnt) evnt = window.event; + if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); } + w2popup.status = 'moving'; + tmp.resizing = true; + tmp.x = evnt.screenX; + tmp.y = evnt.screenY; + tmp.pos_x = $('#w2ui-popup').position().left; + tmp.pos_y = $('#w2ui-popup').position().top; + w2popup.lock({ opacity: 0 }); + $(document).on('mousemove', tmp.mvMove); + $(document).on('mouseup', tmp.mvStop); + if (evnt.stopPropagation) evnt.stopPropagation(); else evnt.cancelBubble = true; + if (evnt.preventDefault) evnt.preventDefault(); else return false; + } - message: function (options) { - $().w2tag(); // hide all tags - if (!options) options = { width: 200, height: 100 }; - if (parseInt(options.width) < 10) options.width = 10; - if (parseInt(options.height) < 10) options.height = 10; - if (typeof options.hideOnClick == 'undefined') options.hideOnClick = false; - - var head = $('#w2ui-popup .w2ui-msg-title'); - if ($('#w2ui-popup .w2ui-popup-message').length == 0) { - var pwidth = parseInt($('#w2ui-popup').width()); - $('#w2ui-popup .w2ui-box1') - .before(''+ - ''); - $('#w2ui-popup .w2ui-popup-message').data('options', options); - } else { - if (typeof options.width == 'undefined') options.width = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'width'); - if (typeof options.height == 'undefined') options.height = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'height'); - } - var display = $('#w2ui-popup .w2ui-popup-message').css('display'); - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-moz-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-ms-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'), - '-o-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)') - }); - if (display == 'none') { - $('#w2ui-popup .w2ui-popup-message').show().html(options.html); - setTimeout(function() { - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transition': '0s', '-moz-transition': '0s', '-ms-transition': '0s', '-o-transition': '0s', - 'z-Index': 1500 - }); // has to be on top of lock - w2popup.lock(); - if (typeof options.onOpen == 'function') options.onOpen(); - }, 300); - } else { - $('#w2ui-popup .w2ui-popup-message').css('z-Index', 250); - var options = $('#w2ui-popup .w2ui-popup-message').data('options'); - $('#w2ui-popup .w2ui-popup-message').remove(); - w2popup.unlock(); - if (typeof options.onClose == 'function') options.onClose(); - } - // timer needs to animation - setTimeout(function () { - $('#w2ui-popup .w2ui-popup-message').css({ - '-webkit-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-moz-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-ms-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'), - '-o-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)') - }); - }, 1); - }, + function mvMove(evnt) { + if (tmp.resizing != true) return; + if (!evnt) evnt = window.event; + tmp.div_x = evnt.screenX - tmp.x; + tmp.div_y = evnt.screenY - tmp.y; + $('#w2ui-popup').css({ + '-webkit-transition': 'none', + '-webkit-transform': 'translate3d('+ tmp.div_x +'px, '+ tmp.div_y +'px, 0px)', + '-moz-transition': 'none', + '-moz-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)', + '-ms-transition': 'none', + '-ms-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)', + '-o-transition': 'none', + '-o-transform': 'translate('+ tmp.div_x +'px, '+ tmp.div_y +'px)' + }); + } - lock: function (msg, showSpinner) { - w2utils.lock($('#w2ui-popup'), msg, showSpinner); - }, + function mvStop(evnt) { + if (tmp.resizing != true) return; + if (!evnt) evnt = window.event; + w2popup.status = 'open'; + tmp.div_x = (evnt.screenX - tmp.x); + tmp.div_y = (evnt.screenY - tmp.y); + $('#w2ui-popup').css({ + 'left': (tmp.pos_x + tmp.div_x) + 'px', + 'top': (tmp.pos_y + tmp.div_y) + 'px', + '-webkit-transition': 'none', + '-webkit-transform': 'translate3d(0px, 0px, 0px)', + '-moz-transition': 'none', + '-moz-transform': 'translate(0px, 0px)', + '-ms-transition': 'none', + '-ms-transform': 'translate(0px, 0px)', + '-o-transition': 'none', + '-o-transform': 'translate(0px, 0px)' + }); + tmp.resizing = false; + $(document).off('mousemove', tmp.mvMove); + $(document).off('mouseup', tmp.mvStop); + w2popup.unlock(); + } + return this; + }, + + keydown: function (event) { + var options = $('#w2ui-popup').data('options'); + if (!options.keyboard) return; + // trigger event + var eventData = w2popup.trigger({ phase: 'before', type: 'keydown', target: 'popup', options: options, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behavior + switch (event.keyCode) { + case 27: + event.preventDefault(); + if ($('#w2ui-popup .w2ui-popup-message').length > 0) w2popup.message(); else w2popup.close(); + break; + } + // event after + w2popup.trigger($.extend(eventData, { phase: 'after'})); + }, - unlock: function () { - w2utils.unlock($('#w2ui-popup')); - }, + close: function (options) { + var obj = this; + var options = $.extend({}, $('#w2ui-popup').data('options'), options); + if ($('#w2ui-popup').length == 0) return; + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'close', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'closing'; + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's opacity, ' + options.speed + 's -webkit-transform', + '-webkit-transform': 'scale(0.9)', + '-moz-transition': options.speed + 's opacity, ' + options.speed + 's -moz-transform', + '-moz-transform': 'scale(0.9)', + '-ms-transition': options.speed + 's opacity, ' + options.speed + 's -ms-transform', + '-ms-transform': 'scale(0.9)', + '-o-transition': options.speed + 's opacity, ' + options.speed + 's -o-transform', + '-o-transform': 'scale(0.9)', + 'opacity': '0' + }); + w2popup.unlockScreen(options); + setTimeout(function () { + $('#w2ui-popup').remove(); + w2popup.status = 'closed'; + // event after + obj.trigger($.extend(eventData, { phase: 'after'})); + }, options.speed * 1000); + // restore active + w2utils.keyboard.active(options._last_w2ui_name); + // remove keyboard events + if (options.keyboard) $(document).off('keydown', this.keydown); + }, + + toggle: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'toggle', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // defatul action + if (options.maximized === true) w2popup.min(); else w2popup.max(); + // event after + setTimeout(function () { + obj.trigger($.extend(eventData, { phase: 'after'})); + }, (options.speed * 1000) + 50); + }, - // --- INTERNAL FUNCTIONS - - lockScreen: function (options) { - if ($('#w2ui-lock').length > 0) return false; - if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); - if (typeof options == 'undefined') options = {}; - options = $.extend({}, w2popup.defaults, options); - // show element - $('body').append(''); - // lock screen - setTimeout(function () { - $('#w2ui-lock').css({ - '-webkit-transition': options.speed +'s opacity', - '-moz-transition': options.speed +'s opacity', - '-ms-transition': options.speed +'s opacity', - '-o-transition': options.speed +'s opacity', - 'opacity': options.opacity - }); - }, 1); - // add events - if (options.modal == true) { - $('#w2ui-lock').on('mousedown', function () { - $('#w2ui-lock').css({ - '-webkit-transition': '.1s', - '-moz-transition': '.1s', - '-ms-transition': '.1s', - '-o-transition': '.1s', - 'opacity': '0.6' - }); - if (window.getSelection) window.getSelection().removeAllRanges(); - }); - $('#w2ui-lock').on('mouseup', function () { - setTimeout(function () { - $('#w2ui-lock').css({ - '-webkit-transition': '.1s', - '-moz-transition': '.1s', - '-ms-transition': '.1s', - '-o-transition': '.1s', - 'opacity': options.opacity + max: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + if (options.maximized === true) return; + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'max', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'resizing'; + options.prevSize = $('#w2ui-popup').css('width') + ':' + $('#w2ui-popup').css('height'); + // do resize + w2popup.resize(10000, 10000, function () { + w2popup.status = 'open'; + options.maximized = true; + obj.trigger($.extend(eventData, { phase: 'after'})); }); - }, 100); - if (window.getSelection) window.getSelection().removeAllRanges(); - }); - } else { - $('#w2ui-lock').on('mouseup', function () { w2popup.close(); }); - } - return true; - }, + }, - unlockScreen: function () { - if ($('#w2ui-lock').length == 0) return false; - var options = $.extend({}, $('#w2ui-popup').data('options'), options); - $('#w2ui-lock').css({ - '-webkit-transition': options.speed +'s opacity', - '-moz-transition': options.speed +'s opacity', - '-ms-transition': options.speed +'s opacity', - '-o-transition': options.speed +'s opacity', - 'opacity': 0 - }); - setTimeout(function () { - $('#w2ui-lock').remove(); - }, options.speed * 1000); - return true; - }, + min: function () { + var obj = this; + var options = $('#w2ui-popup').data('options'); + if (options.maximized !== true) return; + var size = options.prevSize.split(':'); + // trigger event + var eventData = this.trigger({ phase: 'before', type: 'min', target: 'popup', options: options }); + if (eventData.isCancelled === true) return; + // default behavior + w2popup.status = 'resizing'; + // do resize + w2popup.resize(size[0], size[1], function () { + w2popup.status = 'open'; + options.maximized = false; + options.prevSize = null; + obj.trigger($.extend(eventData, { phase: 'after'})); + }); + }, + + get: function () { + return $('#w2ui-popup').data('options'); + }, + + set: function (options) { + w2popup.open(options); + }, + + clear: function() { + $('#w2ui-popup .w2ui-msg-title').html(''); + $('#w2ui-popup .w2ui-msg-body').html(''); + $('#w2ui-popup .w2ui-msg-buttons').html(''); + }, + + reset: function () { + w2popup.open(w2popup.defaults); + }, + + load: function (options) { + w2popup.status = 'loading'; + if (String(options.url) == 'undefined') { + console.log('ERROR: The url parameter is empty.'); + return; + } + var tmp = String(options.url).split('#'); + var url = tmp[0]; + var selector = tmp[1]; + if (String(options) == 'undefined') options = {}; + // load url + var html = $('#w2ui-popup').data(url); + if (typeof html != 'undefined' && html != null) { + popup(html, selector); + } else { + $.get(url, function (data, status, obj) { // should always be $.get as it is template + popup(obj.responseText, selector); + $('#w2ui-popup').data(url, obj.responseText); // remember for possible future purposes + }); + } + function popup(html, selector) { + delete options.url; + $('body').append('' + html + ''); + if (typeof selector != 'undefined' && $('#w2ui-tmp #'+selector).length > 0) { + $('#w2ui-tmp #' + selector).w2popup(options); + } else { + $('#w2ui-tmp > div').w2popup(options); + } + // link styles + if ($('#w2ui-tmp > style').length > 0) { + var style = $('').append($('#w2ui-tmp > style').clone()).html(); + if ($('#w2ui-popup #div-style').length == 0) { + $('#w2ui-popup').append(''); + } + $('#w2ui-popup #div-style').html(style); + } + $('#w2ui-tmp').remove(); + } + }, + + message: function (options) { + $().w2tag(); // hide all tags + if (!options) options = { width: 200, height: 100 }; + if (parseInt(options.width) < 10) options.width = 10; + if (parseInt(options.height) < 10) options.height = 10; + if (typeof options.hideOnClick == 'undefined') options.hideOnClick = false; + var poptions = $('#w2ui-popup').data('options') || {}; + if (typeof options.width == 'undefined' || options.width > poptions.width - 10) options.width = poptions.width - 10; + if (typeof options.height == 'undefined' || options.height > poptions.height - 40) options.height = poptions.height - 40; // title is 30px or so + + var head = $('#w2ui-popup .w2ui-msg-title'); + var pwidth = parseInt($('#w2ui-popup').width()); + var msgCount = $('#w2ui-popup .w2ui-popup-message').length; + // remove message + if ($.trim(options.html) == '') { + $('#w2ui-popup #w2ui-message'+ (msgCount-1)).css('z-Index', 250); + var options = $('#w2ui-popup #w2ui-message'+ (msgCount-1)).data('options') || {}; + $('#w2ui-popup #w2ui-message'+ (msgCount-1)).remove(); + if (typeof options.onClose == 'function') options.onClose(); + if (msgCount == 1) { + w2popup.unlock(); + } else { + $('#w2ui-popup #w2ui-message'+ (msgCount-2)).show(); + } + } else { + // hide previous messages + $('#w2ui-popup .w2ui-popup-message').hide(); + // add message + $('#w2ui-popup .w2ui-box1') + .before('' + + ''); + $('#w2ui-popup #w2ui-message'+ msgCount).data('options', options); + var display = $('#w2ui-popup #w2ui-message'+ msgCount).css('display'); + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-moz-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-ms-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)'), + '-o-transform': (display == 'none' ? 'translateY(-' + options.height + 'px)' : 'translateY(0px)') + }); + if (display == 'none') { + $('#w2ui-popup #w2ui-message'+ msgCount).show().html(options.html); + // timer needs to animation + setTimeout(function () { + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-moz-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-ms-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)'), + '-o-transform': (display == 'none' ? 'translateY(0px)' : 'translateY(-' + options.height + 'px)') + }); + }, 1); + // timer for lock + setTimeout(function() { + $('#w2ui-popup #w2ui-message'+ msgCount).css({ + '-webkit-transition': '0s', '-moz-transition': '0s', '-ms-transition': '0s', '-o-transition': '0s', + 'z-Index': 1500 + }); // has to be on top of lock + if (msgCount == 0) w2popup.lock(); + if (typeof options.onOpen == 'function') options.onOpen(); + }, 300); + } + } + }, + + lock: function (msg, showSpinner) { + var args = Array.prototype.slice.call(arguments, 0); + args.unshift($('#w2ui-popup')); + w2utils.lock.apply(window, args); + }, + + unlock: function () { + w2utils.unlock($('#w2ui-popup')); + }, + + // --- INTERNAL FUNCTIONS + + lockScreen: function (options) { + if ($('#w2ui-lock').length > 0) return false; + if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); + if (typeof options == 'undefined') options = {}; + options = $.extend({}, w2popup.defaults, options); + // show element + $('body').append(''); + // lock screen + setTimeout(function () { + $('#w2ui-lock').css({ + '-webkit-transition': options.speed + 's opacity', + '-moz-transition': options.speed + 's opacity', + '-ms-transition': options.speed + 's opacity', + '-o-transition': options.speed + 's opacity', + 'opacity': options.opacity + }); + }, 1); + // add events + if (options.modal == true) { + $('#w2ui-lock').on('mousedown', function () { + $('#w2ui-lock').css({ + '-webkit-transition': '.1s', + '-moz-transition': '.1s', + '-ms-transition': '.1s', + '-o-transition': '.1s', + 'opacity': '0.6' + }); + // if (window.getSelection) window.getSelection().removeAllRanges(); + }); + $('#w2ui-lock').on('mouseup', function () { + setTimeout(function () { + $('#w2ui-lock').css({ + '-webkit-transition': '.1s', + '-moz-transition': '.1s', + '-ms-transition': '.1s', + '-o-transition': '.1s', + 'opacity': options.opacity + }); + }, 100); + // if (window.getSelection) window.getSelection().removeAllRanges(); + }); + } else { + $('#w2ui-lock').on('mouseup', function () { w2popup.close(); }); + } + return true; + }, - resize: function (width, height, callBack) { - var options = $('#w2ui-popup').data('options'); - // calculate new position - if (parseInt($(window).width()) - 10 < parseInt(width)) width = parseInt($(window).width()) - 10; - if (parseInt($(window).height()) - 10 < parseInt(height)) height = parseInt($(window).height()) - 10; - var top = ((parseInt($(window).height()) - parseInt(height)) / 2) * 0.8; - var left = (parseInt($(window).width()) - parseInt(width)) / 2; - // resize there - $('#w2ui-popup').css({ - '-webkit-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-moz-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-ms-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - '-o-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top', - 'top': top, - 'left': left, - 'width': width, - 'height': height - }); - if (typeof callBack == 'function') { - setTimeout(function () { - callBack(); - }, options.speed * 1000); - } + unlockScreen: function (options) { + if ($('#w2ui-lock').length == 0) return false; + if (typeof options == 'undefined') options = $('#w2ui-popup').data('options'); + if (typeof options == 'undefined') options = {}; + options = $.extend({}, w2popup.defaults, options); + $('#w2ui-lock').css({ + '-webkit-transition': options.speed + 's opacity', + '-moz-transition': options.speed + 's opacity', + '-ms-transition': options.speed + 's opacity', + '-o-transition': options.speed + 's opacity', + 'opacity': 0 + }); + setTimeout(function () { + $('#w2ui-lock').remove(); + }, options.speed * 1000); + return true; + }, + + resize: function (width, height, callBack) { + var options = $('#w2ui-popup').data('options'); + // calculate new position + if (parseInt($(window).width()) - 10 < parseInt(width)) width = parseInt($(window).width()) - 10; + if (parseInt($(window).height()) - 10 < parseInt(height)) height = parseInt($(window).height()) - 10; + var top = ((parseInt($(window).height()) - parseInt(height)) / 2) * 0.8; + var left = (parseInt($(window).width()) - parseInt(width)) / 2; + // resize there + $('#w2ui-popup').css({ + '-webkit-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-moz-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-ms-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + '-o-transition': options.speed + 's width, ' + options.speed + 's height, ' + options.speed + 's left, ' + options.speed + 's top', + 'top': top, + 'left': left, + 'width': width, + 'height': height + }); + setTimeout(function () { + options.width = width; + options.height = height; + if (typeof callBack == 'function') callBack(); + }, (options.speed * 1000) + 50); // give extra 50 ms + } } - } - // merge in event handling - $.extend(w2popup, w2utils.event); + // merge in event handling + $.extend(w2popup, w2utils.event); })(jQuery); @@ -6940,4212 +8480,5213 @@ var w2popup = {}; // --- Common dialogs var w2alert = function (msg, title, callBack) { - if (typeof title == 'undefined') title = w2utils.lang('Notification'); - if (jQuery('#w2ui-popup').length > 0) { - w2popup.message({ - width : 400, - height : 150, - html : ''+ - ' '+ msg +''+ - ''+ - ''+ - ' '+ - '', - onClose : function () { - if (typeof callBack == 'function') callBack(); - } - }); - } else { - w2popup.open({ - width : 450, - height : 200, - showMax : false, - title : title, - body : '' + msg +'', - buttons : '', - onClose : function () { - if (typeof callBack == 'function') callBack(); - } - }); - } -}; - -var w2confirm = function (msg, title, callBack) { - if (typeof callBack == 'undefined' || typeof title == 'function') { - callBack = title; - title = w2utils.lang('Confirmation'); - } - if (typeof title == 'undefined') { - title = w2utils.lang('Confirmation'); - } - if (jQuery('#w2ui-popup').length > 0) { - w2popup.message({ - width : 400, - height : 150, - html : ''+ - ' '+ msg +''+ - ''+ - ''+ - ' '+ - ' '+ - '', - onOpen: function () { - jQuery('#w2ui-popup .w2ui-popup-message .w2ui-popup-button').on('click', function (event) { - w2popup.message(); - if (typeof callBack == 'function') callBack(event.target.id); + if (title == null) title = w2utils.lang('Notification'); + if (jQuery('#w2ui-popup').length > 0 && w2popup.status != 'closing') { + w2popup.message({ + width : 400, + height : 170, + html : '' + + ' ' + msg + '' + + '' + + '' + + ' ' + w2utils.lang('Ok') + '' + + '', + onClose : function () { + if (typeof callBack == 'function') callBack(); + } }); - }, - onKeydown: function (event) { - switch (event.originalEvent.keyCode) { - case 13: // enter - if (typeof callBack == 'function') callBack('Yes'); - w2popup.message(); - break - case 27: // esc - if (typeof callBack == 'function') callBack('No'); - w2popup.message(); - break - } - } - }); - } else { - w2popup.open({ - width : 450, - height : 200, - title : title, - modal : true, - showClose : false, - body : '' + msg +'', - buttons : ''+ - '', - onOpen: function (event) { - event.onComplete = function () { - jQuery('#w2ui-popup .w2ui-popup-button').on('click', function (event) { - w2popup.close(); - if (typeof callBack == 'function') callBack(event.target.id); - }); - } - }, - onKeydown: function (event) { - switch (event.originalEvent.keyCode) { - case 13: // enter - if (typeof callBack == 'function') callBack('Yes'); - w2popup.close(); - break - case 27: // esc - if (typeof callBack == 'function') callBack('No'); - w2popup.close(); - break - } - } - }); - } -}; - -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2tabs - tabs widget - * - $().w2tabs - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - tabs might not work in chromium apps, need bind() - * - on overflow display << >> - * - individual tab onClick (possibly other events) are not working - * - ************************************************************************/ - -(function ($) { - var w2tabs = function (options) { - this.box = null; // DOM Element that holds the element - this.name = null; // unique name for w2ui - this.active = null; - this.tabs = []; - this.right = ''; - this.style = ''; - this.onClick = null; - this.onClose = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - - $.extend(true, this, w2obj.tabs, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2tabs = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2tabs().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // extend tabs - var tabs = method.tabs; - var object = new w2tabs(method); - $.extend(object, { tabs: [], handlers: [] }); - for (var i in tabs) { object.tabs[i] = $.extend({}, w2tabs.prototype.tab, tabs[i]); } - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2tabs' ); + w2popup.open({ + width : 450, + height : 220, + showMax : false, + showClose : false, + title : title, + body : '' + msg + '', + buttons : '' + w2utils.lang('Ok') + '', + onClose : function () { + if (typeof callBack == 'function') callBack(); + } + }); } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2tabs.prototype = { - tab : { - id : null, // commnad to be sent to all event handlers - text : '', - hidden : false, - disabled : false, - closable : false, - hint : '', - onClick : null, - onRefresh : null, - onClose : null - }, - - add: function (tab) { - return this.insert(null, tab); - }, +}; - insert: function (id, tab) { - if (!$.isArray(tab)) tab = [tab]; - // assume it is array - for (var r in tab) { - // checks - if (String(tab[r].id) == 'undefined') { - console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+ this.name +')'); - return; - } - var unique = true; - for (var i in this.tabs) { if (this.tabs[i].id == tab[r].id) { unique = false; break; } } - if (!unique) { - console.log('ERROR: The parameter "id='+ tab[r].id +'" is not unique within the current tabs. (obj: '+ this.name +')'); - return; - } - if (!w2utils.isAlphaNumeric(tab[r].id)) { - console.log('ERROR: The parameter "id='+ tab[r].id +'" must be alpha-numeric + "-_". (obj: '+ this.name +')'); - return; - } - // add tab - var tab = $.extend({}, tab, tab[r]); - if (id == null || typeof id == 'undefined') { - this.tabs.push(tab); +var w2confirm = function (msg, title, callBack) { + var options = {}; + var defaults = { + msg : '', + title : w2utils.lang('Confirmation'), + width : (jQuery('#w2ui-popup').length > 0 ? 400 : 450), + height : (jQuery('#w2ui-popup').length > 0 ? 170 : 220), + yes_text : 'Yes', + yes_class : '', + yes_style : '', + yes_callBack: null, + no_text : 'No', + no_class : '', + no_style : '', + no_callBack : null, + callBack : null + }; + if (arguments.length == 1 && typeof msg == 'object') { + jQuery.extend(options, defaults, msg); + } else { + if (typeof title == 'function') { + jQuery.extend(options, defaults, { + msg : msg, + callBack: title + }) } else { - var middle = this.get(id, true); - this.tabs = this.tabs.slice(0, middle).concat([tab], this.tabs.slice(middle)); + jQuery.extend(options, defaults, { + msg : msg, + title : title, + callBack: callBack + }) } - this.refresh(tab[r].id); - } - }, - - remove: function (id) { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab) return false; - removed++; - // remove from array - this.tabs.splice(this.get(tab.id, true), 1); - // remove from screen - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).remove(); - } - return removed; - }, + } + if (jQuery('#w2ui-popup').length > 0 && w2popup.status != 'closing') { + if (options.width > w2popup.get().width) options.width = w2popup.get().width; + if (options.height > (w2popup.get().height - 50)) options.height = w2popup.get().height - 50; + w2popup.message({ + width : options.width, + height : options.height, + html : '' + + ' ' + options.msg + '' + + '' + + '' + + ' ' + w2utils.lang(options.yes_text) + '' + + ' ' + w2utils.lang(options.no_text) + '' + + '', + onOpen: function () { + jQuery('#w2ui-popup .w2ui-popup-message .btn').on('click', function (event) { + w2popup.message(); + if (typeof options.callBack == 'function') options.callBack(event.target.id); + if (event.target.id == 'Yes' && typeof options.yes_callBack == 'function') options.yes_callBack(); + if (event.target.id == 'No' && typeof options.no_callBack == 'function') options.no_callBack(); + }); + }, + onKeydown: function (event) { + switch (event.originalEvent.keyCode) { + case 13: // enter + if (typeof options.callBack == 'function') options.callBack('Yes'); + if (typeof options.yes_callBack == 'function') options.yes_callBack(); + w2popup.message(); + break + case 27: // esc + if (typeof options.callBack == 'function') options.callBack('No'); + if (typeof options.no_callBack == 'function') options.no_callBack(); + w2popup.message(); + break + } + } + }); - select: function (id) { - if (this.get(id) == null || this.active == id) return false; - this.active = id; - this.refresh(); - return true; - }, + } else { - set: function (id, tab) { - var index = this.get(id, true); - if (index == null) return false; - $.extend(this.tabs[index], tab); - this.refresh(id); - return true; - }, + if (!w2utils.isInt(options.height)) options.height = options.height + 50; + w2popup.open({ + width : options.width, + height : options.height, + title : options.title, + modal : true, + showClose : false, + body : '' + options.msg + '', + buttons : ''+ w2utils.lang(options.yes_text) +''+ + ''+ w2utils.lang(options.no_text) +'', + onOpen: function (event) { + event.onComplete = function () { + jQuery('#w2ui-popup .w2ui-popup-btn').on('click', function (event) { + w2popup.close(); + if (typeof options.callBack == 'function') options.callBack(event.target.id); + if (event.target.id == 'Yes' && typeof options.yes_callBack == 'function') options.yes_callBack(); + if (event.target.id == 'No' && typeof options.no_callBack == 'function') options.no_callBack(); + }); + } + }, + onKeydown: function (event) { + switch (event.originalEvent.keyCode) { + case 13: // enter + if (typeof options.callBack == 'function') options.callBack('Yes'); + if (typeof options.yes_callBack == 'function') options.yes_callBack(); + w2popup.close(); + break + case 27: // esc + if (typeof options.callBack == 'function') options.callBack('No'); + if (typeof options.no_callBack == 'function') options.no_callBack(); + w2popup.close(); + break + } + } + }); + } - get: function (id, returnIndex) { - if (arguments.length == 0) { - var all = []; - for (var i = 0; i < this.tabs.length; i++) if (this.tabs[i].id != null) all.push(this.tabs[i].id); - return all; - } - for (var i in this.tabs) { - if (this.tabs[i].id == id) { - if (returnIndex === true) return i; else return this.tabs[i]; + return { + yes: function (fun) { + options.yes_callBack = fun; + return this; + }, + no: function (fun) { + options.no_callBack = fun; + return this; } - } - return null; - }, - - show: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.hidden === false) continue; - tab.hidden = false; - this.refresh(tab.id); - shown++; - } - return shown; - }, - - hide: function () { - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.hidden === true) continue; - tab.hidden = true; - this.refresh(tab.id); - hidden++; - } - return hidden; - }, - - enable: function (id) { - var enabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.disabled === false) continue; - tab.disabled = false; - this.refresh(tab.id); - enabled++; - } - return enabled; - }, - - disable: function (id) { - var disabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tab = this.get(arguments[a]); - if (!tab || tab.disabled === true) continue; - tab.disabled = true; - this.refresh(tab.id); - disabled++; - } - return disabled; - }, + }; +}; +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2tabs - tabs widget +* - $().w2tabs - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - on overflow display << >> +* +************************************************************************/ - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (String(id) == 'undefined') { - // refresh all - for (var i in this.tabs) this.refresh(this.tabs[i].id); - } - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), object: this.get(id) }); - if (eventData.isCancelled === true) return false; - // create or refresh only one item - var tab = this.get(id); - if (tab == null) return; - if (typeof tab.caption != 'undefined') tab.text = tab.caption; - - var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); - var tabHTML = (tab.closable ? '' : '') + - ' ' + tab.text + ''; - if (jq_el.length == 0) { - // does not exist - create it - var addStyle = ''; - if (tab.hidden) { addStyle += 'display: none;'; } - if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } - html = ''+ tabHTML + ''; - if (this.get(id, true) != this.tabs.length-1 && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).length > 0) { - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).before(html); +(function ($) { + var w2tabs = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.active = null; + this.tabs = []; + this.routeData = {}; // data for dynamic routes + this.right = ''; + this.style = ''; + this.onClick = null; + this.onClose = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(this, { handlers: [] }); + $.extend(true, this, w2obj.tabs, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2tabs = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2tabs')) return; + // extend tabs + var tabs = method.tabs || []; + var object = new w2tabs(method); + for (var i = 0; i < tabs.length; i++) { + object.tabs[i] = $.extend({}, w2tabs.prototype.tab, tabs[i]); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - $(this.box).find('#tabs_'+ this.name +'_right').before(html); - } - } else { - // refresh - jq_el.html(tabHTML); - if (tab.hidden) { jq_el.css('display', 'none'); } - else { jq_el.css('display', ''); } - if (tab.disabled) { jq_el.css({ 'opacity': '0.2', '-moz-opacity': '0.2', '-webkit-opacity': '0.2', '-o-opacity': '0.2', 'filter': 'alpha(opacity=20)' }); } - else { jq_el.css({ 'opacity': '1', '-moz-opacity': '1', '-webkit-opacity': '1', '-o-opacity': '1', 'filter': 'alpha(opacity=100)' }); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2tabs' ); + return undefined; + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2tabs.prototype = { + tab : { + id : null, // command to be sent to all event handlers + text : '', + route : null, + hidden : false, + disabled : false, + closable : false, + hint : '', + onClick : null, + onRefresh : null, + onClose : null + }, + + add: function (tab) { + return this.insert(null, tab); + }, + + insert: function (id, tab) { + if (!$.isArray(tab)) tab = [tab]; + // assume it is array + for (var i = 0; i < tab.length; i++) { + // checks + if (typeof tab[i].id === 'undefined') { + console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+ this.name +')'); + return; + } + if (!w2utils.checkUniqueId(tab[i].id, this.tabs, 'tabs', this.name)) return; + // add tab + var newTab = $.extend({}, w2tabs.prototype.tab, tab[i]); + if (id === null || typeof id === 'undefined') { + this.tabs.push(newTab); + } else { + var middle = this.get(id, true); + this.tabs = this.tabs.slice(0, middle).concat([newTab], this.tabs.slice(middle)); + } + this.refresh(tab[i].id); + } + }, + + remove: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab) return false; + removed++; + // remove from array + this.tabs.splice(this.get(tab.id, true), 1); + // remove from screen + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).remove(); + } + return removed; + }, - render: function (box) { - var time = (new Date()).getTime(); - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - // default action - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - if (String(box) != 'undefined' && box != null) { - if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-tabs') - .html(''); - } - this.box = box; - } - if (!this.box) return; - // render all buttons - var html = ''+ - ' '+ this.right +''+ - ''; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-tabs') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - return (new Date()).getTime() - time; - }, + select: function (id) { + if (this.active == id || this.get(id) === null) return false; + this.active = id; + this.refresh(); + return true; + }, - resize: function () { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // empty function - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + set: function (id, tab) { + var index = this.get(id, true); + if (index === null) return false; + $.extend(this.tabs[index], tab); + this.refresh(id); + return true; + }, + + get: function (id, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var i1 = 0; i1 < this.tabs.length; i1++) { + if (this.tabs[i1].id != null) { + all.push(this.tabs[i1].id); + } + } + return all; + } else { + for (var i2 = 0; i2 < this.tabs.length; i2++) { + if (this.tabs[i2].id == id) { // need to be == since id can be numeric + return (returnIndex === true ? i2 : this.tabs[i2]); + } + } + } + return null; + }, + + show: function () { + var obj = this; + var shown = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.hidden === false) continue; + shown++; + tab.hidden = false; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return shown; + }, + + hide: function () { + var obj = this; + var hidden= 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.hidden === true) continue; + hidden++; + tab.hidden = true; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return hidden; + }, + + enable: function () { + var obj = this; + var enabled = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.disabled === false) continue; + enabled++; + tab.disabled = false; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return enabled; + }, + + disable: function () { + var obj = this; + var disabled = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var tab = this.get(arguments[a]); + if (!tab || tab.disabled === true) continue; + disabled++; + tab.disabled = true; + tmp.push(tab.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return disabled; + }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-tabs') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id !== 'undefined' ? id : this.name), object: this.get(id) }); + if (eventData.isCancelled === true) return; + if (typeof id === 'undefined') { + // refresh all + for (var i = 0; i < this.tabs.length; i++) this.refresh(this.tabs[i].id); + } else { + // create or refresh only one item + var tab = this.get(id); + if (tab === null) return false; + if (typeof tab.caption !== 'undefined') tab.text = tab.caption; + + var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); + var tabHTML = (tab.closable ? '' : '') + + ' ' + tab.text + ''; + if (jq_el.length === 0) { + // does not exist - create it + var addStyle = ''; + if (tab.hidden) { addStyle += 'display: none;'; } + if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } + var html = ''+ tabHTML + ''; + if (this.get(id, true) !== this.tabs.length-1 && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).length > 0) { + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).before(html); + } else { + $(this.box).find('#tabs_'+ this.name +'_right').before(html); + } + } else { + // refresh + jq_el.html(tabHTML); + if (tab.hidden) { jq_el.css('display', 'none'); } + else { jq_el.css('display', ''); } + if (tab.disabled) { jq_el.css({ 'opacity': '0.2', '-moz-opacity': '0.2', '-webkit-opacity': '0.2', '-o-opacity': '0.2', 'filter': 'alpha(opacity=20)' }); } + else { jq_el.css({ 'opacity': '1', '-moz-opacity': '1', '-webkit-opacity': '1', '-o-opacity': '1', 'filter': 'alpha(opacity=100)' }); } + } + } + // right html + $('#tabs_'+ this.name +'_right').html(this.right); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - // =================================================== - // -- Internal Event Handlers - - click: function (id, event) { - var tab = this.get(id); - if (tab == null || tab.disabled) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: id, object: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.active) +' .w2ui-tab').removeClass('active'); - this.active = tab.id; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(id); - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + // default action + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + if (typeof box !== 'undefined' && box !== null) { + if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-tabs') + .html(''); + } + this.box = box; + } + if (!this.box) return false; + // render all buttons + var html = ''+ + ' '+ this.right +''+ + ''; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-tabs') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + return (new Date()).getTime() - time; + }, - animateClose: function(id, event) { - var tab = this.get(id); - if (tab == null || tab.disabled) return false; - // event before - var eventData = this.trigger({ phase: 'before', type: 'close', target: id, object: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default action - var obj = this; - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).css({ - '-webkit-transition': '.2s', - '-moz-transition': '2s', - '-ms-transition': '.2s', - '-o-transition': '.2s', - opacity: '0' }); - setTimeout(function () { - var width = $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).width(); - $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)) - .html('') - setTimeout(function () { - $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).find(':first-child').css({ 'width': '0px' }); - }, 50); - }, 200); - setTimeout(function () { - obj.remove(id); - }, 450); - // event before - this.trigger($.extend(eventData, { phase: 'after' })); - this.refresh(); - }, + resize: function () { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; - animateInsert: function(id, tab) { - if (this.get(id) == null) return; - if (!$.isPlainObject(tab)) return; - // check for unique - var unique = true; - for (var i in this.tabs) { if (this.tabs[i].id == tab.id) { unique = false; break; } } - if (!unique) { - console.log('ERROR: The parameter "id='+ tab.id +'" is not unique within the current tabs. (obj: '+ this.name +')'); - return; - } - // insert simple div - var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); - if (jq_el.length != 0) return; // already exists - // measure width - if (typeof tab.caption != 'undefined') tab.text = tab.caption; - var tmp = ''+ - ''+ - ''+ - (tab.closable ? '' : '') + - ' '+ tab.text +''+ - ''+ - ''; - $('body').append(tmp); - // create dummy element - tabHTML = ' '; - var addStyle = ''; - if (tab.hidden) { addStyle += 'display: none;'; } - if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } - html = ''+ tabHTML +''; - if (this.get(id, true) != this.tabs.length && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).length > 0) { - $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).before(html); - } else { - $(this.box).find('#tabs_'+ this.name +'_right').before(html); - } - // -- move - var obj = this; - setTimeout(function () { - var width = $('#_tmp_simple_tab').width(); - $('#_tmp_tabs').remove(); - $('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id) +' > div').css('width', width+'px'); - }, 1); - setTimeout(function () { - // insert for real - obj.insert(id, tab); - }, 200); - } - } + // intentionaly blank - $.extend(w2tabs.prototype, w2utils.event); - w2obj.tabs = w2tabs; -})(jQuery); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2toolbar - toolbar widget - * - $().w2toolbar - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - on overflow display << >> - * - ************************************************************************/ + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-tabs') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, -(function ($) { - var w2toolbar = function (options) { - this.box = null, // DOM Element that holds the element - this.name = null, // unique name for w2ui - this.items = [], - this.right = '', // HTML text on the right of toolbar - this.onClick = null, - this.onRender = null, - this.onRefresh = null, - this.onResize = null, - this.onDestroy = null - - $.extend(true, this, w2obj.toolbar, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2toolbar = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2toolbar().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - var items = method.items; - // extend items - var object = new w2toolbar(method); - $.extend(object, { items: [], handlers: [] }); - - for (var i in items) { object.items[i] = $.extend({}, w2toolbar.prototype.item, items[i]); } - if ($(this).length != 0) { - object.render($(this)[0]); - } - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2toolbar' ); - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2toolbar.prototype = { - item: { - id : null, // commnad to be sent to all event handlers - type : 'button', // button, check, radio, drop, menu, break, html, spacer - text : '', - html : '', - img : null, - icon : null, - hidden : false, - disabled: false, - checked : false, // used for radio buttons - arrow : true, // arrow down for drop/menu types - hint : '', - group : null, // used for radio buttons - items : null, // for type menu it is an array of items in the menu - onClick : null - }, + // =================================================== + // -- Internal Event Handlers - add: function (items) { - this.insert(null, items); - }, + click: function (id, event) { + var tab = this.get(id); + if (tab === null || tab.disabled) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: id, tab: tab, object: tab, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.active) +' .w2ui-tab').removeClass('active'); + this.active = tab.id; + // route processing + if (tab.route) { + var route = String('/'+ tab.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (this.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(id); + }, - insert: function (id, items) { - if (!$.isArray(items)) items = [items]; - for (var o in items) { - // checks - if (typeof items[o].type == 'undefined') { - console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.'); - return; - } - if ($.inArray(String(items[o].type), ['button', 'check', 'radio', 'drop', 'menu', 'break', 'html', 'spacer']) == -1) { - console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] '+ - 'in w2toolbar.add() method.'); - return; - } - if (typeof items[o].id == 'undefined') { - console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.'); - return; - } - var unique = true; - for (var i = 0; i < this.items.length; i++) { if (this.items[i].id == items[o].id) { unique = false; return; } } - if (!unique) { - console.log('ERROR: The parameter "id" is not unique within the current toolbar.'); - return; - } - if (!w2utils.isAlphaNumeric(items[o].id)) { - console.log('ERROR: The parameter "id" must be alpha-numeric + "-_".'); - return; - } - // add item - var it = $.extend({}, w2toolbar.prototype.item, items[o]); - if (id == null || typeof id == 'undefined') { - this.items.push(it); - } else { - var middle = this.get(id, true); - this.items = this.items.slice(0, middle).concat([it], this.items.slice(middle)); + animateClose: function(id, event) { + var tab = this.get(id); + if (tab === null || tab.disabled) return false; + // event before + var eventData = this.trigger({ phase: 'before', type: 'close', target: id, object: this.get(id), originalEvent: event }); + if (eventData.isCancelled === true) return; + // default action + var obj = this; + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).css({ + '-webkit-transition': '.2s', + '-moz-transition': '2s', + '-ms-transition': '.2s', + '-o-transition': '.2s', + opacity: '0' }); + setTimeout(function () { + var width = $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).width(); + $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)) + .html(''); + setTimeout(function () { + $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).find(':first-child').css({ 'width': '0px' }); + }, 50); + }, 200); + setTimeout(function () { + obj.remove(id); + }, 450); + // event before + this.trigger($.extend(eventData, { phase: 'after' })); + this.refresh(); + }, + + animateInsert: function(id, tab) { + if (this.get(id) === null) return; + if (!$.isPlainObject(tab)) return; + // check for unique + if (!w2utils.checkUniqueId(tab.id, this.tabs, 'tabs', this.name)) return; + // insert simple div + var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)); + if (jq_el.length !== 0) return; // already exists + // measure width + if (typeof tab.caption !== 'undefined') tab.text = tab.caption; + var tmp = ''+ + ''+ + ''+ + (tab.closable ? '' : '') + + ' '+ tab.text +''+ + ''+ + ''; + $('body').append(tmp); + // create dummy element + var tabHTML = ' '; + var addStyle = ''; + if (tab.hidden) { addStyle += 'display: none;'; } + if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; } + var html = ''+ tabHTML +''; + if (this.get(id, true) !== this.tabs.length && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).length > 0) { + $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))].id)).before(html); + } else { + $(this.box).find('#tabs_'+ this.name +'_right').before(html); + } + // -- move + var obj = this; + setTimeout(function () { + var width = $('#_tmp_simple_tab').width(); + $('#_tmp_tabs').remove(); + $('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id) +' > div').css('width', width+'px'); + }, 1); + setTimeout(function () { + // insert for real + obj.insert(id, tab); + }, 200); } - this.refresh(it.id); - } - }, + }; - remove: function (id) { - var removed = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - removed++; - // remove from screen - $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)).remove(); - // remove from array - var ind = this.get(it.id, true); - if (ind) this.items.splice(ind, 1); - } - return removed; - }, - - set: function (id, item) { - var index = this.get(id, true); - if (index == null) return false; - $.extend(this.items[index], item); - this.refresh(id); - return true; - }, + $.extend(w2tabs.prototype, w2utils.event); + w2obj.tabs = w2tabs; +})(jQuery); - get: function (id, returnIndex) { - if (arguments.length == 0) { - var all = []; - for (var i = 0; i < this.items.length; i++) if (this.items[i].id != null) all.push(this.items[i].id); - return all; - } - for (var i = 0; i < this.items.length; i++) { - if (this.items[i].id == id) { - if (returnIndex === true) return i; else return this.items[i]; - } - } - return null; - }, - show: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.hidden = false; - this.refresh(it.id); - } - return items; - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2toolbar - toolbar widget +* - $().w2toolbar - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - on overflow display << >> +* - verticle toolbar +* +************************************************************************/ - hide: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.hidden = true; - this.refresh(it.id); - } - return items; - }, +(function ($) { + var w2toolbar = function (options) { + this.box = null; // DOM Element that holds the element + this.name = null; // unique name for w2ui + this.routeData = {}; // data for dynamic routes + this.items = []; + this.right = ''; // HTML text on the right of toolbar + this.onClick = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.toolbar, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2toolbar = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2toolbar')) return; + // extend items + var items = method.items || []; + var object = new w2toolbar(method); + $.extend(object, { items: [], handlers: [] }); + for (var i = 0; i < items.length; i++) { + object.items[i] = $.extend({}, w2toolbar.prototype.item, items[i]); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; + } else { + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2toolbar' ); + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2toolbar.prototype = { + item: { + id : null, // command to be sent to all event handlers + type : 'button', // button, check, radio, drop, menu, break, html, spacer + text : '', + route : null, // if not null, it is route to go + html : '', + img : null, + icon : null, + count : null, + hidden : false, + disabled : false, + checked : false, // used for radio buttons + arrow : true, // arrow down for drop/menu types + hint : '', + group : null, // used for radio buttons + items : null, // for type menu it is an array of items in the menu + overlay : {}, + onClick : null + }, + + add: function (items) { + this.insert(null, items); + }, + + insert: function (id, items) { + if (!$.isArray(items)) items = [items]; + for (var o = 0; o < items.length; o++) { + // checks + if (typeof items[o].type === 'undefined') { + console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.'); + return; + } + if ($.inArray(String(items[o].type), ['button', 'check', 'radio', 'drop', 'menu', 'break', 'html', 'spacer']) === -1) { + console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] '+ + 'in w2toolbar.add() method.'); + return; + } + if (typeof items[o].id === 'undefined') { + console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.'); + return; + } + if (!w2utils.checkUniqueId(items[o].id, this.items, 'toolbar items', this.name)) return; + // add item + var it = $.extend({}, w2toolbar.prototype.item, items[o]); + if (id == null) { + this.items.push(it); + } else { + var middle = this.get(id, true); + this.items = this.items.slice(0, middle).concat([it], this.items.slice(middle)); + } + this.refresh(it.id); + } + }, + + remove: function () { + var removed = 0; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + removed++; + // remove from screen + $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)).remove(); + // remove from array + var ind = this.get(it.id, true); + if (ind) this.items.splice(ind, 1); + } + return removed; + }, + + set: function (id, item) { + var index = this.get(id, true); + if (index === null) return false; + $.extend(this.items[index], item); + this.refresh(id); + return true; + }, - enable: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.disabled = false; - this.refresh(it.id); - } - return items; - }, + get: function (id, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var i1 = 0; i1 < this.items.length; i1++) if (this.items[i1].id !== null) all.push(this.items[i1].id); + return all; + } + for (var i2 = 0; i2 < this.items.length; i2++) { + if (this.items[i2].id === id) { + if (returnIndex === true) return i2; else return this.items[i2]; + } + } + return null; + }, + + show: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.hidden = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + hide: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.hidden = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + enable: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.disabled = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + disable: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.disabled = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + check: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.checked = true; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, + + uncheck: function () { + var obj = this; + var items = 0; + var tmp = []; + for (var a = 0; a < arguments.length; a++) { + var it = this.get(arguments[a]); + if (!it) continue; + items++; + it.checked = false; + tmp.push(it.id); + } + setTimeout(function () { for (var t in tmp) obj.refresh(tmp[t]); }, 15); // needs timeout + return items; + }, - disable: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.disabled = true; - this.refresh(it.id); - } - return items; - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + + if (box != null) { + if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-toolbar') + .html(''); + } + this.box = box; + } + if (!this.box) return; + // render all buttons + var html = ''+ + ''; + for (var i = 0; i < this.items.length; i++) { + var it = this.items[i]; + if (it.id == null) it.id = "item_" + i; + if (it === null) continue; + if (it.type === 'spacer') { + html += ''; + } else { + html += ''+ this.getItemHTML(it) + + ''; + } + } + html += ''+ this.right +''; + html += ''+ + ''; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-toolbar') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - check: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.checked = true; - this.refresh(it.id); - } - return items; - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id !== 'undefined' ? id : this.name), item: this.get(id) }); + if (eventData.isCancelled === true) return; + + if (id == null) { + // refresh all + for (var i = 0; i < this.items.length; i++) { + var it1 = this.items[i]; + if (it1.id == null) it1.id = "item_" + i; + this.refresh(it1.id); + } + } + // create or refresh only one item + var it = this.get(id); + if (it === null) return false; + + var el = $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)); + var html = this.getItemHTML(it); + if (el.length === 0) { + // does not exist - create it + if (it.type === 'spacer') { + html = ''; + } else { + html = ''+ html + + ''; + } + if (this.get(id, true) === this.items.length-1) { + $(this.box).find('#tb_'+ this.name +'_right').before(html); + } else { + $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(this.items[parseInt(this.get(id, true))+1].id)).before(html); + } + } else { + // refresh + el.html(html); + if (it.hidden) { el.css('display', 'none'); } else { el.css('display', ''); } + if (it.disabled) { el.addClass('disabled'); } else { el.removeClass('disabled'); } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - uncheck: function (id) { - var items = 0; - for (var a = 0; a < arguments.length; a++) { - var it = this.get(arguments[a]); - if (!it) continue; - items++; - it.checked = false; - this.refresh(it.id); - } - return items; - }, + resize: function () { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; - render: function (box) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-toolbar') - .html(''); - } - this.box = box; - } - if (!this.box) return; - // render all buttons - var html = ''+ - ''; - for (var i = 0; i < this.items.length; i++) { - var it = this.items[i]; - if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i; - if (it == null) continue; - if (it.type == 'spacer') { - html += ''; - } else { - html += ''+ this.getItemHTML(it) + - ''; - } - } - html += ''+ this.right +''; - html += ''+ - ''; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-toolbar') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + // intentionaly blank - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id) }); - if (eventData.isCancelled === true) return false; - - if (typeof id == 'undefined') { - // refresh all - for (var i = 0; i < this.items.length; i++) { - var it = this.items[i]; - if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i; - this.refresh(it.id); - } - } - // create or refresh only one item - var it = this.get(id); - if (it == null) return; - - var el = $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)); - var html = this.getItemHTML(it); - if (el.length == 0) { - // does not exist - create it - if (it.type == 'spacer') { - html = ''; - } else { - html = ''+ html + - ''; - } - if (this.get(id, true) == this.items.length-1) { - $(this.box).find('#tb_'+ this.name +'_right').before(html); - } else { - $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(this.items[parseInt(this.get(id, true))+1].id)).before(html); - } - } else { - // refresh - el.html(html); - if (it.hidden) { el.css('display', 'none'); } else { el.css('display', ''); } - if (it.disabled) { el.addClass('disabled'); } else { el.removeClass('disabled'); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - resize: function () { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-toolbar') + .html(''); + } + $(this.box).html(''); + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + // ======================================== + // --- Internal Functions + + getItemHTML: function (item) { + var html = ''; + + if (typeof item.caption !== 'undefined') item.text = item.caption; + if (typeof item.hint === 'undefined') item.hint = ''; + if (typeof item.text === 'undefined') item.text = ''; + + switch (item.type) { + case 'menu': + case 'button': + case 'check': + case 'radio': + case 'drop': + var img = ' '; + if (item.img) img = ''; + if (item.icon) img = ''; + html += ''+ + ''+ + ' '+ + ' ' + + img + + (item.text !== '' ? ''+ item.text +'' : '') + + (item.count != null ? ''+ item.count +'' : '') + + (((item.type === 'drop' || item.type === 'menu') && item.arrow !== false) ? + '' : '') + + ' '+ + ''; + break; - // empty function + case 'break': + html += ''+ + ' '+ + ''; + break; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + case 'html': + html += ''+ + ' ' + item.html + ''+ + ''; + break; + } - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-toolbar') - .html(''); - } - $(this.box).html(''); - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + var newHTML = ''; + if (typeof item.onRender === 'function') newHTML = item.onRender.call(this, item.id, html); + if (typeof this.onRender === 'function') newHTML = this.onRender(item.id, html); + if (newHTML !== '' && newHTML != null) html = newHTML; + return html; + }, - // ======================================== - // --- Internal Functions - - getItemHTML: function (item) { - var html = ''; - - if (typeof item.caption != 'undefined') item.text = item.caption; - if (typeof item.hint == 'undefined') item.hint = ''; - if (typeof item.text == 'undefined') item.text = ''; - - switch (item.type) { - case 'menu': - case 'button': - case 'check': - case 'radio': - case 'drop': - var img = ' '; - if (item.img) img = ''; - if (item.icon) img = ''; - html += ''+ - ''+ - ' '+ - ' ' + - img + - (item.text != '' ? ''+ item.text +'' : '') + - (((item.type == 'drop' || item.type == 'menu') && item.arrow !== false) ? - ' ' : '') + - ' '+ - ''; - break; - - case 'break': - html += ''+ - ' '+ - ''; - break; - - case 'html': - html += ''+ - ' ' + item.html + ''+ - ''; - break; - } - - var newHTML = ''; - if (typeof item.onRender == 'function') newHTML = item.onRender.call(this, item.id, html); - if (typeof this.onRender == 'function') newHTML = this.onRender(item.id, html); - if (newHTML != '' && typeof newHTML != 'undefined') html = newHTML; - return html; - }, + menuClick: function (event) { + var obj = this; + if (event.item && !event.item.disabled) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: event.item.id + ':' + event.subItem.id, item: event.item, + subItem: event.subItem, originalEvent: event.originalEvent }); + if (eventData.isCancelled === true) return; + + // route processing + var it = event.subItem; + if (it.route) { + var route = String('/'+ it.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } - menuClick: function (id, menu_index, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var obj = this; - var it = this.get(id); - if (it && !it.disabled) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id), - subItem: (typeof menu_index != 'undefined' && this.get(id) ? this.get(id).items[menu_index] : null), originalEvent: event }); - if (eventData.isCancelled === true) return false; - - // normal processing - - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - }, + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } + }, - click: function (id, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var obj = this; - var it = this.get(id); - if (it && !it.disabled) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name), - item: this.get(id), originalEvent: event }); - if (eventData.isCancelled === true) return false; - - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('down'); - - if (it.type == 'radio') { - for (var i = 0; i < this.items.length; i++) { - var itt = this.items[i]; - if (itt == null || itt.id == it.id || itt.type != 'radio') continue; - if (itt.group == it.group && itt.checked) { - itt.checked = false; - this.refresh(itt.id); - } - } - it.checked = true; - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } + click: function (id, event) { + var obj = this; + var it = this.get(id); + if (it && !it.disabled) { + // event before + var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id !== 'undefined' ? id : this.name), + item: it, object: it, originalEvent: event }); + if (eventData.isCancelled === true) return; + + var btn = $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button'); + btn.removeClass('down'); + + if (it.type === 'radio') { + for (var i = 0; i < this.items.length; i++) { + var itt = this.items[i]; + if (itt == null || itt.id === it.id || itt.type !== 'radio') continue; + if (itt.group === it.group && itt.checked) { + itt.checked = false; + this.refresh(itt.id); + } + } + it.checked = true; + btn.addClass('checked'); + } - if (it.type == 'drop' || it.type == 'menu') { - if (it.checked) { - // if it was already checked, second click will hide it - it.checked = false; - } else { - // show overlay - setTimeout(function () { - var el = $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id)); - if (!$.isPlainObject(it.overlay)) it.overlay = {}; - if (it.type == 'drop') { - el.w2overlay(it.html, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay)); - } - if (it.type == 'menu') { - el.w2menu(it.items, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay, { - select: function (item, event, index) { obj.menuClick(it.id, index, event); } - })); - } - // window.click to hide it - $(document).on('click', hideDrop); - function hideDrop() { - it.checked = false; - if (it.checked) { - $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } else { - $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked'); + if (it.type === 'drop' || it.type === 'menu') { + if (it.checked) { + // if it was already checked, second click will hide it + it.checked = false; + } else { + // show overlay + setTimeout(function () { + var el = $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id)); + if (!$.isPlainObject(it.overlay)) it.overlay = {}; + var left = (el.width() - 50) / 2; + if (left > 19) left = 19; + if (it.type === 'drop') { + el.w2overlay(it.html, $.extend({ left: left, top: 3 }, it.overlay)); + } + if (it.type === 'menu') { + el.w2menu(it.items, $.extend({ left: left, top: 3 }, it.overlay, { + select: function (event) { + obj.menuClick({ item: it, subItem: event.item, originalEvent: event.originalEvent }); + hideDrop(); + } + })); + } + // window.click to hide it + $(document).on('click', hideDrop); + function hideDrop() { + $(document).off('click', hideDrop); + it.checked = false; + btn.removeClass('checked'); + } + }, 1); + } } - obj.refresh(it.id); - $(document).off('click', hideDrop); - } - }, 1); - } - } - if (it.type == 'check' || it.type == 'drop' || it.type == 'menu') { - it.checked = !it.checked; - if (it.checked) { - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked'); - } else { - $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked'); - } + if (it.type === 'check' || it.type === 'drop' || it.type === 'menu') { + it.checked = !it.checked; + if (it.checked) { + btn.addClass('checked'); + } else { + btn.removeClass('checked'); + } + } + // route processing + if (it.route) { + var route = String('/'+ it.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), this.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + } } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - } - } - } + }; - $.extend(w2toolbar.prototype, w2utils.event); - w2obj.toolbar = w2toolbar; + $.extend(w2toolbar.prototype, w2utils.event); + w2obj.toolbar = w2toolbar; })(jQuery); + /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2sidebar - sidebar widget - * - $().w2sidebar - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - return ids of all subitems - * - add find() method to find nodes by a specific criteria (I want all nodes for exampe) - * - dbl click should be like it is in grid (with timer not HTML dbl click event) - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2sidebar - sidebar widget +* - $().w2sidebar - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - return ids of all subitems +* - add find() method to find nodes by a specific criteria (I want all nodes for exampe) +* - dbl click should be like it is in grid (with timer not HTML dbl click event) +* - reorder with grag and drop +* - add route property that would navigate to a #route +* - node.style is missleading - should be there to apply color for example +* +************************************************************************/ (function ($) { - var w2sidebar = function (options) { - this.name = null; - this.box = null; - this.sidebar = null; - this.parent = null; - this.nodes = []; // Sidebar child nodes - this.menu = []; - this.selected = null; // current selected node (readonly) - this.img = null; - this.icon = null; - this.style = ''; - this.topHTML = ''; - this.bottomHTML = ''; - this.keyboard = true; - this.onClick = null; // Fire when user click on Node Text - this.onDblClick = null; // Fire when user dbl clicks - this.onContextMenu = null; - this.onMenuClick = null; // when context menu item selected - this.onExpand = null; // Fire when node Expands - this.onCollapse = null; // Fire when node Colapses - this.onKeydown = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - - $.extend(true, this, w2obj.sidebar, options); - } - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2sidebar = function(method) { - if (typeof method === 'object' || !method ) { - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2sidebar().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // extend items - var nodes = method.nodes; - var object = new w2sidebar(method); - $.extend(object, { handlers: [], nodes: [] }); - if (typeof nodes != 'undefined') { - object.add(object, nodes); - } - if ($(this).length != 0) { - object.render($(this)[0]); - } - object.sidebar = object; - // register new object - w2ui[object.name] = object; - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2sidebar' ); - } - }; - - // ==================================================== - // -- Implementation of core functionality - - w2sidebar.prototype = { - - node: { - id : null, - text : '', - count : '', - img : null, - icon : null, - nodes : [], - style : '', - selected : false, - expanded : false, - hidden : false, - disabled : false, - group : false, // if true, it will build as a group - plus : false, // if true, plus will be shown even if there is no sub nodes - // events - onClick : null, - onDblClick : null, - onContextMenu : null, - onExpand : null, - onCollapse : null, - // internal - parent : null, // node object - sidebar : null - }, - - add: function (parent, nodes) { - if (arguments.length == 1) { - // need to be in reverse order - nodes = arguments[0]; - parent = this; - } - if (typeof parent == 'string') parent = this.get(parent); - return this.insert(parent, null, nodes); - }, - - insert: function (parent, before, nodes) { - if (arguments.length == 2) { - // need to be in reverse order - nodes = arguments[1]; - before = arguments[0]; - var ind = this.get(before); - if (ind == null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); - return null; - } - parent = this.get(before).parent; - } - if (typeof parent == 'string') parent = this.get(parent); - if (!$.isArray(nodes)) nodes = [nodes]; - for (var o in nodes) { - if (typeof nodes[o].id == 'undefined') { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because it has no id.'); - continue; - } - if (this.get(this, nodes[o].id) != null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node with id='+ nodes[o].id +' (text: '+ txt + ') because another node with the same id already exists.'); - continue; - } - var tmp = $.extend({}, w2sidebar.prototype.node, nodes[o]); - tmp.sidebar= this; - tmp.parent = parent; - var nd = tmp.nodes; - tmp.nodes = []; // very important to re-init empty nodes array - if (before == null) { // append to the end - parent.nodes.push(tmp); + var w2sidebar = function (options) { + this.name = null; + this.box = null; + this.sidebar = null; + this.parent = null; + this.nodes = []; // Sidebar child nodes + this.menu = []; + this.routeData = {}; // data for dynamic routes + this.selected = null; // current selected node (readonly) + this.img = null; + this.icon = null; + this.style = ''; + this.topHTML = ''; + this.bottomHTML = ''; + this.keyboard = true; + this.onClick = null; // Fire when user click on Node Text + this.onDblClick = null; // Fire when user dbl clicks + this.onContextMenu = null; + this.onMenuClick = null; // when context menu item selected + this.onExpand = null; // Fire when node Expands + this.onCollapse = null; // Fire when node Colapses + this.onKeydown = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + + $.extend(true, this, w2obj.sidebar, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2sidebar = function(method) { + if (typeof method === 'object' || !method ) { + // check name parameter + if (!w2utils.checkName(method, 'w2sidebar')) return; + // extend items + var nodes = method.nodes; + var object = new w2sidebar(method); + $.extend(object, { handlers: [], nodes: [] }); + if (typeof nodes != 'undefined') { + object.add(object, nodes); + } + if ($(this).length !== 0) { + object.render($(this)[0]); + } + object.sidebar = object; + // register new object + w2ui[object.name] = object; + return object; + + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - var ind = this.get(parent, before, true); - if (ind == null) { - var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text); - console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); - return null; - } - parent.nodes.splice(ind, 0, tmp); - } - if (typeof nd != 'undefined' && nd.length > 0) { this.insert(tmp, null, nd); } - } - this.refresh(parent.id); - return tmp; - }, - - remove: function () { // multiple arguments - var deleted = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - var ind = this.get(tmp.parent, arguments[a], true); - if (ind == null) continue; - tmp.parent.nodes.splice(ind, 1); - deleted++; - } - if (deleted > 0 && arguments.length == 1) this.refresh(tmp.parent.id); else this.refresh(); - return deleted; - }, + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2sidebar' ); + } + }; + + // ==================================================== + // -- Implementation of core functionality + + w2sidebar.prototype = { + + node: { + id : null, + text : '', + count : null, + img : null, + icon : null, + nodes : [], + style : '', // additional style for subitems + route : null, + selected : false, + expanded : false, + hidden : false, + disabled : false, + group : false, // if true, it will build as a group + groupShowHide : true, + plus : false, // if true, plus will be shown even if there is no sub nodes + // events + onClick : null, + onDblClick : null, + onContextMenu : null, + onExpand : null, + onCollapse : null, + // internal + parent : null, // node object + sidebar : null + }, + + add: function (parent, nodes) { + if (arguments.length == 1) { + // need to be in reverse order + nodes = arguments[0]; + parent = this; + } + if (typeof parent == 'string') parent = this.get(parent); + return this.insert(parent, null, nodes); + }, + + insert: function (parent, before, nodes) { + var txt, ind, tmp, node, nd; + if (arguments.length == 2) { + // need to be in reverse order + nodes = arguments[1]; + before = arguments[0]; + ind = this.get(before); + if (ind === null) { + if (!$.isArray(nodes)) nodes = [nodes]; + txt = (nodes[0].caption != null ? nodes[0].caption : nodes[0].text); + console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); + return null; + } + parent = this.get(before).parent; + } + if (typeof parent == 'string') parent = this.get(parent); + if (!$.isArray(nodes)) nodes = [nodes]; + for (var o in nodes) { + node = nodes[o]; + if (typeof node.id == null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node "'+ txt +'" because it has no id.'); + continue; + } + if (this.get(this, node.id) !== null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node with id='+ node.id +' (text: '+ txt + ') because another node with the same id already exists.'); + continue; + } + tmp = $.extend({}, w2sidebar.prototype.node, node); + tmp.sidebar = this; + tmp.parent = parent; + nd = tmp.nodes || []; + tmp.nodes = []; // very important to re-init empty nodes array + if (before === null) { // append to the end + parent.nodes.push(tmp); + } else { + ind = this.get(parent, before, true); + if (ind === null) { + txt = (node.caption != null ? node.caption : node.text); + console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.'); + return null; + } + parent.nodes.splice(ind, 0, tmp); + } + if (nd.length > 0) { + this.insert(tmp, null, nd); + } + } + this.refresh(parent.id); + return tmp; + }, + + remove: function () { // multiple arguments + var deleted = 0; + var tmp; + for (var a = 0; a < arguments.length; a++) { + tmp = this.get(arguments[a]); + if (tmp === null) continue; + if (this.selected !== null && this.selected === tmp.id) { + this.selected = null; + } + var ind = this.get(tmp.parent, arguments[a], true); + if (ind === null) continue; + if (tmp.parent.nodes[ind].selected) tmp.sidebar.unselect(tmp.id); + tmp.parent.nodes.splice(ind, 1); + deleted++; + } + if (deleted > 0 && arguments.length == 1) this.refresh(tmp.parent.id); else this.refresh(); + return deleted; + }, + + set: function (parent, id, node) { + if (arguments.length == 2) { + // need to be in reverse order + node = id; + id = parent; + parent = this; + } + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return null; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].id === id) { + // make sure nodes inserted correctly + var nodes = node.nodes; + $.extend(parent.nodes[i], node, { nodes: [] }); + if (nodes != null) { + this.add(parent.nodes[i], nodes); + } + this.refresh(id); + return true; + } else { + var rv = this.set(parent.nodes[i], id, node); + if (rv) return true; + } + } + return false; + }, + + get: function (parent, id, returnIndex) { // can be just called get(id) or get(id, true) + if (arguments.length === 0) { + var all = []; + var tmp = this.find({}); + for (var t = 0; t < tmp.length; t++) { + if (tmp[t].id != null) all.push(tmp[t].id); + } + return all; + } else { + if (arguments.length == 1 || (arguments.length == 2 && id === true) ) { + // need to be in reverse order + returnIndex = id; + id = parent; + parent = this; + } + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return null; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].id == id) { + if (returnIndex === true) return i; else return parent.nodes[i]; + } else { + var rv = this.get(parent.nodes[i], id, returnIndex); + if (rv || rv === 0) return rv; + } + } + return null; + } + }, - set: function (parent, id, node) { - if (arguments.length == 2) { - // need to be in reverse order - node = id; - id = parent; - parent = this; - } - // searches all nested nodes - this._tmp = null; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].id == id) { - // make sure nodes inserted correctly - var nodes = node.nodes; - $.extend(parent.nodes[i], node, { nodes: [] }); - if (typeof nodes != 'undefined') { - this.add(parent.nodes[i], nodes); - } - this.refresh(id); - return true; - } else { - this._tmp = this.set(parent.nodes[i], id, node); - if (this._tmp) return true; - } - } - return false; - }, + find: function (parent, params, results) { // can be just called find({ selected: true }) + if (arguments.length == 1) { + // need to be in reverse order + params = parent; + parent = this; + } + if (!results) results = []; + // searches all nested nodes + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return results; + for (var i = 0; i < parent.nodes.length; i++) { + var match = true; + for (var prop in params) { + if (parent.nodes[i][prop] != params[prop]) match = false; + } + if (match) results.push(parent.nodes[i]); + if (parent.nodes[i].nodes.length > 0) results = this.find(parent.nodes[i], params, results); + } + return results; + }, + + hide: function () { // multiple arguments + var hidden = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.hidden = true; + hidden++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return hidden; + }, + + show: function () { // multiple arguments + var shown = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.hidden = false; + shown++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return shown; + }, + + disable: function () { // multiple arguments + var disabled = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.disabled = true; + if (tmp.selected) this.unselect(tmp.id); + disabled++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return disabled; + }, + + enable: function () { // multiple arguments + var enabled = 0; + for (var a = 0; a < arguments.length; a++) { + var tmp = this.get(arguments[a]); + if (tmp === null) continue; + tmp.disabled = false; + enabled++; + } + if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); + return enabled; + }, + + select: function (id) { + var new_node = this.get(id); + if (!new_node) return false; + if (this.selected == id && new_node.selected) return false; + this.unselect(this.selected); + $(this.box).find('#node_'+ w2utils.escapeId(id)) + .addClass('w2ui-selected') + .find('.w2ui-icon').addClass('w2ui-icon-selected'); + new_node.selected = true; + this.selected = id; + return true; + }, + + unselect: function (id) { + var current = this.get(id); + if (!current) return false; + current.selected = false; + $(this.box).find('#node_'+ w2utils.escapeId(id)) + .removeClass('w2ui-selected') + .find('.w2ui-icon').removeClass('w2ui-icon-selected'); + if (this.selected == id) this.selected = null; + return true; + }, + + toggle: function(id) { + var nd = this.get(id); + if (nd === null) return false; + if (nd.plus) { + this.set(id, { plus: false }); + this.expand(id); + this.refresh(id); + return; + } + if (nd.nodes.length === 0) return false; + if (this.get(id).expanded) return this.collapse(id); else return this.expand(id); + }, - get: function (parent, id, returnIndex) { // can be just called get(id) or get(id, true) - if (arguments.length == 1 || (arguments.length == 2 && id === true) ) { - // need to be in reverse order - returnIndex = id; - id = parent; - parent = this; - } - // searches all nested nodes - this._tmp = null; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].id == id) { - if (returnIndex === true) return i; else return parent.nodes[i]; - } else { - this._tmp = this.get(parent.nodes[i], id, returnIndex); - if (this._tmp || this._tmp === 0) return this._tmp; - } - } - return this._tmp; - }, + collapse: function (id) { + var obj = this; + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'collapse', target: id, object: nd }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideUp(200); + $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('+'); + nd.expanded = false; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + setTimeout(function () { obj.refresh(id); }, 200); + return true; + }, + + collapseAll: function (parent) { + if (typeof parent == 'undefined') parent = this; + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return false; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false; + if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); + } + this.refresh(parent.id); + return true; + }, - hide: function () { // multiple arguments - var hidden = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.hidden = true; - hidden++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return hidden; - }, + expand: function (id) { + var obj = this; + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'expand', target: id, object: nd }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideDown(200); + $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('-'); + nd.expanded = true; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + setTimeout(function () { obj.refresh(id); }, 200); + return true; + }, + + expandAll: function (parent) { + if (typeof parent == 'undefined') parent = this; + if (typeof parent == 'string') parent = this.get(parent); + if (parent.nodes == null) return false; + for (var i = 0; i < parent.nodes.length; i++) { + if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true; + if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); + } + this.refresh(parent.id); + }, + + expandParents: function (id) { + var node = this.get(id); + if (node === null) return false; + if (node.parent) { + node.parent.expanded = true; + this.expandParents(node.parent.id); + } + this.refresh(id); + return true; + }, - show: function () { - var shown = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.hidden = false; - shown++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return shown; - }, + click: function (id, event) { + var obj = this; + var nd = this.get(id); + if (nd === null) return; + if (nd.disabled || nd.group) return; // should click event if already selected + // unselect all previsously + $(obj.box).find('.w2ui-node.w2ui-selected').each(function (index, el) { + var oldID = $(el).attr('id').replace('node_', ''); + var oldNode = obj.get(oldID); + if (oldNode != null) oldNode.selected = false; + $(el).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); + }); + // select new one + var newNode = $(obj.box).find('#node_'+ w2utils.escapeId(id)); + var oldNode = $(obj.box).find('#node_'+ w2utils.escapeId(obj.selected)); + newNode.addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); + // need timeout to allow rendering + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'click', target: id, originalEvent: event, node: nd, object: nd }); + if (eventData.isCancelled === true) { + // restore selection + newNode.removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); + oldNode.addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); + return; + } + // default action + if (oldNode !== null) oldNode.selected = false; + obj.get(id).selected = true; + obj.selected = id; + // route processing + if (nd.route) { + var route = String('/'+ nd.route).replace(/\/{2,}/g, '/'); + var info = w2utils.parseRoute(route); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + route = route.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + setTimeout(function () { window.location.hash = route; }, 1); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 1); + }, - disable: function () { // multiple arguments - var disabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.disabled = true; - if (tmp.selected) this.unselect(tmp.id); - disabled++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return disabled; - }, + keydown: function (event) { + var obj = this; + var nd = obj.get(obj.selected); + if (!nd || obj.keyboard !== true) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); + if (eventData.isCancelled === true) return; + // default behaviour + if (event.keyCode == 13 || event.keyCode == 32) { // enter or space + if (nd.nodes.length > 0) obj.toggle(obj.selected); + } + if (event.keyCode == 37) { // left + if (nd.nodes.length > 0 && nd.expanded) { + obj.collapse(obj.selected); + } else { + selectNode(nd.parent); + if (!nd.parent.group) obj.collapse(nd.parent.id); + } + } + if (event.keyCode == 39) { // right + if ((nd.nodes.length > 0 || nd.plus) && !nd.expanded) obj.expand(obj.selected); + } + if (event.keyCode == 38) { // up + selectNode(neighbor(nd, prev)); + } + if (event.keyCode == 40) { // down + selectNode(neighbor(nd, next)); + } + // cancel event if needed + if ($.inArray(event.keyCode, [13, 32, 37, 38, 39, 40]) != -1) { + if (event.preventDefault) event.preventDefault(); + if (event.stopPropagation) event.stopPropagation(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); - enable: function () { // multiple arguments - var enabled = 0; - for (var a = 0; a < arguments.length; a++) { - var tmp = this.get(arguments[a]); - if (tmp == null) continue; - tmp.disabled = false; - enabled++; - } - if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh(); - return enabled; - }, + function selectNode (node, event) { + if (node !== null && !node.hidden && !node.disabled && !node.group) { + obj.click(node.id, event); + setTimeout(function () { obj.scrollIntoView(); }, 50); + } + } - select: function (id) { - if (this.selected == id) return false; - this.unselect(this.selected); - var new_node = this.get(id); - if (!new_node) return false; - $(this.box).find('#node_'+ w2utils.escapeId(id)) - .addClass('w2ui-selected') - .find('.w2ui-icon').addClass('w2ui-icon-selected'); - new_node.selected = true; - this.selected = id; - }, + function neighbor (node, neighborFunc) { + node = neighborFunc(node); + while (node !== null && (node.hidden || node.disabled)) { + if (node.group) break; else node = neighborFunc(node); + } + return node; + } - unselect: function (id) { - var current = this.get(id); - if (!current) return false; - current.selected = false; - $(this.box).find('#node_'+ w2utils.escapeId(id)) - .removeClass('w2ui-selected') - .find('.w2ui-icon').removeClass('w2ui-icon-selected'); - if (this.selected == id) this.selected = null; - return true; - }, + function next (node, noSubs) { + if (node === null) return null; + var parent = node.parent; + var ind = obj.get(node.id, true); + var nextNode = null; + // jump inside + if (node.expanded && node.nodes.length > 0 && noSubs !== true) { + var t = node.nodes[0]; + if (t.hidden || t.disabled || t.group) nextNode = next(t); else nextNode = t; + } else { + if (parent && ind + 1 < parent.nodes.length) { + nextNode = parent.nodes[ind + 1]; + } else { + nextNode = next(parent, true); // jump to the parent + } + } + if (nextNode !== null && (nextNode.hidden || nextNode.disabled || nextNode.group)) nextNode = next(nextNode); + return nextNode; + } - toggle: function(id) { - var nd = this.get(id); - if (nd == null) return; - if (nd.plus) { - this.set(id, { plus: false }); - this.expand(id); - this.refresh(id); - return; - } - if (nd.nodes.length == 0) return; - if (this.get(id).expanded) this.collapse(id); else this.expand(id); - }, + function prev (node) { + if (node === null) return null; + var parent = node.parent; + var ind = obj.get(node.id, true); + var prevNode = (ind > 0) ? lastChild(parent.nodes[ind - 1]) : parent; + if (prevNode !== null && (prevNode.hidden || prevNode.disabled || prevNode.group)) prevNode = prev(prevNode); + return prevNode; + } - collapse: function (id) { - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'collapse', target: id, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideUp('fast'); - $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('+'); - nd.expanded = false; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + function lastChild (node) { + if (node.expanded && node.nodes.length > 0) { + var t = node.nodes[node.nodes.length - 1]; + if (t.hidden || t.disabled || t.group) return prev(t); else return lastChild(t); + } + return node; + } + }, + + scrollIntoView: function (id) { + if (typeof id == 'undefined') id = this.selected; + var nd = this.get(id); + if (nd === null) return; + var body = $(this.box).find('.w2ui-sidebar-div'); + var item = $(this.box).find('#node_'+ w2utils.escapeId(id)); + var offset = item.offset().top - body.offset().top; + if (offset + item.height() > body.height()) { + body.animate({ 'scrollTop': body.scrollTop() + body.height() / 1.3 }, 250, 'linear'); + } + if (offset <= 0) { + body.animate({ 'scrollTop': body.scrollTop() - body.height() / 1.3 }, 250, 'linear'); + } + }, - collapseAll: function (parent) { - if (typeof parent == 'undefined') parent = this; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false; - if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); - } - this.refresh(parent.id); - }, + dblClick: function (id, event) { + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + var nd = this.get(id); + // event before + var eventData = this.trigger({ phase: 'before', type: 'dblClick', target: id, originalEvent: event, object: nd }); + if (eventData.isCancelled === true) return; + // default action + this.toggle(id); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - expand: function (id) { - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'expand', target: id, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideDown('fast'); - $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('-'); - nd.expanded = true; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + contextMenu: function (id, event) { + var obj = this; + var nd = obj.get(id); + if (id != obj.selected) obj.click(id); + // need timeout to allow click to finish first + setTimeout(function () { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: id, originalEvent: event, object: nd }); + if (eventData.isCancelled === true) return; + // default action + if (nd.group || nd.disabled) return; + if (obj.menu.length > 0) { + $(obj.box).find('#node_'+ w2utils.escapeId(id)) + .w2menu(obj.menu, { + left : (event ? event.offsetX || event.pageX : 50) - 25, + onSelect: function (event) { + obj.menuClick(id, parseInt(event.index), event.originalEvent); + } + } + ); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 150); // need timer 150 for FF + }, - expandAll: function (parent) { - if (typeof parent == 'undefined') parent = this; - if (typeof parent == 'string') parent = this.get(parent); - if (parent.nodes == null) return null; - for (var i=0; i < parent.nodes.length; i++) { - if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true; - if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]); - } - this.refresh(parent.id); - }, + menuClick: function (itemId, index, event) { + var obj = this; + // event before + var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: itemId, originalEvent: event, menuIndex: index, menuItem: obj.menu[index] }); + if (eventData.isCancelled === true) return; + // default action + // -- empty + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, - expandParents: function (id) { - var node = this.get(id); - if (node == null) return; - if (node.parent) { - node.parent.expanded = true; - this.expandParents(node.parent.id); - } - this.refresh(id); - }, + render: function (box) { + var time = (new Date()).getTime(); + // event before + var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); + if (eventData.isCancelled === true) return; + // default action + if (typeof box != 'undefined' && box !== null) { + if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-sidebar') + .html(''); + } + this.box = box; + } + if (!this.box) return; + $(this.box) + .attr('name', this.name) + .addClass('w2ui-reset w2ui-sidebar') + .html(''+ + '' + + ''+ + ''+ + '' + ); + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height: $(this.box).height() + 'px' + }); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + // adjust top and bottom + if (this.topHTML !== '') { + $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); + } + if (this.bottomHTML !== '') { + $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // --- + this.refresh(); + return (new Date()).getTime() - time; + }, - click: function (id, event) { - var obj = this; - var nd = this.get(id); - if (nd == null) return; - var old = this.selected; - if (nd.disabled || nd.group) return; // should click event if already selected - // move selected first - $(obj.box).find('#node_'+ w2utils.escapeId(old)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); - $(obj.box).find('#node_'+ w2utils.escapeId(id)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); - // need timeout to allow rendering - setTimeout(function () { - // event before - var eventData = obj.trigger({ phase: 'before', type: 'click', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) { - // restore selection - $(obj.box).find('#node_'+ w2utils.escapeId(id)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected'); - $(obj.box).find('#node_'+ w2utils.escapeId(old)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected'); - return false; - } - // default action - if (old != null) obj.get(old).selected = false; - obj.get(id).selected = true; - obj.selected = id; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - }, + refresh: function (id) { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name) }); + if (eventData.isCancelled === true) return; + // adjust top and bottom + if (this.topHTML !== '') { + $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); + } + if (this.bottomHTML !== '') { + $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); + $(this.box).find('.w2ui-sidebar-div') + .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); + } + // default action + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height: $(this.box).height() + 'px' + }); + var obj = this; + var node, nd; + var nm; + if (typeof id == 'undefined') { + node = this; + nm = '.w2ui-sidebar-div'; + } else { + node = this.get(id); + if (node === null) return; + nm = '#node_'+ w2utils.escapeId(node.id) + '_sub'; + } + var nodeHTML; + if (node !== this) { + var tmp = '#node_'+ w2utils.escapeId(node.id); + nodeHTML = getNodeHTML(node); + $(this.box).find(tmp).before(''); + $(this.box).find(tmp).remove(); + $(this.box).find(nm).remove(); + $('#sidebar_'+ this.name + '_tmp').before(nodeHTML); + $('#sidebar_'+ this.name + '_tmp').remove(); + } + // refresh sub nodes + $(this.box).find(nm).html(''); + for (var i = 0; i < node.nodes.length; i++) { + nd = node.nodes[i]; + nodeHTML = getNodeHTML(nd); + $(this.box).find(nm).append(nodeHTML); + if (nd.nodes.length !== 0) { this.refresh(nd.id); } + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + + function getNodeHTML(nd) { + var html = ''; + var img = nd.img; + if (img === null) img = this.img; + var icon = nd.icon; + if (icon === null) icon = this.icon; + // -- find out level + var tmp = nd.parent; + var level = 0; + while (tmp && tmp.parent !== null) { + if (tmp.group) level--; + tmp = tmp.parent; + level++; + } + if (typeof nd.caption != 'undefined') nd.text = nd.caption; + if (nd.group) { + html = + ''+ + (nd.groupShowHide ? ''+ (!nd.hidden && nd.expanded ? w2utils.lang('Hide') : w2utils.lang('Show')) +'' : '') + + ' '+ nd.text +''+ + ''+ + ''; + } else { + if (nd.selected && !nd.disabled) obj.selected = nd.id; + tmp = ''; + if (img) tmp = ''; + if (icon) tmp = ''; + html = + ''+ + ''+ + ''+ + ' ' + (nd.nodes.length > 0 ? (nd.expanded ? '-' : '+') : (nd.plus ? '+' : '')) + '' + + ''+ + ''+ + tmp + + (nd.count || nd.count === 0 ? ''+ nd.count +'' : '') + + ''+ nd.text +''+ + ''+ + ''+ + ''+ + ''; + } + return html; + } + }, - keydown: function (event) { - var obj = this; - var nd = obj.get(obj.selected); - if (!nd || obj.keyboard !== true) return; - // trigger event - var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default behaviour - if (event.keyCode == 13 || event.keyCode == 32) { // enter or space - if (nd.nodes.length > 0) obj.toggle(obj.selected); - } - if (event.keyCode == 37) { // left - if (nd.nodes.length > 0) { - obj.collapse(obj.selected); - } else { - // collapse parent - if (nd.parent && !nd.parent.disabled && !nd.parent.group) { - obj.collapse(nd.parent.id); - obj.click(nd.parent.id); - setTimeout(function () { obj.scrollIntoView(); }, 50); - } - } - } - if (event.keyCode == 39) { // right - if (nd.nodes.length > 0) obj.expand(obj.selected); - } - if (event.keyCode == 38) { // up - var tmp = prev(nd); - if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); } - } - if (event.keyCode == 40) { // down - var tmp = next(nd); - if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); } - } - // cancel event if needed - if ($.inArray(event.keyCode, [13, 32, 37, 38, 39, 40]) != -1) { - if (event.preventDefault) event.preventDefault(); - if (event.stopPropagation) event.stopPropagation(); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - return; - - function next (node, noSubs) { - if (node == null) return null; - var parent = node.parent; - var ind = obj.get(node.id, true); - var nextNode = null; - // jump inside - if (node.expanded && node.nodes.length > 0 && noSubs !== true) { - var t = node.nodes[0]; - if (!t.disabled && !t.group) nextNode = t; else nextNode = next(t); - } else { - if (parent && ind + 1 < parent.nodes.length) { - nextNode = parent.nodes[ind + 1]; - } else { - nextNode = next(parent, true); // jump to the parent - } - } - if (nextNode != null && (nextNode.disabled || nextNode.group)) nextNode = next(nextNode); - return nextNode; - } - - function prev (node) { - if (node == null) return null; - var parent = node.parent; - var ind = obj.get(node.id, true); - var prevNode = null; - var noSubs = false; - if (ind > 0) { - prevNode = parent.nodes[ind - 1]; - // jump inside parents last node - if (prevNode.expanded && prevNode.nodes.length > 0) { - var t = prevNode.nodes[prevNode.nodes.length - 1]; - if (!t.disabled && !t.group) prevNode = t; else prevNode = prev(t); - } - } else { - prevNode = parent; // jump to the parent - noSubs = true; - } - if (prevNode != null && (prevNode.disabled || prevNode.group)) prevNode = prev(prevNode); - return prevNode; - } - }, + resize: function () { + var time = (new Date()).getTime(); + // if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection + // event before + var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); + if (eventData.isCancelled === true) return; + // default action + $(this.box).css('overflow', 'hidden'); // container should have no overflow + //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'hidden'); + $(this.box).find('> div').css({ + width : $(this.box).width() + 'px', + height : $(this.box).height() + 'px' + }); + //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'auto'); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + return (new Date()).getTime() - time; + }, - scrollIntoView: function (id) { - if (typeof id == 'undefined') id = this.selected; - var nd = this.get(id); - if (nd == null) return; - var body = $(this.box).find('.w2ui-sidebar-div'); - var item = $(this.box).find('#node_'+ w2utils.escapeId(id)); - var offset = item.offset().top - body.offset().top; - if (offset + item.height() > body.height()) { - body.animate({ 'scrollTop': body.scrollTop() + body.height() / 1.3 }); - } - if (offset <= 0) { - body.animate({ 'scrollTop': body.scrollTop() - body.height() / 1.3 }); - } - }, + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); + if (eventData.isCancelled === true) return; + // clean up + if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-sidebar') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - dblClick: function (id, event) { - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - var nd = this.get(id); - // event before - var eventData = this.trigger({ phase: 'before', type: 'dblClick', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - if (nd.nodes.length > 0) this.toggle(id); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + w2utils.lock.apply(window, args); + }, - contextMenu: function (id, event) { - var obj = this; - var nd = obj.get(id); - if (id != obj.selected) obj.click(id); - // need timeout to allow click to finish first - setTimeout(function () { - // event before - var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: id, originalEvent: event, object: nd }); - if (eventData.isCancelled === true) return false; - // default action - if (nd.group || nd.disabled) return; - if (obj.menu.length > 0) { - $(obj.box).find('#node_'+ w2utils.escapeId(id)) - .w2menu(obj.menu, { - left: (event ? event.offsetX || event.pageX : 50) - 25, - select: function (item, event, index) { obj.menuClick(id, index, event); } - } - ); + unlock: function () { + w2utils.unlock(this.box); } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 1); - }, + }; - menuClick: function (itemId, index, event) { - var obj = this; - // event before - var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: itemId, originalEvent: event, menuIndex: index, menuItem: obj.menu[index] }); - if (eventData.isCancelled === true) return false; - // default action - // -- empty - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, + $.extend(w2sidebar.prototype, w2utils.event); + w2obj.sidebar = w2sidebar; +})(jQuery); - render: function (box) { - // event before - var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box }); - if (eventData.isCancelled === true) return false; - // default action - if (typeof box != 'undefined' && box != null) { - if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-sidebar') - .html(''); - } - this.box = box; - } - if (!this.box) return; - $(this.box) - .attr('name', this.name) - .addClass('w2ui-reset w2ui-sidebar') - .html(''+ - '' + - ''+ - ''+ - '' - ); - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - // adjust top and bottom - if (this.topHTML != '') { - $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); - } - if (this.bottomHTML != '') { - $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // --- - this.refresh(); - }, +/************************************************************************ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2field - various field controls +* - $().w2field - jQuery wrapper +* - Dependencies: jQuery, w2utils +* +* == NICE TO HAVE == +* - upload (regular files) +* - BUG with prefix/postfix and arrows (test in different contexts) +* - prefix and suffix are slow (100ms or so) +* - multiple date selection +* - month selection, year selections +* - arrows no longer work (for int) +* - form to support custom types +* - bug: if input is hidden and then enum is applied, then when it becomes visible, it will be 110px +* +************************************************************************/ - refresh: function (id) { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name) }); - if (eventData.isCancelled === true) return false; - // adjust top and bottom - if (this.topHTML != '') { - $(this.box).find('.w2ui-sidebar-top').html(this.topHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px'); - } - if (this.bottomHTML != '') { - $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML); - $(this.box).find('.w2ui-sidebar-div') - .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px'); - } - // default action - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - var obj = this; - if (typeof id == 'undefined') { - var node = this; - var nm = '.w2ui-sidebar-div'; - } else { - var node = this.get(id); - if (node == null) return; - var nm = '#node_'+ w2utils.escapeId(node.id) + '_sub'; - } - if (node != this) { - var tmp = '#node_'+ w2utils.escapeId(node.id); - var nodeHTML = getNodeHTML(node); - $(this.box).find(tmp).before(''); - $(this.box).find(tmp).remove(); - $(this.box).find(nm).remove(); - $('#sidebar_'+ this.name + '_tmp').before(nodeHTML); - $('#sidebar_'+ this.name + '_tmp').remove(); - } - // refresh sub nodes - $(this.box).find(nm).html(''); - for (var i=0; i < node.nodes.length; i++) { - var nodeHTML = getNodeHTML(node.nodes[i]); - $(this.box).find(nm).append(nodeHTML); - if (node.nodes[i].nodes.length != 0) { this.refresh(node.nodes[i].id); } - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - - function getNodeHTML(nd) { - var html = ''; - var img = nd.img; - if (img == null) img = this.img; - var icon = nd.icon; - if (icon == null) icon = this.icon; - // -- find out level - var tmp = nd.parent; - var level = 0; - while (tmp && tmp.parent != null) { - if (tmp.group) level--; - tmp = tmp.parent; - level++; - } - if (typeof nd.caption != 'undefined') nd.text = nd.caption; - if (nd.group) { - html = - ''+ - ' '+ (!nd.hidden && nd.expanded ? w2utils.lang('Hide') : w2utils.lang('Show')) +''+ - ' '+ nd.text +''+ - ''+ - ''; +(function ($) { + + var w2field = function (options) { + // public properties + this.el = null + this.helpers = {}; // object or helper elements + this.type = options.type || 'text'; + this.options = $.extend(true, {}, options); + this.onSearch = options.onSearch || null; + this.onRequest = options.onRequest || null; + this.onLoad = options.onLoad || null; + this.onError = options.onError || null; + this.onClick = options.onClick || null; + this.onAdd = options.onAdd || null; + this.onNew = options.onNew || null; + this.onRemove = options.onRemove || null; + this.onMouseOver = options.onMouseOver || null; + this.onMouseOut = options.onMouseOut || null; + this.onIconClick = options.onIconClick || null; + this.tmp = {}; // temp object + // clean up some options + delete this.options.type; + delete this.options.onSearch; + delete this.options.onRequest; + delete this.options.onLoad; + delete this.options.onError; + delete this.options.onClick; + delete this.options.onMouseOver; + delete this.options.onMouseOut; + delete this.options.onIconClick; + // extend with defaults + $.extend(true, this, w2obj.field); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2field = function (method, options) { + // call direct + if (this.length == 0) { + var pr = w2field.prototype; + if (pr[method]) { + return pr[method].apply(pr, Array.prototype.slice.call(arguments, 1)); + } } else { - if (nd.selected && !nd.disabled) obj.selected = nd.id; - var tmp = ''; - if (img) tmp = ''; - if (icon) tmp = ''; - html = - ''+ - ''+ - ''+ - ' ' + (nd.nodes.length > 0 ? (nd.expanded ? '-' : '+') : (nd.plus ? '+' : '')) + '' + - ''+ - ''+ - tmp + - (nd.count !== '' ? ''+ nd.count +'' : '') + - ''+ nd.text +''+ - ''+ - ''+ - ''+ - ''; + // if without arguments - return the object + if (arguments.length == 0) { + var obj = $(this).data('w2field'); + return obj; + } + if (typeof method == 'string' && typeof options == 'object') { + method = $.extend(true, {}, options, { type: method }); + } + if (typeof method == 'string' && typeof options == 'undefined') { + method = { type: method }; + } + method.type = String(method.type).toLowerCase(); + return this.each(function (index, el) { + var obj = $(el).data('w2field'); + // if object is not defined, define it + if (typeof obj == 'undefined') { + var obj = new w2field(method); + $.extend(obj, { handlers: [] }); + if (el) obj.el = $(el)[0]; + obj.init(); + $(el).data('w2field', obj); + return obj; + } else { // fully re-init + obj.clear(); + if (method.type == 'clear') return; + var obj = new w2field(method); + $.extend(obj, { handlers: [] }); + if (el) obj.el = $(el)[0]; + obj.init(); + $(el).data('w2field', obj); + return obj; + } + return null; + }); } - return html; - } - }, + } - resize: function () { - var time = (new Date()).getTime(); - if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection - // event before - var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name }); - if (eventData.isCancelled === true) return false; - // default action - $(this.box).css('overflow', 'hidden'); // container should have no overflow - //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'hidden'); - $(this.box).find('> div').css({ - width : $(this.box).width() + 'px', - height : $(this.box).height() + 'px' - }); - //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'auto'); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return (new Date()).getTime() - time; - }, + // ==================================================== + // -- Implementation of core functionality - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name }); - if (eventData.isCancelled === true) return false; - // clean up - if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-sidebar') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + /* To add custom types + $().w2field('addType', 'myType', function (options) { + $(this.el).on('keypress', function (event) { + if (event.metaKey || event.ctrlKey || event.altKey + || (event.charCode != event.keyCode && event.keyCode > 0)) return; + var ch = String.fromCharCode(event.charCode); + if (ch != 'a' && ch != 'b' && ch != 'c') { + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + return false; + } + }); + $(this.el).on('blur', function (event) { // keyCode & charCode differ in FireFox + var ch = this.value; + if (ch != 'a' && ch != 'b' && ch != 'c') { + $(this).w2tag(w2utils.lang("Not a single charecter from the set of 'abc'")); + } + }); + }); + */ + + w2field.prototype = { + + custom: {}, // map of custom types + + pallete: [ + ['000000', '444444', '666666', '999999', 'CCCCCC', 'EEEEEE', 'F3F3F3', 'FFFFFF'], + ['FF011B', 'FF9838', 'FFFD59', '01FD55', '00FFFE', '0424F3', '9B24F4', 'FF21F5'], + ['F4CCCC', 'FCE5CD', 'FFF2CC', 'D9EAD3', 'D0E0E3', 'CFE2F3', 'D9D1E9', 'EAD1DC'], + ['EA9899', 'F9CB9C', 'FEE599', 'B6D7A8', 'A2C4C9', '9FC5E8', 'B4A7D6', 'D5A6BD'], + ['E06666', 'F6B26B', 'FED966', '93C47D', '76A5AF', '6FA8DC', '8E7CC3', 'C27BA0'], + ['CC0814', 'E69138', 'F1C232', '6AA84F', '45818E', '3D85C6', '674EA7', 'A54D79'], + ['99050C', 'B45F17', 'BF901F', '37761D', '124F5C', '0A5394', '351C75', '741B47'], + ['660205', '783F0B', '7F6011', '274E12', '0C343D', '063762', '20124D', '4C1030'] + ], + + addType: function (type, handler) { + type = String(type).toLowerCase(); + this.custom[type] = handler; + return true; + }, + + removeType: function (type) { + type = String(type).toLowerCase(); + if (!this.custom[type]) return false; + delete this.custom[type]; + return true + }, + + init: function () { + var obj = this; + var options = this.options; + var defaults; + + // Custom Types + if (typeof this.custom[this.type] == 'function') { + this.custom[this.type].call(this, options); + return; + } + // only for INPUT or TEXTAREA + if (['INPUT', 'TEXTAREA'].indexOf(this.el.tagName) == -1) { + console.log('ERROR: w2field could only be applied to INPUT or TEXTAREA.', this.el); + return; + } - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - w2utils.lock(box, msg, showSpinner); - }, + switch (this.type) { + case 'text': + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'alphanumeric': + case 'hex': + defaults = { + min : null, + max : null, + step : 1, + placeholder : '', + autoFormat : true, + currencyPrefix : w2utils.settings.currencyPrefix, + currencySuffix : w2utils.settings.currencySuffix, + currencyPrecision : w2utils.settings.currencyPrecision, + decimalSymbol : w2utils.settings.decimalSymbol, + groupSymbol : w2utils.settings.groupSymbol, + arrows : false, + keyboard : true, + precision : null, + silent : true, + prefix : '', + suffix : '' + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + options.numberRE = new RegExp('['+ options.groupSymbol + ']', 'g'); + options.moneyRE = new RegExp('['+ options.currencyPrefix + options.currencySuffix + options.groupSymbol +']', 'g'); + options.percentRE = new RegExp('['+ options.groupSymbol + '%]', 'g'); + // no keyboard support needed + if (['text', 'alphanumeric', 'hex'].indexOf(this.type) != -1) { + options.arrows = false; + options.keyboard = false; + } + this.addPrefix(); // only will add if needed + this.addSuffix(); + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder); + break; - unlock: function () { - w2utils.unlock(this.box); - } - } + case 'color': + defaults = { + prefix : '#', + suffix : ' ', + placeholder : '', + arrows : false, + keyboard : false + }; + $.extend(options, defaults); + this.addPrefix(); // only will add if needed + this.addSuffix(); // only will add if needed + // additional checks + $(this.el).attr('maxlength', 6); + if ($(this.el).val() != '') setTimeout(function () { $(obj.el).change(); }, 1); + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder); + break; - $.extend(w2sidebar.prototype, w2utils.event); - w2obj.sidebar = w2sidebar; -})(jQuery); + case 'date': + defaults = { + format : w2utils.settings.date_format, // date format + placeholder : '', + keyboard : true, + silent : true, + start : '', // string or jquery object + end : '', // string or jquery object + blocked : {}, // { '4/11/2011': 'yes' } + colored : {} // { '4/11/2011': 'red:white' } + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder ? options.placeholder : options.format); + break; -/************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2field - various field controls - * - $().w2field - jQuery wrapper - * - Dependencies: jQuery, w2utils - * - * == NICE TO HAVE == - * - select - for select, list - for drop down (needs this in grid) - * - enum add events: onLoad, onRequest, onCompare, onSelect, onDelete, onClick for already selected elements - * - upload (regular files) - * - enum - refresh happens on each key press even if not needed (for speed) - * - BUG with prefix/postfix and arrows (test in different contexts) - * - multiple date selection - * - rewrire everythin in objects (w2ftext, w2fenum, w2fdate) - * - render calendar to the div - * - ************************************************************************/ + case 'time': + defaults = { + format : w2utils.settings.time_format, + placeholder : '', + keyboard : true, + silent : true, + start : '', + end : '' + }; + this.options = $.extend(true, {}, defaults, options); + options = this.options; // since object is re-created, need to re-assign + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder ? options.placeholder : (options.format == 'h12' ? 'hh:mi pm' : 'hh:mi')); + break; -(function ($) { + case 'datetime': + break; - /* SINGELTON PATTERN */ + case 'list': + case 'combo': + defaults = { + items : [], + selected : {}, + placeholder : '', + url : null, // url to pull data from + postData : {}, + minLength : 1, + cacheMax : 250, + maxDropHeight : 350, // max height for drop down menu + match : 'begins', // ['contains', 'is', 'begins', 'ends'] + silent : true, + icon : null, + iconStyle : '', + onSearch : null, // when search needs to be performed + onRequest : null, // when request is submitted + onLoad : null, // when data is received + onError : null, // when data fails to load due to server error or other failure modes + onIconClick : null, + renderDrop : null, // render function for drop down item + prefix : '', + suffix : '', + openOnFocus : false, // if to show overlay onclick or when typing + markSearch : false + }; + options.items = this.normMenu(options.items); // need to be first + if (this.type == 'list') { + // defaults.search = (options.items && options.items.length >= 10 ? true : false); + defaults.openOnFocus = true; + defaults.suffix = ''; + $(this.el).addClass('w2ui-select'); + // if simple value - look it up + if (!$.isPlainObject(options.selected)) { + for (var i in options.items) { + var item = options.items[i]; + if (item && item.id == options.selected) { + options.selected = $.extend(true, {}, item); + break; + } + } + } + } + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + altRows : true // alternate row color + }); + this.options = options; + if (!$.isPlainObject(options.selected)) options.selected = {}; + $(this.el).data('selected', options.selected); + if (options.url) this.request(0); + if (this.type == 'list') this.addFocus(); + this.addPrefix(); + this.addSuffix(); + setTimeout(function () { obj.refresh(); }, 10); // need this for icon refresh + if ($(this.el).attr('placeholder') && options.placeholder == '') options.placeholder = $(this.el).attr('placeholder'); + $(this.el).attr('placeholder', options.placeholder).attr('autocomplete', 'off'); + if (typeof options.selected.text != 'undefined') $(this.el).val(options.selected.text); + break; - var w2field = new (function () { - this.customTypes = []; - }); + case 'enum': + defaults = { + items : [], + selected : [], + placeholder : '', + max : 0, // max number of selected items, 0 - unlim + url : null, // not implemented + postData : {}, + minLength : 1, + cacheMax : 250, + maxWidth : 250, // max width for a single item + maxHeight : 350, // max height for input control to grow + maxDropHeight : 350, // max height for drop down menu + match : 'contains', // ['contains', 'is', 'begins', 'ends'] + silent : true, + openOnFocus : false, // if to show overlay onclick or when typing + markSearch : true, + renderDrop : null, // render function for drop down item + renderItem : null, // render selected item + style : '', // style for container div + onSearch : null, // when search needs to be performed + onRequest : null, // when request is submitted + onLoad : null, // when data is received + onError : null, // when data fails to load due to server error or other failure modes + onClick : null, // when an item is clicked + onAdd : null, // when an item is added + onNew : null, // when new item should be added + onRemove : null, // when an item is removed + onMouseOver : null, // when an item is mouse over + onMouseOut : null // when an item is mouse out + }; + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + suffix : '', + altRows : true // alternate row color + }); + options.items = this.normMenu(options.items); + options.selected = this.normMenu(options.selected); + this.options = options; + if (!$.isArray(options.selected)) options.selected = []; + $(this.el).data('selected', options.selected); + if (options.url) this.request(0); + this.addSuffix(); + this.addMulti(); + break; - // ==================================================== - // -- Registers as a jQuery plugin + case 'file': + defaults = { + selected : [], + placeholder : w2utils.lang('Attach files by dragging and dropping or Click to Select'), + max : 0, + maxSize : 0, // max size of all files, 0 - unlim + maxFileSize : 0, // max size of a single file, 0 -unlim + maxWidth : 250, // max width for a single item + maxHeight : 350, // max height for input control to grow + maxDropHeight : 350, // max height for drop down menu + silent : true, + renderItem : null, // render selected item + style : '', // style for container div + onClick : null, // when an item is clicked + onAdd : null, // when an item is added + onRemove : null, // when an item is removed + onMouseOver : null, // when an item is mouse over + onMouseOut : null // when an item is mouse out + }; + options = $.extend({}, defaults, options, { + align : 'both', // same width as control + altRows : true // alternate row color + }); + this.options = options; + if (!$.isArray(options.selected)) options.selected = []; + $(this.el).data('selected', options.selected); + if ($(this.el).attr('placeholder')) options.placeholder = $(this.el).attr('placeholder'); + this.addMulti(); + break; + } + // attach events + this.tmp = { + onChange : function (event) { obj.change.call(obj, event) }, + onClick : function (event) { obj.click.call(obj, event) }, + onFocus : function (event) { obj.focus.call(obj, event) }, + onBlur : function (event) { obj.blur.call(obj, event) }, + onKeydown : function (event) { obj.keyDown.call(obj, event) }, + onKeyup : function (event) { obj.keyUp.call(obj, event) }, + onKeypress : function (event) { obj.keyPress.call(obj, event) } + } + $(this.el) + .addClass('w2field') + .data('w2field', this) + .on('change', this.tmp.onChange) + .on('click', this.tmp.onClick) // ignore click because it messes overlays + .on('focus', this.tmp.onFocus) + .on('blur', this.tmp.onBlur) + .on('keydown', this.tmp.onKeydown) + .on('keyup', this.tmp.onKeyup) + .on('keypress', this.tmp.onKeypress) + .css({ + 'box-sizing' : 'border-box', + '-webkit-box-sizing' : 'border-box', + '-moz-box-sizing' : 'border-box', + '-ms-box-sizing' : 'border-box', + '-o-box-sizing' : 'border-box' + }); + // format initial value + this.change($.Event('change')); + }, + + clear: function () { + var obj = this; + var options = this.options; + // if money then clear value + if (['money', 'currency'].indexOf(this.type) != -1) { + $(this.el).val($(this.el).val().replace(options.moneyRE, '')); + } + if (this.type == 'percent') { + $(this.el).val($(this.el).val().replace(/%/g, '')); + } + if (this.type == 'color') { + $(this.el).removeAttr('maxlength'); + } + if (this.type == 'list') { + $(this.el).removeClass('w2ui-select'); + } + if (['date', 'time'].indexOf(this.type) != -1) { + if ($(this.el).attr('placeholder') == options.format) $(this.el).attr('placeholder', ''); + } + this.type = 'clear'; + var tmp = $(this.el).data('tmp'); + if (!this.tmp) return; + // restore paddings + if (typeof tmp != 'undefined') { + if (tmp && tmp['old-padding-left']) $(this.el).css('padding-left', tmp['old-padding-left']); + if (tmp && tmp['old-padding-right']) $(this.el).css('padding-right', tmp['old-padding-right']); + } + // remove events and data + $(this.el) + .val(this.clean($(this.el).val())) + .removeClass('w2field') + .removeData() // removes all attached data + .off('change', this.tmp.onChange) + .off('click', this.tmp.onClick) + .off('focus', this.tmp.onFocus) + .off('blur', this.tmp.onBlur) + .off('keydown', this.tmp.onKeydown) + .off('keyup', this.tmp.onKeyup) + .off('keypress', this.tmp.onKeypress); + // remove helpers + for (var h in this.helpers) $(this.helpers[h]).remove(); + this.helpers = {}; + }, + + refresh: function () { + var obj = this; + var options = this.options; + var selected = $(this.el).data('selected'); + var time = (new Date()).getTime(); + // enum + if (['list'].indexOf(this.type) != -1) { + $(obj.el).parent().css('white-space', 'nowrap'); // needs this for arrow alway to appear on the right side + // hide focus and show text + if (obj.helpers.prefix) obj.helpers.prefix.hide(); + setTimeout(function () { + if (!obj.helpers.focus) return; + // if empty show no icon + if (!$.isEmptyObject(selected) && options.icon) { + options.prefix = ''+ + ''; + obj.addPrefix(); + } else { + options.prefix = ''; + obj.addPrefix(); + } + // focus helpder + var focus = obj.helpers.focus.find('input'); + if ($(focus).val() == '') { + $(focus).css('opacity', 0).prev().css('opacity', 0); + $(obj.el).val(selected && selected.text != null ? selected.text : ''); + $(obj.el).attr('placeholder', options.placeholder || ''); + } else { + $(focus).css('opacity', 1).prev().css('opacity', 1); + $(obj.el).val(''); + $(obj.el).removeAttr('placeholder'); + setTimeout(function () { + if (obj.helpers.prefix) obj.helpers.prefix.hide(); + var tmp = 'position: absolute; opacity: 0; margin: 4px 0px 0px 2px; background-position: left !important;'; + if (options.icon) { + $(focus).css('margin-left', '17px'); + $(obj.helpers.focus).find('.icon-search').attr('style', tmp + 'width: 11px !important; opacity: 1'); + } else { + $(focus).css('margin-left', '0px'); + $(obj.helpers.focus).find('.icon-search').attr('style', tmp + 'width: 0px !important; opacity: 0'); + } + }, 1); + } + // if readonly or disabled + if ($(obj.el).prop('readonly') || $(obj.el).prop('disabled')) { + setTimeout(function () { + $(obj.helpers.prefix).css('opacity', '0.6'); + $(obj.helpers.suffix).css('opacity', '0.6'); + }, 1); + } else { + setTimeout(function () { + $(obj.helpers.prefix).css('opacity', '1'); + $(obj.helpers.suffix).css('opacity', '1'); + }, 1); + } + }, 1); + } + if (['enum', 'file'].indexOf(this.type) != -1) { + var html = ''; + for (var s in selected) { + var it = selected[s]; + var ren = ''; + if (typeof options.renderItem == 'function') { + ren = options.renderItem(it, s, ' '); + } else { + ren = ' '+ + (obj.type == 'enum' ? it.text : it.name + ' - '+ w2utils.size(it.size) +''); + } + html += ''+ + ren +''; + } + var div = obj.helpers.multi; + var ul = div.find('ul'); + div.attr('style', div.attr('style') + ';' + options.style); + if ($(obj.el).prop('readonly') || $(obj.el).prop('disabled')) { + div.addClass('w2ui-readonly'); + div.css('pointer-events', 'none').find('li').css('opacity', '0.6'); + $(obj.helpers.multi).find('input').prop('readonly', true); + } else { + div.removeClass('w2ui-readonly'); + div.css('pointer-events', 'auto').find('li').css('opacity', '1'); + $(obj.helpers.multi).find('input').prop('readonly', false); + } + // celan + div.find('.w2ui-enum-placeholder').remove(); + ul.find('li').not('li.nomouse').remove(); + // add new list + if (html != '') { + ul.prepend(html); + } else if (typeof options.placeholder != 'undefined') { + var style = + 'padding-top: ' + $(this.el).css('padding-top') + ';'+ + 'padding-left: ' + $(this.el).css('padding-left') + '; ' + + 'box-sizing: ' + $(this.el).css('box-sizing') + '; ' + + 'line-height: ' + $(this.el).css('line-height') + '; ' + + 'font-size: ' + $(this.el).css('font-size') + '; ' + + 'font-family: ' + $(this.el).css('font-family') + '; '; + div.prepend(''+ options.placeholder + ''); + } + // ITEMS events + div.find('li') + .data('mouse', 'out') + .on('click', function (event) { + var item = selected[$(event.target).attr('index')]; + if ($(event.target).hasClass('nomouse')) return; + event.stopPropagation(); + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'click', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + if ($(event.target).hasClass('w2ui-list-remove')) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'remove', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + $().w2overlay(); + selected.splice($(event.target).attr('index'), 1); + $(obj.el).trigger('change'); + $(event.target).parent().fadeOut('fast'); + setTimeout(function () { + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 300); + } + if (obj.type == 'file' && !$(event.target).hasClass('w2ui-list-remove')) { + var preview = ''; + if ((/image/i).test(item.type)) { // image + preview = ''+ + ' '+ + ''; + } + var td1 = 'style="padding: 3px; text-align: right; color: #777;"'; + var td2 = 'style="padding: 3px"'; + preview += ''+ + ' '+ + ' '+ w2utils.lang('Name') +':'+ item.name +''+ + ' '+ w2utils.lang('Size') +':'+ w2utils.size(item.size) +''+ + ' '+ w2utils.lang('Type') +':' + + ' '+ item.type +''+ + ' '+ + ' '+ w2utils.lang('Modified') +':'+ w2utils.date(item.modified) +''+ + ' '+ + ''; + $(event.target).w2overlay(preview); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }) + .on('mouseover', function (event) { + var tmp = event.target; + if (tmp.tagName != 'LI') tmp = tmp.parentNode; + if ($(tmp).hasClass('nomouse')) return; + if ($(tmp).data('mouse') == 'out') { + var item = selected[$(tmp).attr('index')]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'mouseOver', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + $(tmp).data('mouse', 'over'); + }) + .on('mouseout', function (event) { + var tmp = event.target; + if (tmp.tagName != 'LI') tmp = tmp.parentNode; + if ($(tmp).hasClass('nomouse')) return; + $(tmp).data('mouse', 'leaving'); + setTimeout(function () { + if ($(tmp).data('mouse') == 'leaving') { + $(tmp).data('mouse', 'out'); + var item = selected[$(tmp).attr('index')]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'f', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + }, 0); + }); + // adjust height + $(this.el).height('auto'); + var cntHeight = $(div).find('> div').height() + w2utils.getSize(div, '+height') * 2; + if (cntHeight < 26) cntHeight = 26; + if (cntHeight > options.maxHeight) cntHeight = options.maxHeight; + if (div.length > 0) div[0].scrollTop = 1000; + var inpHeight = w2utils.getSize($(this.el), 'height') - 2; + if (inpHeight > cntHeight) cntHeight = inpHeight + $(div).css({ 'height': cntHeight + 'px', overflow: (cntHeight == options.maxHeight ? 'auto' : 'hidden') }); + if (cntHeight < options.maxHeight) $(div).prop('scrollTop', 0); + $(this.el).css({ 'height' : (cntHeight + 2) + 'px' }); + } + return (new Date()).getTime() - time; + }, + + reset: function () { + var obj = this; + var type = this.type; + this.clear(); + this.type = type; + this.init(); + }, + + clean: function (val) { + var options = this.options; + val = String(val).trim(); + // clean + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(this.type) != -1) { + if (typeof val == 'string') val = val.replace(options.decimalSymbol, '.'); + if (options.autoFormat && ['money', 'currency'].indexOf(this.type) != -1) val = String(val).replace(options.moneyRE, ''); + if (options.autoFormat && this.type == 'percent') val = String(val).replace(options.percentRE, ''); + if (options.autoFormat && ['int', 'float'].indexOf(this.type) != -1) val = String(val).replace(options.numberRE, ''); + if (parseFloat(val) == val) { + if (options.min !== null && val < options.min) { val = options.min; $(this.el).val(options.min); } + if (options.max !== null && val > options.max) { val = options.max; $(this.el).val(options.max); } + } + if (val !== '' && w2utils.isFloat(val)) val = Number(val); else val = ''; + } + return val; + }, + + format: function (val) { + var options = this.options; + // autoformat numbers or money + if (options.autoFormat && val != '') { + switch (this.type) { + case 'money': + case 'currency': + val = w2utils.formatNumber(Number(val).toFixed(options.currencyPrecision), options.groupSymbol); + if (val != '') val = options.currencyPrefix + val + options.currencySuffix; + break; + case 'percent': + val = w2utils.formatNumber(options.precision ? Number(val).toFixed(options.precision) : val, options.groupSymbol); + if (val != '') val += '%'; + break; + case 'float': + val = w2utils.formatNumber(options.precision ? Number(val).toFixed(options.precision) : val, options.groupSymbol); + break; + case 'int': + val = w2utils.formatNumber(val, options.groupSymbol); + break; + } + } + return val; + }, + + change: function (event) { + var obj = this; + var options = obj.options; + // numeric + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(this.type) != -1) { + // check max/min + var val = $(this.el).val(); + var new_val = this.format(this.clean($(this.el).val())); + // if was modified + if (val != '' && val != new_val) { + $(this.el).val(new_val).change(); + // cancel event + event.stopPropagation(); + event.preventDefault(); + return false; + } + } + // color + if (this.type == 'color') { + var color = '#' + $(this.el).val(); + if ($(this.el).val().length != 6 && $(this.el).val().length != 3) color = ''; + $(this.el).next().find('div').css('background-color', color); + if ($(obj.el).is(':focus')) this.updateOverlay(); + } + // list, enum + if (['list', 'enum', 'file'].indexOf(this.type) != -1) { + obj.refresh(); + // need time out to show icon indent properly + setTimeout(function () { obj.refresh(); }, 5); + } + // date, time + if (['date', 'time'].indexOf(this.type) != -1) { + // convert linux timestamps + var tmp = parseInt(obj.el.value); + if (w2utils.isInt(tmp) && tmp > 1000) { + if (this.type == 'time') $(obj.el).val(w2utils.formatTime(new Date(tmp), options.format)).change(); + if (this.type == 'date') $(obj.el).val(w2utils.formatDate(new Date(tmp), options.format)).change(); + } + } + }, - $.fn.w2field = function(method) { - // Method calling logic - if (w2field[method]) { - return w2field[method].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object') { - return w2field.init.apply( this, arguments ); - } else if ( typeof method === 'string') { - return w2field.init.apply( this, [{ type: method }] ); - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2field'); - } - }; - - $.extend(w2field, { - // CONTEXT: this - is jQuery object - init: function (options) { - var obj = w2field; - return $(this).each(function (field, index) { - // Check for Custom Types - if (typeof w2field.customTypes[options.type.toLowerCase()] == 'function') { - w2field.customTypes[options.type.toLowerCase()].call(this, options); - return; - } - // Common Types - var tp = options.type.toLowerCase(); - switch (tp) { - - case 'clear': // removes any previous field type - $(this) - .off('focus') - .off('blur') - .off('keypress') - .off('keydown') - .off('change') - .removeData(); // removes all attached data - if ($(this).prev().hasClass('w2ui-list')) { // if enum - $(this).prev().remove(); - $(this).removeAttr('tabindex').css('border-color', '').show(); - } - if ($(this).prev().hasClass('w2ui-upload')) { // if upload - $(this).prev().remove(); - $(this).removeAttr('tabindex').css('border-color', '').show(); - } - if ($(this).prev().hasClass('w2ui-field-helper')) { // helpers - $(this).css('padding-left', $(this).css('padding-top')); - $(this).prev().remove(); - } - if ($(this).next().hasClass('w2ui-field-helper')) { // helpers - $(this).css('padding-right', $(this).css('padding-top')); - $(this).next().remove(); - } - if ($(this).next().hasClass('w2ui-field-helper')) { // helpers - $(this).next().remove(); - } - break; - - case 'text': - case 'int': - case 'float': - case 'money': - case 'alphanumeric': - case 'hex': - var el = this; - var defaults = { - min : null, - max : null, - arrows : false, - keyboard: true, - suffix : '', - prefix : '' + click: function (event) { + event.stopPropagation(); + // lists + if (['list', 'combo', 'enum'].indexOf(this.type) != -1) { + if (!$(this.el).is(':focus')) this.focus(event); } - options = $.extend({}, defaults, options); - if (['text', 'alphanumeric', 'hex'].indexOf(tp) != -1) { - options.arrows = false; - options.keyboard = false; - } - // init events - $(this) - .data('options', options) - .on('keypress', function (event) { // keyCode & charCode differ in FireFox + // other fields with drops + if (['date', 'time', 'color'].indexOf(this.type) != -1) { + this.updateOverlay(); + } + }, + + focus: function (event) { + var obj = this; + var options = this.options; + // color, date, time + if (['color', 'date', 'time'].indexOf(obj.type) !== -1) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + setTimeout(function () { obj.updateOverlay(); }, 150); + } + // menu + if (['list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($(obj.el).attr('readonly') || $(obj.el).attr('disabled')) return; + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + setTimeout(function () { + if (obj.type == 'list' && $(obj.el).is(':focus')) { + $(obj.helpers.focus).find('input').focus(); + return; + } + obj.search(); + setTimeout(function () { obj.updateOverlay(); }, 1); + }, 1); + } + // file + if (obj.type == 'file') { + $(obj.helpers.multi).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + } + }, + + blur: function (event) { + var obj = this; + var options = obj.options; + var val = $(obj.el).val().trim(); + // hide overlay + if (['color', 'date', 'time', 'list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + } + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(obj.type) != -1) { + if (val !== '' && !obj.checkType(val)) { + $(obj.el).val('').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid number'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + } + // date or time + if (['date', 'time'].indexOf(obj.type) != -1) { + // check if in range + if (val !== '' && !obj.inRange(obj.el.value)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not in range'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } else { + if (obj.type == 'date' && val !== '' && !w2utils.isDate(obj.el.value, options.format)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid date'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + if (obj.type == 'time' && val !== '' && !w2utils.isTime(obj.el.value)) { + $(obj.el).val('').removeData('selected').change(); + if (options.silent === false) { + $(obj.el).w2tag('Not a valid time'); + setTimeout(function () { $(obj.el).w2tag(''); }, 3000); + } + } + } + } + // clear search input + if (obj.type == 'enum') { + $(obj.helpers.multi).find('input').val('').width(20); + } + // file + if (obj.type == 'file') { + $(obj.helpers.multi).css({ 'outline': 'none' }); + } + }, + + keyPress: function (event) { + var obj = this; + var options = obj.options; + // ignore wrong pressed key + if (['int', 'float', 'money', 'currency', 'percent', 'hex', 'color', 'alphanumeric'].indexOf(obj.type) != -1) { + // keyCode & charCode differ in FireFox if (event.metaKey || event.ctrlKey || event.altKey || (event.charCode != event.keyCode && event.keyCode > 0)) return; - if (event.keyCode == 13) $(this).change(); var ch = String.fromCharCode(event.charCode); - if (!checkType(ch, true)) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - return false; + if (!obj.checkType(ch, true) && event.keyCode != 13) { + event.preventDefault(); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + return false; } - }) - .on('keydown', function (event, extra) { - if (!options.keyboard) return; + } + // update date popup + if (['date', 'time'].indexOf(obj.type) != -1) { + setTimeout(function () { obj.updateOverlay(); }, 1); + } + }, + + keyDown: function (event, extra) { + var obj = this; + var options = obj.options; + var key = event.keyCode || (extra && extra.keyCode); + // numeric + if (['int', 'float', 'money', 'currency', 'percent'].indexOf(obj.type) != -1) { + if (!options.keyboard || $(obj.el).attr('readonly')) return; var cancel = false; - var v = $(el).val(); - if (!checkType(v)) v = options.min || 0; else v = parseFloat(v); - var key = event.keyCode || extra.keyCode; - var inc = 1; + var val = parseFloat($(obj.el).val().replace(options.moneyRE, '')) || 0; + var inc = options.step; if (event.ctrlKey || event.metaKey) inc = 10; switch (key) { - case 38: // up - $(el).val((v + inc <= options.max || options.max == null ? v + inc : options.max)).change(); - if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) ); - cancel = true; - break; - case 40: // down - $(el).val((v - inc >= options.min || options.min == null ? v - inc : options.min)).change(); - if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) ); - cancel = true; - break; + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + $(obj.el).val((val + inc <= options.max || options.max === null ? Number((val + inc).toFixed(12)) : options.max)).change(); + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + $(obj.el).val((val - inc >= options.min || options.min === null ? Number((val - inc).toFixed(12)) : options.min)).change(); + cancel = true; + break; } if (cancel) { - event.preventDefault(); - // set cursor to the end - setTimeout(function () { el.setSelectionRange(el.value.length, el.value.length); }, 0); + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + }, 0); + } + } + // date + if (obj.type == 'date') { + if (!options.keyboard || $(obj.el).attr('readonly')) return; + var cancel = false; + var daymil = 24*60*60*1000; + var inc = 1; + if (event.ctrlKey || event.metaKey) inc = 10; + var dt = w2utils.isDate($(obj.el).val(), options.format, true); + if (!dt) { dt = new Date(); daymil = 0; } + switch (key) { + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + var newDT = w2utils.formatDate(dt.getTime() + daymil, options.format); + if (inc == 10) newDT = w2utils.formatDate(new Date(dt.getFullYear(), dt.getMonth()+1, dt.getDate()), options.format); + $(obj.el).val(newDT).change(); + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + var newDT = w2utils.formatDate(dt.getTime() - daymil, options.format); + if (inc == 10) newDT = w2utils.formatDate(new Date(dt.getFullYear(), dt.getMonth()-1, dt.getDate()), options.format); + $(obj.el).val(newDT).change(); + cancel = true; + break; } - }) - .on('change', function (event) { - // check max/min - var v = $(el).val(); - var cancel = false; - if (options.min != null && v != '' && v < options.min) { $(el).val(options.min).change(); cancel = true; } - if (options.max != null && v != '' && v > options.max) { $(el).val(options.max).change(); cancel = true; } if (cancel) { - event.stopPropagation(); - event.preventDefault(); - return false; - } - // check validity - if (this.value != '' && !checkType(this.value)) $(this).val(options.min != null ? options.min : ''); - }); - if ($(this).val() == '' && options.min != null) $(this).val(options.min); - if (options.prefix != '') { - $(this).before( - ''+ - options.prefix + - ''); - var helper = $(this).prev(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : $(this).css('padding-left'), - 'padding-right' : 0, - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px', - 'margin-left' : 0, - 'margin-right' : 0 - }) - .on('click', function () { - $(this).next().focus(); - }); - $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 5) + 'px'); - } - var pr = parseInt($(this).css('padding-right')); - if (options.arrows != '') { - $(this).after( - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ' '+ - ''); - var height = w2utils.getSize(this, 'height'); - var helper = $(this).next(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'height' : ($(this).height() + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom')) ) + 'px', - 'padding' : '0px', - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : '0px', - 'border-left' : '1px solid silver' - }) - .css('margin-left', '-'+ (helper.width() + parseInt($(this).css('margin-right')) + 12) + 'px') - .on('mousedown', function (event) { - var btn = this; - var evt = event; - $('body').on('mouseup', tmp); - $('body').data('_field_update_timer', setTimeout(update, 700)); - update(false); - // timer function - function tmp() { - clearTimeout($('body').data('_field_update_timer')); - $('body').off('mouseup', tmp); - } - // update function - function update(notimer) { - $(el).focus().trigger($.Event("keydown"), { - keyCode : ($(evt.target).attr('type') == 'up' ? 38 : 40) + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + obj.updateOverlay(); + }, 0); + } + } + // time + if (obj.type == 'time') { + if (!options.keyboard || $(obj.el).attr('readonly')) return; + var cancel = false; + var inc = (event.ctrlKey || event.metaKey ? 60 : 1); + var val = $(obj.el).val(); + var time = obj.toMin(val) || obj.toMin((new Date()).getHours() + ':' + ((new Date()).getMinutes() - 1)); + switch (key) { + case 38: // up + if (event.shiftKey) break; // no action if shift key is pressed + time += inc; + cancel = true; + break; + case 40: // down + if (event.shiftKey) break; // no action if shift key is pressed + time -= inc; + cancel = true; + break; + } + if (cancel) { + $(obj.el).val(obj.fromMin(time)).change(); + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + }, 0); + } + } + // color + if (obj.type == 'color') { + if ($(obj.el).attr('readonly')) return; + // paste + if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) { + $(obj.el).prop('maxlength', 7); + setTimeout(function () { + var val = $(obj).val(); + if (val.substr(0, 1) == '#') val = val.substr(1); + if (!w2utils.isHex(val)) val = ''; + $(obj).val(val).prop('maxlength', 6).change(); + }, 20); + } + if ((event.ctrlKey || event.metaKey) && !event.shiftKey) { + if (typeof obj.tmp.cind1 == 'undefined') { + obj.tmp.cind1 = -1; + obj.tmp.cind2 = -1; + } else { + switch (key) { + case 38: // up + obj.tmp.cind1--; + break; + case 40: // down + obj.tmp.cind1++; + break; + case 39: // right + obj.tmp.cind2++; + break; + case 37: // left + obj.tmp.cind2--; + break; + } + if (obj.tmp.cind1 < 0) obj.tmp.cind1 = 0; + if (obj.tmp.cind1 > this.pallete.length - 1) obj.tmp.cind1 = this.pallete.length - 1; + if (obj.tmp.cind2 < 0) obj.tmp.cind2 = 0; + if (obj.tmp.cind2 > this.pallete[0].length - 1) obj.tmp.cind2 = this.pallete[0].length - 1; + } + if ([37, 38, 39, 40].indexOf(key) != -1) { + $(obj.el).val(this.pallete[obj.tmp.cind1][obj.tmp.cind2]).change(); + event.preventDefault(); + } + } + } + // list/select/combo + if (['list', 'combo', 'enum'].indexOf(obj.type) != -1) { + if ($(obj.el).attr('readonly')) return; + var cancel = false; + var selected = $(obj.el).data('selected'); + var focus = $(obj.helpers.focus).find('input'); + if (obj.type == 'list') { + if ([37, 38, 39, 40].indexOf(key) == -1) obj.refresh(); // arrows + } + // apply arrows + switch (key) { + case 27: // escape + if (obj.type == 'list') { + if ($(focus).val() != '') $(focus).val(''); + event.stopPropagation(); // escape in field should not close popup + } + break; + case 37: // left + case 39: // right + // cancel = true; + break; + case 13: // enter + if ($('#w2ui-overlay').length == 0) break; // no action if overlay not open + var item = options.items[options.index]; + var multi = $(obj.helpers.multi).find('input'); + if (obj.type == 'enum') { + if (item != null) { + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'add', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + item = eventData.item; // need to reassign because it could be recreated by user + // default behavior + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete item.hidden; + delete obj.tmp.force_open; + selected.push(item); + $(obj.el).change(); + multi.val('').width(20); + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } else { + // trigger event + item = { id: multi.val(), text: multi.val() } + var eventData = obj.trigger({ phase: 'before', type: 'new', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + item = eventData.item; // need to reassign because it could be recreated by user + // default behavior + if (typeof obj.onNew == 'function') { + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete obj.tmp.force_open; + selected.push(item); + $(obj.el).change(); + multi.val('').width(20); + obj.refresh(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + if (item) $(obj.el).data('selected', item).val(item.text).change(); + if ($(obj.el).val() == '' && $(obj.el).data('selected')) $(obj.el).removeData('selected').val('').change(); + if (obj.type == 'list') { + focus.val(''); + obj.refresh(); + } + // hide overlay + obj.tmp.force_hide = true; + } + break; + case 8: // backspace + case 46: // delete + if (obj.type == 'enum' && key == 8) { + if ($(obj.helpers.multi).find('input').val() == '' && selected.length > 0) { + var item = selected[selected.length - 1]; + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'remove', target: obj.el, originalEvent: event.originalEvent, item: item }); + if (eventData.isCancelled === true) return; + // default behavior + selected.pop(); + $(obj.el).trigger('change'); + obj.refresh(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } + if (obj.type == 'list' && $(focus).val() == '') { + $(obj.el).data('selected', {}).change(); + obj.refresh(); + } + break; + case 38: // up + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : 0; + options.index--; + while (options.index > 0 && options.items[options.index].hidden) options.index--; + if (options.index == 0 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } + cancel = true; + break; + case 40: // down + options.index = w2utils.isInt(options.index) ? parseInt(options.index) : -1; + options.index++; + while (options.index < options.items.length-1 && options.items[options.index].hidden) options.index++; + if (options.index == options.items.length-1 && options.items[options.index].hidden) { + while (options.items[options.index] && options.items[options.index].hidden) options.index--; + } + // show overlay if not shown + var input = obj.el; + if (['enum'].indexOf(obj.type) != -1) input = obj.helpers.multi.find('input'); + if ($(input).val() == '' && $('#w2ui-overlay').length == 0) { + obj.tmp.force_open = true; + } else { + cancel = true; + } + break; + } + if (cancel) { + if (options.index < 0) options.index = 0; + if (options.index >= options.items.length) options.index = options.items.length -1; + obj.updateOverlay(); + // cancel event + event.preventDefault(); + setTimeout(function () { + // set cursor to the end + if (obj.type == 'enum') { + var tmp = obj.helpers.multi.find('input').get(0); + tmp.setSelectionRange(tmp.value.length, tmp.value.length); + } else if (obj.type == 'list') { + var tmp = obj.helpers.focus.find('input').get(0); + tmp.setSelectionRange(tmp.value.length, tmp.value.length); + } else { + obj.el.setSelectionRange(obj.el.value.length, obj.el.value.length); + } + }, 0); + return; + } + // expand input + if (obj.type == 'enum') { + var input = obj.helpers.multi.find('input'); + var search = input.val(); + input.width(((search.length + 2) * 8) + 'px'); + } + // run search + if ([16, 17, 18, 20, 37, 39, 91].indexOf(key) == -1) { // no refreah on crtl, shift, left/right arrows, etc + setTimeout(function () { + if (!obj.tmp.force_hide) obj.request(); + obj.search(); + }, 1); + } + } + }, + + keyUp: function (event) { + if (this.type == 'color') { + if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) $(this).prop('maxlength', 6); + } + }, + + clearCache: function () { + var options = this.options; + options.items = []; + this.tmp.xhr_loading = false; + this.tmp.xhr_search = ''; + this.tmp.xhr_total = -1; + this.search(); + }, + + request: function (interval) { + var obj = this; + var options = this.options; + var search = $(obj.el).val() || ''; + // if no url - do nothing + if (!options.url) return; + // -- + if (obj.type == 'enum') { + var tmp = $(obj.helpers.multi).find('input'); + if (tmp.length == 0) search = ''; else search = tmp.val(); + } + if (obj.type == 'list') { + var tmp = $(obj.helpers.focus).find('input'); + if (tmp.length == 0) search = ''; else search = tmp.val(); + } + if (options.minLength != 0 && search.length < options.minLength) { + options.items = []; // need to empty the list + this.updateOverlay(); + return; + } + if (typeof interval == 'undefined') interval = 350; + if (typeof obj.tmp.xhr_search == 'undefined') obj.tmp.xhr_search = ''; + if (typeof obj.tmp.xhr_total == 'undefined') obj.tmp.xhr_total = -1; + // check if need to search + if (options.url && $(obj.el).prop('readonly') != true && ( + (options.items.length === 0 && obj.tmp.xhr_total !== 0) || + (obj.tmp.xhr_total == options.cacheMax && search.length > obj.tmp.xhr_search.length) || + (search.length >= obj.tmp.xhr_search.length && search.substr(0, obj.tmp.xhr_search.length) != obj.tmp.xhr_search) || + (search.length < obj.tmp.xhr_search.length) + )) { + // empty list + obj.tmp.xhr_loading = true; + obj.search(); + // timeout + clearTimeout(obj.tmp.timeout); + obj.tmp.timeout = setTimeout(function () { + // trigger event + var url = options.url; + var postData = { + search : search, + max : options.cacheMax + }; + $.extend(postData, options.postData); + var eventData = obj.trigger({ phase: 'before', type: 'request', target: obj.el, url: url, postData: postData }); + if (eventData.isCancelled === true) return; + url = eventData.url; + postData = eventData.postData; + // console.log('REMOTE SEARCH:', search); + if (obj.tmp.xhr) obj.tmp.xhr.abort(); + var ajaxOptions = { + type : 'GET', + url : url, + data : postData, + dataType : 'JSON' // expected from server + }; + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + obj.tmp.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + // trigger event + var eventData2 = obj.trigger({ phase: 'before', type: 'load', target: obj.el, search: postData.search, data: data, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + data = eventData2.data; + if (typeof data == 'string') data = JSON.parse(data); + if (data.status != 'success') { + console.log('ERROR: server did not return proper structure. It should return', { status: 'success', items: [{ id: 1, text: 'item' }] }); + return; + } + // remove all extra items if more then needed for cache + if (data.items.length > options.cacheMax) data.items.splice(options.cacheMax, 100000); + // remember stats + obj.tmp.xhr_loading = false; + obj.tmp.xhr_search = search; + obj.tmp.xhr_total = data.items.length; + options.items = obj.normMenu(data.items); + if (search == '' && data.items.length == 0) obj.tmp.emptySet = true; else obj.tmp.emptySet = false; + obj.search(); + // console.log('-->', 'retrieved:', obj.tmp.xhr_total); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', target: obj.el, search: search, error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', items: [{ id: 1, text: 'item' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + // reset stats + obj.clearCache(); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, interval); + } + }, + + search: function () { + var obj = this; + var options = this.options; + var search = $(obj.el).val(); + var target = obj.el; + var ids = []; + var selected= $(obj.el).data('selected'); + if (obj.type == 'enum') { + target = $(obj.helpers.multi).find('input'); + search = target.val(); + for (var s in selected) { if (selected[s]) ids.push(selected[s].id); } + } + if (obj.type == 'list') { + target = $(obj.helpers.focus).find('input'); + search = target.val(); + for (var s in selected) { if (selected[s]) ids.push(selected[s].id); } + } + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'search', target: target, search: search }); + if (eventData.isCancelled === true) return; + if (obj.tmp.xhr_loading !== true) { + var shown = 0; + for (var i in options.items) { + var item = options.items[i]; + var prefix = ''; + var suffix = ''; + if (['is', 'begins'].indexOf(options.match) != -1) prefix = '^'; + if (['is', 'ends'].indexOf(options.match) != -1) suffix = '$'; + try { + var re = new RegExp(prefix + search + suffix, 'i'); + if (re.test(item.text) || item.text == '...') item.hidden = false; else item.hidden = true; + } catch (e) {} + // do not show selected items + if (obj.type == 'enum' && $.inArray(item.id, ids) != -1) item.hidden = true; + if (item.hidden !== true) shown++; + } + if (obj.type != 'combo') { // don't preselect first for combo + options.index = 0; + while (options.items[options.index] && options.items[options.index].hidden) options.index++; + } else { + options.index = -1; + } + if (shown <= 0) options.index = -1; + options.spinner = false; + obj.updateOverlay(); + setTimeout(function () { + var html = $('#w2ui-overlay').html() || ''; + if (options.markSearch && html.indexOf('$.fn.w2menuHandler') != -1) { // do not highlight when no items + $('#w2ui-overlay').w2marker(search); + } + }, 1); + } else { + options.items.splice(0, options.cacheMax); + options.spinner = true; + obj.updateOverlay(); + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, + + updateOverlay: function () { + var obj = this; + var options = this.options; + // color + if (this.type == 'color') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay(obj.getColorHTML()); + } else { + $('#w2ui-overlay').html(obj.getColorHTML()); + } + // bind events + $('#w2ui-overlay .color') + .on('mousedown', function (event) { + var color = $(event.originalEvent.target).attr('name'); + var index = $(event.originalEvent.target).attr('index').split(':'); + obj.tmp.cind1 = index[0]; + obj.tmp.cind2 = index[1]; + $(obj.el).val(color).change(); + $(this).html(''); + }) + .on('mouseup', function () { + setTimeout(function () { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); + }, 10); }); - if (notimer !== false) $('body').data('_field_update_timer', setTimeout(update, 60)); - }; - }); - pr += helper.width() + 12; - $(this).css('padding-right', pr + 'px'); - } - if (options.suffix != '') { - $(this).after( - ''+ - options.suffix + - ''); - var helper = $(this).next(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : '3px', - 'padding-right' : $(this).css('padding-right'), - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px' - }) - .on('click', function () { - $(this).prev().focus(); - }); - helper.css('margin-left', '-'+ (helper.width() + parseInt($(this).css('padding-right')) + 5) + 'px'); - pr += helper.width() + 3; - $(this).css('padding-right', pr + 'px'); } + // date + if (this.type == 'date') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay('', { + css: { "background-color": "#f5f5f5" } + }); + } + var month, year; + var dt = w2utils.isDate($(obj.el).val(), obj.options.format, true); + if (dt) { month = dt.getMonth() + 1; year = dt.getFullYear(); } + (function refreshCalendar(month, year) { + $('#w2ui-overlay > div > div').html(obj.getMonthHTML(month, year)); + $('#w2ui-overlay .w2ui-calendar-title') + .on('mousedown', function () { + if ($(this).next().hasClass('w2ui-calendar-jump')) { + $(this).next().remove(); + } else { + var selYear, selMonth; + $(this).after(''); + $(this).next().hide().html(obj.getYearHTML()).fadeIn(200); + setTimeout(function () { + $('#w2ui-overlay .w2ui-calendar-jump') + .find('.w2ui-jump-month, .w2ui-jump-year') + .on('click', function () { + if ($(this).hasClass('w2ui-jump-month')) { + $(this).parent().find('.w2ui-jump-month').removeClass('selected'); + $(this).addClass('selected'); + selMonth = $(this).attr('name'); + } + if ($(this).hasClass('w2ui-jump-year')) { + $(this).parent().find('.w2ui-jump-year').removeClass('selected'); + $(this).addClass('selected'); + selYear = $(this).attr('name'); + } + if (selYear != null && selMonth != null) { + $('#w2ui-overlay .w2ui-calendar-jump').fadeOut(100); + setTimeout(function () { refreshCalendar(parseInt(selMonth)+1, selYear); }, 100); + } + }); + $('#w2ui-overlay .w2ui-calendar-jump >:last-child').prop('scrollTop', 2000); + }, 1); + } + }); + $('#w2ui-overlay .w2ui-date') + .on('mousedown', function () { + var day = $(this).attr('date'); + $(obj.el).val(day).change(); + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + }) + .on('mouseup', function () { + setTimeout(function () { + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); + }, 10); + }); + $('#w2ui-overlay .previous').on('mousedown', function () { + var tmp = obj.options.current.split('/'); + tmp[0] = parseInt(tmp[0]) - 1; + refreshCalendar(tmp[0], tmp[1]); + }); + $('#w2ui-overlay .next').on('mousedown', function () { + var tmp = obj.options.current.split('/'); + tmp[0] = parseInt(tmp[0]) + 1; + refreshCalendar(tmp[0], tmp[1]); + }); + }) (month, year); + } + // date + if (this.type == 'time') { + if ($(obj.el).attr('readonly')) return; + if ($('#w2ui-overlay').length == 0) { + $(obj.el).w2overlay('', { + css: { "background-color": "#fff" } + }); + } + var h24 = (this.options.format == 'h24' ? true : false); + $('#w2ui-overlay > div').html(obj.getHourHTML()); + $('#w2ui-overlay .w2ui-time') + .on('mousedown', function (event) { + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + var hour = $(this).attr('hour'); + $(obj.el).val((hour > 12 && !h24 ? hour - 12 : hour) + ':00' + (!h24 ? (hour < 12 ? ' am' : ' pm') : '')).change(); + }) + .on('mouseup', function () { + var hour = $(this).attr('hour'); + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + $(obj.el).w2overlay('', { css: { "background-color": "#fff" } }); + $('#w2ui-overlay > div').html(obj.getMinHTML(hour)); + $('#w2ui-overlay .w2ui-time') + .on('mousedown', function () { + $(this).css({ 'background-color': '#B6D5FB', 'border-color': '#aaa' }); + var min = $(this).attr('min'); + $(obj.el).val((hour > 12 && !h24 ? hour - 12 : hour) + ':' + (min < 10 ? 0 : '') + min + (!h24 ? (hour < 12 ? ' am' : ' pm') : '')).change(); + }) + .on('mouseup', function () { + setTimeout(function () { if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay').removeData('keepOpen')[0].hide(); }, 10); + }); + }); + } + // list + if (['list', 'combo', 'enum'].indexOf(this.type) != -1) { + var el = this.el; + var input = this.el; + if (this.type == 'enum') { + el = $(this.helpers.multi); + input = $(el).find('input'); + } + if (this.type == 'list') { + input = $(this.helpers.focus).find('input'); + } + if ($(input).is(':focus')) { + if (options.openOnFocus === false && $(input).val() == '' && obj.tmp.force_open !== true) { + $().w2overlay(); + return; + } + if (obj.tmp.force_hide) { + $().w2overlay(); + setTimeout(function () { + delete obj.tmp.force_hide; + }, 1); + return; + } + if ($(input).val() != '') delete obj.tmp.force_open; + if ($('#w2ui-overlay').length == 0) options.index = 0; + var msgNoItems = w2utils.lang('No matches'); + if (options.url != null && $(input).val().length < options.minLength && obj.tmp.emptySet !== true) msgNoItems = options.minLength + ' ' + w2utils.lang('letters or more...'); + if (options.url != null && $(input).val() == '' && obj.tmp.emptySet !== true) msgNoItems = w2utils.lang('Type to search....'); + $(el).w2menu('refresh', $.extend(true, {}, options, { + search : false, + render : options.renderDrop, + maxHeight : options.maxDropHeight, + msgNoItems : msgNoItems, + // selected with mouse + onSelect: function (event) { + if (obj.type == 'enum') { + var selected = $(obj.el).data('selected'); + if (event.item) { + // trigger event + var eventData = obj.trigger({ phase: 'before', type: 'add', target: obj.el, originalEvent: event.originalEvent, item: event.item }); + if (eventData.isCancelled === true) return; + // default behavior + if (selected.length >= options.max && options.max > 0) selected.pop(); + delete event.item.hidden; + selected.push(event.item); + $(obj.el).data('selected', selected).change(); + $(obj.helpers.multi).find('input').val('').width(20); + obj.refresh(); + if ($("#w2ui-overlay").length > 0) $('#w2ui-overlay')[0].hide(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } + } else { + $(obj.el).data('selected', event.item).val(event.item.text).change(); + if (obj.helpers.focus) obj.helpers.focus.find('input').val(''); + } + } + })); + } + } + }, + + inRange: function (str) { + var inRange = false; + if (this.type == 'date') { + var dt = w2utils.isDate(str, this.options.format, true); + if (dt) { + // enable range + if (this.options.start || this.options.end) { + var st = (typeof this.options.start == 'string' ? this.options.start : $(this.options.start).val()); + var en = (typeof this.options.end == 'string' ? this.options.end : $(this.options.end).val()); + var start = w2utils.isDate(st, this.options.format, true); + var end = w2utils.isDate(en, this.options.format, true); + var current = new Date(dt); + if (!start) start = current; + if (!end) end = current; + if (current >= start && current <= end) inRange = true; + } else { + inRange = true; + } + // block predefined dates + if (this.options.blocked && $.inArray(str, this.options.blocked) != -1) inRange = false; + } + } + if (this.type == 'time') { + if (this.options.start || this.options.end) { + var tm = this.toMin(str); + var tm1 = this.toMin(this.options.start); + var tm2 = this.toMin(this.options.end); + if (!tm1) tm1 = tm; + if (!tm2) tm2 = tm; + if (tm >= tm1 && tm <= tm2) inRange = true; + } else { + inRange = true; + } + } + return inRange; + }, - function checkType(ch, loose) { - switch (tp) { - case 'int': - if (loose && ['-'].indexOf(ch) != -1) return true; - return w2utils.isInt(ch); - break; - case 'float': - if (loose && ['-','.'].indexOf(ch) != -1) return true; - return w2utils.isFloat(ch); - break; - case 'money': - if (loose && ['-','.','$','€','£','¥'].indexOf(ch) != -1) return true; - return w2utils.isMoney(ch); - break; - case 'hex': - return w2utils.isHex(ch); - break; - case 'alphanumeric': - return w2utils.isAlphaNumeric(ch); - break; + /* + * INTERNAL FUNCTIONS + */ + + checkType: function (ch, loose) { + var obj = this; + switch (obj.type) { + case 'int': + if (loose && ['-', obj.options.groupSymbol].indexOf(ch) != -1) return true; + return w2utils.isInt(ch.replace(obj.options.numberRE, '')); + case 'percent': + ch = ch.replace(/%/g, ''); + case 'float': + if (loose && ['-', w2utils.settings.decimalSymbol, obj.options.groupSymbol].indexOf(ch) != -1) return true; + return w2utils.isFloat(ch.replace(obj.options.numberRE, '')); + case 'money': + case 'currency': + if (loose && ['-', obj.options.decimalSymbol, obj.options.groupSymbol, obj.options.currencyPrefix, obj.options.currencySuffix].indexOf(ch) != -1) return true; + return w2utils.isFloat(ch.replace(obj.options.moneyRE, '')); + case 'hex': + case 'color': + return w2utils.isHex(ch); + case 'alphanumeric': + return w2utils.isAlphaNumeric(ch); } return true; - } - break; + }, - case 'date': + addPrefix: function () { var obj = this; - var defaults = { - format : w2utils.settings.date_format, // date format - start : '', // start of selectable range - end : '', // end of selectable range - blocked : {}, // {'4/11/2011': 'yes'} - colored : {} // {'4/11/2011': 'red:white'} - } - options = $.extend({}, defaults, options); - // -- insert div for calendar - $(this) // remove transtion needed for functionality - .css( { 'transition': 'none', '-webkit-transition': 'none', '-moz-transition': 'none', '-ms-transition': 'none', '-o-transition': 'none' }) - .data("options", options) - .on('focus', function () { - var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight); - var left = parseFloat($(obj).offset().left); - clearInterval($(obj).data('mtimer')); - $('#global_calendar_div').remove(); - $('body').append(''+ - ''); - $('#global_calendar_div') - .html($().w2field('calendar_get', obj.value, options)) - .css({ - left: left + 'px', - top: top + 'px' - }) - .data('el', obj) - .show(); - var max = $(window).width() + $(document).scrollLeft() - 1; - if (left + $('#global_calendar_div').width() > max) { - $('#global_calendar_div').css('left', (max - $('#global_calendar_div').width()) + 'px'); - } - // monitors - var mtimer = setInterval(function () { - var max = $(window).width() + $(document).scrollLeft() - 1; - var left = $(obj).offset().left; - if (left + $('#global_calendar_div').width() > max) left = max - $('#global_calendar_div').width(); - // monitor if moved - if ($('#global_calendar_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - $('#global_calendar_div').css({ - '-webkit-transition': '.2s', - left: left + 'px', - top : ($(obj).offset().top + obj.offsetHeight) + 'px' - }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - } - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval(mtimer); - $('#global_calendar_div').remove(); - return; - } - }, 100); - $(obj).data('mtimer', mtimer); - }) - .on('blur', function (event) { - // trim empty spaces - $(obj).val($.trim($(obj).val())); - // check if date is valid - if ($.trim($(obj).val()) != '' && !w2utils.isDate($(obj).val(), options.format)) { - $(this).w2tag(w2utils.lang('Not a valid date') + ': '+ options.format); - } - clearInterval($(obj).data('mtimer')); - $('#global_calendar_div').remove(); - }) - .on('keypress', function (event) { - var obj = this; - setTimeout(function () { - $('#global_calendar_div').html( $().w2field('calendar_get', obj.value, options) ); - }, 10); - }); setTimeout(function () { - // if it is unix time - convert to readable date - if (w2utils.isInt(obj.value)) obj.value = w2utils.formatDate(obj.value, options.format); + if (obj.type === 'clear') return; + var helper; + var tmp = $(obj.el).data('tmp') || {}; + if (tmp['old-padding-left']) $(obj.el).css('padding-left', tmp['old-padding-left']); + tmp['old-padding-left'] = $(obj.el).css('padding-left'); + $(obj.el).data('tmp', tmp); + // remove if already displaed + if (obj.helpers.prefix) $(obj.helpers.prefix).remove(); + if (obj.options.prefix !== '') { + // add fresh + $(obj.el).before( + ''+ + obj.options.prefix + + '' + ); + helper = $(obj.el).prev(); + helper + .css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'padding-top' : $(obj.el).css('padding-top'), + 'padding-bottom' : $(obj.el).css('padding-bottom'), + 'padding-left' : $(obj.el).css('padding-left'), + 'padding-right' : 0, + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 2) + 'px', + 'margin-bottom' : (parseInt($(obj.el).css('margin-bottom'), 10) + 1) + 'px', + 'margin-left' : $(obj.el).css('margin-left'), + 'margin-right' : 0 + }) + .on('click', function (event) { + if (obj.options.icon && typeof obj.onIconClick == 'function') { + // event before + var eventData = obj.trigger({ phase: 'before', type: 'iconClick', target: obj.el, el: $(this).find('span.w2ui-icon')[0] }); + if (eventData.isCancelled === true) return; + + // intentionally empty + + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + } else { + if (obj.type == 'list') { + $(obj.helpers.focus).find('input').focus(); + } else { + $(obj.el).focus(); + } + } + }); + $(obj.el).css('padding-left', (helper.width() + parseInt($(obj.el).css('padding-left'), 10)) + 'px'); + // remember helper + obj.helpers.prefix = helper; + } }, 1); - break; - - case 'time': - break; + }, - case 'datetime': - break; - - case 'color': + addSuffix: function () { var obj = this; - var defaults = { - prefix : '#', - suffix : '' - } - options = $.extend({}, defaults, options); - // -- insert div for color - $(this) - .attr('maxlength', 6) - .on('focus', function () { - var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight); - var left = parseFloat($(obj).offset().left); - clearInterval($(obj).data('mtimer')); - $('#global_color_div').remove(); - $('body').append(''+ - ''); - $('#global_color_div') - .html($().w2field('getColorHTML', obj.value)) - .css({ - left: left + 'px', - top: top + 'px' - }) - .data('el', obj) - .show(); - var max = $(window).width() + $(document).scrollLeft() - 1; - if (left + $('#global_color_div').width() > max) { - $('#global_color_div').css('left', (max - $('#global_color_div').width()) + 'px'); - } - // monitors - var mtimer = setInterval(function () { - var max = $(window).width() + $(document).scrollLeft() - 1; - var left = $(obj).offset().left; - if (left + $('#global_color_div').width() > max) left = max - $('#global_color_div').width(); - // monitor if moved - if ($('#global_color_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - $('#global_color_div').css({ - '-webkit-transition': '.2s', - left: left + 'px', - top : ($(obj).offset().top + obj.offsetHeight) + 'px' - }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - } - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval(mtimer); - $('#global_color_div').remove(); - return; - } - }, 100); - $(obj).data('mtimer', mtimer); - }) - .on('click', function () { - $(this).trigger('focus'); - }) - .on('blur', function (event) { - // trim empty spaces - $(obj).val($.trim($(obj).val())); - clearInterval($(obj).data('mtimer')); - $('#global_color_div').remove(); - }) - .on('keydown', function (event) { // need this for cut/paster - if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) { - var obj = this; - $(this).prop('maxlength', 7); - setTimeout(function () { - var val = $(obj).val(); - if (val.substr(0, 1) == '#') val = val.substr(1); - if (!w2utils.isHex(val)) val = ''; - $(obj).val(val).prop('maxlength', 6).change(); - }, 20); - } - }) - .on('keyup', function (event) { - if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) $(this).prop('maxlength', 6); - }) - .on('keypress', function (event) { // keyCode & charCode differ in FireFox - if (event.keyCode == 13) $(this).change(); - //if (event.ct) - var ch = String.fromCharCode(event.charCode); - if (!w2utils.isHex(ch, true)) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - return false; - } - }) - .on('change', function (event) { - var color = '#' + $(this).val(); - if ($(this).val().length != 6 && $(this).val().length != 3) color = ''; - $(this).next().find('div').css('background-color', color); - }); - if (options.prefix != '') { - $(this).before( - ''+ - options.prefix + - ''); - var helper = $(this).prev(); - helper - .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : $(this).css('padding-left'), - 'padding-right' : 0, - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px', - 'margin-left' : 0, - 'margin-right' : 0 + var helper, pr; + setTimeout(function () { + if (obj.type === 'clear') return; + var tmp = $(obj.el).data('tmp') || {}; + if (tmp['old-padding-right']) $(obj.el).css('padding-right', tmp['old-padding-right']); + tmp['old-padding-right'] = $(obj.el).css('padding-right'); + $(obj.el).data('tmp', tmp); + pr = parseInt($(obj.el).css('padding-right'), 10); + if (obj.options.arrows) { + // remove if already displaed + if (obj.helpers.arrows) $(obj.helpers.arrows).remove(); + // add fresh + $(obj.el).after( + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ''); + var height = w2utils.getSize(obj.el, 'height'); + helper = $(obj.el).next(); + helper.css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'height' : ($(obj.el).height() + parseInt($(obj.el).css('padding-top'), 10) + parseInt($(obj.el).css('padding-bottom'), 10) ) + 'px', + 'padding' : 0, + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 1) + 'px', + 'margin-bottom' : 0, + 'border-left' : '1px solid silver' + }) + .css('margin-left', '-'+ (helper.width() + parseInt($(obj.el).css('margin-right'), 10) + 12) + 'px') + .on('mousedown', function (event) { + $('body').on('mouseup', tmp); + $('body').data('_field_update_timer', setTimeout(update, 700)); + update(false); + // timer function + function tmp() { + clearTimeout($('body').data('_field_update_timer')); + $('body').off('mouseup', tmp); + } + // update function + function update(notimer) { + $(obj.el).focus(); + obj.keyDown($.Event("keydown"), { + keyCode : ($(event.target).attr('type') == 'up' ? 38 : 40) + }); + if (notimer !== false) $('body').data('_field_update_timer', setTimeout(update, 60)); + } + }); + pr += helper.width() + 12; + $(obj.el).css('padding-right', pr + 'px'); + // remember helper + obj.helpers.arrows = helper; + } + if (obj.options.suffix !== '') { + // remove if already displaed + if (obj.helpers.suffix) $(obj.helpers.suffix).remove(); + // add fresh + $(obj.el).after( + ''+ + obj.options.suffix + + ''); + helper = $(obj.el).next(); + helper + .css({ + 'color' : $(obj.el).css('color'), + 'font-family' : $(obj.el).css('font-family'), + 'font-size' : $(obj.el).css('font-size'), + 'padding-top' : $(obj.el).css('padding-top'), + 'padding-bottom' : $(obj.el).css('padding-bottom'), + 'padding-left' : '3px', + 'padding-right' : $(obj.el).css('padding-right'), + 'margin-top' : (parseInt($(obj.el).css('margin-top'), 10) + 2) + 'px', + 'margin-bottom' : (parseInt($(obj.el).css('margin-bottom'), 10) + 1) + 'px' + }) + .on('click', function (event) { + if (obj.type == 'list') { + $(obj.helpers.focus).find('input').focus(); + } else { + $(obj.el).focus(); + } + }); + + helper.css('margin-left', '-'+ (w2utils.getSize(helper, 'width') + parseInt($(obj.el).css('margin-right'), 10) + 2) + 'px'); + pr += helper.width() + 3; + $(obj.el).css('padding-right', pr + 'px'); + // remember helper + obj.helpers.suffix = helper; + } + }, 1); + }, + + addFocus: function () { + var obj = this; + var options = this.options; + var width = 0; // 11 - show search icon, 0 do not show + // clean up & init + $(obj.helpers.focus).remove(); + // build helper + var html = + ''+ + ' '+ + ' '+ + ''; + $(obj.el).attr('tabindex', -1).before(html); + var helper = $(obj.el).prev(); + obj.helpers.focus = helper; + helper.css({ + width : $(obj.el).width(), + "margin-top" : $(obj.el).css('margin-top'), + "margin-left" : (parseInt($(obj.el).css('margin-left')) + parseInt($(obj.el).css('padding-left'))) + 'px', + "margin-bottom" : $(obj.el).css('margin-bottom'), + "margin-right" : $(obj.el).css('margin-right') }) - .on('click', function () { - $(this).next().focus(); - }); - $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 2) + 'px'); - } - if (options.suffix != '') { - $(this).after( - ''+ - options.suffix + - ''); - var helper = $(this).next(); - helper + .find('input') .css({ - 'color' : $(this).css('color'), - 'font-family' : $(this).css('font-family'), - 'font-size' : $(this).css('font-size'), - 'padding-top' : $(this).css('padding-top'), - 'padding-bottom': $(this).css('padding-bottom'), - 'padding-left' : '3px', - 'padding-right' : $(this).css('padding-right'), - 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px', - 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px' - }) - .on('click', function () { - $(this).prev().focus(); + cursor : 'default', + width : '100%', + outline : 'none', + opacity : 1, + margin : 0, + border : '1px solid transparent', + padding : $(obj.el).css('padding-top'), + "padding-left" : 0, + "margin-left" : (width > 0 ? width + 6 : 0), + "background-color" : 'transparent' }); - helper.css('margin-left', '-'+ (helper.width() + parseInt($(this).css('padding-right')) + 4) + 'px'); - var pr = helper.width() + parseInt($(this).css('padding-right')) + 4; - $(this).css('padding-right', pr + 'px'); - // set color to current - helper.find('div').css('background-color', '#' + $(obj).val()); - } - break; - - case 'select': - case 'list': - if (this.tagName != 'SELECT') { - console.log('ERROR: You can only apply $().w2field(\'list\') to a SELECT element'); - return; - } - var defaults = { - url : '', - items : [], - value : null, - showNone : true - }; - var obj = this; - var settings = $.extend({}, defaults, options); - $(obj).data('settings', settings); - // define refresh method - obj.refresh = function () { - var settings = $(obj).data('settings'); - var html = ''; - var items = w2field.cleanItems(settings.items); - // build options - if (settings.showNone) html = '- '+ w2utils.lang('none') +' -'; - for (var i in items) { - if (!settings.showNone && settings.value == null) settings.value = items[i].id; - html += ''+ items[i].text + ''; - } - $(obj).html(html); - $(obj).val(settings.value); - if ($(obj).val() != settings.value) $(obj).change(); - } - // pull from server - if (settings.url != '' ) { - $.ajax({ - type : 'GET', - dataType : 'text', - url : settings.url, - complete: function (xhr, status) { - if (status == 'success') { - var data = $.parseJSON(xhr.responseText); - var settings = $(obj).data('settings'); - settings.items = w2field.cleanItems(data.items); - $(obj).data('settings', settings); - obj.refresh(); - } - } - }); - } else { // refresh local - obj.refresh(); - } - break; - - case 'enum': - if (this.tagName != 'INPUT') { - console.log('ERROR: You can only apply $().w2field(\'enum\') to an INPUT element'); - return; - } - var defaults = { - url : '', - items : [], - selected : [], // preselected items - max : 0, // maximum number of items that can be selected 0 for unlim - maxHeight : 172, // max height for input control to grow - showAll : false, // if true then show selected item in drop down - match : 'begins with', // ['begins with', 'contains'] - render : null, // render(item, selected) - maxCache : 500, // number items to cache - onShow : null, // when overlay is shown onShow(settings) - onHide : null, // when overlay is hidden onHide(settings) - onAdd : null, // onAdd(item, settings) - onRemove : null, // onRemove(index, settings) - onItemOver : null, - onItemOut : null, - onItemClick : null - } - var obj = this; - var settings = $.extend({}, defaults, options); - - // normalize items and selected - settings.items = w2field.cleanItems(settings.items); - settings.selected = w2field.cleanItems(settings.selected); - - $(this).data('selected', settings.selected); - $(this).css({ - 'padding' : '0px', - 'border-color' : 'transparent', - 'background-color' : 'transparent', - 'outline' : 'none' - }); - - // add item to selected - this.add = function (item) { - if ($(this).attr('readonly')) return; - var selected = $(this).data('selected'); - var settings = $(this).data('settings'); - if (typeof settings.onAdd == 'function') { - var cancel = settings.onAdd(item, settings); - if (cancel === false) return; - } - if (!$.isArray(selected)) selected = []; - if (settings.max != 0 && settings.max <= selected.length) { - // if max reached, replace last - selected.splice(selected.length - 1, 1); - } - selected.push(item); - $(this).data('last_del', null); - $(this).trigger('change'); - } - - this.remove = function (index) { - var settings = $(this).data('settings'); - if (typeof settings.onRemove == 'function') { - var cancel = settings.onRemove(index, settings); - if (cancel === false) return; - } - if ($(this).attr('readonly')) return; - $(this).data('selected').splice(index, 1); - $(this).parent().find('[title=Remove][index='+ index +']').remove(); - this.refresh(); - w2field.list_render.call(this); - $(this).trigger('change'); - } - - this.show = function () { - if ($(this).attr('readonly')) return; - var settings = $(this).data('settings'); - // insert global div - if ($('#w2ui-global-items').length == 0) { - $('body').append(''); - } else { - // ignore second click - return; - } - var div = $('#w2ui-global-items'); - div.css({ - display : 'block', - left : ($(obj).offset().left) + 'px', - top : ($(obj).offset().top + obj.offsetHeight + 3) + 'px' - }) - .width(w2utils.getSize(obj, 'width')) - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - - // show drop content - w2field.list_render.call(obj); - - // monitors - var monitor = function () { - var div = $('#w2ui-global-items'); - // monitor if destroyed - if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) { - clearInterval($(obj).data('mtimer')); - hide(); - return; - } - // monitor if moved - if (div.data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) { - div.css({ - '-webkit-transition': '.2s', - left: ($(obj).offset().left) + 'px', - top : ($(obj).offset().top + obj.offsetHeight + 3) + 'px' - }) - .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)); - // if moved then resize - setTimeout(function () { - w2field.list_render.call(obj, $(obj).data('last_search')); - }, 200); - } - if (div.length > 0) $(obj).data('mtimer', setTimeout(monitor, 100)); - }; - $(obj).data('mtimer', setTimeout(monitor, 100)); - // onShow - if (typeof settings.onShow == 'function') settings.onShow.call(this, settings); - } - - this.hide = function () { - var settings = $(this).data('settings'); - clearTimeout($(obj).data('mtimer')); - $('#w2ui-global-items').remove(); - // onShow - if (typeof settings.onHide == 'function') settings.onHide.call(this, settings); - } - - // render controls with all items in it - this.refresh = function () { - var obj = this; - // remove all items - $($(this).data('div')).remove(); - // rebuild it - var margin = 'margin-top: ' + $(this).css('margin-top') + '; ' + - 'margin-bottom: ' + $(this).css('margin-bottom') + '; ' + - 'margin-left: ' + $(this).css('margin-left') + '; ' + - 'margin-right: ' + $(this).css('margin-right') + '; '+ - 'width: ' + (w2utils.getSize(this, 'width') - - parseInt($(this).css('margin-left')) - - parseInt($(this).css('margin-right'))) + 'px; '; - var html = ''+ - ''; - var selected = $(this).data('selected'); - for (var s in selected) { - html += ''+ - ' '+ - selected[s].text + - ''; - } - html += ''+ - ' '+ - ''+ - ''+ - ''; - $(this).before(html); - - var div = $(this).prev()[0]; - $(this).data('div', div); - // click on item - $(div).find('li') - .data('mouse', 'out') - .on('click', function (event) { - if ($(event.target).hasClass('nomouse')) return; - if (event.target.title == w2utils.lang('Remove')) { - obj.remove($(event.target).attr('index')); - return; - } - event.stopPropagation(); - if (typeof settings.onItemClick == 'function') settings.onItemClick.call(this, settings); - }) - .on('mouseover', function (event) { - var tmp = event.target; - if (tmp.tagName != 'LI') tmp = tmp.parentNode; - if ($(tmp).hasClass('nomouse')) return; - if ($(tmp).data('mouse') == 'out') { - if (typeof settings.onItemOver == 'function') settings.onItemOver.call(this, settings); - } - $(tmp).data('mouse', 'over'); - }) - .on('mouseout', function (event) { - var tmp = event.target; - if (tmp.tagName != 'LI') tmp = tmp.parentNode; - if ($(tmp).hasClass('nomouse')) return; - $(tmp).data('mouse', 'leaving'); - setTimeout(function () { - if ($(tmp).data('mouse') == 'leaving') { - $(tmp).data('mouse', 'out'); - if (typeof settings.onItemOut == 'function') settings.onItemOut.call(this, settings); - } - }, 0); - }); - $(div) // click on item + // INPUT events + helper.find('input') .on('click', function (event) { - $(this).find('input').focus(); + if ($('#w2ui-overlay').length == 0) obj.focus(event); + event.stopPropagation(); }) - .find('input') .on('focus', function (event) { - $(div).css({ 'outline': 'auto 5px -webkit-focus-ring-color', 'outline-offset': '-2px' }); - obj.show(); - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + $(obj.el).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + $(this).val(''); + $(obj.el).triggerHandler('focus'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; }) .on('blur', function (event) { - $(div).css('outline', 'none'); - obj.hide(); - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }); - // adjust height - obj.resize(); - } - this.resize = function () { - var settings = $(this).data('settings'); - var div = $(this).prev(); - var cntHeight = $(div).find('>div').height(); //w2utils.getSize(div, 'height'); - if (cntHeight < 23) cntHeight = 23; - if (cntHeight > settings.maxHeight) cntHeight = settings.maxHeight; - $(div).height(cntHeight + (cntHeight % 23 == 0 ? 0 : 23 - cntHeight % 23) ); - if (div.length > 0) div[0].scrollTop = 1000; - $(this).height(cntHeight); - } - // init control - $(this).data('settings', settings).attr('tabindex', -1); + $(obj.el).css('outline', 'none'); + $(this).val(''); + obj.refresh(); + $(obj.el).triggerHandler('blur'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('keyup', function (event) { obj.keyUp(event) }) + .on('keydown', function (event) { obj.keyDown(event) }) + .on('keypress', function (event) { obj.keyPress(event); }); + // MAIN div + helper.on('click', function (event) { $(this).find('input').focus(); }); obj.refresh(); - break; - - case 'upload': - if (this.tagName != 'INPUT') { - console.log('ERROR: You can only apply $().w2field(\'upload\') to an INPUT element'); - return; - } - // init defaults - var defaults = { - url : '', // not yet implemented - base64 : true, // if true max file size is 20mb (only tru for now) - hint : w2utils.lang('Attach files by dragging and dropping or Click to Select'), - max : 0, // max number of files, 0 - unlim - maxSize : 0, // max size of all files, 0 - unlim - maxFileSize : 0, // max size of a single file, 0 -unlim - onAdd : null, - onRemove : null, - onItemClick : null, - onItemDblClick : null, - onItemOver : null, - onItemOut : null, - onProgress : null, // not yet implemented - onComplete : null // not yet implemented - } - var obj = this; - var settings = $.extend({}, defaults, options); - if (settings.base64 === true) { - if (settings.maxSize == 0) settings.maxSize = 20 * 1024 * 1024; // 20mb - if (settings.maxFileSize == 0) settings.maxFileSize = 20 * 1024 * 1024; // 20mb - } - var selected = settings.selected; - delete settings.selected; - if (!$.isArray(selected)) selected = []; - $(this).data('selected', selected).data('settings', settings).attr('tabindex', -1); - w2field.upload_init.call(this); - - this.refresh = function () { - var obj = this; - var div = $(this).data('div'); - var settings = $(this).data('settings'); - var selected = $(this).data('selected'); - $(div).find('li').remove(); - $(div).find('> span:first-child').css('line-height', ($(div).height() - w2utils.getSize(div, '+height') - 8) + 'px'); - for (var s in selected) { - var file = selected[s]; - // add li element - var cnt = $(div).find('.file-list li').length; - $(div).find('> span:first-child').remove(); - $(div).find('.file-list').append('' + - ' ' + - ' ' + file.name + '' + - ' - ' + w2utils.size(file.size) + ''+ - ''); - var li = $(div).find('.file-list #file-' + cnt); - var previewHTML = ""; - if ((/image/i).test(file.type)) { // image - previewHTML = ''+ - ' '+ - ''; - } - var td1 = 'style="padding: 3px; text-align: right; color: #777;"'; - var td2 = 'style="padding: 3px"'; - previewHTML += ''+ - ' '+ - ' Name:'+ file.name +''+ - ' Size:'+ w2utils.size(file.size) +''+ - ' Type:' + - ' '+ file.type +''+ - ' '+ - ' Modified:'+ w2utils.date(file.modified) +''+ - ' '+ - ''; - li.data('file', file) - .on('click', function (event) { - if (typeof settings.onItemClick == 'function') { - var ret = settings.onItemClick.call(obj, $(this).data('file')); - if (ret === false) return; - } - if (!$(event.target).hasClass('file-delete')) event.stopPropagation(); - }) - .on('dblclick', function (event) { - if (typeof settings.onItemDblClick == 'function') { - var ret = settings.onItemDblClick.call(obj, $(this).data('file')); - if (ret === false) return; - } - event.stopPropagation(); - if (document.selection) document.selection.empty(); else document.defaultView.getSelection().removeAllRanges(); - }) - .on('mouseover', function (event) { - if (typeof settings.onItemOver == 'function') { - var ret = settings.onItemOver.call(obj, $(this).data('file')); - if (ret === false) return; - } - var file = $(this).data('file'); - $(this).w2overlay( - previewHTML.replace('##FILE##', (file.content ? 'data:'+ file.type +';base64,'+ file.content : '')), - { top: -4 } - ); - }) - .on('mouseout', function () { - if (typeof settings.onItemOut == 'function') { - var ret = settings.onItemOut.call(obj, $(this).data('file')); - if (ret === false) return; - } - $(this).w2overlay(); - }); - } + }, + + addMulti: function () { + var obj = this; + var options = this.options; + // clean up & init + $(obj.helpers.multi).remove(); + // build helper + var html = ''; + var margin = + 'margin-top : 0px; ' + + 'margin-bottom : 0px; ' + + 'margin-left : ' + $(obj.el).css('margin-left') + '; ' + + 'margin-right : ' + $(obj.el).css('margin-right') + '; '+ + 'width : ' + (w2utils.getSize(obj.el, 'width') + - parseInt($(obj.el).css('margin-left'), 10) + - parseInt($(obj.el).css('margin-right'), 10)) + + 'px;'; + if (obj.type == 'enum') { + html = ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ' ' + ' '+ + ' '+ + ''; } - this.refresh(); - break; - - case 'slider': - // for future reference - break; - - default: - console.log('ERROR: w2field does not recognize "'+ options.type + '" field type.'); - break; - } - }); - }, - - // ****************************************************** - // -- Implementation - - addType: function (type, handler) { - w2field.customTypes[String(type).toLowerCase()] = handler; - }, - - cleanItems: function (items) { - var newItems = []; - for (var i in items) { - var id = ''; - var text = ''; - var opt = items[i]; - if (opt == null) continue; - if ($.isPlainObject(items)) { - id = i; - text = opt; - } else { - if (typeof opt == 'object') { - if (typeof opt.id != 'undefined') id = opt.id; - if (typeof opt.value != 'undefined') id = opt.value; - if (typeof opt.txt != 'undefined') text = opt.txt; - if (typeof opt.text != 'undefined') text = opt.text; - } - if (typeof opt == 'string') { - if (String(opt) == '') continue; - id = opt; - text = opt; - opt = {}; - } - } - if (w2utils.isInt(id)) id = parseInt(id); - if (w2utils.isFloat(id)) id = parseFloat(id); - newItems.push($.extend({}, opt, { id: id, text: text })); - } - return newItems; - }, - - // ****************************************************** - // -- Upload - - upload_init: function () { - var obj = this; // this -> input element - var settings = $(this).data('settings'); - // create drop area if needed - var el = $(obj).prev(); - if (el.length > 0 && el[0].tagName == 'DIV' && el.hasClass('w2ui-upload')) el.remove(); - // rebuild it - var margin = 'margin-top: ' + $(obj).css('margin-top') + '; ' + - 'margin-bottom: ' + $(obj).css('margin-bottom') + '; ' + - 'margin-left: ' + $(obj).css('margin-left') + '; ' + - 'margin-right: ' + $(obj).css('margin-right') + '; '+ - 'width: ' + (w2utils.getSize(obj, 'width') - - parseInt($(obj).css('margin-left')) - - parseInt($(obj).css('margin-right'))) + 'px; '+ - 'height: ' + (w2utils.getSize(obj, 'height') - - parseInt($(obj).css('margin-top')) - - parseInt($(obj).css('margin-bottom'))) + 'px; '; - var html = - ''+ - ' '+ settings.hint +''+ - ' '+ - ' '+ - ''; - $(obj) - .css({ - 'display1' : 'none', - 'border-color' : 'transparent' - }) - .before(html); - $(obj).data('div', $(obj).prev()[0]); - var div = $(obj).data('div'); - // if user selects files through input control - $(div).find('.file-input') - .off('change') - .on('change', function () { - if (typeof this.files !== "undefined") { - for (var i = 0, l = this.files.length; i < l; i++) { - w2field.upload_add.call(obj, this.files[i]); - } - } - }); - - // if user clicks drop zone - $(div) - .off('click') - .on('click', function (event) { - $(div).w2tag(); - if (event.target.tagName == 'LI' || $(event.target).hasClass('file-size')) { - return; - } - if ($(event.target).hasClass('file-delete')) { - w2field.upload_remove.call(obj, event.target.parentNode); - return; - } - if (event.target.tagName != 'INPUT') { - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var cnt = 0; - for (var s in selected) { cnt++; } - if (cnt < settings.max || settings.max == 0) $(div).find('.file-input').click(); - } - }) - .off('dragenter') - .on('dragenter', function (event) { - $(div).addClass('dragover'); - }) - .off('dragleave') - .on('dragleave', function (event) { - $(div).removeClass('dragover'); - }) - .off('drop') - .on('drop', function (event) { - $(div).removeClass('dragover'); - var files = event.originalEvent.dataTransfer.files; - for (var i=0, l=files.length; i input element - var div = $(obj).data('div'); - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var newItem = { - name : file.name, - type : file.type, - modified : file.lastModifiedDate, - size : file.size, - content : null - }; - var size = 0; - var cnt = 0; - for (var s in selected) { size += selected[s].size; cnt++; } - // check params - if (settings.maxFileSize != 0 && newItem.size > settings.maxFileSize) { - var err = 'Maximum file size is '+ w2utils.size(settings.maxFileSize); - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (settings.maxSize != 0 && size + newItem.size > settings.maxSize) { - var err = 'Maximum total size is '+ w2utils.size(settings.maxFileSize); - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (settings.max != 0 && cnt >= settings.max) { - var err = 'Maximum number of files is '+ settings.max; - $(div).w2tag(err); - console.log('ERROR: '+ err); - return; - } - if (typeof settings.onAdd == 'function') { - var ret = settings.onAdd.call(obj, newItem); - if (ret === false) return; - } - selected.push(newItem); - // read file as base64 - if (typeof FileReader !== "undefined" && settings.base64 === true) { - var reader = new FileReader(); - // need a closure - reader.onload = (function () { - return function (event) { - var fl = event.target.result; - var ind = fl.indexOf(','); - newItem.content = fl.substr(ind+1); - obj.refresh(); - $(obj).trigger('change'); - }; - })(); - reader.readAsDataURL(file); - } else { - obj.refresh(); - $(obj).trigger('change'); - } - }, - - upload_remove: function (li) { - var obj = this; // this -> input element - var div = $(obj).data('div'); - var settings = $(obj).data('settings'); - var selected = $(obj).data('selected'); - var file = $(li).data('file'); - // run event - if (typeof settings.onRemove == 'function') { - var ret = settings.onRemove.call(obj, file); - if (ret === false) return false; - } - // remove from selected - for (var i = selected.length - 1; i >= 0; i--) { - if (selected[i].name == file.name && selected[i].size == file.size) { - selected.splice(i, 1); - } - } - $(li).fadeOut('fast'); - setTimeout(function () { - $(li).remove(); - // if all files remoted - if (selected.length == 0) { - $(div).prepend(''+ settings.hint +''); - } - obj.refresh(); - $(obj).trigger('change'); - }, 300); - }, - - // ****************************************************** - // -- Enum - - list_render: function (search) { - var obj = this; - var div = $('#w2ui-global-items'); - var settings = $(this).data('settings'); - var items = settings.items; - var selected = $(this).data('selected'); - if (div.length == 0) return; // if it is hidden - - // build overall html - if (typeof search == 'undefined') { - var html = ''; - html += ''; - div.html(html); - search = ''; - } - $(this).data('last_search', search); - if (typeof $(obj).data('last_index') == 'undefined' || $(obj).data('last_index') == null) $(obj).data('last_index', 0); - - // pull items from url - if (typeof settings.last_total == 'undefined') settings.last_total = -1; - if (typeof settings.last_search_len == 'undefined') settings.last_search_len = 0; - if (typeof settings.last_search_match == 'undefined') settings.last_search_match = -1; - if (settings.url != '' && ( - (items.length == 0 && settings.last_total != 0) - || (search.length > settings.last_search_len && settings.last_total > settings.maxCache) - || (search.length < settings.last_search_match && search.length != settings.last_search_len) - ) - ) { - var match = false; - if (settings.last_total < settings.maxCache) match = true; - $.ajax({ - type : 'GET', - dataType : 'text', - url : settings.url, - data : { - search : search, - max : settings.maxCache - }, - complete: function (xhr, status) { - settings.last_total = 0; - if (status == 'success') { - var data = $.parseJSON(xhr.responseText); - if (match == false && data.total < settings.maxCache) { settings.last_search_match = search.length; } - settings.last_search_len = search.length; - settings.last_total = data.total - settings.items = data.items; - w2field.list_render.call(obj, search); - } - } - }); - } - - // build items - var i = 0; - var ihtml = ''; - // get ids of all selected items - var ids = []; - for (var a in selected) ids.push(w2utils.isInt(selected[a].id) ? parseInt(selected[a].id) : String(selected[a].id)) - // build list - var group = ''; - for (var a in items) { - var id = items[a].id; - var txt = items[a].text; - // if already selected - if ($.inArray(w2utils.isInt(id) ? parseInt(id) : String(id), ids) != -1 && settings.showAll !== true) continue; - // check match with search - var txt1 = String(search).toLowerCase(); - var txt2 = txt.toLowerCase(); - var match = (txt1.length <= txt2.length && txt2.substr(0, txt1.length) == txt1); - if (settings.match.toLowerCase() == 'contains' && txt2.indexOf(txt1) != -1) match = true; - if (match) { - if (typeof settings['render'] == 'function') { - txt = settings['render'](items[a], selected); - } - if (txt !== false) { - // render group if needed - if (typeof items[a].group != 'undefined' && items[a].group != group) { - group = items[a].group; - ihtml += ''+ group +''; - } - // render item - ihtml += '\n'+ - txt +''; - if (i == $(obj).data('last_index')) $(obj).data('last_item', items[a]); - i++; - } - } - } - ihtml += ''; - if (i == 0) { - ihtml = ''+ w2utils.lang('No items found') +''; - var noItems = true; - } - div.find('.w2ui-items-list').html(ihtml); - $(this).data('last_max', i-1); - - // scroll selected into view - if (div.find('li.selected').length > 0) div.find('li.selected')[0].scrollIntoView(false); - - // if menu goes off screen - add scrollbar - div.css({ '-webkit-transition': '0s', height : 'auto' }); - var max_height = parseInt($(document).height()) - parseInt(div.offset().top) - 8; - if (parseInt(div.height()) > max_height) { - div.css({ - height : (max_height - 5) + 'px', - overflow: 'show' - }); - $(div).find('.w2ui-items-list').css({ - height : (max_height - 15) + 'px', - overflow: 'auto' - }); - } - - // add events - $(div) - .off('mousedown') - .on('mousedown', function (event) { - var target = event.target; - if (target.tagName != "LI") target = $(target).parents('li'); - var id = $(target).attr('index'); - if (!id) return; - var item = settings.items[id]; - if (typeof id == 'undefined') { if (event.preventDefault) event.preventDefault(); else return false; } - obj.add(item); - $(obj).data('last_index', 0); - obj.refresh(); - w2field.list_render.call(obj, ''); - } - ); - $(obj).prev().find('li > input') - .val(search) - .css('max-width', ($(div).width() - 25) + 'px') - .width(((search.length + 2) * 6) + 'px') - .focus() - .on('click', function (event) { - if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; - }) - .off('keyup') - .on('keyup', function (event) { - var inp = this; - setTimeout(function () { - var curr = $(obj).data('last_index'); - switch (event.keyCode) { - case 38: // up - curr--; - if (curr < 0) curr = 0; - $(obj).data('last_index', curr); - if (event.preventDefault) event.preventDefault(); - break; - case 40: // down - curr++; - if (curr > $(obj).data('last_max')) curr = $(obj).data('last_max'); - $(obj).data('last_index', curr); - if (event.preventDefault) event.preventDefault(); - break; - case 13: // enter - if (typeof $(obj).data('last_item') == 'undefined' || $(obj).data('last_item') == null || noItems === true) break; - var selected = $(obj).data('selected'); - obj.add($(obj).data('last_item')); - // select next - if (curr > $(obj).data('last_max') - 1) curr = $(obj).data('last_max')-1; - $(obj).data('last_index', curr); - $(obj).data('last_item', null); - // refrech - $(inp).val(''); + if (obj.type == 'file') { + html = ''+ + ' '+ + ' '+ + ' ' + ' '+ + ''; + } + $(obj.el) + .before(html) + .css({ + 'background-color' : 'transparent', + 'border-color' : 'transparent' + }); + + var div = $(obj.el).prev(); + obj.helpers.multi = div; + if (obj.type == 'enum') { + $(obj.el).attr('tabindex', -1); + // INPUT events + div.find('input') + .on('click', function (event) { + if ($('#w2ui-overlay').length == 0) obj.focus(event); + $(obj.el).triggerHandler('click'); + }) + .on('focus', function (event) { + $(div).css({ 'outline': 'auto 5px #7DB4F3', 'outline-offset': '-2px' }); + $(obj.el).triggerHandler('focus'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('blur', function (event) { + $(div).css('outline', 'none'); + $(obj.el).triggerHandler('blur'); + if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; + }) + .on('keyup', function (event) { obj.keyUp(event) }) + .on('keydown', function (event) { obj.keyDown(event) }) + .on('keypress', function (event) { div.find('.w2ui-enum-placeholder').remove(); obj.keyPress(event); }); + // MAIN div + div.on('click', function (event) { $(this).find('input').focus(); }); + } + if (obj.type == 'file') { + $(obj.el).css('outline', 'none'); + div.on('click', function (event) { + $(obj.el).focus(); + if ($(obj.el).attr('readonly')) return; + obj.blur(event); + div.find('input').click(); + }) + .on('dragenter', function (event) { + if ($(obj.el).attr('readonly')) return; + $(div).addClass('w2ui-file-dragover'); + }) + .on('dragleave', function (event) { + if ($(obj.el).attr('readonly')) return; + var tmp = $(event.target).parents('.w2ui-field-helper'); + if (tmp.length == 0) $(div).removeClass('w2ui-file-dragover'); + }) + .on('drop', function (event) { + if ($(obj.el).attr('readonly')) return; + $(div).removeClass('w2ui-file-dragover'); + var files = event.originalEvent.dataTransfer.files; + for (var i=0, l=files.length; i options.maxFileSize) { + err = 'Maximum file size is '+ w2utils.size(options.maxFileSize); + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + if (options.maxSize !== 0 && size + newItem.size > options.maxSize) { + err = 'Maximum total size is '+ w2utils.size(options.maxSize); + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + if (options.max !== 0 && cnt >= options.max) { + err = 'Maximum number of files is '+ options.max; + if (options.silent === false) $(obj.el).w2tag(err); + console.log('ERROR: '+ err); + return; + } + selected.push(newItem); + // read file as base64 + if (typeof FileReader !== "undefined") { + var reader = new FileReader(); + // need a closure + reader.onload = (function () { + return function (event) { + var fl = event.target.result; + var ind = fl.indexOf(','); + newItem.content = fl.substr(ind+1); + obj.refresh(); + $(obj.el).trigger('change'); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }; + })(); + reader.readAsDataURL(file); + } else { obj.refresh(); - if (event.preventDefault) event.preventDefault(); - break; - case 8: // backspace - if (String(inp.value) == '') { - if (typeof $(obj).data('last_del') == 'undefined' || $(obj).data('last_del') == null) { - // mark for deletion - var selected = $(obj).data('selected'); - if (!$.isArray(selected)) selected = []; - $(obj).data('last_del', selected.length-1); - // refrech - obj.refresh(); - } else { - // delete marked one - var selected = $(obj).data('selected'); - obj.remove(selected.length - 1); - } + $(obj.el).trigger('change'); + } + }, + + normMenu: function (menu) { + if ($.isArray(menu)) { + for (var m = 0; m < menu.length; m++) { + if (typeof menu[m] == 'string') { + menu[m] = { id: menu[m], text: menu[m] }; + } else { + if (typeof menu[m].text != 'undefined' && typeof menu[m].id == 'undefined') menu[m].id = menu[m].text; + if (typeof menu[m].text == 'undefined' && typeof menu[m].id != 'undefined') menu[m].text = menu[m].id; + if (typeof menu[m].caption != 'undefined') menu[m].text = menu[m].caption; + } } - break; - default: - $(obj).data('last_index', 0); - $(obj).data('last_del', null); - break; + return menu; + } else if (typeof menu == 'object') { + var tmp = [] + for (var m in menu) tmp.push({ id: m, text: menu[m] }); + return tmp; } - // adjust height - obj.resize(); - - // refresh menu - if (!(event.keyCode == 8 && String(inp.value) == '')) { - $(obj).prev().find('li').css('opacity', '1'); - $(obj).data('last_del', null); + }, + + getColorHTML: function () { + var html = ''+ + ''; + for (var i = 0; i < 8; i++) { + html += ''; + for (var j = 0; j < 8; j++) { + html += ''+ + ' '+ + ' '+ ($(this.el).val() == this.pallete[i][j] ? '' : ' ')+ + ' '+ + ''; + } + html += ''; + if (i < 2) html += ''; } - if ($.inArray(event.keyCode, [16,91,37,39]) == -1) { // command and shift keys and arrows - w2field.list_render.call(obj, inp.value); + html += ''; + return html; + }, + + getMonthHTML: function (month, year) { + var td = new Date(); + var months = w2utils.settings.fullmonths; + var days = w2utils.settings.fulldays; + var daysCount = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']; + var today = td.getFullYear() + '/' + (Number(td.getMonth()) + 1) + '/' + td.getDate(); + // normalize date + year = w2utils.isInt(year) ? parseInt(year) : td.getFullYear(); + month = w2utils.isInt(month) ? parseInt(month) : td.getMonth() + 1; + if (month > 12) { month -= 12; year++; } + if (month < 1 || month === 0) { month += 12; year--; } + if (year/4 == Math.floor(year/4)) { daysCount[1] = '29'; } else { daysCount[1] = '28'; } + this.options.current = month + '/' + year; + + // start with the required date + td = new Date(year, month-1, 1); + var weekDay = td.getDay(); + var tabDays = w2utils.settings.shortdays; + var dayTitle = ''; + for ( var i = 0, len = tabDays.length; i < len; i++) { + dayTitle += '' + tabDays[i] + ''; } - }, 10); - }) - }, - - // ****************************************************** - // -- Calendar - - calendar_get: function (date, options) { - var td = new Date(); - var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900); - if (String(date) == '' || String(date) == 'undefined') date = w2utils.formatDate(today, options.format); - if (!w2utils.isDate(date, options.format)) date = w2utils.formatDate(today, options.format); - // format date - var tmp = date.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); - var tmp2 = options.format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); - var dt = new Date(); - if (tmp2 == 'mm/dd/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]); - if (tmp2 == 'm/d/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]); - if (tmp2 == 'dd/mm/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]); - if (tmp2 == 'd/m/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]); - if (tmp2 == 'yyyy/dd/mm') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]); - if (tmp2 == 'yyyy/d/m') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]); - if (tmp2 == 'yyyy/mm/dd') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]); - if (tmp2 == 'yyyy/m/d') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]); - var html = '' + - ''+ $().w2field('calendar_month', (dt.getMonth() + 1), dt.getFullYear(), options) +''+ - // ''+ - ''; - return html; - }, - - calendar_next: function(month_year) { - var tmp = String(month_year).split('/'); - var month = tmp[0]; - var year = tmp[1]; - if (parseInt(month) < 12) { - month = parseInt(month) + 1; - } else { - month = 1; - year = parseInt(year) + 1; - } - var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options'); - $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) ); - }, - - calendar_previous: function(month_year) { - var tmp = String(month_year).split('/'); - var month = tmp[0]; - var year = tmp[1]; - if (parseInt(month) > 1) { - month = parseInt(month) - 1; - } else { - month = 12; - year = parseInt(year) - 1; - } - var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options'); - $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) ); - }, - - calendar_month: function(month, year, options) { - var td = new Date(); - var months = w2utils.settings.fullmonths; - var days = w2utils.settings.fulldays; - var daysCount = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']; - var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900); - - year = Number(year); - month = Number(month); - if (year === null || year === '') year = String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900; - if (month === null || month === '') month = Number(td.getMonth())+1; - if (month > 12) { month = month - 12; year++; } - if (month < 1 || month == 0) { month = month + 12; year--; } - if (year/4 == Math.floor(year/4)) { daysCount[1] = '29'; } else { daysCount[1] = '28'; } - if (year == null) { year = td.getYear(); } - if (month == null) { month = td.getMonth()-1; } - - // start with the required date - var td = new Date(); - td.setDate(1); - td.setMonth(month-1); - td.setYear(year); - var weekDay = td.getDay(); - var tabDays = w2utils.settings.shortdays; - var dayTitle = ''; - for ( var i = 0, len = tabDays.length; i < len; i++) { - dayTitle += '' + tabDays[i] + ''; - } - var html = - ''+ - ' <- '+ - ' -> '+ - months[month-1] +', '+ year + - ''+ - ''+ - ' ' + dayTitle + ''+ - ' '; - - var day = 1; - for (var ci=1; ci<43; ci++) { - if (weekDay == 0 && ci == 1) { - for (var ti=0; ti<6; ti++) html += ' '; - ci += 6; - } else { - if (ci < weekDay || day > daysCount[month-1]) { - html += ' '; - if ((ci)%7 == 0) html += ''; - continue; - } - } - var dt = month + '/' + day + '/' + year; - - var className = ''; - if (ci % 7 == 6) className = 'w2ui-saturday'; - if (ci % 7 == 0) className = 'w2ui-sunday'; - if (dt == today) className += ' w2ui-today'; - - var dspDay = day; - var col = ''; - var bgcol = ''; - var blocked = ''; - if (options.colored) if (options.colored[dt] != undefined) { // if there is predefined colors for dates - tmp = options.colored[dt].split(':'); - bgcol = 'background-color: ' + tmp[0] + ';'; - col = 'color: ' + tmp[1] + ';'; - } - var noSelect = false; - // enable range - if (options.start || options.end) { - var start = new Date(options.start); - var end = new Date(options.end); - var current = new Date(dt); - if (current < start || current > end) { - blocked = ' w2ui-blocked-date'; - noSelect = true; - } - } - // block predefined dates - if (options.blocked && $.inArray(dt, options.blocked) != -1) { - blocked = ' w2ui-blocked-date'; - noSelect = true; - } - html += ''+ dspDay + ''; - if (ci % 7 == 0 || (weekDay == 0 && ci == 1)) html += ''; - day++; - } - html += ''; - return html; - }, + var html = + ''+ + ' '+ + ' '+ + months[month-1] +', '+ year + + ''+ + ''+ + ' ' + dayTitle + ''+ + ' '; + + var day = 1; + for (var ci=1; ci<43; ci++) { + if (weekDay === 0 && ci == 1) { + for (var ti=0; ti<6; ti++) html += ' '; + ci += 6; + } else { + if (ci < weekDay || day > daysCount[month-1]) { + html += ' '; + if ((ci) % 7 === 0) html += ''; + continue; + } + } + var dt = year + '/' + month + '/' + day; + + var className = ''; + if (ci % 7 == 6) className = ' w2ui-saturday'; + if (ci % 7 === 0) className = ' w2ui-sunday'; + if (dt == today) className += ' w2ui-today'; + + var dspDay = day; + var col = ''; + var bgcol = ''; + var tmp_dt = w2utils.formatDate(dt, this.options.format); + if (this.options.colored && this.options.colored[tmp_dt] !== undefined) { // if there is predefined colors for dates + tmp = this.options.colored[tmp_dt].split(':'); + bgcol = 'background-color: ' + tmp[0] + ';'; + col = 'color: ' + tmp[1] + ';'; + } + html += ''+ + dspDay + + ''; + if (ci % 7 === 0 || (weekDay === 0 && ci == 1)) html += ''; + day++; + } + html += ''; + return html; + }, + + getYearHTML: function () { + var months = w2utils.settings.shortmonths; + var mhtml = ''; + var yhtml = ''; + for (var m in months) { + mhtml += ''+ months[m] + ''; + } + for (var y = 1950; y <= 2020; y++) { + yhtml += ''+ y + '' + } + return ''+ mhtml +''+ yhtml +''; + }, - getColorHTML: function (color) { - var html = ''+ - ''; - var colors = [ - ['000000', '444444', '666666', '999999', 'CCCCCC', 'EEEEEE', 'F3F3F3', 'FFFFFF'], - ['FF011B', 'FF9838', 'FFFD59', '01FD55', '00FFFE', '0424F3', '9B24F4', 'FF21F5'], - ['F4CCCC', 'FCE5CD', 'FFF2CC', 'D9EAD3', 'D0E0E3', 'CFE2F3', 'D9D1E9', 'EAD1DC'], - ['EA9899', 'F9CB9C', 'FEE599', 'B6D7A8', 'A2C4C9', '9FC5E8', 'B4A7D6', 'D5A6BD'], - ['E06666', 'F6B26B', 'FED966', '93C47D', '76A5AF', '6FA8DC', '8E7CC3', 'C27BA0'], - ['CC0814', 'E69138', 'F1C232', '6AA84F', '45818E', '3D85C6', '674EA7', 'A54D79'], - ['99050C', 'B45F17', 'BF901F', '37761D', '124F5C', '0A5394', '351C75', '741B47'], - ['660205', '783F0B', '7F6011', '274E12', '0C343D', '063762', '20124D', '4C1030'] - ]; - for (var i=0; i<8; i++) { - html += ''; - for (var j=0; j<8; j++) { - html += ''+ - ' '+ - ' '+ (color == colors[i][j] ? '' : ' ')+ - ' '+ - ''; + getHourHTML: function () { + var tmp = []; + var h24 = (this.options.format == 'h24' ? true : false); + for (var a=0; a<24; a++) { + var time = (a >= 12 && !h24 ? a - 12 : a) + ':00' + (!h24 ? (a < 12 ? ' am' : ' pm') : ''); + if (a == 12 && !h24) time = '12:00 pm'; + if (!tmp[Math.floor(a/8)]) tmp[Math.floor(a/8)] = ''; + var tm1 = this.fromMin(this.toMin(time)); + var tm2 = this.fromMin(this.toMin(time) + 59); + tmp[Math.floor(a/8)] += ''+ time +''; + } + var html = + ''+ + ' '+ tmp[0] +'' + + ' '+ tmp[1] +'' + + ' '+ tmp[2] +'' + + ''; + return html; + }, + + getMinHTML: function (hour) { + if (typeof hour == 'undefined') hour = 0; + var h24 = (this.options.format == 'h24' ? true : false); + var tmp = []; + for (var a=0; a<60; a+=5) { + var time = (hour > 12 && !h24 ? hour - 12 : hour) + ':' + (a < 10 ? 0 : '') + a + ' ' + (!h24 ? (hour < 12 ? 'am' : 'pm') : ''); + var ind = a < 20 ? 0 : (a < 40 ? 1 : 2); + if (!tmp[ind]) tmp[ind] = ''; + tmp[ind] += ''+ time +''; + } + var html = + ''+ + ' '+ tmp[0] +'' + + ' '+ tmp[1] +'' + + ' '+ tmp[2] +'' + + ''; + return html; + }, + + toMin: function (str) { + if (typeof str != 'string') return null; + var tmp = str.split(':'); + if (tmp.length == 2) { + tmp[0] = parseInt(tmp[0]); + tmp[1] = parseInt(tmp[1]); + if (str.indexOf('pm') != -1 && tmp[0] != 12) tmp[0] += 12; + } else { + return null; + } + return tmp[0] * 60 + tmp[1]; + }, + + fromMin: function (time) { + var ret = ''; + if (time >= 24 * 60) time = time % (24 * 60); + if (time < 0) time = 24 * 60 + time; + var hour = Math.floor(time/60); + var min = ((time % 60) < 10 ? '0' : '') + (time % 60); + if (this.options.format.indexOf('h24') != -1) { + ret = hour + ':' + min; + } else { + ret = (hour <= 12 ? hour : hour - 12) + ':' + min + ' ' + (hour >= 12 ? 'pm' : 'am'); + } + return ret; } - html += ''; - if (i < 2) html += ''; - } - html += ''; - return html; } - }); - w2obj.field = w2field; + $.extend(w2field.prototype, w2utils.event); + w2obj.field = w2field; }) (jQuery); /************************************************************************ - * Library: Web 2.0 UI for jQuery (using prototypical inheritance) - * - Following objects defined - * - w2form - form widget - * - $().w2form - jQuery wrapper - * - Dependencies: jQuery, w2utils, w2fields, w2tabs, w2toolbar, w2alert - * - * == NICE TO HAVE == - * - refresh(field) - would refresh only one field - * - include delta on save - * - ************************************************************************/ +* Library: Web 2.0 UI for jQuery (using prototypical inheritance) +* - Following objects defined +* - w2form - form widget +* - $().w2form - jQuery wrapper +* - Dependencies: jQuery, w2utils, w2fields, w2tabs, w2toolbar, w2alert +* +* == NICE TO HAVE == +* - refresh(field) - would refresh only one field +* - include delta on save +* - create an example how to do cascadic dropdown +* - form should read into items +* - two way data bindings +* - verify validation of fields +* - when field is blank, set record.field = null +* - show/hide a field +* - added getChanges() - not complete +* +************************************************************************/ (function ($) { - var w2form = function(options) { - // public properties - this.name = null; - this.header = ''; - this.box = null; // HTML element that hold this element - this.url = ''; - this.formURL = ''; // url where to get form HTML - this.formHTML = ''; // form HTML (might be loaded from the url) - this.page = 0; // current page - this.recid = 0; // can be null or 0 - this.fields = []; - this.actions = {}; - this.record = {}; - this.original = {}; - this.postData = {}; - this.toolbar = {}; // if not empty, then it is toolbar - this.tabs = {}; // if not empty, then it is tabs object - - this.style = ''; - this.focus = 0; // focus first or other element - this.msgNotJSON = w2utils.lang('Return data is not in JSON format.'); - this.msgRefresh = w2utils.lang('Refreshing...'); - this.msgSaving = w2utils.lang('Saving...'); - - // events - this.onRequest = null; - this.onLoad = null; - this.onValidate = null; - this.onSubmit = null; - this.onSave = null; - this.onChange = null; - this.onRender = null; - this.onRefresh = null; - this.onResize = null; - this.onDestroy = null; - this.onAction = null; - this.onToolbar = null; - this.onError = null; - - // internal - this.isGenerated = false; - this.last = { - xhr : null // jquery xhr requests - } + var w2form = function(options) { + // public properties + this.name = null; + this.header = ''; + this.box = null; // HTML element that hold this element + this.url = ''; + this.routeData = {}; // data for dynamic routes + this.formURL = ''; // url where to get form HTML + this.formHTML = ''; // form HTML (might be loaded from the url) + this.page = 0; // current page + this.recid = 0; // can be null or 0 + this.fields = []; + this.actions = {}; + this.record = {}; + this.original = {}; + this.postData = {}; + this.toolbar = {}; // if not empty, then it is toolbar + this.tabs = {}; // if not empty, then it is tabs object + + this.style = ''; + this.focus = 0; // focus first or other element + this.msgNotJSON = w2utils.lang('Return data is not in JSON format.'); + this.msgAJAXerror = w2utils.lang('AJAX error. See console for more details.'); + this.msgRefresh = w2utils.lang('Refreshing...'); + this.msgSaving = w2utils.lang('Saving...'); + + // events + this.onRequest = null; + this.onLoad = null; + this.onValidate = null; + this.onSubmit = null; + this.onSave = null; + this.onChange = null; + this.onRender = null; + this.onRefresh = null; + this.onResize = null; + this.onDestroy = null; + this.onAction = null; + this.onToolbar = null; + this.onError = null; + + // internal + this.isGenerated = false; + this.last = { + xhr: null // jquery xhr requests + } + + $.extend(true, this, w2obj.form, options); + }; + + // ==================================================== + // -- Registers as a jQuery plugin + + $.fn.w2form = function(method) { + if (typeof method === 'object' || !method ) { + var obj = this; + // check name parameter + if (!w2utils.checkName(method, 'w2form')) return; + // remember items + var record = method.record; + var original = method.original; + var fields = method.fields; + var toolbar = method.toolbar; + var tabs = method.tabs; + // extend items + var object = new w2form(method); + $.extend(object, { record: {}, original: {}, fields: [], tabs: {}, toolbar: {}, handlers: [] }); + if ($.isArray(tabs)) { + $.extend(true, object.tabs, { tabs: [] }); + for (var t in tabs) { + var tmp = tabs[t]; + if (typeof tmp === 'object') object.tabs.tabs.push(tmp); else object.tabs.tabs.push({ id: tmp, caption: tmp }); + } + } else { + $.extend(true, object.tabs, tabs); + } + $.extend(true, object.toolbar, toolbar); + // reassign variables + for (var p in fields) { + var field = $.extend(true, {}, fields[p]); + if (typeof field.name == 'undefined' && typeof field.field != 'undefined') field.name = field.field; + if (typeof field.field == 'undefined' && typeof field.name != 'undefined') field.field = field.name; + object.fields[p] = field; + } + for (var p in record) { + if ($.isPlainObject(record[p])) { + object.record[p] = $.extend(true, {}, record[p]); + } else { + object.record[p] = record[p]; + } + } + for (var p in original) { + if ($.isPlainObject(original[p])) { + object.original[p] = $.extend(true, {}, original[p]); + } else { + object.original[p] = original[p]; + } + } + if (obj.length > 0) object.box = obj[0]; + // render if necessary + if (object.formURL != '') { + $.get(object.formURL, function (data) { // should always be $.get as it is template + object.formHTML = data; + object.isGenerated = true; + if ($(object.box).length != 0 || data.length != 0) { + $(object.box).html(data); + object.render(object.box); + } + }); + } else if (object.formHTML != '') { + // it is already loaded into formHTML + } else if ($(this).length != 0 && $.trim($(this).html()) != '') { + object.formHTML = $(this).html(); + } else { // try to generate it + object.formHTML = object.generateHTML(); + } + // register new object + w2ui[object.name] = object; + // render if not loaded from url + if (object.formURL == '') { + if (String(object.formHTML).indexOf('w2ui-page') == -1) { + object.formHTML = ''+ object.formHTML +''; + } + $(object.box).html(object.formHTML); + object.isGenerated = true; + object.render(object.box); + } + return object; - $.extend(true, this, w2obj.form, options); - }; - - // ==================================================== - // -- Registers as a jQuery plugin - - $.fn.w2form = function(method) { - if (typeof method === 'object' || !method ) { - var obj = this; - // check required parameters - if (!method || typeof method.name == 'undefined') { - console.log('ERROR: The parameter "name" is required but not supplied in $().w2form().'); - return; - } - if (typeof w2ui[method.name] != 'undefined') { - console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').'); - return; - } - if (!w2utils.isAlphaNumeric(method.name)) { - console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '); - return; - } - // remember items - var record = method.record; - var original = method.original; - var fields = method.fields; - var toolbar = method.toolbar; - var tabs = method.tabs; - // extend items - var object = new w2form(method); - $.extend(object, { record: {}, original: {}, fields: [], tabs: {}, toolbar: {}, handlers: [] }); - if ($.isArray(tabs)) { - $.extend(true, object.tabs, { tabs: [] }); - for (var t in tabs) { - var tmp = tabs[t]; - if (typeof tmp == 'object') object.tabs.tabs.push(tmp); else object.tabs.tabs.push({ id: tmp, caption: tmp }); - } - } else { - $.extend(true, object.tabs, tabs); - } - $.extend(true, object.toolbar, toolbar); - // reassign variables - for (var p in fields) object.fields[p] = $.extend(true, {}, fields[p]); - for (var p in record) { - if ($.isPlainObject(record[p])) { - object.record[p] = $.extend(true, {}, record[p]); - } else { - object.record[p] = record[p]; - } - } - for (var p in original) { - if ($.isPlainObject(original[p])) { - object.original[p] = $.extend(true, {}, original[p]); + } else if (w2ui[$(this).attr('name')]) { + var obj = w2ui[$(this).attr('name')]; + obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); + return this; } else { - object.original[p] = original[p]; - } - } - if (obj.length > 0) object.box = obj[0]; - // render if necessary - if (object.formURL != '') { - $.get(object.formURL, function (data) { - object.formHTML = data; - object.isGenerated = true; - if ($(object.box).length != 0 || data.length != 0) { - $(object.box).html(data); - object.render(object.box); - } - }); - } else if (object.formHTML != '') { - // it is already loaded into formHTML - } else if ($(this).length != 0 && $.trim($(this).html()) != '') { - object.formHTML = $(this).html(); - } else { // try to generate it - object.formHTML = object.generateHTML(); - } - // register new object - w2ui[object.name] = object; - // render if not loaded from url - if (object.formURL == '') { - if (String(object.formHTML).indexOf('w2ui-page') == -1) { - object.formHTML = ''+ object.formHTML +''; - } - $(object.box).html(object.formHTML); - object.isGenerated = true; - object.render(object.box); - } - return object; - - } else if (w2ui[$(this).attr('name')]) { - var obj = w2ui[$(this).attr('name')]; - obj[method].apply(obj, Array.prototype.slice.call(arguments, 1)); - return this; - } else { - console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2form'); - } - } - - // ==================================================== - // -- Implementation of core functionality - - w2form.prototype = { - - get: function (field, returnIndex) { - for (var f in this.fields) { - if (this.fields[f].name == field) { - if (returnIndex === true) return f; else return this.fields[f]; - } - } - return null; - }, - - set: function (field, obj) { - for (var f in this.fields) { - if (this.fields[f].name == field) { - $.extend(this.fields[f] , obj); - this.refresh(); - return true; + console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2form'); } - } - return false; - }, - - reload: function (callBack) { - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url && this.recid != 0) { - //this.clear(); - this.request(callBack); - } else { - this.refresh(); - if (typeof callBack == 'function') callBack(); - } - }, + }; - clear: function () { - this.recid = 0; - this.record = {}; - // clear all enum fields - for (var f in this.fields) { - var field = this.fields[f]; - } - $().w2tag(); - this.refresh(); - }, + // ==================================================== + // -- Implementation of core functionality - error: function (msg) { - var obj = this; - // let the management of the error outside of the grid - var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack(); - return false; - } - // need a time out because message might be already up) - setTimeout(function () { w2alert(msg, 'Error'); }, 1); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + w2form.prototype = { - validate: function (showErrors) { - if (typeof showErrors == 'undefined') showErrors = true; - // validate before saving - var errors = []; - for (var f in this.fields) { - var field = this.fields[f]; - if (this.record[field.name] == null) this.record[field.name] = ''; - switch (field.type) { - case 'int': - if (this.record[field.name] && !w2utils.isInt(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not an integer') }); - } - break; - case 'float': - if (this.record[field.name] && !w2utils.isFloat(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a float') }); - } - break; - case 'money': - if (this.record[field.name] && !w2utils.isMoney(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not in money format') }); - } - break; - case 'hex': - if (this.record[field.name] && !w2utils.isHex(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a hex number') }); - } - break; - case 'email': - if (this.record[field.name] && !w2utils.isEmail(this.record[field.name])) { - errors.push({ field: field, error: w2utils.lang('Not a valid email') }); - } - break; - case 'checkbox': - // convert true/false - if (this.record[field.name] == true) this.record[field.name] = 1; else this.record[field.name] = 0; - break; - case 'date': - // format date before submit - if (this.record[field.name] && !w2utils.isDate(this.record[field.name], field.options.format)) { - errors.push({ field: field, error: w2utils.lang('Not a valid date') + ': ' + field.options.format }); + get: function (field, returnIndex) { + if (arguments.length === 0) { + var all = []; + for (var f1 in this.fields) { + if (this.fields[f1].name != null) all.push(this.fields[f1].name); + } + return all; } else { - // convert to universal timestamp with time zone - //var d = new Date(this.record[field.name]); - //var tz = (d.getTimezoneOffset() > 0 ? '+' : '-') + Math.floor(d.getTimezoneOffset()/60) + ':' + (d.getTimezoneOffset() % 60); - //this.record[field.name] = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + ' ' - // + d.getHours() + ':' + d.getSeconds() + ':' + d.getMilliseconds() + tz; - //this.record[field.name + '_unix'] = Math.round(d.getTime() / 1000); - //this.record[field.name] = w2utils.formatDate(this.record[field.name], 'mm/dd/yyyy'); - } - break; - case 'select': - case 'list': - break; - case 'enum': - break; - } - // === check required - if field is '0' it should be considered not empty - var val = this.record[field.name]; - if ( field.required && (val === '' || ($.isArray(val) && val.length == 0)) ) { - errors.push({ field: field, error: w2utils.lang('Required field') }); - } - if ( field.equalto && this.record[field.name]!=this.record[field.equalto] ) { - errors.push({ field: field, error: w2utils.lang('Field should be equal to ')+field.equalto }); - } - } - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'validate', errors: errors }); - if (eventData.isCancelled === true) return errors; - // show error - if (showErrors) for (var e in eventData.errors) { - var err = eventData.errors[e]; - $(err.field.el).w2tag(err.error, { "class": 'w2ui-error' }); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - return errors; - }, - - request: function (postData, callBack) { // if (1) param then it is call back if (2) then postData and callBack - var obj = this; - // check for multiple params - if (typeof postData == 'function') { - callBack = postData; - postData = null; - } - if (typeof postData == 'undefined' || postData == null) postData = {}; - if (!this.url || (typeof this.url == 'object' && !this.url.get)) return; - if (this.recid == null || typeof this.recid == 'undefined') this.recid = 0; - // build parameters list - var params = {}; - // add list params - params['cmd'] = 'get-record'; - params['name'] = this.name; - params['recid'] = this.recid; - // append other params - $.extend(params, this.postData); - $.extend(params, postData); - // event before - var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: this.url, postData: params }); - if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return false; } - // default action - this.record = {}; - this.original = {}; - // call server to get data - this.lock(this.msgRefresh); - var url = eventData.url; - if (typeof eventData.url == 'object' && eventData.url.get) url = eventData.url.get; - if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; - this.last.xhr = $.ajax({ - type : 'GET', - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - complete : function (xhr, status) { - obj.unlock(); - // event before - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'load', xhr: xhr, status: status }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + for (var f2 in this.fields) { + if (this.fields[f2].name == field) { + if (returnIndex === true) return f2; else return this.fields[f2]; + } + } + return null; + } + }, + + set: function (field, obj) { + for (var f in this.fields) { + if (this.fields[f].name == field) { + $.extend(this.fields[f] , obj); + this.refresh(); + return true; + } + } return false; - } - // parse server response - var responseText = obj.last.xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } - } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : obj.msgNotJSON, - responseText : responseText - } - } - if (data['status'] == 'error') { - obj.error(data['message']); - } else { - obj.record = $.extend({}, data.record); - obj.original = $.extend({}, data.record); - } - } - } else { - obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); - } - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.refresh(); - // call back - if (typeof callBack == 'function') callBack(data); - } - }); - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + }, - submit: function (postData, callBack) { - return this.save(postData, callBack); - }, + reload: function (callBack) { + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && this.recid != 0) { + // this.clear(); + this.request(callBack); + } else { + // this.refresh(); // no need to refresh + if (typeof callBack == 'function') callBack(); + } + }, - save: function (postData, callBack) { - var obj = this; - // check for multiple params - if (typeof postData == 'function') { - callBack = postData; - postData = null; - } - // validation - var errors = obj.validate(true); - if (errors.length !== 0) { - obj.goto(errors[0].field.page); - return; - } - // submit save - if (typeof postData == 'undefined' || postData == null) postData = {}; - if (!obj.url || (typeof obj.url == 'object' && !obj.url.save)) { - console.log("ERROR: Form cannot be saved because no url is defined."); - return; - } - obj.lock(obj.msgSaving + ' '); - // need timer to allow to lock - setTimeout(function () { - // build parameters list - var params = {}; - // add list params - params['cmd'] = 'save-record'; - params['name'] = obj.name; - params['recid'] = obj.recid; - // append other params - $.extend(params, obj.postData); - $.extend(params, postData); - params.record = $.extend(true, {}, obj.record); - // convert before submitting - for (var f in obj.fields) { - var field = obj.fields[f]; - switch (String(field.type).toLowerCase()) { - case 'date': // to yyyy-mm-dd format - var dt = params.record[field.name]; - if (field.options.format.toLowerCase() == 'dd/mm/yyyy' || field.options.format.toLowerCase() == 'dd-mm-yyyy' - || field.options.format.toLowerCase() == 'dd.mm.yyyy') { - var tmp = dt.replace(/-/g, '/').replace(/\./g, '/').split('/'); - var dt = new Date(tmp[2] + '-' + tmp[1] + '-' + tmp[0]); - } - params.record[field.name] = w2utils.formatDate(dt, 'yyyy-mm-dd'); - break; - } - } - // event before - var eventData = obj.trigger({ phase: 'before', type: 'submit', target: obj.name, url: obj.url, postData: params }); - if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Saving aborted.' }); - return false; - } - // default action - var url = eventData.url; - if (typeof eventData.url == 'object' && eventData.url.save) url = eventData.url.save; - if (obj.last.xhr) try { obj.last.xhr.abort(); } catch (e) {}; - obj.last.xhr = $.ajax({ - type : (w2utils.settings.RESTfull ? (obj.recid == 0 ? 'POST' : 'PUT') : 'POST'), - url : url, - data : String($.param(eventData.postData, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'), - dataType : 'text', - xhr : function() { - var xhr = new window.XMLHttpRequest(); - // upload - xhr.upload.addEventListener("progress", function(evt) { - if (evt.lengthComputable) { - var percent = Math.round(evt.loaded / evt.total * 100); - $('#'+ obj.name + '_progress').text(''+ percent + '%'); - } - }, false); - return xhr; - }, - complete : function (xhr, status) { - obj.unlock(); + clear: function () { + this.recid = 0; + this.record = {}; + $().w2tag(); + this.refresh(); + }, - // event before - var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'save', xhr: xhr, status: status }); + error: function (msg) { + var obj = this; + // let the management of the error outside of the grid + var eventData = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr }); if (eventData.isCancelled === true) { - if (typeof callBack == 'function') callBack({ status: 'error', message: 'Saving aborted.' }); - return false; + if (typeof callBack == 'function') callBack(); + return; } - // parse server response - var responseText = xhr.responseText; - if (status != 'error') { - // default action - if (typeof responseText != 'undefined' && responseText != '') { - var data; - // check if the onLoad handler has not already parsed the data - if (typeof responseText == "object") { - data = responseText; - } else { - // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes - try { eval('data = '+ responseText); } catch (e) { } + // need a time out because message might be already up) + setTimeout(function () { w2alert(msg, 'Error'); }, 1); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, + + validate: function (showErrors) { + if (typeof showErrors == 'undefined') showErrors = true; + $().w2tag(); // hide all tags before validating + // validate before saving + var errors = []; + for (var f in this.fields) { + var field = this.fields[f]; + if (this.record[field.name] == null) this.record[field.name] = ''; + switch (field.type) { + case 'int': + if (this.record[field.name] && !w2utils.isInt(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not an integer') }); + } + break; + case 'float': + if (this.record[field.name] && !w2utils.isFloat(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a float') }); + } + break; + case 'money': + if (this.record[field.name] && !w2utils.isMoney(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not in money format') }); + } + break; + case 'color': + case 'hex': + if (this.record[field.name] && !w2utils.isHex(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a hex number') }); + } + break; + case 'email': + if (this.record[field.name] && !w2utils.isEmail(this.record[field.name])) { + errors.push({ field: field, error: w2utils.lang('Not a valid email') }); + } + break; + case 'checkbox': + // convert true/false + if (this.record[field.name] == true) this.record[field.name] = 1; else this.record[field.name] = 0; + break; + case 'date': + // format date before submit + if (!field.options.format) field.options.format = w2utils.settings.date_format; + if (this.record[field.name] && !w2utils.isDate(this.record[field.name], field.options.format)) { + errors.push({ field: field, error: w2utils.lang('Not a valid date') + ': ' + field.options.format }); + } else { + } + break; + case 'list': + case 'combo': + break; + case 'enum': + break; } - if (typeof data == 'undefined') { - data = { - status : 'error', - message : obj.msgNotJSON, - responseText : responseText - } + // === check required - if field is '0' it should be considered not empty + var val = this.record[field.name]; + if (field.required && (val === '' || ($.isArray(val) && val.length == 0) || ($.isPlainObject(val) && $.isEmptyObject(val)))) { + errors.push({ field: field, error: w2utils.lang('Required field') }); + } + if (field.equalto && this.record[field.name] != this.record[field.equalto]) { + errors.push({ field: field, error: w2utils.lang('Field should be equal to ') + field.equalto }); } - if (data['status'] == 'error') { - obj.error(data['message']); + } + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'validate', errors: errors }); + if (eventData.isCancelled === true) return; + // show error + if (showErrors) for (var e in eventData.errors) { + var err = eventData.errors[e]; + if (err.field.type == 'radio') { // for radio and checkboxes + $($(err.field.el).parents('div')[0]).w2tag(err.error, { "class": 'w2ui-error' }); + } else if (['enum', 'file'].indexOf(err.field.type) != -1) { + (function (err) { + setTimeout(function () { + var fld = $(err.field.el).data('w2field').helpers.multi; + $(err.field.el).w2tag(err.error); + $(fld).addClass('w2ui-error'); + }, 1); + })(err); } else { - obj.original = $.extend({}, obj.record); + $(err.field.el).w2tag(err.error, { "class": 'w2ui-error' }); } - } - } else { - obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + this.goto(errors[0].field.page); } // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - obj.refresh(); - // call back - if (typeof callBack == 'function') callBack(data); - } - }); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }, 50); - }, + this.trigger($.extend(eventData, { phase: 'after' })); + return errors; + }, + + getChanges: function () { + var differ = function(record, original, result) { + for (var i in record) { + if (typeof record[i] == "object") { + result[i] = differ(record[i], original[i] || {}, {}); + if (!result[i] || $.isEmptyObject(result[i])) delete result[i]; + } else if (record[i] != original[i]) { + result[i] = record[i]; + } + } + return result; + } + return differ(this.record, this.original, {}); + }, - lock: function (msg, showSpinner) { - var box = $(this.box).find('> div:first-child'); - w2utils.lock(box, msg, showSpinner); - }, + request: function (postData, callBack) { // if (1) param then it is call back if (2) then postData and callBack + var obj = this; + // check for multiple params + if (typeof postData == 'function') { + callBack = postData; + postData = null; + } + if (typeof postData == 'undefined' || postData == null) postData = {}; + if (!this.url || (typeof this.url == 'object' && !this.url.get)) return; + if (this.recid == null || typeof this.recid == 'undefined') this.recid = 0; + // build parameters list + var params = {}; + // add list params + params['cmd'] = 'get-record'; + params['recid'] = this.recid; + // append other params + $.extend(params, this.postData); + $.extend(params, postData); + // event before + var eventData = this.trigger({ phase: 'before', type: 'request', target: this.name, url: this.url, postData: params }); + if (eventData.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return; } + // default action + this.record = {}; + this.original = {}; + // call server to get data + this.lock(this.msgRefresh); + var url = eventData.url; + if (typeof eventData.url == 'object' && eventData.url.get) url = eventData.url.get; + if (this.last.xhr) try { this.last.xhr.abort(); } catch (e) {}; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text' // expected from server + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'RESTFULL') { + ajaxOptions.type = 'GET'; + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } + this.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.unlock(); + // event before + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'load', xhr: xhr }); + if (eventData.isCancelled === true) { + if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); + return; + } + // parse server response + var data; + var responseText = obj.last.xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : obj.msgNotJSON, + responseText : responseText + } + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + obj.record = $.extend({}, data.record); + obj.original = $.extend({}, data.record); + } + } + } else { + obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + data = { + status : 'error', + message : obj.msgAJAXerror, + responseText : responseText + }; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.refresh(); + // call back + if (typeof callBack == 'function') callBack(data); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + if (status != 'abort') { + var data; + try { data = $.parseJSON(xhr.responseText) } catch (e) {} + console.log('ERROR: Server communication failed.', + '\n EXPECTED:', { status: 'success', items: [{ id: 1, text: 'item' }] }, + '\n OR:', { status: 'error', message: 'error message' }, + '\n RECEIVED:', typeof data == 'object' ? data : xhr.responseText); + } + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - unlock: function () { - var obj = this; - setTimeout(function () { w2utils.unlock(obj.box); }, 25); // needed timer so if server fast, it will not flash - }, + submit: function (postData, callBack) { + return this.save(postData, callBack); + }, - goto: function (page) { - if (typeof page != 'undefined') this.page = page; - // if it was auto size, resize it - if ($(this.box).data('auto-size') === true) $(this.box).height(0); - this.refresh(); - }, + save: function (postData, callBack) { + var obj = this; + $(this.box).find(':focus').change(); // trigger onchange + // check for multiple params + if (typeof postData == 'function') { + callBack = postData; + postData = null; + } + // validation + var errors = obj.validate(true); + if (errors.length !== 0) return; + // submit save + if (typeof postData == 'undefined' || postData == null) postData = {}; + if (!obj.url || (typeof obj.url == 'object' && !obj.url.save)) { + console.log("ERROR: Form cannot be saved because no url is defined."); + return; + } + obj.lock(obj.msgSaving + ' '); + // need timer to allow to lock + setTimeout(function () { + // build parameters list + var params = {}; + // add list params + params['cmd'] = 'save-record'; + params['recid'] = obj.recid; + // append other params + $.extend(params, obj.postData); + $.extend(params, postData); + params.record = $.extend(true, {}, obj.record); + // event before + var eventData = obj.trigger({ phase: 'before', type: 'submit', target: obj.name, url: obj.url, postData: params }); + if (eventData.isCancelled === true) return; + // default action + var url = eventData.url; + if (typeof eventData.url == 'object' && eventData.url.save) url = eventData.url.save; + if (obj.last.xhr) try { obj.last.xhr.abort(); } catch (e) {}; + // process url with routeData + if (!$.isEmptyObject(obj.routeData)) { + var info = w2utils.parseRoute(url); + if (info.keys.length > 0) { + for (var k = 0; k < info.keys.length; k++) { + if (obj.routeData[info.keys[k].name] == null) continue; + url = url.replace((new RegExp(':'+ info.keys[k].name, 'g')), obj.routeData[info.keys[k].name]); + } + } + } + var ajaxOptions = { + type : 'POST', + url : url, + data : eventData.postData, + dataType : 'text', // expected from server + xhr : function() { + var xhr = new window.XMLHttpRequest(); + // upload + xhr.upload.addEventListener("progress", function(evt) { + if (evt.lengthComputable) { + var percent = Math.round(evt.loaded / evt.total * 100); + $('#'+ obj.name + '_progress').text(''+ percent + '%'); + } + }, false); + return xhr; + } + }; + if (w2utils.settings.dataType == 'HTTP') { + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'RESTFULL') { + if (obj.recid != 0) ajaxOptions.type = 'PUT'; + ajaxOptions.data = String($.param(ajaxOptions.data, false)).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } + if (w2utils.settings.dataType == 'JSON') { + ajaxOptions.type = 'POST'; + ajaxOptions.data = JSON.stringify(ajaxOptions.data); + ajaxOptions.contentType = 'application/json'; + } - generateHTML: function () { - var pages = []; // array for each page - for (var f in this.fields) { - var html = ''; - var field = this.fields[f]; - if (typeof field.html == 'undefined') field.html = {}; - field.html = $.extend(true, { caption: '', span: 6, attr: '', text: '', page: 0 }, field.html); - if (field.html.caption == '') field.html.caption = field.name; - var input = ''; - if (field.type == 'list') input = ''; - if (field.type == 'checkbox') input = ''; - if (field.type == 'textarea') input = ''; - html += '\n '+ field.html.caption +':'+ - '\n '+ - input + field.html.text + - ''; - if (typeof pages[field.html.page] == 'undefined') pages[field.html.page] = ''; - pages[field.html.page] += html; - } - for (var p in pages) pages[p] += '\n'; - // buttons if any - var buttons = ''; - if (!$.isEmptyObject(this.actions)) { - buttons += '\n'; - for (var a in this.actions) { - buttons += '\n '; - } - buttons += '\n'; - } - return pages.join('') + buttons; - }, + obj.last.xhr = $.ajax(ajaxOptions) + .done(function (data, status, xhr) { + obj.unlock(); + // event before + var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'save', xhr: xhr, status: status }); + if (eventData.isCancelled === true) return; + // parse server response + var data; + var responseText = xhr.responseText; + if (status != 'error') { + // default action + if (typeof responseText != 'undefined' && responseText != '') { + // check if the onLoad handler has not already parsed the data + if (typeof responseText == "object") { + data = responseText; + } else { + // $.parseJSON or $.getJSON did not work because those expect perfect JSON data - where everything is in double quotes + // + // TODO: avoid (potentially malicious) code injection from the response. + try { eval('data = '+ responseText); } catch (e) { } + } + if (typeof data == 'undefined') { + data = { + status : 'error', + message : obj.msgNotJSON, + responseText : responseText + } + } + if (data['status'] == 'error') { + obj.error(data['message']); + } else { + obj.original = $.extend({}, obj.record); + } + } + } else { + obj.error('AJAX Error ' + xhr.status + ': '+ xhr.statusText); + data = { + status : 'error', + message : obj.msgAJAXerror, + responseText : responseText + }; + } + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + obj.refresh(); + // call back + if (data.status == 'success' && typeof callBack == 'function') callBack(data); + }) + .fail(function (xhr, status, error) { + // trigger event + var errorObj = { status: status, error: error, rawResponseText: xhr.responseText }; + var eventData2 = obj.trigger({ phase: 'before', type: 'error', error: errorObj, xhr: xhr }); + if (eventData2.isCancelled === true) return; + // default behavior + console.log('ERROR: server communication failed. The server should return', + { status: 'success' }, 'OR', { status: 'error', message: 'error message' }, + ', instead the AJAX request produced this: ', errorObj); + // event after + obj.trigger($.extend(eventData2, { phase: 'after' })); + }); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }, 50); + }, + + lock: function (msg, showSpinner) { + var box = $(this.box).find('> div:first-child'); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(box); + w2utils.lock.apply(window, args); + }, + + unlock: function () { + var obj = this; + setTimeout(function () { w2utils.unlock(obj.box); }, 25); // needed timer so if server fast, it will not flash + }, - action: function (action, event) { - // event before - var eventData = this.trigger({ phase: 'before', target: action, type: 'action', originalEvent: event }); - if (eventData.isCancelled === true) return false; - // default actions - if (typeof (this.actions[action]) == 'function') { - this.actions[action].call(this, event); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - }, + goto: function (page) { + if (typeof page != 'undefined') this.page = page; + // if it was auto size, resize it + if ($(this.box).data('auto-size') === true) $(this.box).height(0); + this.refresh(); + }, + + generateHTML: function () { + var pages = []; // array for each page + var group = ''; + var page; + for (var f in this.fields) { + var html = ''; + var field = this.fields[f]; + if (typeof field.html == 'undefined') field.html = {}; + field.html = $.extend(true, { caption: '', span: 6, attr: '', text: '', page: 0 }, field.html); + if (typeof page == 'undefined') page = field.html.page; + if (field.html.caption == '') field.html.caption = field.name; + var input = ''; + if ((field.type === 'pass') || (field.type === 'password')){ + input = ''; + } + if (field.type == 'checkbox') input = ''; + if (field.type == 'textarea') input = ''; + if (field.type == 'toggle') input = ''; + if (field.html.group) { + if (group != '') html += '\n '; + html += '\n '+ field.html.group + '\n '; + group = field.html.group; + } + if (field.html.page != page && group != '') { + pages[pages.length-1] += '\n '; + group = ''; + } + html += '\n '+ + '\n ' + w2utils.lang(field.html.caption) +''+ + '\n '+ input + w2utils.lang(field.html.text) + ''+ + '\n '; + if (typeof pages[field.html.page] == 'undefined') pages[field.html.page] = ''; + pages[field.html.page] += html; + page = field.html.page; + } + if (group != '') pages[pages.length-1] += '\n '; + if (this.tabs.tabs) { + for (var i = 0; i < this.tabs.tabs.length; i++) if (typeof pages[i] == 'undefined') pages[i] = ''; + } + for (var p in pages) pages[p] = '' + pages[p] + '\n'; + // buttons if any + var buttons = ''; + if (!$.isEmptyObject(this.actions)) { + var addClass = ''; + buttons += '\n'; + for (var a in this.actions) { + if (['save', 'update', 'create'].indexOf(a.toLowerCase()) != -1) addClass = 'btn-green'; else addClass = ''; + buttons += '\n '+ w2utils.lang(a) +''; + } + buttons += '\n'; + } + return pages.join('') + buttons; + }, - resize: function () { - var obj = this; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'resize' }); - if (eventData.isCancelled === true) return false; - // default behaviour - var main = $(this.box).find('> div'); - var header = $(this.box).find('> div .w2ui-form-header'); - var toolbar = $(this.box).find('> div .w2ui-form-toolbar'); - var tabs = $(this.box).find('> div .w2ui-form-tabs'); - var page = $(this.box).find('> div .w2ui-page'); - var cpage = $(this.box).find('> div .w2ui-page.page-'+ this.page); - var dpage = $(this.box).find('> div .w2ui-page.page-'+ this.page + ' > div'); - var buttons = $(this.box).find('> div .w2ui-buttons'); - // if no height, calculate it - resizeElements(); - if (parseInt($(this.box).height()) == 0 || $(this.box).data('auto-size') === true) { - $(this.box).height( - (header.length > 0 ? w2utils.getSize(header, 'height') : 0) + - (this.tabs.tabs.length > 0 ? w2utils.getSize(tabs, 'height') : 0) + - (this.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') : 0) + - (page.length > 0 ? w2utils.getSize(dpage, 'height') + w2utils.getSize(cpage, '+height') + 12 : 0) + // why 12 ??? - (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0) - ); - $(this.box).data('auto-size', true); - } - resizeElements(); - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - - function resizeElements() { - // resize elements - main.width($(obj.box).width()).height($(obj.box).height()); - toolbar.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0)); - tabs.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) - + (obj.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') : 0)); - page.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) - + (obj.toolbar.items.length > 0 ? w2utils.getSize(toolbar, 'height') + 5 : 0) - + (obj.tabs.tabs.length > 0 ? w2utils.getSize(tabs, 'height') + 5 : 0)); - page.css('bottom', (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0)); - } - }, + action: function (action, event) { + // event before + var eventData = this.trigger({ phase: 'before', target: action, type: 'action', originalEvent: event }); + if (eventData.isCancelled === true) return; + // default actions + if (typeof (this.actions[action]) == 'function') { + this.actions[action].call(this, event); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + }, - refresh: function () { - var obj = this; - if (!this.box) return; - if (!this.isGenerated || typeof $(this.box).html() == 'undefined') return; - // update what page field belongs - $(this.box).find('input, textarea, select').each(function (index, el) { - var name = (typeof $(el).attr('name') != 'undefined' ? $(el).attr('name') : $(el).attr('id')); - var field = obj.get(name); - if (field) { - // find page - var div = $(el).parents('.w2ui-page'); - if (div.length > 0) { - for (var i = 0; i < 100; i++) { - if (div.hasClass('page-'+i)) { field.page = i; break; } - } - } - } - }); - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh', page: this.page }) - if (eventData.isCancelled === true) return false; - // default action - $(this.box).find('.w2ui-page').hide(); - $(this.box).find('.w2ui-page.page-' + this.page).show(); - $(this.box).find('.w2ui-form-header').html(this.header); - // refresh tabs if needed - if (typeof this.tabs == 'object' && this.tabs.tabs.length > 0) { - $('#form_'+ this.name +'_tabs').show(); - this.tabs.active = this.tabs.tabs[this.page].id; - this.tabs.refresh(); - } else { - $('#form_'+ this.name +'_tabs').hide(); - } - // refresh tabs if needed - if (typeof this.toolbar == 'object' && this.toolbar.items.length > 0) { - $('#form_'+ this.name +'_toolbar').show(); - this.toolbar.refresh(); - } else { - $('#form_'+ this.name +'_toolbar').hide(); - } - // refresh values of all fields - for (var f in this.fields) { - var field = this.fields[f]; - field.el = $(this.box).find('[name="'+ String(field.name).replace(/\\/g, '\\\\') +'"]')[0]; - if (typeof field.el == 'undefined') { - console.log('ERROR: Cannot associate field "'+ field.name + '" with html control. Make sure html control exists with the same name.'); - //return; - } - if (field.el) field.el.id = field.name; - $(field.el).off('change').on('change', function () { - var value_new = this.value; - var value_previous = obj.record[this.name] ? obj.record[this.name] : ''; - var field = obj.get(this.name); - if ((field.type == 'enum' || field.type == 'upload') && $(this).data('selected')) { - var new_arr = $(this).data('selected'); - var cur_arr = obj.record[this.name]; - var value_new = []; - var value_previous = []; - if ($.isArray(new_arr)) for (var i in new_arr) value_new[i] = $.extend(true, {}, new_arr[i]); // clone array - if ($.isArray(cur_arr)) for (var i in cur_arr) value_previous[i] = $.extend(true, {}, cur_arr[i]); // clone array - } - // event before - var eventData = obj.trigger({ phase: 'before', target: this.name, type: 'change', value_new: value_new, value_previous: value_previous }); - if (eventData.isCancelled === true) { - $(this).val(obj.record[this.name]); // return previous value - return false; - } - // default action - var val = this.value; - if (this.type == 'checkbox') val = this.checked ? true : false; - if (this.type == 'radio') val = this.checked ? true : false; - if (field.type == 'enum') val = value_new; - if (field.type == 'upload') val = value_new; - obj.record[this.name] = val; - // event after - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - if (field.required) { - $(field.el).parent().addClass('w2ui-required'); - } else { - $(field.el).parent().removeClass('w2ui-required'); - } - } - // attach actions on buttons - $(this.box).find('button, input[type=button]').each(function (index, el) { - $(el).off('click').on('click', function (event) { - var action = this.value; - if (this.name) action = this.name; - if (this.id) action = this.id; - obj.action(action, event); - }); - }); - // init controls with record - for (var f in this.fields) { - var field = this.fields[f]; - var value = (typeof this.record[field.name] != 'undefined' ? this.record[field.name] : ''); - if (!field.el) continue; - switch (String(field.type).toLowerCase()) { - case 'email': - case 'text': - case 'textarea': - field.el.value = value; - break; - case 'date': - if (!field.options) field.options = {}; - if (!field.options.format) field.options.format = w2utils.settings.date_format; - field.el.value = value; - this.record[field.name] = value; - $(field.el).w2field($.extend({}, field.options, { type: 'date' })); - break; - case 'int': - field.el.value = value; - $(field.el).w2field('int'); - break; - case 'float': - field.el.value = value; - $(field.el).w2field('float'); - break; - case 'money': - field.el.value = value; - $(field.el).w2field('money'); - break; - case 'hex': - field.el.value = value; - $(field.el).w2field('hex'); - break; - case 'alphanumeric': - field.el.value = value; - $(field.el).w2field('alphaNumeric'); - break; - case 'checkbox': - if (this.record[field.name] == true || this.record[field.name] == 1 || this.record[field.name] == 't') { - $(field.el).prop('checked', true); + resize: function () { + var obj = this; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'resize' }); + if (eventData.isCancelled === true) return; + // default behaviour + var main = $(this.box).find('> div'); + var header = $(this.box).find('> div .w2ui-form-header'); + var toolbar = $(this.box).find('> div .w2ui-form-toolbar'); + var tabs = $(this.box).find('> div .w2ui-form-tabs'); + var page = $(this.box).find('> div .w2ui-page'); + var cpage = $(this.box).find('> div .w2ui-page.page-'+ this.page); + var dpage = $(this.box).find('> div .w2ui-page.page-'+ this.page + ' > div'); + var buttons = $(this.box).find('> div .w2ui-buttons'); + // if no height, calculate it + resizeElements(); + if (parseInt($(this.box).height()) == 0 || $(this.box).data('auto-size') === true) { + $(this.box).height( + (header.length > 0 ? w2utils.getSize(header, 'height') : 0) + + ((typeof this.tabs === 'object' && $.isArray(this.tabs.tabs) && this.tabs.tabs.length > 0) ? w2utils.getSize(tabs, 'height') : 0) + + ((typeof this.toolbar == 'object' && $.isArray(this.toolbar.items) && this.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') : 0) + + (page.length > 0 ? w2utils.getSize(dpage, 'height') + w2utils.getSize(cpage, '+height') + 12 : 0) + // why 12 ??? + (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0) + ); + $(this.box).data('auto-size', true); + } + resizeElements(); + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + + function resizeElements() { + // resize elements + main.width($(obj.box).width()).height($(obj.box).height()); + toolbar.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0)); + tabs.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) + + ((typeof obj.toolbar == 'object' && $.isArray(obj.toolbar.items) && obj.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') : 0)); + page.css('top', (obj.header != '' ? w2utils.getSize(header, 'height') : 0) + + ((typeof obj.toolbar == 'object' && $.isArray(obj.toolbar.items) && obj.toolbar.items.length > 0) ? w2utils.getSize(toolbar, 'height') + 5 : 0) + + ((typeof obj.tabs === 'object' && $.isArray(obj.tabs.tabs) && obj.tabs.tabs.length > 0) ? w2utils.getSize(tabs, 'height') + 5 : 0)); + page.css('bottom', (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0)); + } + }, + + refresh: function () { + var time = (new Date()).getTime(); + var obj = this; + if (!this.box) return; + if (!this.isGenerated || typeof $(this.box).html() == 'undefined') return; + // update what page field belongs + $(this.box).find('input, textarea, select').each(function (index, el) { + var name = (typeof $(el).attr('name') != 'undefined' ? $(el).attr('name') : $(el).attr('id')); + var field = obj.get(name); + if (field) { + // find page + var div = $(el).parents('.w2ui-page'); + if (div.length > 0) { + for (var i = 0; i < 100; i++) { + if (div.hasClass('page-'+i)) { field.page = i; break; } + } + } + } + }); + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh', page: this.page }) + if (eventData.isCancelled === true) return; + // default action + $(this.box).find('.w2ui-page').hide(); + $(this.box).find('.w2ui-page.page-' + this.page).show(); + $(this.box).find('.w2ui-form-header').html(this.header); + // refresh tabs if needed + if (typeof this.tabs === 'object' && $.isArray(this.tabs.tabs) && this.tabs.tabs.length > 0) { + $('#form_'+ this.name +'_tabs').show(); + this.tabs.active = this.tabs.tabs[this.page].id; + this.tabs.refresh(); } else { - $(field.el).prop('checked', false); - } - break; - case 'password': - // hide passwords - field.el.value = value; - break; - case 'select': - case 'list': - $(field.el).w2field($.extend({}, field.options, { type: 'list', value: value })); - break; - case 'enum': - if (typeof field.options == 'undefined' || (typeof field.options.url == 'undefined' && typeof field.options.items == 'undefined')) { - console.log("ERROR: (w2form."+ obj.name +") the field "+ field.name +" defined as enum but not field.options.url or field.options.items provided."); - break; - } - // normalize value - this.record[field.name] = w2obj.field.cleanItems(value); - value = this.record[field.name]; - $(field.el).w2field( $.extend({}, field.options, { type: 'enum', selected: value }) ); - break; - case 'upload': - $(field.el).w2field($.extend({}, field.options, { type: 'upload', selected: value })); - break; - default: - console.log('ERROR: field type "'+ field.type +'" is not recognized.'); - break; - } - } - // wrap pages in div - var tmp = $(this.box).find('.w2ui-page'); - for (var i = 0; i < tmp.length; i++) { - if ($(tmp[i]).find('> *').length > 1) $(tmp[i]).wrapInner(''); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - this.resize(); - }, + $('#form_'+ this.name +'_tabs').hide(); + } + // refresh tabs if needed + if (typeof this.toolbar == 'object' && $.isArray(this.toolbar.items) && this.toolbar.items.length > 0) { + $('#form_'+ this.name +'_toolbar').show(); + this.toolbar.refresh(); + } else { + $('#form_'+ this.name +'_toolbar').hide(); + } + // refresh values of all fields + for (var f in this.fields) { + var field = this.fields[f]; + if (typeof field.name == 'undefined' && typeof field.field != 'undefined') field.name = field.field; + if (typeof field.field == 'undefined' && typeof field.name != 'undefined') field.field = field.name; + field.$el = $(this.box).find('[name="'+ String(field.name).replace(/\\/g, '\\\\') +'"]'); + field.el = field.$el[0]; + if (typeof field.el == 'undefined') { + console.log('ERROR: Cannot associate field "'+ field.name + '" with html control. Make sure html control exists with the same name.'); + //return; + } + if (field.el) field.el.id = field.name; + var tmp = $(field).data('w2field'); + if (tmp) tmp.clear(); + $(field.$el).off('change').on('change', function () { + var value_new = this.value; + var value_previous = obj.record[this.name] ? obj.record[this.name] : ''; + var field = obj.get(this.name); + if (['list', 'enum', 'file'].indexOf(field.type) != -1 && $(this).data('selected')) { + var nv = $(this).data('selected'); + var cv = obj.record[this.name]; + if ($.isArray(nv)) { + value_new = []; + for (var i in nv) value_new[i] = $.extend(true, {}, nv[i]); // clone array + } + if ($.isPlainObject(nv)) { + value_new = $.extend(true, {}, nv); // clone object + } + if ($.isArray(cv)) { + value_previous = []; + for (var i in cv) value_previous[i] = $.extend(true, {}, cv[i]); // clone array + } + if ($.isPlainObject(cv)) { + value_previous = $.extend(true, {}, cv); // clone object + } + } + if (field.type == 'toggle') value_new = ($(this).prop('checked') ? 1 : 0); + // clean extra chars + if (['int', 'float', 'percent', 'money', 'currency'].indexOf(field.type) != -1) { + value_new = $(this).data('w2field').clean(value_new); + } + if (value_new === value_previous) return; + // event before + var eventData = obj.trigger({ phase: 'before', target: this.name, type: 'change', value_new: value_new, value_previous: value_previous }); + if (eventData.isCancelled === true) { + $(this).val(obj.record[this.name]); // return previous value + return; + } + // default action + var val = this.value; + if (this.type == 'select') val = this.value; + if (this.type == 'checkbox') val = this.checked ? true : false; + if (this.type == 'radio') { + field.$el.each(function (index, el) { + if (el.checked) val = el.value; + }); + } + if (['int', 'float', 'percent', 'money', 'currency', 'list', 'combo', 'enum', 'file', 'toggle'].indexOf(field.type) != -1) { + val = value_new; + } + if (['enum', 'file'].indexOf(field.type) != -1) { + if (val.length > 0) { + var fld = $(field.el).data('w2field').helpers.multi; + $(fld).removeClass('w2ui-error'); + } + } + obj.record[this.name] = val; + // event after + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + if (field.required) { + $(field.el).parent().parent().addClass('w2ui-required'); + } else { + $(field.el).parent().parent().removeClass('w2ui-required'); + } + } + // attach actions on buttons + $(this.box).find('button, input[type=button]').each(function (index, el) { + $(el).off('click').on('click', function (event) { + var action = this.value; + if (this.id) action = this.id; + if (this.name) action = this.name; + obj.action(action, event); + }); + }); + // init controls with record + for (var f in this.fields) { + var field = this.fields[f]; + var value = (typeof this.record[field.name] != 'undefined' ? this.record[field.name] : ''); + if (!field.el) continue; + field.type = String(field.type).toLowerCase(); + if (!field.options) field.options = {}; + switch (field.type) { + case 'text': + case 'textarea': + case 'email': + case 'pass': + case 'password': + field.el.value = value; + break; + case 'int': + case 'float': + case 'money': + case 'currency': + case 'percent': + case 'hex': + case 'alphanumeric': + case 'color': + case 'date': + case 'time': + field.el.value = value; + $(field.el).w2field($.extend({}, field.options, { type: field.type })); + break; + case 'toggle': + if (w2utils.isFloat(value)) value = parseFloat(value); + $(field.el).prop('checked', (value ? true : false)); + this.record[field.name] = (value ? 1 : 0); + break; + // enums + case 'list': + case 'combo': + if (field.type == 'list') { + var tmp_value = ($.isPlainObject(value) ? value.id : value); + // normalized options + var items = field.options.items; + if ($.isArray(items) && items.length > 0 && !$.isPlainObject(items[0])) { + field.options.items = w2obj.field.prototype.normMenu(items); + } + // find value from items + for (var i in field.options.items) { + var item = field.options.items[i]; + if (item.id == tmp_value) { + value = $.extend(true, {}, item); + obj.record[field.name] = value; + console.log(1); + break; + } + } + } else if (field.type == 'combo' && !$.isPlainObject(value)) { + field.el.value = value; + } else if ($.isPlainObject(value) && typeof value.text != 'undefined') { + field.el.value = value.text; + } else { + field.el.value = ''; + } + if (!$.isPlainObject(value)) value = {}; + $(field.el).w2field($.extend({}, field.options, { type: field.type, selected: value })); + break; + case 'enum': + case 'file': + if (!$.isArray(value)) value = []; + $(field.el).w2field($.extend({}, field.options, { type: field.type, selected: value })); + break; + + // standard HTML + case 'select': + // generate options + var items = field.options.items; + if (typeof items != 'undefined' && items.length > 0) { + items = w2obj.field.prototype.normMenu(items); + $(field.el).html(''); + for (var it in items) { + $(field.el).append('' + items[it].text + ' *').length > 1) $(tmp[i]).wrapInner(''); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + this.resize(); + return (new Date()).getTime() - time; + }, - render: function (box) { - var obj = this; - if (typeof box == 'object') { - // remove from previous box - if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { - $(this.box).removeAttr('name') - .removeClass('w2ui-reset w2ui-form') - .html(''); - } - this.box = box; - } - if (!this.isGenerated) return; - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: (typeof box != 'undefined' ? box : this.box) }); - if (eventData.isCancelled === true) return false; - // default actions - var html = '' + - (this.header != '' ? '' + this.header + '' : '') + - ' ' + - ' ' + - this.formHTML + - ''; - $(this.box).attr('name', this.name) - .addClass('w2ui-reset w2ui-form') - .html(html); - if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; - - // init toolbar regardless it is defined or not - if (typeof this.toolbar['render'] == 'undefined') { - this.toolbar = $().w2toolbar($.extend({}, this.toolbar, { name: this.name +'_toolbar', owner: this })); - this.toolbar.on('click', function (event) { - var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); - if (eventData.isCancelled === true) return false; - // no default action - obj.trigger($.extend(eventData, { phase: 'after' })); - }); - } - if (typeof this.toolbar == 'object' && typeof this.toolbar.render == 'function') { - this.toolbar.render($('#form_'+ this.name +'_toolbar')[0]); - } - // init tabs regardless it is defined or not - if (typeof this.tabs['render'] == 'undefined') { - this.tabs = $().w2tabs($.extend({}, this.tabs, { name: this.name +'_tabs', owner: this })); - this.tabs.on('click', function (event) { - obj.goto(this.get(event.target, true)); - }); - } - if (typeof this.tabs == 'object' && typeof this.tabs.render == 'function') { - this.tabs.render($('#form_'+ this.name +'_tabs')[0]); - } - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - // after render actions - this.resize(); - var url = (typeof this.url != 'object' ? this.url : this.url.get); - if (url && this.recid != 0) { - this.request(); - } else { - this.refresh(); - } - // attach to resize event - if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event - this.tmp_resize = function (event) { w2ui[obj.name].resize(); } - $(window).off('resize', 'body').on('resize', 'body', this.tmp_resize); - } - setTimeout(function () { obj.resize(); obj.refresh(); }, 150); // need timer because resize is on timer - // focus on load - function focusEl() { - var inputs = $(obj.box).find('input, select, textarea'); - if (inputs.length > obj.focus) inputs[obj.focus].focus(); - } - if (this.focus >= 0) setTimeout(focusEl, 500); // need timeout to allow form to render - }, + render: function (box) { + var time = (new Date()).getTime(); + var obj = this; + if (typeof box == 'object') { + // remove from previous box + if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { + $(this.box).removeAttr('name') + .removeClass('w2ui-reset w2ui-form') + .html(''); + } + this.box = box; + } + if (!this.isGenerated) return; + if (!this.box) return; + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: (typeof box != 'undefined' ? box : this.box) }); + if (eventData.isCancelled === true) return; + // default actions + if ($.isEmptyObject(this.original) && !$.isEmptyObject(this.record)) { + this.original = $.extend(true, {}, this.record); + } + var html = '' + + (this.header != '' ? '' + this.header + '' : '') + + ' ' + + ' ' + + this.formHTML + + ''; + $(this.box).attr('name', this.name) + .addClass('w2ui-reset w2ui-form') + .html(html); + if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style; + + // init toolbar regardless it is defined or not + if (typeof this.toolbar.render !== 'function') { + this.toolbar = $().w2toolbar($.extend({}, this.toolbar, { name: this.name +'_toolbar', owner: this })); + this.toolbar.on('click', function (event) { + var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event }); + if (eventData.isCancelled === true) return; + // no default action + obj.trigger($.extend(eventData, { phase: 'after' })); + }); + } + if (typeof this.toolbar == 'object' && typeof this.toolbar.render == 'function') { + this.toolbar.render($('#form_'+ this.name +'_toolbar')[0]); + } + // init tabs regardless it is defined or not + if (typeof this.tabs.render !== 'function') { + this.tabs = $().w2tabs($.extend({}, this.tabs, { name: this.name +'_tabs', owner: this })); + this.tabs.on('click', function (event) { + obj.goto(this.get(event.target, true)); + }); + } + if (typeof this.tabs == 'object' && typeof this.tabs.render == 'function') { + this.tabs.render($('#form_'+ this.name +'_tabs')[0]); + } + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + // after render actions + this.resize(); + var url = (typeof this.url != 'object' ? this.url : this.url.get); + if (url && this.recid != 0) { + this.request(); + } else { + this.refresh(); + } + // attach to resize event + if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event + this.tmp_resize = function (event) { w2ui[obj.name].resize(); } + $(window).off('resize', 'body').on('resize', 'body', this.tmp_resize); + } + setTimeout(function () { obj.resize(); obj.refresh(); }, 150); // need timer because resize is on timer + // focus on load + function focusEl() { + var inputs = $(obj.box).find('input, select, textarea'); + if (inputs.length > obj.focus) inputs[obj.focus].focus(); + } + if (this.focus >= 0) setTimeout(focusEl, 500); // need timeout to allow form to render + return (new Date()).getTime() - time; + }, - destroy: function () { - // event before - var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); - if (eventData.isCancelled === true) return false; - // clean up - if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); - if (typeof this.tabs == 'object' && this.tabs.destroy) this.tabs.destroy(); - if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { - $(this.box) - .removeAttr('name') - .removeClass('w2ui-reset w2ui-form') - .html(''); - } - delete w2ui[this.name]; - // event after - this.trigger($.extend(eventData, { phase: 'after' })); - $(window).off('resize', 'body') - } - } + destroy: function () { + // event before + var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' }); + if (eventData.isCancelled === true) return; + // clean up + if (typeof this.toolbar == 'object' && this.toolbar.destroy) this.toolbar.destroy(); + if (typeof this.tabs == 'object' && this.tabs.destroy) this.tabs.destroy(); + if ($(this.box).find('#form_'+ this.name +'_tabs').length > 0) { + $(this.box) + .removeAttr('name') + .removeClass('w2ui-reset w2ui-form') + .html(''); + } + delete w2ui[this.name]; + // event after + this.trigger($.extend(eventData, { phase: 'after' })); + $(window).off('resize', 'body') + } + }; - $.extend(w2form.prototype, w2utils.event); - w2obj.form = w2form; + $.extend(w2form.prototype, w2utils.event); + w2obj.form = w2form; })(jQuery); diff --git a/js/w2ui.min.js b/js/w2ui.min.js index 2135cb1..1db7571 100644 --- a/js/w2ui.min.js +++ b/js/w2ui.min.js @@ -1 +1 @@ -var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function nt(n){var t=/^[-]?[0-9]+$/;return t.test(n)}function tt(n){var t=new RegExp(w2utils.settings.float);return t.test(n)}function d(n){var t=new RegExp(w2utils.settings.currency);return t.test(n)}function w(n){var t=/^[a-fA-F0-9]+$/;return t.test(n)}function b(n){var t=/^[a-zA-Z0-9_-]+$/;return t.test(n)}function k(n){var t=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return t.test(n)}function et(n,t,i){if(!n)return!1;t||(t=w2utils.settings.date_format);var r=n.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),o=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase(),s="Invalid Date",u,f,e;return(o=="mm/dd/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="m/d/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="dd/mm/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="d/m/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="yyyy/dd/mm"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/d/m"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/mm/dd"&&(u=r[1],f=r[2],e=r[0]),o=="yyyy/m/d"&&(u=r[1],f=r[2],e=r[0]),s=new Date(u+"/"+f+"/"+e),typeof u=="undefined")?!1:s=="Invalid Date"?!1:s.getMonth()+1!=u||s.getDate()!=f||s.getFullYear()!=e?!1:i===!0?s:!0}function ot(t){var r,i;return String(t)=="undefined"?!1:(t=t.toUpperCase(),r=t.indexOf("PM")>=0||t.indexOf("AM")>=0?12:23,t=n.trim(t.replace("AM","")),t=n.trim(t.replace("PM","")),i=t.split(":"),i.length!=2)?!1:i[0]==""||parseInt(i[0])<0||parseInt(i[0])>r||!this.isInt(i[0])?!1:i[1]==""||parseInt(i[1])<0||parseInt(i[1])>59||!this.isInt(i[1])?!1:!0}function st(n){var f,i;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),f=new Date(n),w2utils.isInt(n)&&(f=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(f=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(f=new Date(i[2],Number(i[0])-1,i[1])),f=="Invalid Time"))return"";var e=new Date,t=(e.getTime()-f.getTime())/1e3,r="",u="";return t<60?(r=Math.floor(t),u="sec",t<0&&(r=0,u="sec")):t<3600?(r=Math.floor(t/60),u="min"):t<86400?(r=Math.floor(t/3600),u="hour"):t<2592e3?(r=Math.floor(t/86400),u="day"):t<31104e3?(r=Math.floor(t/259200)/10,u="month"):t>=31104e3&&(r=Math.floor(t/3110400)/10,u="year"),r+" "+u+(r>1?"s":"")}function ft(n){var o=w2utils.settings.shortmonths,t,i,f,r;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(t=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(t=new Date(i[2],Number(i[0])-1,i[1])),t=="Invalid Date"))return"";f=new Date,r=new Date,r.setTime(r.getTime()-864e5);var u=o[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),h=o[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),c=o[r.getMonth()]+" "+r.getDate()+", "+r.getFullYear(),l=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),s=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=u;return u==h&&(e=l),u==c&&(e=w2utils.lang("Yesterday")),''+e+""}function it(n){if(!w2utils.isFloat(n)||n=="")return"";if(n=parseFloat(n),n==0)return 0;var i=["Bt","KB","MB","GB","TB"],t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t==0?0:1)+" "+i[t]}function rt(n){var t="";return(w2utils.isFloat(n)||w2utils.isInt(n)||w2utils.isMoney(n))&&(t=String(n).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")),t}function ut(n,t){var s=w2utils.settings.shortmonths,o=w2utils.settings.fullmonths,r,i;if((typeof t=="undefined"&&(t=this.settings.date_format),typeof n=="undefined"||n==""||n==null)||(r=new Date(n),w2utils.isInt(n)&&(r=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(r=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(r=new Date(i[2],Number(i[0])-1,i[1])),r=="Invalid Date"))return"";var f=r.getFullYear(),u=r.getMonth(),e=r.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[u]).replace("mon",w2utils.settings.shortmonths[u]).replace(/yyyy/g,f).replace(/yyy/g,f).replace(/yy/g,String(f).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+f).replace(/mm/g,(u+1<10?"0":"")+(u+1)).replace(/dd/g,(e<10?"0":"")+e).replace(/(^|[^a-z$])m/g,"$1"+(u+1)).replace(/(^|[^a-z$])d/g,"$1"+e)}function e(n,t){var h=w2utils.settings.shortmonths,s=w2utils.settings.fullmonths,i;if((typeof t=="undefined"&&(t=this.settings.time_format),typeof n=="undefined"||n==""||n==null)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),i=="Invalid Date"))return"";var e="am",u=i.getHours(),o=i.getHours(),r=i.getMinutes(),f=i.getSeconds();return r<10&&(r="0"+r),f<10&&(f="0"+f),(t.indexOf("am")!=-1||t.indexOf("pm")!=-1)&&(u>=12&&(e="pm"),u>12&&(u=u-12)),t.toLowerCase().replace("am",e).replace("pm",e).replace("hh",u).replace("h24",o).replace("mm",r).replace("mi",r).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+u).replace(/(^|[^a-z$])m/g,"$1"+r).replace(/(^|[^a-z$])s/g,"$1"+f)}function o(n,t){var i;return i=typeof t!="string"?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1])}function s(t){if(t==null)return t;switch(typeof t){case"string":t=n.trim(String(t).replace(/(<([^>]+)>)/ig,""));break;case"object":for(var i in t)t[i]=this.stripTags(t[i])}return t}function f(n){if(n==null)return n;switch(typeof n){case"string":n=String(n).replace(/&/g,"&").replace(/>/g,">").replace(/\|\/? {}\\])/g,"\\$1")}function r(n){function l(n){for(var n=String(n).replace(/\r\n/g,"\n"),i="",t,r=0;r127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",s,f,u,h,c,o,r,i=0,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);i>2,c=(s&3)<<4|f>>4,o=(f&15)<<2|u>>6,r=u&63,isNaN(f)?o=r=64:isNaN(u)&&(r=64),e=e+t.charAt(h)+t.charAt(c)+t.charAt(o)+t.charAt(r);return e}function u(n){function l(n){for(var u="",t=0,i=0,f=0,r=0;t191&&i<224?(r=n.charCodeAt(t+1),u+=String.fromCharCode((i&31)<<6|r&63),t+=2):(r=n.charCodeAt(t+1),c3=n.charCodeAt(t+2),u+=String.fromCharCode((i&15)<<12|(r&63)<<6|c3&63),t+=3);return u}var t="",s,o,c,h,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i>4,o=(f&15)<<4|r>>2,c=(r&3)<<6|e,t=t+String.fromCharCode(s),r!=64&&(t=t+String.fromCharCode(o)),e!=64&&(t=t+String.fromCharCode(c));return t=l(t)}function v(t,i,r,u){function f(n,t,i){var r=!!window.webkitURL;return r||typeof i=="undefined"||(t=i),";"+n+": "+t+"; -webkit-"+n+": "+t+"; -moz-"+n+": "+t+"; -ms-"+n+": "+t+"; -o-"+n+": "+t+";"}var o=n(t).width(),s=n(t).height(),e=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+=f("perspective","700px")+"; overflow: hidden;",t.style.cssText+="; position: absolute; z-index: 1019; "+f("backface-visibility","hidden"),i.style.cssText+="; position: absolute; z-index: 1020; "+f("backface-visibility","hidden");switch(r){case"slide-left":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)")},1);break;case"slide-right":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0px, 0, 0)","translate(0px, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)")},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; z-index: 0; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)")},1);break;case"slide-up":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":t.style.cssText+="overflow: hidden; "+f("-transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(180deg)")},1);break;case"flip-right":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(-180deg)")},1);break;case"flip-down":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(-180deg)")},1);break;case"flip-up":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(180deg)")},1);break;case"pop-in":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(.8)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1)")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+";"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(1)")+"; opacity: 1;",i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")},1)}setTimeout(function(){r=="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020")),i&&n(i).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t&&(n(t).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t.parentNode&&n(t.parentNode).css({"-webkit-perspective":"","-moz-perspective":"","-ms-perspective":"","-o-perspective":""})),typeof u=="function"&&u()},e*1e3)}function y(t,i,r){i||i==0||(i=""),w2utils.unlock(t),n(t).find(">:first-child").before(''),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg");f.data("old_opacity",f.css("opacity")).css("opacity","0").show(),u.data("old_opacity",u.css("opacity")).css("opacity","0").show(),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg"),o=(n(t).width()-w2utils.getSize(u,"width"))/2,e=(n(t).height()*.9-w2utils.getSize(u,"height"))/2;f.css({opacity:f.data("old_opacity"),left:"0px",top:"0px",width:"100%",height:"100%"}),i||u.css({"background-color":"transparent",border:"0px"}),r===!0&&(i='"+i),u.html(i).css({opacity:u.data("old_opacity"),left:o+"px",top:e+"px"})},10)},10),n().w2tag()}function p(t){n(t).find(".w2ui-lock").remove(),n(t).find(".w2ui-lock-msg").remove()}function a(t,i){var f={left:parseInt(n(t).css("border-left-width"))||0,right:parseInt(n(t).css("border-right-width"))||0,top:parseInt(n(t).css("border-top-width"))||0,bottom:parseInt(n(t).css("border-bottom-width"))||0},u={left:parseInt(n(t).css("margin-left"))||0,right:parseInt(n(t).css("margin-right"))||0,top:parseInt(n(t).css("margin-top"))||0,bottom:parseInt(n(t).css("margin-bottom"))||0},r={left:parseInt(n(t).css("padding-left"))||0,right:parseInt(n(t).css("padding-right"))||0,top:parseInt(n(t).css("padding-top"))||0,bottom:parseInt(n(t).css("padding-bottom"))||0};switch(i){case"top":return f.top+u.top+r.top;case"bottom":return f.bottom+u.bottom+r.bottom;case"left":return f.left+u.left+r.left;case"right":return f.right+u.right+r.right;case"width":return f.left+f.right+u.left+u.right+r.left+r.right+parseInt(n(t).width());case"height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom+parseInt(n(t).height());case"+width":return f.left+f.right+u.left+u.right+r.left+r.right;case"+height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom}return 0}function h(n){var t=this.settings.phrases[n];return typeof t=="undefined"?n:t}function c(t){t||(t="en-us"),t.length==5&&(t="locale/"+t+".json"),n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(t){w2utils.settings=n.extend(!0,w2utils.settings,t)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function l(){if(t.scrollBarSize)return t.scrollBarSize;var i='\t1';return n("body").append(i),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}var t={};return{settings:{locale:"en-us",date_format:"m/d/yyyy",date_display:"Mon d, yyyy",time_format:"hh:mi pm",currency:"^[$€£¥]?[-]?[0-9]*[.]?[0-9]+$",currencySymbol:"$",float:"^[-]?[0-9]*[.]?[0-9]+$",shortmonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],fullmonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortdays:["M","T","W","T","F","S","S"],fulldays:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],RESTfull:!1,phrases:{}},isInt:nt,isFloat:tt,isMoney:d,isHex:w,isAlphaNumeric:b,isEmail:k,isDate:et,isTime:ot,age:st,date:ft,size:it,formatNumber:rt,formatDate:ut,formatTime:e,formatDateTime:o,stripTags:s,encodeTags:f,escapeId:i,base64encode:r,base64decode:u,transition:v,lock:y,unlock:p,lang:h,locale:c,getSize:a,scrollBarSize:l}}(jQuery),w2popup,w2alert,w2confirm;w2utils.event={on:function(n,t){if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .on() method of "+this.name);return}if(typeof t=="undefined"){console.log("ERROR: You must specify event handler function when calling .on() method of "+this.name);return}this.handlers.push({event:n,handler:t})},off:function(n,t){var r,u,i;if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({},{type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .off() method of "+this.name);return}typeof t=="undefined"&&(t=null),r=[];for(u in this.handlers)i=this.handlers[u],(i.event.type==n.type||n.type=="*")&&(i.event.target==n.target||n.target==null)&&(i.handler==t||t==null)||r.push(i);this.handlers=r},trigger:function(n){var n=jQuery.extend({type:null,phase:"before",target:null,isStopped:!1,isCancelled:!1},n,{preventDefault:function(){this.isCancelled=!0},stopPropagation:function(){this.isStopped=!0}}),e,t,r,i,f;for(typeof n.target=="undefined"&&(n.target=null),e=this.handlers.length-1;e>=0;e--)if(t=this.handlers[e],(t.event.type==n.type||t.event.type=="*")&&(t.event.target==n.target||t.event.target==null)&&(t.event.execute==n.phase||t.event.execute=="*"||t.event.phase=="*")&&(n=jQuery.extend({},t.event,n),r=[],i=RegExp(/\((.*?)\)/).exec(t.handler),i&&(r=i[1].split(/\s*,\s*/)),r.length==2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;if(f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase=="before"&&typeof this[f]=="function"){var u=this[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}if(typeof n.object!="undefined"&&n.object!=null&&n.phase=="before"&&typeof n.object[f]=="function"){var u=n.object[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}return n.phase=="after"&&n.onComplete!=null&&n.onComplete.call(this,n),n}},w2utils.keyboard=function(n){function f(){jQuery(document).on("keydown",e);jQuery(document).on("mousedown",o)}function e(n){var i=n.target.tagName;jQuery.inArray(i,["INPUT","SELECT","TEXTAREA"])==-1&&jQuery(n.target).prop("contenteditable")!="true"&&t&&w2ui[t]&&typeof w2ui[t].keydown=="function"&&w2ui[t].keydown.call(w2ui[t],n)}function o(n){var r=n.target.tagName,i=jQuery(n.target).parents(".w2ui-reset");i.length>0&&(t=i.attr("name"))}function i(n){if(typeof n=="undefined")return t;t=n}function r(){t=null}function u(){}var t=null;return n.active=i,n.clear=r,n.register=u,f(),n}({}),function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))},n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name")),typeof n=="string"&&w2ui[n]&&w2ui[n].destroy(),typeof n=="object"&&n.destroy()},n.fn.w2marker=function(t){return t==""||typeof t=="undefined"?n(this).each(function(n,t){t.innerHTML=t.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1")}):n(this).each(function(n,i){var f,r,u;typeof t=="string"&&(t=[t]),i.innerHTML=i.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1");for(f in t)r=t[f],typeof r!="string"&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(//g,"<"),u=new RegExp(r+"(?!([^<]+)?>)","gi"),i.innerHTML=i.innerHTML.replace(u,function(n){return''+n+""})})},n.fn.w2tag=function(t,i){if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),typeof i["class"]=="undefined"&&(i["class"]=""),n(this).length==0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");typeof r=="undefined"&&(r={}),n(n(i).data("taged-el")).removeClass(r["class"]),clearInterval(n(i).data("timer")),n(i).remove()});return}return n(this).each(function(r,u){var h=u.id,f=w2utils.escapeId(u.id),s,o;if(t==""||t==null||typeof t=="undefined")n("#w2ui-tag-"+f).css("opacity",0),setTimeout(function(){clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove()},300);else{clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n("body").append('0?"w2ui-tag-popup":"")+'" \tstyle="">'),s=setInterval(function(){if(n(u).length==0||n(u).offset().left==0&&n(u).offset().top==0){clearInterval(n("#w2ui-tag-"+f).data("timer")),e();return}n("#w2ui-tag-"+f).data("position")!=n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top&&n("#w2ui-tag-"+f).css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top)},100),setTimeout(function(){n(u).offset()&&(n("#w2ui-tag-"+f).css({opacity:"1",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).html(' '+t+" ").data("text",t).data("taged-el",u).data("options",i).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top).data("timer",s),n(u).off("keypress",e).on("keypress",e).off("change",e).on("change",e).css(i.css).addClass(i["class"]),typeof i.onShow=="function"&&i.onShow())},1),o="",n(u).length>0&&(o=n(u)[0].style.cssText);function e(){n("#w2ui-tag-"+f).length<=0||(clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n(u).off("keypress",e).removeClass(i["class"]),n(u).length>0&&(n(u)[0].style.cssText=o),typeof i.onHide=="function"&&i.onHide())}}})},n.fn.w2overlay=function(t,i){function e(){var t;(typeof i.onHide=="function"&&(t=i.onHide()),t!==!1)&&(n("#w2ui-overlay").remove(),n(document).off("click",e))}function o(){n(document).on("click",e);if(n("#w2ui-overlay > div").length>0){var u=n("#w2ui-overlay > div").height(),r=n("#w2ui-overlay> div").width(),t=window.innerHeight-n("#w2ui-overlay > div").offset().top-7;u>t&&n("#w2ui-overlay> div").height(t).width(r+w2utils.scrollBarSize()).css({"overflow-y":"auto"}),r=n("#w2ui-overlay> div").width(),t=window.innerWidth-n("#w2ui-overlay > div").offset().left-7,r>t&&n("#w2ui-overlay> div").width(t).css({"overflow-x":"auto"}),typeof i.onShow=="function"&&i.onShow()}}var u,f,r;if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),this.length==0||t==""||typeof t=="undefined")return e(),n(this);n("#w2ui-overlay").length>0&&n(document).click(),n("body").append('0?"w2ui-overlay-popup":"")+'">\t'),u=this,r=n("#w2ui-overlay div"),r.css(i.css).html(t),typeof i["class"]!="undefined"&&r.addClass(i["class"]),typeof i.top=="undefined"&&(i.top=0),typeof i.left=="undefined"&&(i.left=0),typeof i.width=="undefined"&&(i.width=100),typeof i.height=="undefined"&&(i.height=0),f=r.css("background-color"),r=n("#w2ui-overlay"),typeof f!="undefined"&&f!="rgba(0, 0, 0, 0)"&&f!="transparent"&&r.css("background-color",f);r.css({display:"none",left:n(u).offset().left+i.left+"px",top:n(u).offset().top+w2utils.getSize(n(u),"height")+3+i.top+"px","min-width":i.width?i.width:"auto","min-height":i.height?i.height:"auto"}).fadeIn("fast").data("position",n(u).offset().left+"x"+(n(u).offset().top+u.offsetHeight)).on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0});return setTimeout(o,0),n(this)},n.fn.w2menu=function(t,i){function r(){for(var f='',n,i,u,r=0;r ",n.img&&(u=''),n.icon&&(u=''),f+=""+u+"\t"+n.text+"";return f+=""}return(typeof i.select=="undefined"&&typeof i.onSelect=="function"&&(i.select=i.onSelect),typeof i.select!="function")?(console.log("ERROR: options.select is required to be a function, not "+typeof i.select+" in $().w2menu(menu, options)"),n(this)):n.isArray(t)?(n.fn.w2menuHandler=function(n,r){i.select(t[r],n,r)},n(this).w2overlay(r(),i)):(console.log("ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)"),n(this))}}(jQuery),function($){var w2grid=function(n){this.name=null,this.box=null,this.header="",this.url="",this.columns=[],this.columnGroups=[],this.records=[],this.summary=[],this.searches=[],this.searchData=[],this.sortData=[],this.postData={},this.toolbar={},this.show={header:!1,toolbar:!1,footer:!1,columnHeaders:!0,lineNumbers:!1,expandColumn:!1,selectColumn:!1,emptyRecords:!0,toolbarReload:!0,toolbarColumns:!0,toolbarSearch:!0,toolbarAdd:!1,toolbarEdit:!1,toolbarDelete:!1,toolbarSave:!1,selectionBorder:!0,recordTitles:!0},this.autoLoad=!0,this.fixedBody=!0,this.recordHeight=24,this.keyboard=!0,this.selectType="row",this.multiSearch=!0,this.multiSelect=!0,this.multiSort=!0,this.markSearchResults=!0,this.total=0,this.buffered=0,this.limit=100,this.offset=0,this.style="",this.ranges=[],this.onAdd=null,this.onEdit=null,this.onRequest=null,this.onLoad=null,this.onDelete=null,this.onDeleted=null,this.onSave=null,this.onSaved=null,this.onSelect=null,this.onUnselect=null,this.onClick=null,this.onDblClick=null,this.onColumnClick=null,this.onColumnResize=null,this.onSort=null,this.onSearch=null,this.onChange=null,this.onExpand=null,this.onCollapse=null,this.onError=null,this.onKeydown=null,this.onToolbar=null,this.onColumnOnOff=null,this.onCopy=null,this.onPaste=null,this.onSelectionExtend=null,this.onEditField=null,this.onRender=null,this.onRefresh=null,this.onReload=null,this.onResize=null,this.onDestroy=null,this.last={field:"all",caption:w2utils.lang("All Fields"),logic:"OR",search:"",searchIds:[],multi:!1,scrollTop:0,scrollLeft:0,selected:[],sortData:null,sortCount:0,xhr:null,range_start:null,range_end:null,sel_ind:null,sel_col:null,sel_type:null},this.isIOS=navigator.userAgent.toLowerCase().indexOf("iphone")!=-1||navigator.userAgent.toLowerCase().indexOf("ipod")!=-1||navigator.userAgent.toLowerCase().indexOf("ipad")!=-1?!0:!1,$.extend(!0,this,w2obj.grid,n)};$.fn.w2grid=function(n){var i,u,a,r,e,o,s;if(typeof n!="object"&&n){if(w2ui[$(this).attr("name")])return s=w2ui[$(this).attr("name")],s[n].apply(s,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+n+" does not exist on jQuery.w2grid")}else{if(!n||typeof n.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().');return}if(typeof w2ui[n.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+").");return}if(!w2utils.isAlphaNumeric(n.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var h=n.columns,l=n.columnGroups,f=n.records,c=n.searches,y=n.searchData,v=n.sortData,w=n.postData,p=n.toolbar,t=new w2grid(n);$.extend(t,{postData:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]}),t.onExpand!=null&&(t.show.expandColumn=!0),$.extend(!0,t.toolbar,p);for(i in h)t.columns[i]=$.extend(!0,{},h[i]);for(i in l)t.columnGroups[i]=$.extend(!0,{},l[i]);for(i in c)t.searches[i]=$.extend(!0,{},c[i]);for(i in y)t.searchData[i]=$.extend(!0,{},y[i]);for(i in v)t.sortData[i]=$.extend(!0,{},v[i]);t.postData=$.extend(!0,{},w);for(u in f){if(f[u].recid==null||typeof f[u].recid=="undefined"){console.log("ERROR: Cannot add records without recid. (obj: "+t.name+")");return}t.records[u]=$.extend(!0,{},f[u])}t.records.length>0&&(t.buffered=t.records.length);for(a in t.columns)(r=t.columns[a],typeof r.searchable!="undefined"&&t.getSearch(r.field)==null)&&(e=r.searchable,o="",r.searchable===!0&&(e="text",o='size="20"'),t.addSearch({field:r.field,caption:r.caption,type:e,attr:o}));return t.initToolbar(),$(this).length!=0&&t.render($(this)[0]),w2ui[t.name]=t,t}},w2grid.prototype={msgDelete:w2utils.lang("Are you sure you want to delete selected records?"),msgNotJSON:w2utils.lang("Returned data is not in valid JSON format."),msgRefresh:w2utils.lang("Refreshing..."),buttons:{reload:{type:"button",id:"reload",img:"icon-reload",hint:w2utils.lang("Reload data in the list")},columns:{type:"drop",id:"column-on-off",img:"icon-columns",hint:w2utils.lang("Show/hide columns"),arrow:!1,html:""},search:{type:"html",id:"search",html:'"},"search-go":{type:"check",id:"search-advanced",caption:w2utils.lang("Search..."),hint:w2utils.lang("Open Search Fields")},add:{type:"button",id:"add",caption:w2utils.lang("Add New"),hint:w2utils.lang("Add new record"),img:"icon-add"},edit:{type:"button",id:"edit",caption:w2utils.lang("Edit"),hint:w2utils.lang("Edit selected record"),img:"icon-edit",disabled:!0},"delete":{type:"button",id:"delete",caption:w2utils.lang("Delete"),hint:w2utils.lang("Delete selected records"),img:"icon-delete",disabled:!0},save:{type:"button",id:"save",caption:w2utils.lang("Save"),hint:w2utils.lang("Save changed records"),img:"icon-save"}},add:function(n){var i,t,r;$.isArray(n)||(n=[n]),i=0;for(t in n){if(n[t].recid==null||typeof n[t].recid=="undefined"){console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");continue}this.records.push(n[t]),i++}return this.buffered=this.records.length,r=typeof this.url!="object"?this.url:this.url.get,r||(this.localSort(),this.localSearch()),this.refresh(),i},find:function(n,t){var f,i,u,r,e;for((typeof n=="undefined"||n==null)&&(n={}),f=[],i=0;i0&&!o)for(f in this.last.searchIds)this.last.searchIds[f]==r&&(r=f);$(u).replaceWith(this.getRecordHTML(r,s))}}return!0},get:function(n,t){for(var i=0;i=0;n--)this.records[n].recid==arguments[t]&&(this.records.splice(n,1),r++);return i=typeof this.url!="object"?this.url:this.url.get,i||(this.buffered=this.records.length,this.localSort(),this.localSearch()),this.refresh(),r},addColumn:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.columns.length):(typeof n=="string"&&(n=this.getColumn(n,!0)),n===null&&(n=this.columns.length)),$.isArray(t)||(t=[t]);for(i in t)this.columns.splice(n,0,t[i]),n++,r++;return this.initColumnOnOff(),this.refresh(),r},removeColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&(this.columns.splice(n,1),i++);return this.initColumnOnOff(),this.refresh(),i},getColumn:function(n,t){for(var i=0;i=0;n--)this.columns[n].field==arguments[t]&&(this.columns[n].hidden=!this.columns[n].hidden,i++);return this.refresh(),i},showColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!1&&(this.columns[n].hidden=!1,i++);return this.refresh(),i},hideColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!0&&(this.columns[n].hidden=!0,i++);return this.refresh(),i},addSearch:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.searches.length):(typeof n=="string"&&(n=this.getSearch(n,!0)),n===null&&(n=this.searches.length)),$.isArray(t)||(t=[t]);for(i in t)this.searches.splice(n,0,t[i]),n++,r++;return this.searchClose(),r},removeSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&(this.searches.splice(n,1),i++);return this.searchClose(),i},getSearch:function(n,t){for(var i=0;i=0;n--)this.searches[n].field==arguments[t]&&(this.searches[n].hidden=!this.searches[n].hidden,i++);return this.searchClose(),i},showSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!1&&(this.searches[n].hidden=!1,i++);return this.searchClose(),i},hideSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!0&&(this.searches[n].hidden=!0,i++);return this.searchClose(),i},getSearchData:function(n){for(var t in this.searchData)if(this.searchData[t].field==n)return this.searchData[t];return null},localSort:function(n){var r=typeof this.url!="object"?this.url:this.url.get,i,t;if(r){console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");return}if(!$.isEmptyObject(this.sortData))return i=+new Date,t=this,this.records.sort(function(n,i){var e=0,f,r,u;for(f in t.sortData)if(r=n[t.sortData[f].field],u=i[t.sortData[f].field],String(t.sortData[f].field).indexOf(".")!=-1&&(r=t.parseField(n,t.sortData[f].field),u=t.parseField(i,t.sortData[f].field)),typeof r=="string"&&(r=$.trim(r.toLowerCase())),typeof u=="string"&&(u=$.trim(u.toLowerCase())),r>u&&(e=t.sortData[f].direction=="asc"?1:-1),r0&&!a){this.total=0;for(l in this.records){s=this.records[l],u=0;for(v in this.searchData)if(i=this.searchData[v],t=this.getSearch(i.field),i!=null){t==null&&(t={field:i.field,type:i.type}),f=String(c.parseField(s,t.field)).toLowerCase(),typeof i.value!="undefined"&&($.isArray(i.value)?(r=i.value[0],e=i.value[1]):r=String(i.value).toLowerCase());switch(i.operator){case"is":s[t.field]==i.value&&u++,t.type=="date"&&(o=new Date(Number(f)),f=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),r=Number(r),e=Number(f)+864e5,r>=f&&r<=e&&u++);break;case"between":t.type=="int"&&parseInt(s[t.field])>=parseInt(r)&&parseInt(s[t.field])<=parseInt(e)&&u++,t.type=="float"&&parseFloat(s[t.field])>=parseFloat(r)&&parseFloat(s[t.field])<=parseFloat(e)&&u++,t.type=="date"&&(o=new Date(Number(e)),e=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),e=Number(e)+864e5,f>=r&&f=0&&u++;break;case"ends with":f.indexOf(r)==f.length-r.length&&u++}}(this.last.logic=="OR"&&u!=0||this.last.logic=="AND"&&u==this.searchData.length)&&this.last.searchIds.push(parseInt(l))}this.total=this.last.searchIds.length}return this.buffered=this.total,h=+new Date-h,n!==!0&&setTimeout(function(){c.status("Search took "+h/1e3+" sec")},10),h},getRangeData:function(n,t){var o=this.get(n[0].recid,!0),c=this.get(n[1].recid,!0),s=n[0].column,h=n[1].column,r=[],u,f,i,e;if(s==h)for(u=o;u<=c;u++)f=this.records[u],e=f[this.columns[s].field]||null,t!==!0?r.push(e):r.push({data:e,column:s,index:u,record:f});else if(o==c)for(f=this.records[o],i=s;i<=h;i++)e=f[this.columns[i].field]||null,t!==!0?r.push(e):r.push({data:e,column:i,index:o,record:f});else for(u=o;u<=c;u++)for(f=this.records[u],r.push([]),i=s;i<=h;i++)e=f[this.columns[i].field],t!==!0?r[r.length-1].push(e):r[r.length-1].push({data:e,column:i,index:u,record:f});return r},addRange:function(n){var o=0,t,u,e,f,s;if(this.selectType=="row")return o;$.isArray(n)||(n=[n]);for(t in n){if(typeof n[t]!="object"&&(n[t]={name:"selection"}),n[t].name=="selection"){if(this.show.selectionBorder===!1)continue;if(u=this.getSelection(),u.length==0){this.removeRange(n[t].name);continue}else var i=u[0],r=u[u.length-1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]")}else var i=n[t].range[0],r=n[t].range[1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]");if(i){e={name:n[t].name,range:[{recid:i.recid,column:i.column},{recid:r.recid,column:r.column}],style:n[t].style||""},f=!1;for(s in this.ranges)if(this.ranges[s].name==n[t].name){f=t;break}f!==!1?this.ranges[f]=e:this.ranges.push(e),o++}}return this.refreshRanges(),o},removeRange:function(){for(var r=0,i,n,t=0;t=0;n--)this.ranges[n].name==i&&(this.ranges.splice(n,1),r++);return r},refreshRanges:function(){function l(t){var i=n.getSelection();n.last.move={type:"expand",x:t.screenX,y:t.screenY,divX:0,divY:0,recid:i[0].recid,column:i[0].column,originalRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}],newRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}]};$(document).off("mousemove",f).on("mousemove",f);$(document).off("mouseup",e).on("mouseup",e)}function f(t){var r=n.last.move,e,o,u,f;if(r&&r.type=="expand"&&(r.divX=t.screenX-r.x,r.divY=t.screenY-r.y,u=t.originalEvent.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(o=parseInt($(u).attr("col"))),u=$(u).parents("tr")[0],e=$(u).attr("recid"),r.newRange[1].recid!=e||r.newRange[1].column!=o)){if(f=$.extend({},r.newRange),r.newRange=[{recid:r.recid,column:r.column},{recid:e,column:o}],i=n.trigger($.extend(i,{originalRange:r.originalRange,newRange:r.newRange})),i.isCancelled===!0){r.newRange=f,i.newRange=f;return}n.removeRange("grid-selection-expand"),n.addRange({name:"grid-selection-expand",range:i.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"})}}function e(){n.removeRange("grid-selection-expand"),delete n.last.move,$(document).off("mousemove",f),$(document).off("mouseup",e),n.trigger($.extend(i,{phase:"after"}))}var n=this,a=+new Date,o=$("#grid_"+this.name+"_records"),c,i;for(c in this.ranges){var t=this.ranges[c],h=t.range[0],s=t.range[1],r=$("#grid_"+this.name+"_rec_"+h.recid+" td[col="+h.column+"]"),u=$("#grid_"+this.name+"_rec_"+s.recid+" td[col="+s.column+"]");$("#grid_"+this.name+"_"+t.name).length==0?o.append(''+(t.name=="selection"?'':"")+""):$("#grid_"+this.name+"_"+t.name).attr("style",t.style),r.length>0&&u.length>0&&$("#grid_"+this.name+"_"+t.name).css({left:r.position().left-1+o.scrollLeft()+"px",top:r.position().top-1+o.scrollTop()+"px",width:u.position().left-r.position().left+u.width()+3+"px",height:u.position().top-r.position().top+u.height()+3+"px"})}$(this.box).find("#grid_"+this.name+"_resizer").off("mousedown").on("mousedown",l);return i={phase:"before",type:"selectionExtend",target:n.name,originalRange:null,newRange:null},+new Date-a},select:function(){for(var s=0,r,o,e,f,u,i=0;i td[col="+r+"]").addClass("w2ui-selected"),s++,n.selected&&($("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)).data("selected","yes"),$("#grid_"+this.name+"_cell_"+h+"_select_check").prop("checked",!0))}this.trigger($.extend(u,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},unselect:function(){for(var s=0,f,i,h,o,r,e,t=0;t td[col="+i+"]").removeClass("w2ui-selected"),s++,r.length==0&&(n.selected=!1,$("#grid_"+this.name+"_rec_"+w2utils.escapeId(u)).removeData("selected"),$("#grid_"+this.name+"_cell_"+c+"_select_check").prop("checked",!1))}this.trigger($.extend(e,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},selectAll:function(){var r,n,u,f,t,i;if(this.multiSelect!==!1&&(r=this.trigger({phase:"before",type:"select",target:this.name,all:!0}),r.isCancelled!==!0)){n=[];for(u in this.columns)n.push(parseInt(u));if(f=typeof this.url!="object"?this.url:this.url.get,f)this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()}),this.refresh();else if(this.searchData.length==0)this.set({selected:!0}),this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()});else{for(t=0;t=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"),this.addRange("selection"),this.trigger($.extend(r,{phase:"after"}))}},selectNone:function(){var f=this.trigger({phase:"before",type:"unselect",target:this.name,all:!0}),r,n,t,i,u;if(f.isCancelled!==!0){this.last.selected=[];for(r in this.records)if(n=this.records[r],n.selected===!0&&(n.selected=!1,t=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.recid)),t.removeClass("w2ui-selected").removeData("selected"),$("#grid_"+this.name+"_cell_"+r+"_select_check").prop("checked",!1),this.selectType!="row")){i=n.selectedColumns;for(u in i)t.find(" > td[col="+i[u]+"]").removeClass("w2ui-selected");n.selectedColumns=[]}this.toolbar.disable("edit","delete"),this.removeRange("selection"),this.trigger($.extend(f,{phase:"after"}))}},getSelection:function(n){var t,i,r,u,f;if(this.selectType=="row"){t=this.find({selected:!0},!0),i=[];for(r in t)n===!0?i.push(t[r]):i.push(this.records[t[r]].recid);return i}t=this.find({selected:!0},!0),i=[];for(r in t){u=this.records[t[r]];for(f in u.selectedColumns)i.push({recid:u.recid,index:parseInt(t[r]),column:u.selectedColumns[f]})}return i},search:function(n,t){var it=this,nt=typeof this.url!="object"?this.url:this.url.get,u=[],v=this.last.multi,a=this.last.logic,g=this.last.field,p=this.last.search,f,d,h,s,c,r,o,k,b,i,y;if(arguments.length==0){p="";for(f in this.searches){var i=this.searches[f],l=$("#grid_"+this.name+"_operator_"+f).val(),e=$("#grid_"+this.name+"_field_"+f).val(),w=$("#grid_"+this.name+"_field2_"+f).val();if(e!=""&&e!=null||typeof w!="undefined"&&w!=""){r={field:i.field,type:i.type,operator:l},l=="between"?$.extend(r,{value:[e,w]}):l=="in"?$.extend(r,{value:e.split(",")}):$.extend(r,{value:e});try{i.type=="date"&&l=="between"&&(r.value[0]=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime(),r.value[1]=w2utils.isDate(w,w2utils.settings.date_format,!0).getTime()),i.type=="date"&&l=="is"&&(r.value=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime())}catch(tt){}u.push(r)}}u.length>0&&!nt?(v=!0,a="AND"):(v=!0,a="AND")}if(typeof n=="string"&&(g=n,p=t,v=!1,a="OR",typeof t!="undefined"))if(n.toLowerCase()=="all")if(this.searches.length>0)for(f in this.searches)i=this.searches[f],(i.type=="text"||i.type=="int"&&w2utils.isInt(t)||i.type=="float"&&w2utils.isFloat(t)||i.type=="money"&&w2utils.isMoney(t)||i.type=="hex"&&w2utils.isHex(t)||i.type=="date"&&w2utils.isDate(t)||i.type=="alphaNumeric"&&w2utils.isAlphaNumeric(t))&&(r={field:i.field,type:i.type,operator:i.type=="text"?"contains":"is",value:t},u.push(r)),i.type=="int"&&String(t).indexOf("-")!=-1&&(c=String(t).split("-"),r={field:i.field,type:i.type,operator:"between",value:[c[0],c[1]]},u.push(r));else for(d in this.columns)r={field:this.columns[d].field,type:"text",operator:"contains",value:t},u.push(r);else if(i=this.getSearch(n),i==null&&(i={field:n,type:"text"}),i.field==n&&(this.last.caption=i.caption),t!=""){if(h="contains",s=t,w2utils.isInt(t)&&(h="is",s=t),i.type=="int"&&t!=""&&(String(t).indexOf("-")!=-1&&(r=t.split("-"),r.length==2&&(h="between",s=[parseInt(r[0]),parseInt(r[1])])),String(t).indexOf(",")!=-1)){r=t.split(","),h="in",s=[];for(c in r)s.push(r[c])}r={field:i.field,type:i.type,operator:h,value:s},u.push(r)}if($.isArray(n)){o="AND",typeof t=="string"&&(o=t.toUpperCase(),o!="OR"&&o!="AND"&&(o="AND")),p="",v=!0,a=o;for(k in n)b=n[k],i=this.getSearch(b.field),i==null&&(i={type:"text",operator:"contains"}),u.push($.extend(!0,{},i,b))}(y=this.trigger({phase:"before",type:"search",target:this.name,searchData:u,searchField:n?n:"multi",searchValue:t?t:"multi"}),y.isCancelled!==!0)&&(this.searchData=y.searchData,this.last.field=g,this.last.search=p,this.last.multi=v,this.last.logic=a,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),this.set({expanded:!1}),nt?(this.last.xhr_offset=0,this.reload()):(this.localSearch(),this.refresh()),this.trigger($.extend(y,{phase:"after"})))},searchOpen:function(){if(this.box&&this.searches.length!=0){var n=this;$("#tb_"+this.name+"_toolbar_item_search-advanced").w2overlay(this.getSearchesHTML(),{left:-10,"class":"w2ui-grid-searches",onShow:function(){n.last.logic=="OR"&&(n.searchData=[]),n.initSearches(),$("#w2ui-overlay .w2ui-grid-searches").data("grid-name",n.name);var t=$("#w2ui-overlay .w2ui-grid-searches *[rel=search]");t.length>0&&t[0].focus()}})}},searchClose:function(){this.box&&this.searches.length!=0&&(this.toolbar&&this.toolbar.uncheck("search-advanced"),$("#w2ui-overlay .w2ui-grid-searches").length>0&&$().w2overlay())},searchShowFields:function(n){var r,i,t;for(typeof n=="undefined"&&(n=$("#grid_"+this.name+"_search_all")),r='',i=-1;i"+t.caption+""}r+="",$(n).w2overlay(r,{left:-15,top:7})},searchReset:function(n){var t=this.trigger({phase:"before",type:"search",target:this.name,searchData:[]});t.isCancelled!==!0&&(this.searchData=[],this.last.search="",this.last.logic="OR",this.last.multi&&(this.multiSearch?(this.last.field="all",this.last.caption=w2utils.lang("All Fields")):(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption)),this.last.multi=!1,this.last.xhr_offset=0,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),n||this.reload(),this.trigger($.extend(t,{phase:"after"})))},clear:function(n){this.offset=0,this.total=0,this.buffered=0,this.records=[],this.summary=[],this.last.scrollTop=0,this.last.scrollLeft=0,this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,n||this.refresh()},reset:function(n){this.offset=0,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,this.searchReset(n),this.last.sortData!=null&&(this.sortData=this.last.sortData),this.set({selected:!1,expanded:!1},!0),n||this.refresh()},skip:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.offset=parseInt(n),(this.offset<0||!w2utils.isInt(this.offset))&&(this.offset=0),this.offset>this.total&&(this.offset=this.total-this.limit),this.records=[],this.buffered=0,this.last.xhr_offset=0,this.last.pull_more=!0,this.last.scrollTop=0,this.last.scrollLeft=0,$("#grid_"+this.name+"_records").prop("scrollTop",0),this.initColumnOnOff(),this.reload()):console.log("ERROR: grid.skip() can only be called when you have remote data source.")},load:function(n,t){if(typeof n=="undefined"){console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.');return}this.request("get-records",{},n,t)},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.last.xhr_offset>0&&this.last.xhr_offset div"),o.type=="enum"&&console.log("ERROR: Grid's inline editing does not support enum field type."),(o.type=="list"||o.type=="select")&&console.log("ERROR: Grid's inline editing does not support list/select field type."),typeof o.inTag=="undefined"&&(o.inTag=""),typeof o.outTag=="undefined"&&(o.outTag=""),typeof o.style=="undefined"&&(o.style=""),typeof o.items=="undefined"&&(o.items=[]),h=f.changed&&f.changes[e.field]?w2utils.stripTags(f.changes[e.field]):w2utils.stripTags(f[e.field]),(h==null||typeof h=="undefined")&&(h=""),typeof i!="undefined"&&i!=null&&(h=i),v=typeof e.style!="undefined"?e.style+";":"",$.inArray(e.render,["number","int","float","money","percent"])!=-1&&(v+="text-align: right;"),c.addClass("w2ui-editable").html('"+o.outTag);c.find("input").w2field(o.type).on("blur",function(){if(u.parseField(f,e.field)!=this.value){var r=u.trigger({phase:"before",type:"change",target:u.name,input_id:this.id,recid:n,column:t,value_new:this.value,value_previous:f.changes?f.changes[e.field]:u.parseField(f,e.field),value_original:u.parseField(f,e.field)});r.isCancelled===!0||(f.changed=!0,f.changes=f.changes||{},f.changes[e.field]=r.value_new,u.trigger($.extend(r,{phase:"after"})))}else f.changes&&delete f.changes[e.field],$.isEmptyObject(f.changes)&&delete f.changes;$(a).replaceWith(u.getRecordHTML(s,a.attr("line")))}).on("keydown",function(i){function a(n){var t=n+1;return u.columns.length==t?n:u.columns[t].hidden?a(t):t}function v(n){var t=n-1;return t<0?n:u.columns[t].hidden?v(t):t}function c(n){var t=n+1;return u.records.length==t?n:t}function l(n){var t=n-1;return t<0?n:t}var o=!1,r,h;switch(i.keyCode){case 9:o=!0,r=i.shiftKey?v(t):a(t),r!=t&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:n,column:r})):u.editField(n,r,null,i)},1));break;case 13:o=!0,r=i.shiftKey?l(s):c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 38:o=!0,r=l(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 40:o=!0,r=c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 27:h=f.changed&&f.changes[e.field]?f.changes[e.field]:u.parseField(f,e.field),this.value=typeof h!="undefined"?h:"",this.blur(),setTimeout(function(){u.select({recid:n,column:t})},1)}o&&i.preventDefault&&i.preventDefault()});typeof i=="undefined"||i==null?c.find("input").focus():c.find("input").val("").focus().val(i),u.trigger($.extend(l,{phase:"after"}))}},"delete":function(n){var o=this,f=this.trigger({phase:"before",target:this.name,type:"delete",force:n}),t,e,u,r,i;if(f.isCancelled===!0)return!1;if(n=f.force,t=this.getSelection(),t.length!=0){if(this.msgDelete!=""&&!n){w2confirm(o.msgDelete,w2utils.lang("Delete Confirmation"),function(n){n=="Yes"&&w2ui[o.name].delete(!0)});return}if(e=typeof this.url!="object"?this.url:this.url.remove,e)this.request("delete-records");else if(typeof t[0]!="object")this.remove.apply(this,t);else{for(u in t)r=this.columns[t[u].column].field,i=this.get(t[u].recid,!0),i!=null&&r!="recid"&&(this.records[i][r]="",this.records[i].changed&&(this.records[i].changes[r]=""));this.refresh()}this.trigger($.extend(f,{phase:"after"}))}},click:function(n,t){var g=+new Date,i=null,b,c,nt,f,r,p,y,a,h,s,v,u,tt,e,k,o;if(typeof n=="object"&&(i=n.column,n=n.recid),w2utils.isInt(n)&&(n=parseInt(n)),typeof t=="undefined"&&(t={}),g-parseInt(this.last.click_time)<250&&t.type=="click"){this.dblClick(n,t);return}if(this.last.click_time=g,i==null&&t.target&&(u=t.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(i=parseInt($(u).attr("col")))),b=this.trigger({phase:"before",target:this.name,type:"click",recid:n,column:i,originalEvent:t}),b.isCancelled===!0)return!1;c=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n)).parents("tr"),c.length>0&&String(c.attr("id")).indexOf("expanded_row")!=-1&&(nt=c.parents(".w2ui-grid").attr("name"),w2ui[nt].selectNone(),c.parents(".w2ui-grid").find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()})),$(this.box).find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()}),f=this,r=this.getSelection(),$("#grid_"+this.name+"_check_all").prop("checked",!1);var d=this.get(n,!0),l=this.records[d],w=[];if(f.last.sel_ind=d,f.last.sel_col=i,f.last.sel_recid=n,f.last.sel_type="click",t.shiftKey&&r.length>0){if(r[0].recid)for(h=this.get(r[0].recid,!0),s=this.get(n,!0),i>r[0].column?(p=r[0].column,y=i):(p=i,y=r[0].column),a=p;a<=y;a++)w.push(a);else h=this.get(r[0],!0),s=this.get(n,!0);for(v=[],h>s&&(u=h,h=s,s=u),tt=typeof this.url!="object"?this.url:this.url.get,e=h;e<=s;e++)if(!(this.searchData.length>0)||tt||$.inArray(e,this.last.searchIds)!=-1)if(this.selectType=="row")v.push(this.records[e].recid);else for(k in w)v.push({recid:this.records[e].recid,column:w[k]});this.select.apply(this,v)}else(t.ctrlKey||t.shiftKey||t.metaKey)&&this.multiSelect||this.showSelectColumn?(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),o===!0?this.unselect({recid:n,column:i}):this.select({recid:l.recid,column:i}),setTimeout(function(){window.getSelection&&window.getSelection().removeAllRanges()},10)):(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),r.length>300?this.selectNone():this.unselect.apply(this,r),o===!0?this.unselect({recid:n,column:i}):this.select({recid:n,column:i}));this.status(),f.last.selected=this.getSelection(),f.initResize(),this.trigger($.extend(b,{phase:"after"}))},columnClick:function(n,t){var i=this.trigger({phase:"before",type:"columnClick",target:this.name,field:n,originalEvent:t});if(i.isCancelled===!0)return!1;this.sort(n,null,t&&(t.ctrlKey||t.metaKey)?!0:!1),this.trigger($.extend(i,{phase:"after"}))},keydown:function(n){function st(n){if(n+10&&n0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n>t.records.length)break;n++}return n}return null}function ht(n){if(n>0&&t.last.searchIds.length==0||t.last.searchIds.length>0&&n>t.last.searchIds[0]){if(n--,t.last.searchIds.length>0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n<0)break;n--}return n}return null}function et(n){var i=n+1;return t.columns.length==i?n:t.columns[i].hidden?findNext(i):i}function ot(n){var i=n-1;return i<0?n:t.columns[i].hidden?findPrev(i):i}function g(){if(t.last.sel_type!="click")return!1;if(t.selectType!="row"){if(t.last.sel_type="key",i.length>1){for(var n in i)if(i[n].recid==t.last.sel_recid&&i[n].column==t.last.sel_col){i.splice(n,1);break}return t.unselect.apply(t,i),!0}return!1}return(t.last.sel_type="key",i.length>1)?(i.splice(i.indexOf(t.records[t.last.sel_ind].recid),1),t.unselect.apply(t,i),!0):!1}var t=this,it,b,i,c,y,d,a,v,h,l,f,o,rt,e,u;if(t.keyboard===!0){if(it=t.trigger({phase:"before",type:"keydown",target:t.name,originalEvent:n}),it.isCancelled===!0)return!1;if(i=t.getSelection(),i.length!=0){var ct=$("#grid_"+t.name+"_records"),f=i[0],r=[],ft=i[i.length-1];if(typeof f=="object"){for(f=i[0].recid,r=[],b=0;;){if(!i[b]||i[b].recid!=f)break;r.push(i[b].column),b++}ft=i[i.length-1].recid}var p=t.get(f,!0),w=t.get(ft,!0),ut=t.get(f),k=$("#grid_"+t.name+"_rec_"+w2utils.escapeId(t.records[p].recid)),s=!1;switch(n.keyCode){case 8:case 46:t.delete(),s=!0,n.stopPropagation();break;case 27:i=t.getSelection(),t.selectNone(),i.length>0&&(typeof i[0]=="object"?t.select({recid:i[0].recid,column:i[0].column}):t.select(i[0])),s=!0;break;case 13:case 32:r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 65:if(!n.metaKey&&!n.ctrlKey)break;t.selectAll(),s=!0;break;case 70:if(!n.metaKey&&!n.ctrlKey)break;$("#grid_"+t.name+"_search_all").focus(),s=!0;break;case 13:if(this.selectType=="row"){if(k.length<=0||t.show.expandColumn!==!0)break;t.toggle(f,n),s=!0}else r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 37:if(l=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[p].recid)).parents("tr"),l.length>0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].set(f,{expanded:!1}),w2ui[o].collapse(f),w2ui[o].click(f),s=!0;break}if(this.selectType=="row"){if(k.length<=0||ut.expanded!==!0)break;t.set(f,{expanded:!1},!0),t.collapse(f,n)}else if(c=ot(r[0]),c!=r[0])if(n.shiftKey){if(g())return;var u=[],tt=[],nt=[];if(r.indexOf(this.last.sel_col)==0&&r.length>1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[r.length-1]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:c});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:c},n);else if(!n.shiftKey)for(h=1;h1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[0]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:a});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:a},n);else if(!n.shiftKey)for(h=0;h0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[d.length-1].recid),s=!0;break}if(n.shiftKey){if(g())return;if(t.selectType=="row")t.last.sel_ind>c&&t.last.sel_ind!=w?t.unselect(t.records[w].recid):t.select(t.records[c].recid);else if(t.last.sel_ind>c&&t.last.sel_ind!=w){c=w,u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.unselect.apply(t,u)}else{u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.select.apply(t,u)}}else t.selectNone(),t.click({recid:t.records[c].recid,column:r[0]},n);t.scrollIntoView(c),n.preventDefault&&n.preventDefault()}else{if(!n.shiftKey)for(h=1;h0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 40:if(k.length<=0)break;if(t.records[w].expanded&&(y=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[w].recid)+"_expanded_row").find(".w2ui-grid"),y.length>0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[0].recid),s=!0;break}if(a=st(w),a!=null){if(n.shiftKey){if(g())return;if(t.selectType=="row")this.last.sel_ind0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.next().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 86:(n.ctrlKey||n.metaKey)&&($("body").append(''),$("#_tmp_copy_data").focus(),setTimeout(function(){t.paste($("#_tmp_copy_data").val()),$("#_tmp_copy_data").remove()},50));break;case 88:(n.ctrlKey||n.metaKey)&&setTimeout(function(){t.delete(!0)},100);case 67:(n.ctrlKey||n.metaKey)&&(rt=t.copy(),$("body").append(''+rt+""),$("#_tmp_copy_data").focus().select(),setTimeout(function(){$("#_tmp_copy_data").remove()},50))}for(u=[187,189],e=48;e<=90;e++)u.push(e);u.indexOf(n.keyCode)==-1||n.ctrlKey||n.metaKey||s||(r.length==0&&r.push(0),u=String.fromCharCode(n.keyCode),n.keyCode==187&&(u="="),n.keyCode==189&&(u="-"),n.shiftKey||(u=u.toLowerCase()),t.editField(f,r[0],u,n),s=!0),s&&n.preventDefault&&n.preventDefault(),t.trigger($.extend(it,{phase:"after"}))}}},scrollIntoView:function(n){var f,t,r,i,u;if(typeof n=="undefined"){if(f=this.getSelection(),f.length==0)return;n=this.get(f[0],!0)}(t=$("#grid_"+this.name+"_records"),t.length!=0)&&((r=this.last.searchIds.length,t.height()>this.recordHeight*(r>0?r:this.records.length))||(r>0&&(n=this.last.searchIds.indexOf(n)),i=Math.floor(t[0].scrollTop/this.recordHeight),u=i+Math.floor(t.height()/this.recordHeight),n==i&&t.animate({scrollTop:t.scrollTop()-t.height()/1.3}),n==u&&t.animate({scrollTop:t.scrollTop()+t.height()/1.3}),(nu)&&t.animate({scrollTop:(n-1)*this.recordHeight})))},dblClick:function(n,t){var i,r,f,u;if(window.getSelection&&window.getSelection().removeAllRanges(),i=null,typeof n=="object"&&(i=n.column,n=n.recid),typeof t=="undefined"&&(t={}),i==null&&t.target&&(r=t.target,r.tagName!="TD"&&(r=$(r).parents("td")[0]),i=parseInt($(r).attr("col"))),f=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:n,column:i,originalEvent:t}),f.isCancelled===!0)return!1;this.selectNone(),u=this.columns[i],u&&$.isPlainObject(u.editable)?this.editField(n,i,null,t):(this.select({recid:n,column:i}),this.last.selected=this.getSelection()),this.trigger($.extend(f,{phase:"after"}))},toggle:function(n){var t=this.get(n);return t.expanded===!0?this.collapse(n):this.expand(n)},expand:function(n){function u(){var r=$("#grid_"+i.name+"_rec_"+t+"_expanded"),u=$("#grid_"+i.name+"_rec_"+t+"_expanded_row .w2ui-expanded1 > div");r.height()<5||(r.css("opacity",1),u.show().css("opacity",1),$("#grid_"+i.name+"_cell_"+i.get(n,!0)+"_expand div").html("-"))}var e=this.get(n),i=this,t=w2utils.escapeId(n),o,f,r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length>0?!1:e.expanded=="none"?!1:(o=1+(this.show.selectColumn?1:0),f="",$("#grid_"+this.name+"_rec_"+t).after(''+(this.show.lineNumbers?'':"")+'\t\t\t\t\t'),r=this.trigger({phase:"before",type:"expand",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded",ready:u}),r.isCancelled===!0)?($("#grid_"+this.name+"_rec_"+t+"_expanded_row").remove(),!1):($("#grid_"+this.name+"_rec_"+t).attr("expanded","yes").addClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded_row").show(),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html(''),e.expanded=!0,setTimeout(u,300),this.trigger($.extend(r,{phase:"after"})),this.resizeRecords(),!0)},collapse:function(n){var u=this.get(n),i=this,t=w2utils.escapeId(n),r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length==0?!1:(r=this.trigger({phase:"before",type:"collapse",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded"}),r.isCancelled===!0)?!1:($("#grid_"+this.name+"_rec_"+t).removeAttr("expanded").removeClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded").css("opacity",0),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html("+"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded").height("0px"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded_row").remove(),delete u.expanded,i.trigger($.extend(r,{phase:"after"})),i.resizeRecords()},300)},200),!0)},sort:function(n,t,i){var f=this.trigger({phase:"before",type:"sort",target:this.name,field:n,direction:t,multiField:i}),r,u,e;if(f.isCancelled===!0)return!1;if(typeof n!="undefined"){r=this.sortData.length;for(u in this.sortData)if(this.sortData[u].field==n){r=u;break}if(typeof t=="undefined"||t==null)if(typeof this.sortData[r]=="undefined")t="asc";else switch(String(this.sortData[r].direction)){case"asc":t="desc";break;case"desc":t="asc";break;default:t="asc"}this.multiSort===!1&&(this.sortData=[],r=0),i!=!0&&(this.sortData=[],r=0),typeof this.sortData[r]=="undefined"&&(this.sortData[r]={}),this.sortData[r].field=n,this.sortData[r].direction=t}else this.sortData=[];e=typeof this.url!="object"?this.url:this.url.get,e?(this.trigger($.extend(f,{phase:"after"})),this.last.xhr_offset=0,this.reload()):(this.localSort(),this.searchData.length>0&&this.localSearch(!0),this.trigger($.extend(f,{phase:"after"})),this.refresh())},copy:function(){var t=this.getSelection(),n,c,i,f,r,o,e;if(t.length==0)return"";if(n="",typeof t[0]=="object"){var s=t[0].column,h=t[0].column,u=[];for(i in t)t[i].columnh&&(h=t[i].column),u.indexOf(t[i].index)==-1&&u.push(t[i].index);u.sort();for(c in u){for(f=u[c],r=s;r<=h;r++)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}}else for(i in t){f=this.get(t[i],!0);for(r in this.columns)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}return(n=n.substr(0,n.length-1),e=this.trigger({phase:"before",type:"copy",target:this.name,text:n}),e.isCancelled===!0)?"":(n=e.text,this.trigger($.extend(e,{phase:"after"})),n)},paste:function(n){var e=this.getSelection(),o=this.get(e[0].recid,!0),u=e[0].column,i=this.trigger({phase:"before",type:"paste",target:this.name,text:n,index:o,column:u}),s,n,a,l,c,h;if(i.isCancelled!==!0){if(n=i.text,this.selectType=="row"||e.length==0){console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected."),this.trigger($.extend(i,{phase:"after"}));return}s=[],n=n.split("\n");for(a in n){var v=n[a].split("\t"),r=0,t=this.records[o],f=[];for(l in v)this.columns[u+r]&&(c=this.columns[u+r].field,t.changed=!0,t.changes=t.changes||{},t.changes[c]=v[l],f.push(u+r),r++);for(h in f)s.push({recid:t.recid,column:f[h]});o++}this.selectNone(),this.select.apply(this,s),this.refresh(),this.trigger($.extend(i,{phase:"after"}))}},resize:function(){var t=this,i=+new Date,n;if(window.getSelection&&window.getSelection().removeAllRanges(),this.box&&$(this.box).attr("name")==this.name)return($(this.box).find("> div").css("width",$(this.box).width()).css("height",$(this.box).height()),n=this.trigger({phase:"before",type:"resize",target:this.name}),n.isCancelled===!0)?!1:(t.resizeBoxes(),t.resizeRecords(),this.trigger($.extend(n,{phase:"after"})),+new Date-i)},refresh:function(){var n=this,h=+new Date,c=typeof this.url!="object"?this.url:this.url.get,o,u,t,r,f,i,e,s;if(this.total<=0&&!c&&this.searchData.length==0&&(this.total=this.records.length,this.buffered=this.total),window.getSelection&&window.getSelection().removeAllRanges(),this.toolbar.disable("edit","delete"),this.box){if(o=this.trigger({phase:"before",target:this.name,type:"refresh"}),o.isCancelled===!0)return!1;this.show.header?$("#grid_"+this.name+"_header").html(this.header+" ").show():$("#grid_"+this.name+"_header").hide(),this.show.toolbar?this.toolbar&&this.toolbar.get("column-on-off")&&this.toolbar.get("column-on-off").checked||($("#grid_"+this.name+"_toolbar").show(),typeof this.toolbar=="object"&&(this.toolbar.refresh(),t=$("#grid_"+n.name+"_search_all"),t.val(this.last.search))):$("#grid_"+this.name+"_toolbar").hide(),this.searchClose(),u=$("#grid_"+n.name+"_search_all"),this.searches.length==0&&(this.last.field="all"),!this.multiSearch&&this.last.field=="all"&&this.searches.length>0&&(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption);for(i in this.searches)this.searches[i].field==this.last.field&&(this.last.caption=this.searches[i].caption);if(this.last.multi?u.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]"):u.attr("placeholder",this.last.caption),this._focus_when_refreshed===!0&&(clearTimeout(n._focus_timer),n._focus_timer=setTimeout(function(){u.length>0&&u[0].focus(),delete n._focus_when_refreshed,delete n._focus_timer},600)),t=this.find({summary:!0},!0),t.length>0){for(r in t)this.summary.push(this.records[t[r]]);for(r=t.length-1;r>=0;r--)this.records.splice(t[r],1);this.total=this.total-t.length,this.buffered=this.buffered-t.length}if(f="",f+='"+this.getRecordsHTML()+'\t'+this.getColumnsHTML()+"",$("#grid_"+this.name+"_body").html(f),this.summary.length>0?$("#grid_"+this.name+"_summary").html(this.getSummaryHTML()).show():$("#grid_"+this.name+"_summary").hide(),this.show.footer?$("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show():$("#grid_"+this.name+"_footer").hide(),this.last.selected.length>0)for(i in this.last.selected)this.get(this.last.selected[i])!=null&&this.select(this.get(this.last.selected[i]).recid);this.searchData.length>0?$("#grid_"+this.name+"_searchClear").show():$("#grid_"+this.name+"_searchClear").hide(),$("#grid_"+this.name+"_check_all").prop("checked",!0),$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),e=n.find({expanded:!0},!0);for(s in e)n.records[e[s]].expanded=!1;return setTimeout(function(){var t=$.trim($("#grid_"+n.name+"_search_all").val());t!=""&&$(n.box).find(".w2ui-grid-data > div").w2marker(t)},50),this.trigger($.extend(o,{phase:"after"})),n.resize(),n.addRange("selection"),setTimeout(function(){n.resize(),n.scroll()},1),+new Date-h}},render:function(n){function e(n){if(!t.last.move||t.last.move.type!="expand"){t.last.move={x:n.screenX,y:n.screenY,divX:0,divY:0,recid:$(n.target).parents("tr").attr("recid"),column:n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"),type:"select",start:!0};$(document).on("mousemove",r);$(document).on("mouseup",u)}}function r(n){var i,y,o,v,u,s,r,e,f;if(t.last.move&&t.last.move.type=="select"&&(t.last.move.divX=n.screenX-t.last.move.x,t.last.move.divY=n.screenY-t.last.move.y,!(Math.abs(t.last.move.divX)<=1)||!(Math.abs(t.last.move.divY)<=1))&&(t.last.move.start&&t.last.move.recid&&(t.selectNone(),t.last.move.start=!1),i=[],y=n.target.tagName=="TR"?$(n.target).attr("recid"):$(n.target).parents("tr").attr("recid"),typeof y!="undefined")){var h=t.get(t.last.move.recid,!0),l=t.get(y,!0),a=parseInt(t.last.move.column),c=parseInt(n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"));if(h>l&&(u=h,h=l,l=u),u="ind1:"+h+",ind2;"+l+",col1:"+a+",col2:"+c,t.last.move.range!=u){for(t.last.move.range=u,o=h;o<=l;o++)if(!(t.last.searchIds.length>0)||t.last.searchIds.indexOf(o)!=-1)if(t.selectType!="row")for(a>c&&(u=a,a=c,c=u),u=[],v=a;v<=c;v++)t.columns[v].hidden||i.push({recid:t.records[o].recid,column:parseInt(v)});else i.push(t.records[o].recid);if(t.selectType!="row"){r=t.getSelection(),u=[];for(e in i){s=!1;for(f in r)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:i[e].recid,column:i[e].column})}t.select.apply(t,u),u=[];for(f in r){s=!1;for(e in i)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:r[f].recid,column:r[f].column})}t.unselect.apply(t,u)}else if(t.multiSelect){r=t.getSelection();for(e in i)r.indexOf(i[e])==-1&&t.select(i[e]);for(f in r)i.indexOf(r[f])==-1&&t.unselect(r[f])}}}}function u(){t.last.move&&t.last.move.type=="select"&&(delete t.last.move,$(document).off("mousemove",r),$(document).off("mouseup",u))}var t=this,f=+new Date,i;if(window.getSelection&&window.getSelection().removeAllRanges(),typeof n!="undefined"&&n!=null&&($(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),this.box=n),this.box){if(this.last.sortData==null&&(this.last.sortData=this.sortData),i=this.trigger({phase:"before",target:this.name,type:"render",box:n}),i.isCancelled===!0)return!1;$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html('\t\t\t\t\t'),this.selectType!="row"&&$(this.box).addClass("w2ui-ss"),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.initToolbar(),this.toolbar!=null&&this.toolbar.render($("#grid_"+this.name+"_toolbar")[0]),$("#grid_"+this.name+"_footer").html(this.getFooterHTML()),this.refresh(),this.reload();$(this.box).on("mousedown",e);$(this.box).on("selectstart",function(){return!1});if(this.trigger($.extend(i,{phase:"after"})),$(".w2ui-layout").length==0){this.tmp_resize=function(){w2ui[t.name].resize()};$(window).off("resize",this.tmp_resize).on("resize",this.tmp_resize)}return+new Date-f}},destroy:function(){var n=this.trigger({phase:"before",target:this.name,type:"destroy"});if(n.isCancelled===!0)return!1;$(window).off("resize",this.tmp_resize),typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),$(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),delete w2ui[this.name],this.trigger($.extend(n,{phase:"after"}))},initColumnOnOff:function(){var i,n,t,r,u;if(this.show.toolbarColumns){i=this,n='';for(t in this.columns)r=this.columns[t],n+='\t\t'+(this.columns[t].caption==""?"- column "+(t+1)+" -":this.columns[t].caption)+"";n+='',u=typeof this.url!="object"?this.url:this.url.get,u&&(n+='\t\t\t'+w2utils.lang("Skip")+' "+w2utils.lang("Records")+"\t"),n+='\t"+w2utils.lang("Toggle Line Numbers")+'\t"+w2utils.lang("Reset Column Size")+"",n+="",this.toolbar.get("column-on-off").html=n}},columnOnOff:function(n,t,i,r){var h=this.trigger({phase:"before",target:this.name,type:"columnOnOff",checkbox:n,field:i,originalEvent:t}),o,s,e,u,f;if(h.isCancelled===!0)return!1;o=this;for(s in this.records)this.records[s].expanded===!0&&(this.records[s].expanded=!1);if(e=!0,i=="line-numbers")this.show.lineNumbers=!this.show.lineNumbers,this.refresh();else if(i=="skip")w2utils.isInt(r)||(r=0),o.skip(r);else if(i=="resize"){for(u in this.columns)typeof this.columns[u].sizeOriginal!="undefined"&&(this.columns[u].size=this.columns[u].sizeOriginal);this.initResize(),this.resize()}else f=this.getColumn(i),f.hidden?($(n).prop("checked",!0),this.showColumn(f.field)):($(n).prop("checked",!1),this.hideColumn(f.field)),e=!1;this.initColumnOnOff(),e&&setTimeout(function(){$().w2overlay(),o.toolbar.uncheck("column-on-off")},100),this.trigger($.extend(h,{phase:"after"}))},initToolbar:function(){var t,i,r,n;if(typeof this.toolbar.render=="undefined"){t=this.toolbar.items,this.toolbar.items=[],this.toolbar=$().w2toolbar($.extend(!0,{},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.show.toolbarReload&&this.toolbar.items.push($.extend(!0,{},this.buttons.reload)),this.show.toolbarColumns&&(this.toolbar.items.push($.extend(!0,{},this.buttons.columns)),this.initColumnOnOff()),(this.show.toolbarReload||this.show.toolbarColumn)&&this.toolbar.items.push({type:"break",id:"break0"}),this.show.toolbarSearch&&(i='\t'+this.buttons.search.html+'\t\t\t\t\t\t\t \t",this.toolbar.items.push({type:"html",id:"search",html:i}),this.multiSearch&&this.searches.length>0&&this.toolbar.items.push($.extend(!0,{},this.buttons["search-go"]))),this.show.toolbarSearch&&(this.show.toolbarAdd||this.show.toolbarEdit||this.show.toolbarDelete||this.show.toolbarSave)&&this.toolbar.items.push({type:"break",id:"break1"}),this.show.toolbarAdd&&this.toolbar.items.push($.extend(!0,{},this.buttons.add)),this.show.toolbarEdit&&this.toolbar.items.push($.extend(!0,{},this.buttons.edit)),this.show.toolbarDelete&&this.toolbar.items.push($.extend(!0,{},this.buttons["delete"])),this.show.toolbarSave&&((this.show.toolbarAdd||this.show.toolbarDelete||this.show.toolbarEdit)&&this.toolbar.items.push({type:"break",id:"break2"}),this.toolbar.items.push($.extend(!0,{},this.buttons.save)));for(r in t)this.toolbar.items.push(t[r]);n=this;this.toolbar.on("click",function(t){var i=n.trigger({phase:"before",type:"toolbar",target:t.target,originalEvent:t}),r,s,h,u,f,c,e,o;if(i.isCancelled===!0)return!1;r=t.target;switch(r){case"reload":if(s=n.trigger({phase:"before",type:"reload",target:n.name}),s.isCancelled===!0)return!1;h=typeof n.url!="object"?n.url:n.url.get,h?n.clear(!0):(n.last.scrollTop=0,n.last.scrollLeft=0,n.last.range_start=null,n.last.range_end=null),n.reload(),n.trigger($.extend(s,{phase:"after"}));break;case"column-on-off":for(u in n.columns)n.columns[u].hidden?$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!1):$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!0);n.initResize(),n.resize();break;case"search-advanced":if(f=this,c=this.get(r),c.checked)n.searchClose(),setTimeout(function(){f.uncheck(r)},1);else{n.searchOpen(),t.originalEvent.stopPropagation();function l(){f.uncheck(r),$(document).off("click","body",l)}$(document).on("click","body",l)}break;case"add":i=n.trigger({phase:"before",target:n.name,type:"add",recid:null}),n.trigger($.extend(i,{phase:"after"}));break;case"edit":e=n.getSelection(),o=null,e.length==1&&(o=e[0]),i=n.trigger({phase:"before",target:n.name,type:"edit",recid:o}),n.trigger($.extend(i,{phase:"after"}));break;case"delete":n.delete();break;case"save":n.save()}n.trigger($.extend(i,{phase:"after"}))})}return},initSearches:function(){var o=this,t,n,r,e,i,u,f;for(t in this.searches){n=this.searches[t],r=this.getSearchData(n.field);switch(String(n.type).toLowerCase()){case"alphaNumeric":case"text":$("#grid_"+this.name+"_operator_"+t).val("begins with");break;case"int":case"float":case"hex":case"money":case"date":$("#grid_"+this.name+"_field_"+t).w2field("clear").w2field(n.type),$("#grid_"+this.name+"_field2_"+t).w2field("clear").w2field(n.type);break;case"list":e='--';for(i in n.items)$.isPlainObject(n.items[i])?(u=n.items[i].id,f=n.items[i].text,typeof u=="undefined"&&typeof n.items[i].value!="undefined"&&(u=n.items[i].value),typeof f=="undefined"&&typeof n.items[i].caption!="undefined"&&(f=n.items[i].caption),u==null&&(u=""),e+=''+f+""):e+=''+n.items[i]+"";$("#grid_"+this.name+"_field_"+t).html(e)}r!=null&&($("#grid_"+this.name+"_operator_"+t).val(r.operator).trigger("change"),$.isArray(r.value)?r.operator=="in"?$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"):($("#grid_"+this.name+"_field_"+t).val(r.value[0]).trigger("change"),$("#grid_"+this.name+"_field2_"+t).val(r.value[1]).trigger("change")):typeof r.value!="udefined"&&$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"))}$("#w2ui-overlay .w2ui-grid-searches *[rel=search]").on("keypress",function(n){n.keyCode==13&&o.search()})},initResize:function(){var n=this;$(this.box).find(".w2ui-resizer").off("click").on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault&&n.preventDefault()}).off("mousedown").on("mousedown",function(t){var r,i,f,u;t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),n.resizing=!0,n.last.tmp={x:t.screenX,y:t.screenY,gx:t.screenX,gy:t.screenY,col:parseInt($(this).attr("name"))},t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault&&t.preventDefault();for(r in n.columns)typeof n.columns[r].sizeOriginal=="undefined"&&(n.columns[r].sizeOriginal=n.columns[r].size),n.columns[r].size=n.columns[r].sizeCalculated;i={phase:"before",type:"columnResize",target:n.name,column:n.last.tmp.col,field:n.columns[n.last.tmp.col].field},i=n.trigger($.extend(i,{resizeBy:0,originalEvent:t})),f=function(t){if(n.resizing==!0){if(t||(t=window.event),i=n.trigger($.extend(i,{resizeBy:t.screenX-n.last.tmp.gx,originalEvent:t})),i.isCancelled===!0){i.isCancelled=!1;return}n.last.tmp.x=t.screenX-n.last.tmp.x,n.last.tmp.y=t.screenY-n.last.tmp.y,n.columns[n.last.tmp.col].size=parseInt(n.columns[n.last.tmp.col].size)+n.last.tmp.x+"px",n.resizeRecords(),n.last.tmp.x=t.screenX,n.last.tmp.y=t.screenY}},u=function(t){delete n.resizing,$(document).off("mousemove","body"),$(document).off("mouseup","body"),n.resizeRecords(),n.trigger($.extend(i,{phase:"after",originalEvent:t}))};$(document).on("mousemove","body",f);$(document).on("mouseup","body",u)}).each(function(n,t){var i=$(t).parent();$(t).css({height:"25px","margin-left":i.width()-3+"px"})})},resizeBoxes:function(){var o=$(this.box).find("> div"),n=$("#grid_"+this.name+"_header"),i=$("#grid_"+this.name+"_toolbar"),r=$("#grid_"+this.name+"_summary"),t=$("#grid_"+this.name+"_footer"),u=$("#grid_"+this.name+"_body"),e=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");this.show.header&&n.css({top:"0px",left:"0px",right:"0px"}),this.show.toolbar&&i.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+"px",left:"0px",right:"0px"}),this.show.footer&&t.css({bottom:"0px",left:"0px",right:"0px"}),this.summary.length>0&&r.css({bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+"px",left:"0px",right:"0px"}),u.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+(this.show.toolbar?w2utils.getSize(i,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+(this.summary.length>0?w2utils.getSize(r,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){var i=this,rt,c,h,d,y,e,s,b,u,t,n;$(this.box).find(".w2ui-empty-record").remove();var g=$(this.box),v=$(this.box).find("> div"),nt=$("#grid_"+this.name+"_header"),tt=$("#grid_"+this.name+"_toolbar"),a=$("#grid_"+this.name+"_summary"),it=$("#grid_"+this.name+"_footer"),l=$("#grid_"+this.name+"_body"),r=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");if(this.fixedBody?(rt=v.height()-(this.show.header?w2utils.getSize(nt,"height"):0)-(this.show.toolbar?w2utils.getSize(tt,"height"):0)-(a.css("display")!="none"?w2utils.getSize(a,"height"):0)-(this.show.footer?w2utils.getSize(it,"height"):0),l.css("height",rt)):setTimeout(function(){var n=w2utils.getSize(r,"height")+w2utils.getSize($("#grid_"+i.name+"_records table"),"height");i.height=n+w2utils.getSize(v,"+height")+(i.show.header?w2utils.getSize(nt,"height"):0)+(i.show.toolbar?w2utils.getSize(tt,"height"):0)+(a.css("display")!="none"?w2utils.getSize(a,"height"):0)+(i.show.footer?w2utils.getSize(it,"height"):0),v.css("height",i.height),l.css("height",n),g.css("height",w2utils.getSize(v,"height")+w2utils.getSize(g,"+height"))},1),c=!1,h=!1,l.width()<$(f).find(">table").width()&&(c=!0),l.height()-r.height()<$(f).find(">table").height()+(c?w2utils.scrollBarSize():0)&&(h=!0),this.fixedBody||(h=!1,c=!1),c||h?(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":c?"auto":"hidden","overflow-y":h?"auto":"hidden"})):(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px",overflow:"hidden"}),f.length>0&&(this.last.scrollTop=0,this.last.scrollLeft=0)),this.show.emptyRecords&&!h&&(d=Math.floor(f.height()/this.recordHeight)+1,this.fixedBody))for(y=this.buffered;y<=d;y++){for(e="",e+='',this.show.lineNumbers&&(e+=''),this.show.selectColumn&&(e+=''),this.show.expandColumn&&(e+=''),s=0;!0&&this.columns.length>0;){if(n=this.columns[s],n.hidden)if(s++,typeof this.columns[s]=="undefined")break;else continue;if(e+='',s++,typeof this.columns[s]=="undefined")break}e+='',e+="",$("#grid_"+this.name+"_records > table").append(e)}if(l.length>0){var p=parseInt(l.width())-(h?w2utils.scrollBarSize():0)-(this.show.lineNumbers?34:0)-(this.show.selectColumn?26:0)-(this.show.expandColumn?26:0),k=p,o=0,w=!1;for(t=0;tk&&n.hidden!==!0&&(n.hidden=!0,w=!0),n.gridMinWidth0)for(t=0;tparseInt(n.max)&&(n.sizeCalculated=n.max+"px"),b+=parseInt(n.sizeCalculated));if(u=parseInt(k)-parseInt(b),u>0&&o>0)for(t=0;;){if(n=this.columns[t],typeof n=="undefined"){t=0;continue}if(n.hidden||n.sizeType=="px"){t++;continue}if(n.sizeCalculated=parseInt(n.sizeCalculated)+1+"px",u--,u==0)break;t++}else u>0&&r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();r.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-head-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),r.find("> table > tbody > tr").length==3&&r.find("> table > tbody > tr:nth-child(1) td").html("").css({height:"0px",border:"0px",padding:"0px",margin:"0px"}),f.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",(u>0&&o==0?u:0)+"px")}),a.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),this.initResize(),this.refreshRanges(),this.last.scrollTop!=""&&f.length>0&&(r.prop("scrollLeft",this.last.scrollLeft),f.prop("scrollTop",this.last.scrollTop),f.prop("scrollLeft",this.last.scrollLeft))},getSearchesHTML:function(){for(var i='',f=!1,n,u,r,t=0;t",f=!0),typeof n.inTag=="undefined"&&(n.inTag=""),typeof n.outTag=="undefined"&&(n.outTag=""),typeof n.type=="undefined"&&(n.type="text"),n.type=="text"&&(r='\t'+w2utils.lang("is")+'\t'+w2utils.lang("begins with")+'\t'+w2utils.lang("contains")+'\t'+w2utils.lang("ends with")+""),(n.type=="int"||n.type=="float"||n.type=="date")&&(r='\t"+w2utils.lang("is")+""+(n.type=="date"?"":''+w2utils.lang("in")+"")+'\t'+w2utils.lang("between")+""),n.type=="list"&&(r='is '),i+='\t'+u+'\t'+n.caption+'\t'+r+'\t';switch(n.type){case"alphaNumeric":case"text":i+='";break;case"int":case"float":case"hex":case"money":case"date":i+=' - ";break;case"list":i+='"}i+=n.outTag+"\t"}return i+='\t\t\t\t\t\t\t\t\t\t'},getColumnsHTML:function(){function r(){var i="",u,f,t,r,e,o,s;for(n.columnGroups[n.columnGroups.length-1].caption!=""&&n.columnGroups.push({caption:""}),n.show.lineNumbers&&(i+='\t '),n.show.selectColumn&&(i+='\t '),n.show.expandColumn&&(i+='\t '),u=0,f=0;f'),i+='"+s+'\t'+(r.caption==""?" ":r.caption)+"\t"}else i+='\t'+(t.caption==""?" ":t.caption)+"\t";u+=t.span}return i+=""}function t(t){var u="",f,s,r,i,c,e,o,h;for(n.show.lineNumbers&&(u+='\t#"),n.show.selectColumn&&(u+='\t\t\t\t"),n.show.expandColumn&&(u+='\t '),f=0,s=0,r=0;r'),u+='"+h+'\t'+(i.caption==""?" ":i.caption)+"\t")}return u+=' ',u+=""}var n=this,i="";return this.show.columnHeaders&&(i=this.columnGroups.length>0?t(!0)+r()+t(!1):t(!0)),i},getRecordsHTML:function(){var r,i,n,t;for(this.show_extra=this.buffered>300?30:300,r=$("#grid_"+this.name+"_records"),i=Math.floor(r.height()/this.recordHeight)+this.show_extra+1,this.fixedBody||(i=this.buffered),n=""+this.getRecordHTML(-1,0),n+='\t',t=0;t\t\t',this.last.range_start=0,this.last.range_end=i,n},getSummaryHTML:function(){var t,n;if(this.summary.length!=0){for(t="",n=0;n"}},scroll:function(){function d(){i.markSearchResults!==!1&&(clearTimeout(i.last.marker_timer),i.last.marker_timer=setTimeout(function(){var n=[],r,t;for(r in i.searchData)t=i.searchData[r],$.inArray(t.value,n)==-1&&n.push(t.value);n.length>0&&$(i.box).find(".w2ui-grid-data > div").w2marker(n)},50))}var nt=+new Date,i=this,t=$("#grid_"+this.name+"_records"),l,v,p,f,e,h,s,y,k,u,o,r,g,a,b,w,c;if(this.records.length!=0&&t.length!=0&&t.height()!=0){if(this.show_extra=this.buffered>300?30:300,t.height()0&&this.refresh();return}if(l=Math.floor(t[0].scrollTop/this.recordHeight+1),v=Math.floor(t[0].scrollTop/this.recordHeight+1)+Math.round(t.height()/this.recordHeight),l>this.buffered&&(l=this.buffered),v>this.buffered&&(v=this.buffered),p=typeof this.url!="object"?this.url:this.url.get,$("#grid_"+this.name+"_footer .w2ui-footer-right").html(w2utils.formatNumber(this.offset+l)+"-"+w2utils.formatNumber(this.offset+v)+" "+w2utils.lang("of")+" "+w2utils.formatNumber(this.total)+(p?" ("+w2utils.lang("buffered")+" "+w2utils.formatNumber(this.buffered)+(this.offset>0?", skip "+w2utils.formatNumber(this.offset):"")+")":"")),p||this.fixedBody&&!(this.total<=300)){if(f=Math.floor(t[0].scrollTop/this.recordHeight)-this.show_extra,e=f+Math.floor(t.height()/this.recordHeight)+this.show_extra*2+1,f<1&&(f=1),e>this.total&&(e=this.total),h=t.find("#grid_"+this.name+"_rec_top"),s=t.find("#grid_"+this.name+"_rec_bottom"),String(h.next().prop("id")).indexOf("_expanded_row")!=-1&&h.next().remove(),String(s.prev().prop("id")).indexOf("_expanded_row")!=-1&&s.prev().remove(),y=parseInt(h.next().attr("line")),k=parseInt(s.prev().attr("line")),y=y-this.show_extra+2&&f>1)return;for(;;){if(u=t.find("#grid_"+this.name+"_rec_bottom").prev(),u.attr("line")=="top")break;if(parseInt(u.attr("line"))>e)u.remove();else break}for(u=t.find("#grid_"+this.name+"_rec_top").next(),o=u.attr("line"),o=="bottom"&&(o=e),r=parseInt(o)-1;r>=f;r--)this.records[r-1]&&(this.records[r-1].expanded===!0&&(this.records[r-1].expanded=!1),h.after(this.getRecordHTML(r-1,r)));d(),setTimeout(function(){i.refreshRanges()},0)}if(g=(f-1)*i.recordHeight,a=(this.buffered-e)*i.recordHeight,a<0&&(a=0),h.css("height",g+"px"),s.css("height",a+"px"),i.last.range_start=f,i.last.range_end=e,b=Math.floor(t[0].scrollTop/this.recordHeight),w=b+Math.floor(t.height()/this.recordHeight),w+10>this.buffered&&this.last.pull_more!==!0&&this.buffered'),i.last.pull_more=!0,i.last.xhr_offset+=i.limit,i.request("get-records")});c.find("td").text().indexOf("Load")==-1&&c.find("td").html("Load "+i.limit+" More...")}this.buffered>=this.total-this.offset&&$("#grid_"+this.name+"_rec_more").hide();return}}},getRecordHTML:function(n,t,i){var r="",c,a,v,o,e,u,f,s,l;if(n==-1){r+='',this.show.lineNumbers&&(r+=''),this.show.selectColumn&&(r+=''),this.show.expandColumn&&(r+='');for(c in this.columns)this.columns[c].hidden||(r+='');return r+='',r+=""}if(a=typeof this.url!="object"?this.url:this.url.get,i!==!0)if(this.searchData.length>0&&!a){if(n>=this.last.searchIds.length)return"";n=this.last.searchIds[n],record=this.records[n]}else{if(n>=this.records.length)return"";record=this.records[n]}else{if(n>=this.summary.length)return"";record=this.summary[n]}if(!record)return"";for(v=w2utils.escapeId(record.recid),o=!1,record.selected&&this.selectType=="row"&&(o=!0),r+='",this.show.lineNumbers&&(r+=''+(i!==!0?""+t+"":"")+""),this.show.selectColumn&&(r+=''+(i!==!0?'\t\t\t\t":"")+""),this.show.expandColumn&&(e="",e=record.expanded===!0?"-":"+",record.expanded=="none"&&(e=""),record.expanded=="spinner"&&(e=''),r+=''+(i!==!0?'\t\t\t"+e+" ":"")+""),u=0;;){if(f=this.columns[u],f.hidden)if(u++,typeof this.columns[u]=="undefined")break;else continue;var y=record.changed&&record.changes[f.field],p=this.getCellHTML(n,u,i),h="";if(typeof f.render=="string"&&(s=f.render.toLowerCase().split(":"),$.inArray(s[0],["number","int","float","money","percent"])!=-1&&(h="text-align: right"),$.inArray(s[0],["date"])!=-1&&(h="text-align: right")),l=!1,record.selected&&$.inArray(u,record.selectedColumns)!=-1&&(l=!0),r+='"+p+"",u++,typeof this.columns[u]=="undefined")break}return r+='',r+=""},getCellHTML:function(n,t,i){var f=this.columns[t],e=i!==!0?this.records[n]:this.summary[n],r=this.parseField(e,f.field),c=e.changed&&typeof e.changes[f.field]!="undefined",s;if(c&&(r=e.changes[f.field]),(r==null||typeof r=="undefined")&&(r=""),typeof f.render!="undefined"){if(typeof f.render=="function"&&(r=f.render.call(this,e,n,t),r.length>=4&&r.substr(0,4)!=""+r+"")),typeof f.render=="object"&&(r=""+f.render[r]+""),typeof f.render=="string"){var u=f.render.toLowerCase().split(":"),h="",o="";$.inArray(u[0],["number","int","float","money","percent"])!=-1&&(typeof u[1]!="undefined"&&w2utils.isInt(u[1])||(u[1]=0),u[1]>20&&(u[1]=20),u[1]<0&&(u[1]=0),u[0]=="money"&&(u[1]=2,h=w2utils.settings.currencySymbol),u[0]=="percent"&&(o="%",u[1]!=="0"&&(u[1]=1)),u[0]=="int"&&(u[1]=0),r=""+h+w2utils.formatNumber(Number(r).toFixed(u[1]))+o+""),u[0]=="date"&&((typeof u[1]=="undefined"||u[1]=="")&&(u[1]=w2utils.settings.date_display),r=""+h+w2utils.formatDate(r,u[1])+o+""),u[0]=="age"&&(r=""+h+w2utils.age(r)+o+"")}}else this.show.recordTitles?(s=String(r).replace(/"/g,"''"),typeof f.title!="undefined"&&(typeof f.title=="function"&&(s=f.title.call(this,e,n,t)),typeof f.title=="string"&&(s=f.title)),r=''+r+""):r=""+r+"";return(r==null||typeof r=="undefined")&&(r=""),r},getFooterHTML:function(){return'\t\t\t'},status:function(n){var r,t,i;typeof n!="undefined"?$("#grid_"+this.name+"_footer").find(".w2ui-footer-left").html(n):(r="",t=this.getSelection(),t.length>0&&(r=String(t.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")+" "+w2utils.lang("selected"),i=t[0],typeof i=="object"&&(i=i.recid+", "+w2utils.lang("Column")+": "+i.column),t.length==1&&(r=w2utils.lang("Record ID")+": "+i+" ")),$("#grid_"+this.name+"_footer .w2ui-footer-left").html(r),t.length==1?this.toolbar.enable("edit"):this.toolbar.disable("edit"),t.length>=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"))},lock:function(n,t){var i=$(this.box).find("> div:first-child");setTimeout(function(){w2utils.lock(i,n,t)},10)},unlock:function(){var n=this.box;setTimeout(function(){w2utils.unlock(n)},25)},parseField:function(n,t){var i="",r,u;try{i=n,r=String(t).split(".");for(u in r)i=i[r[u]]}catch(f){i=""}return i}},$.extend(w2grid.prototype,w2utils.event),w2obj.grid=w2grid}(jQuery),function(n){var t=function(t){this.box=null,this.name=null,this.panels=[],this.tmp={},this.padding=1,this.resizer=4,this.style="",this.onShow=null,this.onHide=null,this.onResizing=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.layout,t)};n.fn.w2layout=function(i){function s(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.tabs),u==null||r==null)?!1:(n.isArray(r)&&(r={tabs:r}),n().w2destroy(t.name+"_"+i+"_tabs"),u.tabs=n().w2tabs(n.extend({},r,{owner:t,name:t.name+"_"+i+"_tabs"})),u.show.tabs=!0,!0)}function o(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.toolbar),u==null||r==null)?!1:(n.isArray(r)&&(r={items:r}),n().w2destroy(t.name+"_"+i+"_toolbar"),u.toolbar=n().w2toolbar(n.extend({},r,{owner:t,name:t.name+"_"+i+"_toolbar"})),u.show.toolbar=!0,!0)}var f,r,u,e;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return e=w2ui[n(this).attr("name")],e[i].apply(e,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2layout")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}f=i.panels,r=new t(i),n.extend(r,{handlers:[],panels:[]});for(u in f)r.panels[u]=n.extend(!0,{},t.prototype.panel,f[u]),(n.isPlainObject(r.panels[u].tabs)||n.isArray(r.panels[u].tabs))&&s(r,f[u].type),(n.isPlainObject(r.panels[u].toolbar)||n.isArray(r.panels[u].toolbar))&&o(r,f[u].type);for(u in{top:"",left:"",main:"",preview:"",right:"",bottom:""})r.get(u)==null&&(r.panels[u]=n.extend(!0,{},t.prototype.panel,{type:u,hidden:!0,size:50}));return n(this).length>0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={panel:{type:null,size:100,minSize:20,hidden:!1,resizable:!1,overflow:"auto",style:"",content:"",tabs:null,toolbar:null,width:null,height:null,show:{toolbar:!1,tabs:!1},onRefresh:null,onShow:null,onHide:null},html:function(n,t,i){return this.content(n,t,i)},content:function(t,i,r){var s=this,u=this.get(t),o,h,c,e,f;return t=="css"?(n("#layout_"+s.name+"_panel_css").html(""),!0):u==null?!1:n("#layout_"+this.name+"_panel2_"+u.type).length>0?!1:(n("#layout_"+this.name+"_panel_"+u.type).scrollTop(0),i==null||typeof i=="undefined")?u.content:i instanceof jQuery?(console.log("ERROR: You can not pass jQuery object to w2layout.content() method"),!1):(o=n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-content"),h=n(o).position().top,o.attr("class","w2ui-panel-content"),o.length>0&&typeof u.style!="undefined"&&(o[0].style.cssText=u.style),u.content==""?(u.content=i,u.hidden||this.refresh(t)):(u.content=i,u.hidden||(r!=null&&r!=""&&typeof r!="undefined"?(c="layout_"+this.name+"_panel_"+u.type,e=n("#"+c+" > .w2ui-panel-content"),e.after(''),f=n("#"+c+" > .w2ui-panel-content.new-panel"),e.css("top",h),f.css("top",h),typeof i=="object"?(i.box=f[0],i.render()):f.html(i),w2utils.transition(e[0],f[0],r,function(){e.remove(),f.removeClass("new-panel"),f.css("overflow",u.overflow),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100)})):u.hidden||this.refresh(t))),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100),!0)},load:function(t,i,r,u){var f=this;return t=="css"?(n.get(i,function(n,i,r){f.content(t,r.responseText),u&&u()}),!0):this.get(t)!=null?(n.get(i,function(n,i,e){f.content(t,e.responseText,r),u&&u(),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){f.resize()},100)}),!0):!1},sizeTo:function(t,i){var r=this,u=r.get(t);return u==null?!1:(n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".35s","-moz-transition":".35s","-ms-transition":".35s","-o-transition":".35s"}),setTimeout(function(){r.set(t,{size:i})},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.resize()},500),!0)},show:function(t,i){var r=this,f=this.trigger({phase:"before",type:"show",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!1,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"}),u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"})},250),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},hide:function(t,i){var r=this,f=this.trigger({phase:"before",type:"hide",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!0,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n("#layout_"+r.name+"_resizer_"+t).hide(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(n("#layout_"+r.name+"_resizer_"+t).hide(),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},toggle:function(n,t){var i=this.get(n);return i==null?!1:i.hidden?this.show(n,t):this.hide(n,t)},set:function(t,i){var r=this.get(t,!0);return r==null?!1:(n.extend(this.panels[r],i),this.refresh(t),this.resize(),!0)},get:function(n,t){var r=null,i;for(i in this.panels)if(this.panels[i].type==n)return t===!0?i:this.panels[i];return null},el:function(t){var i=n("#layout_"+this.name+"_panel_"+t+" .w2ui-panel-content");return i.length!=1?null:i[0]},hideToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").hide(),this.resize())},showToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").show(),this.resize())},toggleToolbar:function(n){var t=this.get(n);t&&(t.show.toolbar?this.hideToolbar(n):this.showToolbar(n))},hideTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").hide(),this.resize())},showTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").show(),this.resize())},toggleTabs:function(n){var t=this.get(n);t&&(t.show.tabs?this.hideTabs(n):this.showTabs(n))},render:function(t){function a(){i.tmp.events={resize:function(){w2ui[i.name].resize()},resizeStart:c,mousemove:h,mouseup:s};n(window).on("resize",i.tmp.events.resize);n(document).on("mousemove",i.tmp.events.mousemove);n(document).on("mouseup",i.tmp.events.mouseup)}function c(t,r){i.box&&(r||(r=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.tmp.resize={type:t,x:r.screenX,y:r.screenY,div_x:0,div_y:0,value:0},(t=="left"||t=="right")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.left)),(t=="top"||t=="preview"||t=="bottom")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.top)))}function s(t){var u,f;if(i.box&&(t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),typeof i.tmp.resize!="undefined")){if(i.tmp.div_x!=0||i.tmp.resize.div_y!=0){var e=i.get("top"),o=i.get("bottom"),r=i.get(i.tmp.resize.type),h=parseInt(n(i.box).height()),c=parseInt(n(i.box).width()),s=String(r.size);switch(i.tmp.resize.type){case"top":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_y,f=0;break;case"bottom":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=0;break;case"preview":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=(e&&!e.hidden?e.sizeCalculated:0)+(o&&!o.hidden?o.sizeCalculated:0);break;case"left":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_x,f=0;break;case"right":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_x,f=0}r.size=s.substr(s.length-1)=="%"?Math.floor(u*100/(r.type=="left"||r.type=="right"?c:h-f)*100)/100+"%":u,i.resize()}n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type).removeClass("active"),delete i.tmp.resize}}function h(t){var f,u,r;if(i.box&&(t||(t=window.event),typeof i.tmp.resize!="undefined")){if(f=i.get(i.tmp.resize.type),u=i.trigger({phase:"before",type:"resizing",target:i.tmp.resize.type,object:f,originalEvent:t}),u.isCancelled===!0)return!1;r=n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type),r.hasClass("active")||r.addClass("active"),i.tmp.resize.div_x=t.screenX-i.tmp.resize.x,i.tmp.resize.div_y=t.screenY-i.tmp.resize.y,i.tmp.resizing=="left"&&i.get("left").minSize-i.tmp.resize.div_x>i.get("left").width&&(i.tmp.resize.div_x=i.get("left").minSize-i.get("left").width),i.tmp.resize.type=="left"&&i.get("main").minSize+i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").width-i.get("main").minSize),i.tmp.resize.type=="right"&&i.get("right").minSize+i.tmp.resize.div_x>i.get("right").width&&(i.tmp.resize.div_x=i.get("right").width-i.get("right").minSize),i.tmp.resize.type=="right"&&i.get("main").minSize-i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").minSize-i.get("main").width),i.tmp.resize.type=="top"&&i.get("top").minSize-i.tmp.resize.div_y>i.get("top").height&&(i.tmp.resize.div_y=i.get("top").minSize-i.get("top").height),i.tmp.resize.type=="top"&&i.get("main").minSize+i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").height-i.get("main").minSize),i.tmp.resize.type=="bottom"&&i.get("bottom").minSize+i.tmp.resize.div_y>i.get("bottom").height&&(i.tmp.resize.div_y=i.get("bottom").height-i.get("bottom").minSize),i.tmp.resize.type=="bottom"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height),i.tmp.resize.type=="preview"&&i.get("preview").minSize+i.tmp.resize.div_y>i.get("preview").height&&(i.tmp.resize.div_y=i.get("preview").height-i.get("preview").minSize),i.tmp.resize.type=="preview"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height);switch(i.tmp.resize.type){case"top":case"preview":case"bottom":i.tmp.resize.div_x=0,r.length>0&&(r[0].style.top=i.tmp.resize.value+i.tmp.resize.div_y+"px");break;case"left":case"right":i.tmp.resize.div_y=0,r.length>0&&(r[0].style.left=i.tmp.resize.value+i.tmp.resize.div_x+"px")}i.trigger(n.extend(u,{phase:"after"}))}}var i=this,o,f,r,u,l,e;if((window.getSelection&&window.getSelection().removeAllRanges(),o=+new Date,f=i.trigger({phase:"before",type:"render",target:i.name,box:t}),f.isCancelled===!0)||(typeof t!="undefined"&&t!=null&&(n(i.box).find("#layout_"+i.name+"_panel_main").length>0&&n(i.box).removeAttr("name").removeClass("w2ui-layout").html(""),i.box=t),!i.box))return!1;n(i.box).attr("name",i.name).addClass("w2ui-layout").html(""),n(i.box).length>0&&(n(i.box)[0].style.cssText+=i.style),r=["top","left","main","preview","right","bottom"];for(u in r)l=i.get(r[u]),e='\t\t\t',n(i.box).find(" > div").append(e);return n(i.box).find(" > div").append('0&&(f.css("overflow",i.overflow)[0].style.cssText+=";"+i.style),i.resizable===!0?n("#layout_"+this.name+"_resizer_"+t).show():n("#layout_"+this.name+"_resizer_"+t).hide(),typeof i.content=="object"&&i.content.render?(i.content.box=n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content")[0],i.content.render()):n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content").html(i.content),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-tabs"),i.show.tabs?u.find("[name="+i.tabs.name+"]").length==0&&i.tabs!=null?u.w2render(i.tabs):i.tabs.refresh():u.html("").removeClass("w2ui-tabs").hide(),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-toolbar"),i.show.toolbar?u.find("[name="+i.toolbar.name+"]").length==0&&i.toolbar!=null?u.w2render(i.toolbar):i.toolbar.refresh():u.html("").removeClass("w2ui-toolbar").hide()}else{if(n("#layout_"+r.name+"_panel_main").length<=0){r.render();return}r.resize();for(i in this.panels)r.refresh(this.panels[i].type)}return r.trigger(n.extend(e,{phase:"after"})),+new Date-o}},resize:function(){var ut,nt,y,h,u,tt,b,a,p;if((window.getSelection&&window.getSelection().removeAllRanges(),!this.box)||(ut=+new Date,nt=this.trigger({phase:"before",type:"resize",target:this.name,panel:this.tmp.resizing}),nt.isCancelled===!0))return!1;this.padding<0&&(this.padding=0),y=parseInt(n(this.box).width()),h=parseInt(n(this.box).height()),n(this.box).find(" > div").css({width:y+"px",height:h+"px"});var p=this,it=this.get("main"),l=this.get("preview"),s=this.get("left"),c=this.get("right"),r=this.get("top"),f=this.get("bottom"),et=!0,ft=l!=null&&l.hidden!=!0?!0:!1,d=s!=null&&s.hidden!=!0?!0:!1,rt=c!=null&&c.hidden!=!0?!0:!1,w=r!=null&&r.hidden!=!0?!0:!1,g=f!=null&&f.hidden!=!0?!0:!1;for(a in{top:"",left:"",right:"",bottom:"",preview:""})u=this.get(a),tt=String(u.size),u&&tt.substr(tt.length-1)=="%"?(b=h,u.type=="preview"&&(b=b-(r&&!r.hidden?r.sizeCalculated:0)-(f&&!f.hidden?f.sizeCalculated:0)),u.sizeCalculated=parseInt((u.type=="left"||u.type=="right"?y:b)*parseFloat(u.size)/100)):u.sizeCalculated=parseInt(u.size),u.sizeCalculatedthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_top").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("top",n),!1}))}else n("#layout_"+this.name+"_panel_top").hide();if(s!=null&&s.hidden!=!0){var o=0,e=0+(w?r.sizeCalculated+this.padding:0),t=s.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_left");window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_left").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("left",n),!1}))}else n("#layout_"+this.name+"_panel_left").hide(),n("#layout_"+this.name+"_resizer_left").hide();if(c!=null&&c.hidden!=!0){var o=y-c.sizeCalculated,e=0+(w?r.sizeCalculated+this.padding:0),t=c.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0);n("#layout_"+this.name+"_panel_right").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),c.width=t,c.height=i,c.resizable&&(o=o-this.padding,t=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_right").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("right",n),!1}))}else n("#layout_"+this.name+"_panel_right").hide();if(f!=null&&f.hidden!=!0){var o=0,e=h-f.sizeCalculated,t=y,i=f.sizeCalculated;n("#layout_"+this.name+"_panel_bottom").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),f.width=t,f.height=i,f.resizable&&(e=e-(this.padding==0?0:this.padding),i=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_bottom").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("bottom",n),!1}))}else n("#layout_"+this.name+"_panel_bottom").hide();var o=0+(d?s.sizeCalculated+this.padding:0),e=0+(w?r.sizeCalculated+this.padding:0),t=y-(d?s.sizeCalculated+this.padding:0)-(rt?c.sizeCalculated+this.padding:0),i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0)-(ft?l.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_main");if(window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeight0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_preview").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("preview",n),!1}))}else n("#layout_"+this.name+"_panel_preview").hide();for(a in{top:"",left:"",main:"",preview:"",right:"",bottom:""}){var k=this.get(a),u="#layout_"+this.name+"_panel_"+a+" > .w2ui-panel-",h=0;k.show.tabs&&(k.tabs!=null&&w2ui[this.name+"_"+a+"_tabs"]&&w2ui[this.name+"_"+a+"_tabs"].resize(),h+=w2utils.getSize(n(u+"tabs").css({display:"block"}),"height")),k.show.toolbar&&(k.toolbar!=null&&w2ui[this.name+"_"+a+"_toolbar"]&&w2ui[this.name+"_"+a+"_toolbar"].resize(),h+=w2utils.getSize(n(u+"toolbar").css({top:h+"px",display:"block"}),"height")),n(u+"content").css({display:"block"}).css({top:h+"px"})}return p=this,clearTimeout(this._resize_timer),this._resize_timer=setTimeout(function(){var t,i;for(t in w2ui)typeof w2ui[t].resize=="function"&&(w2ui[t].panels=="undefined"&&w2ui[t].resize(),i=n(w2ui[t].box).parents(".w2ui-layout"),i.length>0&&i.attr("name")==p.name&&w2ui[t].resize())},100),this.trigger(n.extend(nt,{phase:"after"})),+new Date-ut},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});return t.isCancelled===!0?!1:typeof w2ui[this.name]=="undefined"?!1:(n(this.box).find("#layout_"+this.name+"_panel_main").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-layout").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})),this.tmp.events&&this.tmp.events.resize&&n(window).off("resize",this.tmp.events.resize),this.tmp.events&&this.tmp.events.mousemove&&n(document).off("mousemove",this.tmp.events.mousemove),this.tmp.events&&this.tmp.events.mouseup&&n(document).off("mouseup",this.tmp.events.mouseup),!0)},lock:function(t,i,r){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var u="#layout_"+this.name+"_panel_"+t;w2utils.lock(u,i,r)},unlock:function(t){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var i="#layout_"+this.name+"_panel_"+t;w2utils.unlock(i)}},n.extend(t.prototype,w2utils.event),w2obj.layout=t}(jQuery),w2popup={},function(n){n.fn.w2popup=function(t,i){typeof t=="undefined"&&(i={},t="open"),n.isPlainObject(t)&&(i=t,t="open"),t=t.toLowerCase(),t=="load"&&typeof i=="string"&&(i={url:i}),t=="open"&&typeof i.url!="undefined"&&(t="load"),typeof i=="undefined"&&(i={});var r={};return n(this).length>0&&(n(this).find("div[rel=title], div[rel=body], div[rel=buttons]").length>0?(n(this).find("div[rel=title]").length>0&&(r.title=n(this).find("div[rel=title]").html()),n(this).find("div[rel=body]").length>0&&(r.body=n(this).find("div[rel=body]").html(),r.style=n(this).find("div[rel=body]")[0].style.cssText),n(this).find("div[rel=buttons]").length>0&&(r.buttons=n(this).find("div[rel=buttons]").html())):(r.title=" ",r.body=n(this).html()),parseInt(n(this).css("width"))!=0&&(r.width=parseInt(n(this).css("width"))),parseInt(n(this).css("height"))!=0&&(r.height=parseInt(n(this).css("height")))),w2popup[t](n.extend({},r,i))},w2popup={defaults:{title:"",body:"",buttons:"",style:"",color:"#000",opacity:.4,speed:.3,modal:!1,maximized:!1,keyboard:!0,width:500,height:300,showClose:!0,showMax:!1,transition:null},handlers:[],onOpen:null,onClose:null,onMax:null,onMin:null,onKeydown:null,open:function(t){function w(n){if(n||(n=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.resizing=!0,i.tmp_x=n.screenX,i.tmp_y=n.screenY,n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault)n.preventDefault();else return!1}function c(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}))}function h(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-popup").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-popup").css("top"))+parseInt(i.tmp_div_y)+"px"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-panel").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-panel").css("top"))+parseInt(i.tmp_div_y)+"px"}),i.resizing=!1)}var p=this,o=n("#w2ui-popup").data("options"),t=n.extend({},this.defaults,{body:""},o,t),e,f,v,y,r,u,a,l,s,i;if(n("#w2ui-popup").length==0&&(w2popup.handlers=[],w2popup.onMax=null,w2popup.onMin=null,w2popup.onOpen=null,w2popup.onClose=null,w2popup.onKeydown=null),t.onOpen&&(w2popup.onOpen=t.onOpen),t.onClose&&(w2popup.onClose=t.onClose),t.onMax&&(w2popup.onMax=t.onMax),t.onMin&&(w2popup.onMin=t.onMin),t.onKeydown&&(w2popup.onKeydown=t.onKeydown),window.innerHeight==undefined?(e=document.documentElement.offsetWidth,f=document.documentElement.offsetHeight,w2utils.engine=="IE7"&&(e+=21,f+=4)):(e=window.innerWidth,f=window.innerHeight),parseInt(e)-10',t.title!=""&&(r+=''+(t.showClose?'Close':"")+(t.showMax?'Max':"")+t.title+""),r+='',r+=''+t.body+"",r+="",r+='',r+='',r+="",t.buttons!=""&&(r+=''+t.buttons+""),r+="",n("body").append(r),setTimeout(function(){n("#w2ui-popup .w2ui-box2").hide(),n("#w2ui-popup").css({"-webkit-transition":t.speed+"s opacity, "+t.speed+"s -webkit-transform","-webkit-transform":"scale(1)","-moz-transition":t.speed+"s opacity, "+t.speed+"s -moz-transform","-moz-transform":"scale(1)","-ms-transition":t.speed+"s opacity, "+t.speed+"s -ms-transform","-ms-transform":"scale(1)","-o-transition":t.speed+"s opacity, "+t.speed+"s -o-transform","-o-transform":"scale(1)",opacity:"1"})},1),setTimeout(function(){n("#w2ui-popup").css({"-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":""}),p.trigger(n.extend(u,{phase:"after"}))},t.speed*1e3)}else{if(u=this.trigger({phase:"before",type:"open",target:"popup",options:t,present:!0}),u.isCancelled===!0)return;(typeof o=="undefined"||o.width!=t.width||o.height!=t.height)&&(n("#w2ui-panel").remove(),w2popup.resize(t.width,t.height)),a=n("#w2ui-popup .w2ui-box2 > .w2ui-msg-body").html(t.body),a.length>0&&(a[0].style.cssText=t.style),n("#w2ui-popup .w2ui-msg-buttons").html(t.buttons),n("#w2ui-popup .w2ui-msg-title").html((t.showClose?'Close':"")+(t.showMax?'Max':"")+t.title),l=n("#w2ui-popup .w2ui-box1")[0],s=n("#w2ui-popup .w2ui-box2")[0],w2utils.transition(l,s,t.transition),s.className="w2ui-box1",l.className="w2ui-box2",n(s).addClass("w2ui-current-box"),n("#w2ui-popup").data("prev-size",null),setTimeout(function(){p.trigger(n.extend(u,{phase:"after"}))},1)}if(t._last_w2ui_name=w2utils.keyboard.active(),w2utils.keyboard.active(null),n("#w2ui-popup").data("options",t),t.keyboard)n(document).on("keydown",this.keydown);i={resizing:!1};n("#w2ui-popup .w2ui-msg-title").on("mousedown",function(n){w(n)}).on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});n("#w2ui-popup .w2ui-msg-body").on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});n("#w2ui-lock").on("mousemove",function(n){c(n)}).on("mouseup",function(n){h(n)});return this},keydown:function(t){var r=n("#w2ui-popup").data("options"),i;if(r.keyboard&&(i=w2popup.trigger({phase:"before",type:"keydown",target:"popup",options:r,object:w2popup,originalEvent:t}),i.isCancelled!==!0)){switch(t.keyCode){case 27:t.preventDefault(),n("#w2ui-popup .w2ui-popup-message").length>0?w2popup.message():w2popup.close()}w2popup.trigger(n.extend(i,{phase:"after"}))}},close:function(t){var r=this,t=n.extend({},n("#w2ui-popup").data("options"),t),i=this.trigger({phase:"before",type:"close",target:"popup",options:t});i.isCancelled!==!0&&(n("#w2ui-popup, #w2ui-panel").css({"-webkit-transition":t.speed+"s opacity, "+t.speed+"s -webkit-transform","-webkit-transform":"scale(0.9)","-moz-transition":t.speed+"s opacity, "+t.speed+"s -moz-transform","-moz-transform":"scale(0.9)","-ms-transition":t.speed+"s opacity, "+t.speed+"s -ms-transform","-ms-transform":"scale(0.9)","-o-transition":t.speed+"s opacity, "+t.speed+"s -o-transform","-o-transform":"scale(0.9)",opacity:"0"}),w2popup.unlockScreen(),setTimeout(function(){n("#w2ui-popup").remove(),n("#w2ui-panel").remove(),r.trigger(n.extend(i,{phase:"after"}))},t.speed*1e3),w2utils.keyboard.active(t._last_w2ui_name),t.keyboard&&n(document).off("keydown",this.keydown))},toggle:function(){var t=n("#w2ui-popup").data("options");t.maximized===!0?w2popup.min():w2popup.max()},max:function(){var r=this,t=n("#w2ui-popup").data("options"),i;t.maximized!==!0&&(i=this.trigger({phase:"before",type:"max",target:"popup",options:t}),i.isCancelled!==!0)&&(t.maximized=!0,t.prevSize=n("#w2ui-popup").css("width")+":"+n("#w2ui-popup").css("height"),n("#w2ui-popup").data("options",t),w2popup.resize(1e4,1e4,function(){r.trigger(n.extend(i,{phase:"after"}))}))},min:function(){var u=this,t=n("#w2ui-popup").data("options"),i,r;t.maximized===!0&&(i=t.prevSize.split(":"),r=this.trigger({phase:"before",type:"min",target:"popup",options:t}),r.isCancelled!==!0)&&(t.maximized=!1,t.prevSize=null,n("#w2ui-popup").data("options",t),w2popup.resize(i[0],i[1],function(){u.trigger(n.extend(r,{phase:"after"}))}))},get:function(){return n("#w2ui-popup").data("options")},set:function(n){w2popup.open(n)},clear:function(){n("#w2ui-popup .w2ui-msg-title").html(""),n("#w2ui-popup .w2ui-msg-body").html(""),n("#w2ui-popup .w2ui-msg-buttons").html("")},reset:function(){w2popup.open(w2popup.defaults)},load:function(t){function u(i,r){if(delete t.url,n("body").append(''+i+""),typeof r!="undefined"&&n("#w2ui-tmp #"+r).length>0?n("#w2ui-tmp #"+r).w2popup(t):n("#w2ui-tmp > div").w2popup(t),n("#w2ui-tmp > style").length>0){var u=n("").append(n("#w2ui-tmp > style").clone()).html();n("#w2ui-popup #div-style").length==0&&n("#w2ui-ppopup").append(''),n("#w2ui-popup #div-style").html(u)}n("#w2ui-tmp").remove()}var i;if(String(t.url)=="undefined"){console.log("ERROR: The url parameter is empty.");return}var f=String(t.url).split("#"),r=f[0],e=f[1];String(t)=="undefined"&&(t={}),i=n("#w2ui-popup").data(r),typeof i!="undefined"&&i!=null?u(i,e):n.get(r,function(t,i,f){u(f.responseText,e),n("#w2ui-popup").data(r,f.responseText)})},message:function(t){var r,u,i,t;n().w2tag(),t||(t={width:200,height:100}),parseInt(t.width)<10&&(t.width=10),parseInt(t.height)<10&&(t.height=10),typeof t.hideOnClick=="undefined"&&(t.hideOnClick=!1),r=n("#w2ui-popup .w2ui-msg-title"),n("#w2ui-popup .w2ui-popup-message").length==0?(u=parseInt(n("#w2ui-popup").width()),n("#w2ui-popup .w2ui-box1").before('"),n("#w2ui-popup .w2ui-popup-message").data("options",t)):(typeof t.width=="undefined"&&(t.width=w2utils.getSize(n("#w2ui-popup .w2ui-popup-message"),"width")),typeof t.height=="undefined"&&(t.height=w2utils.getSize(n("#w2ui-popup .w2ui-popup-message"),"height"))),i=n("#w2ui-popup .w2ui-popup-message").css("display"),n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-moz-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-ms-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)","-o-transform":i=="none"?"translateY(-"+t.height+"px)":"translateY(0px)"}),i=="none"?(n("#w2ui-popup .w2ui-popup-message").show().html(t.html),setTimeout(function(){n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s","z-Index":1500}),w2popup.lock(),typeof t.onOpen=="function"&&t.onOpen()},300)):(n("#w2ui-popup .w2ui-popup-message").css("z-Index",250),t=n("#w2ui-popup .w2ui-popup-message").data("options"),n("#w2ui-popup .w2ui-popup-message").remove(),w2popup.unlock(),typeof t.onClose=="function"&&t.onClose()),setTimeout(function(){n("#w2ui-popup .w2ui-popup-message").css({"-webkit-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-moz-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-ms-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)","-o-transform":i=="none"?"translateY(0px)":"translateY(-"+t.height+"px)"})},1)},lock:function(t,i){w2utils.lock(n("#w2ui-popup"),t,i)},unlock:function(){w2utils.unlock(n("#w2ui-popup"))},lockScreen:function(t){if(n("#w2ui-lock").length>0)return!1;if(typeof t=="undefined"&&(t=n("#w2ui-popup").data("options")),typeof t=="undefined"&&(t={}),t=n.extend({},w2popup.defaults,t),n("body").append(''),setTimeout(function(){n("#w2ui-lock").css({"-webkit-transition":t.speed+"s opacity","-moz-transition":t.speed+"s opacity","-ms-transition":t.speed+"s opacity","-o-transition":t.speed+"s opacity",opacity:t.opacity})},1),t.modal==!0){n("#w2ui-lock").on("mousedown",function(){n("#w2ui-lock").css({"-webkit-transition":".1s","-moz-transition":".1s","-ms-transition":".1s","-o-transition":".1s",opacity:"0.6"}),window.getSelection&&window.getSelection().removeAllRanges()});n("#w2ui-lock").on("mouseup",function(){setTimeout(function(){n("#w2ui-lock").css({"-webkit-transition":".1s","-moz-transition":".1s","-ms-transition":".1s","-o-transition":".1s",opacity:t.opacity})},100),window.getSelection&&window.getSelection().removeAllRanges()})}else n("#w2ui-lock").on("mouseup",function(){w2popup.close()});return!0},unlockScreen:function(){if(n("#w2ui-lock").length==0)return!1;var t=n.extend({},n("#w2ui-popup").data("options"),t);return n("#w2ui-lock").css({"-webkit-transition":t.speed+"s opacity","-moz-transition":t.speed+"s opacity","-ms-transition":t.speed+"s opacity","-o-transition":t.speed+"s opacity",opacity:0}),setTimeout(function(){n("#w2ui-lock").remove()},t.speed*1e3),!0},resize:function(t,i,r){var u=n("#w2ui-popup").data("options"),e,f;parseInt(n(window).width())-100?w2popup.message({width:400,height:150,html:'\t\t'+n+'\t\t',onClose:function(){typeof i=="function"&&i()}}):w2popup.open({width:450,height:200,showMax:!1,title:t,body:''+n+"",buttons:'',onClose:function(){typeof i=="function"&&i()}})},w2confirm=function(n,t,i){(typeof i=="undefined"||typeof t=="function")&&(i=t,t=w2utils.lang("Confirmation")),typeof t=="undefined"&&(t=w2utils.lang("Confirmation")),jQuery("#w2ui-popup").length>0?w2popup.message({width:400,height:150,html:'\t\t'+n+'\t\t\t\t',onOpen:function(){jQuery("#w2ui-popup .w2ui-popup-message .w2ui-popup-button").on("click",function(n){w2popup.message(),typeof i=="function"&&i(n.target.id)})},onKeydown:function(n){switch(n.originalEvent.keyCode){case 13:typeof i=="function"&&i("Yes"),w2popup.message();break;case 27:typeof i=="function"&&i("No"),w2popup.message()}}}):w2popup.open({width:450,height:200,title:t,modal:!0,showClose:!1,body:''+n+"",buttons:'',onOpen:function(n){n.onComplete=function(){jQuery("#w2ui-popup .w2ui-popup-button").on("click",function(n){w2popup.close(),typeof i=="function"&&i(n.target.id)})}},onKeydown:function(n){switch(n.originalEvent.keyCode){case 13:typeof i=="function"&&i("Yes"),w2popup.close();break;case 27:typeof i=="function"&&i("No"),w2popup.close()}}})},function(n){var t=function(t){this.box=null,this.name=null,this.active=null,this.tabs=[],this.right="",this.style="",this.onClick=null,this.onClose=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.tabs,t)};n.fn.w2tabs=function(i){var e,r,f,u;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return u=w2ui[n(this).attr("name")],u[i].apply(u,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2tabs")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2tabs().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}e=i.tabs,r=new t(i),n.extend(r,{tabs:[],handlers:[]});for(f in e)r.tabs[f]=n.extend({},t.prototype.tab,e[f]);return n(this).length!=0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={tab:{id:null,text:"",hidden:!1,disabled:!1,closable:!1,hint:"",onClick:null,onRefresh:null,onClose:null},add:function(n){return this.insert(null,n)},insert:function(t,i){var r,f,e,i,u;n.isArray(i)||(i=[i]);for(r in i){if(String(i[r].id)=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+this.name+")");return}f=!0;for(e in this.tabs)if(this.tabs[e].id==i[r].id){f=!1;break}if(!f){console.log('ERROR: The parameter "id='+i[r].id+'" is not unique within the current tabs. (obj: '+this.name+")");return}if(!w2utils.isAlphaNumeric(i[r].id)){console.log('ERROR: The parameter "id='+i[r].id+'" must be alpha-numeric + "-_". (obj: '+this.name+")");return}i=n.extend({},i,i[r]),t==null||typeof t=="undefined"?this.tabs.push(i):(u=this.get(t,!0),this.tabs=this.tabs.slice(0,u).concat([i],this.tabs.slice(u))),this.refresh(i[r].id)}},remove:function(){for(var u=0,r,i=0;i":"")+'\t"+i.text+"",r.length==0?(u="",i.hidden&&(u+="display: none;"),i.disabled&&(u+="opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);"),html=''+f+"",this.get(t,!0)!=this.tabs.length-1&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).before(html):n(this.box).find("#tabs_"+this.name+"_right").before(html)):(r.html(f),i.hidden?r.css("display","none"):r.css("display",""),i.disabled?r.css({opacity:"0.2","-moz-opacity":"0.2","-webkit-opacity":"0.2","-o-opacity":"0.2",filter:"alpha(opacity=20)"}):r.css({opacity:"1","-moz-opacity":"1","-webkit-opacity":"1","-o-opacity":"1",filter:"alpha(opacity=100)"})),this.trigger(n.extend(e,{phase:"after"})),+new Date-s)},render:function(t){var u=+new Date,i=this.trigger({phase:"before",type:"render",target:this.name,box:t}),r;return i.isCancelled===!0?!1:(window.getSelection&&window.getSelection().removeAllRanges(),String(t)!="undefined"&&t!=null&&(n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),this.box=t),!this.box)?void 0:(r='\t'+this.right+"",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-tabs").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.trigger(n.extend(i,{phase:"after"})),this.refresh(),+new Date-u)},resize:function(){window.getSelection&&window.getSelection().removeAllRanges();var t=this.trigger({phase:"before",type:"resize",target:this.name});if(t.isCancelled===!0)return!1;this.trigger(n.extend(t,{phase:"after"}))},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},click:function(t,i){var u=this.get(t),r;if(u==null||u.disabled||(r=this.trigger({phase:"before",type:"click",target:t,object:this.get(t),originalEvent:i}),r.isCancelled===!0))return!1;n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.active)+" .w2ui-tab").removeClass("active"),this.active=u.id,this.trigger(n.extend(r,{phase:"after"})),this.refresh(t)},animateClose:function(t,i){var u=this.get(t),f,r;if(u==null||u.disabled||(f=this.trigger({phase:"before",type:"close",target:t,object:this.get(t),originalEvent:i}),f.isCancelled===!0))return!1;r=this,n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(u.id)).css({"-webkit-transition":".2s","-moz-transition":"2s","-ms-transition":".2s","-o-transition":".2s",opacity:"0"}),setTimeout(function(){var t=n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).width();n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).html(''),setTimeout(function(){n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).find(":first-child").css({width:"0px"})},50)},200),setTimeout(function(){r.remove(t)},450),this.trigger(n.extend(f,{phase:"after"})),this.refresh()},animateInsert:function(t,i){var f,e,o,s,r,u;if(this.get(t)!=null&&n.isPlainObject(i)){f=!0;for(e in this.tabs)if(this.tabs[e].id==i.id){f=!1;break}if(!f){console.log('ERROR: The parameter "id='+i.id+'" is not unique within the current tabs. (obj: '+this.name+")");return}(o=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id)),o.length==0)&&(typeof i.caption!="undefined"&&(i.text=i.caption),s=''+(i.closable?'':"")+'\t'+i.text+"",n("body").append(s),tabHTML=' ',r="",i.hidden&&(r+="display: none;"),i.disabled&&(r+="opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);"),html=''+tabHTML+"",this.get(t,!0)!=this.tabs.length&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).before(html):n(this.box).find("#tabs_"+this.name+"_right").before(html),u=this,setTimeout(function(){var t=n("#_tmp_simple_tab").width();n("#_tmp_tabs").remove(),n("#tabs_"+u.name+"_tab_"+w2utils.escapeId(i.id)+" > div").css("width",t+"px")},1),setTimeout(function(){u.insert(t,i)},200))}}},n.extend(t.prototype,w2utils.event),w2obj.tabs=t}(jQuery),function(n){var t=function(t){this.box=null,this.name=null,this.items=[],this.right="",this.onClick=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.toolbar,t)};n.fn.w2toolbar=function(i){var e,r,f,u;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return u=w2ui[n(this).attr("name")],u[i].apply(u,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2toolbar")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2toolbar().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}e=i.items,r=new t(i),n.extend(r,{items:[],handlers:[]});for(f in e)r.items[f]=n.extend({},t.prototype.item,e[f]);return n(this).length!=0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={item:{id:null,type:"button",text:"",html:"",img:null,icon:null,hidden:!1,disabled:!1,checked:!1,arrow:!0,hint:"",group:null,items:null,onClick:null},add:function(n){this.insert(null,n)},insert:function(i,r){var u,s,e,f,o;n.isArray(r)||(r=[r]);for(u in r){if(typeof r[u].type=="undefined"){console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.');return}if(n.inArray(String(r[u].type),["button","check","radio","drop","menu","break","html","spacer"])==-1){console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] in w2toolbar.add() method.');return}if(typeof r[u].id=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.');return}for(s=!0,e=0;e table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),this.box=t),this.box){for(r='',u=0;u':''+this.getItemHTML(i)+"");r+=''+this.right+"",r+="",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-toolbar").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.trigger(n.extend(f,{phase:"after"}))}},refresh:function(t){var o=+new Date,e,f,i,r,u;if(window.getSelection&&window.getSelection().removeAllRanges(),e=this.trigger({phase:"before",type:"refresh",target:typeof t!="undefined"?t:this.name,item:this.get(t)}),e.isCancelled===!0)return!1;if(typeof t=="undefined")for(f=0;f':''+u+"",this.get(t,!0)==this.items.length-1?n(this.box).find("#tb_"+this.name+"_right").before(u):n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(this.items[parseInt(this.get(t,!0))+1].id)).before(u)):(r.html(u),i.hidden?r.css("display","none"):r.css("display",""),i.disabled?r.addClass("disabled"):r.removeClass("disabled")),this.trigger(n.extend(e,{phase:"after"})),+new Date-o},resize:function(){var i=+new Date,t;return(window.getSelection&&window.getSelection().removeAllRanges(),t=this.trigger({phase:"before",type:"resize",target:this.name}),t.isCancelled===!0)?!1:(this.trigger(n.extend(t,{phase:"after"})),+new Date-i)},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),n(this.box).html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},getItemHTML:function(n){var t="",r,i;typeof n.caption!="undefined"&&(n.text=n.caption),typeof n.hint=="undefined"&&(n.hint=""),typeof n.text=="undefined"&&(n.text="");switch(n.type){case"menu":case"button":case"check":case"radio":case"drop":r=" ",n.img&&(r=''),n.icon&&(r=''),t+=' '+r+(n.text!=""?''+n.text+"":"")+((n.type=="drop"||n.type=="menu")&&n.arrow!==!1?' ':"")+" ";break;case"break":t+=' ';break;case"html":t+=' '+n.html+""}return i="",typeof n.onRender=="function"&&(i=n.onRender.call(this,n.id,t)),typeof this.onRender=="function"&&(i=this.onRender(n.id,t)),i!=""&&typeof i!="undefined"&&(t=i),t},menuClick:function(t,i,r){var e,f,u;if(window.getSelection&&window.getSelection().removeAllRanges(),e=this,f=this.get(t),f&&!f.disabled){if(u=this.trigger({phase:"before",type:"click",target:typeof t!="undefined"?t:this.name,item:this.get(t),subItem:typeof i!="undefined"&&this.get(t)?this.get(t).items[i]:null,originalEvent:r}),u.isCancelled===!0)return!1;this.trigger(n.extend(u,{phase:"after"}))}},click:function(t,i){var f,r,o,e,u;if(window.getSelection&&window.getSelection().removeAllRanges(),f=this,r=this.get(t),r&&!r.disabled){if(o=this.trigger({phase:"before",type:"click",target:typeof t!="undefined"?t:this.name,item:this.get(t),originalEvent:i}),o.isCancelled===!0)return!1;if(n("#tb_"+this.name+"_item_"+w2utils.escapeId(r.id)+" table.w2ui-button").removeClass("down"),r.type=="radio"){for(e=0;e0&&this.insert(e,null,h)}return this.refresh(i.id),e},remove:function(){for(var r=0,n,i,t=0;t0&&arguments.length==1?this.refresh(n.parent.id):this.refresh(),r},set:function(t,i,r){var u,f;if(arguments.length==2&&(r=i,i=t,t=this),this._tmp=null,typeof t=="string"&&(t=this.get(t)),t.nodes==null)return null;for(u=0;u+'),r.expanded=!1,this.trigger(n.extend(i,{phase:"after"})),this.resize()},collapseAll:function(n){if(typeof n=="undefined"&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return null;for(var t=0;t0&&this.collapseAll(n.nodes[t]);this.refresh(n.id)},expand:function(t){var r=this.get(t),i=this.trigger({phase:"before",type:"expand",target:t,object:r});if(i.isCancelled===!0)return!1;n(this.box).find("#node_"+w2utils.escapeId(t)+"_sub").slideDown("fast"),n(this.box).find("#node_"+w2utils.escapeId(t)+" .w2ui-node-dots:first-child").html('-'),r.expanded=!0,this.trigger(n.extend(i,{phase:"after"})),this.resize()},expandAll:function(n){if(typeof n=="undefined"&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return null;for(var t=0;t0&&this.collapseAll(n.nodes[t]);this.refresh(n.id)},expandParents:function(n){var t=this.get(n);t!=null&&(t.parent&&(t.parent.expanded=!0,this.expandParents(t.parent.id)),this.refresh(n))},click:function(t,i){var r=this,f=this.get(t),u;f!=null&&((u=this.selected,f.disabled||f.group)||(n(r.box).find("#node_"+w2utils.escapeId(u)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),n(r.box).find("#node_"+w2utils.escapeId(t)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),setTimeout(function(){var e=r.trigger({phase:"before",type:"click",target:t,originalEvent:i,object:f});if(e.isCancelled===!0)return n(r.box).find("#node_"+w2utils.escapeId(t)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),n(r.box).find("#node_"+w2utils.escapeId(u)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),!1;u!=null&&(r.get(u).selected=!1),r.get(t).selected=!0,r.selected=t,r.trigger(n.extend(e,{phase:"after"}))},1)))},keydown:function(t){function f(n,t){var u;if(n==null)return null;var e=n.parent,o=i.get(n.id,!0),r=null;return n.expanded&&n.nodes.length>0&&t!==!0?(u=n.nodes[0],r=u.disabled||u.group?f(u):u):r=e&&o+10?(t=f.nodes[u-1],t.expanded&&t.nodes.length>0&&(r=t.nodes[t.nodes.length-1],t=r.disabled||r.group?e(r):r)):(t=f,o=!0),t!=null&&(t.disabled||t.group)&&(t=e(t)),t}var i=this,r=i.get(i.selected),o,u;if(r&&i.keyboard===!0){if(o=i.trigger({phase:"before",type:"keydown",target:i.name,originalEvent:t}),o.isCancelled===!0)return!1;(t.keyCode==13||t.keyCode==32)&&r.nodes.length>0&&i.toggle(i.selected),t.keyCode==37&&(r.nodes.length>0?i.collapse(i.selected):!r.parent||r.parent.disabled||r.parent.group||(i.collapse(r.parent.id),i.click(r.parent.id),setTimeout(function(){i.scrollIntoView()},50))),t.keyCode==39&&r.nodes.length>0&&i.expand(i.selected),t.keyCode==38&&(u=e(r),u!=null&&(i.click(u.id,t),setTimeout(function(){i.scrollIntoView()},50))),t.keyCode==40&&(u=f(r),u!=null&&(i.click(u.id,t),setTimeout(function(){i.scrollIntoView()},50))),n.inArray(t.keyCode,[13,32,37,38,39,40])!=-1&&(t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()),i.trigger(n.extend(o,{phase:"after"}));return}},scrollIntoView:function(t){var f;if(typeof t=="undefined"&&(t=this.selected),f=this.get(t),f!=null){var i=n(this.box).find(".w2ui-sidebar-div"),u=n(this.box).find("#node_"+w2utils.escapeId(t)),r=u.offset().top-i.offset().top;r+u.height()>i.height()&&i.animate({scrollTop:i.scrollTop()+i.height()/1.3}),r<=0&&i.animate({scrollTop:i.scrollTop()-i.height()/1.3})}},dblClick:function(t,i){window.getSelection&&window.getSelection().removeAllRanges();var u=this.get(t),r=this.trigger({phase:"before",type:"dblClick",target:t,originalEvent:i,object:u});if(r.isCancelled===!0)return!1;u.nodes.length>0&&this.toggle(t),this.trigger(n.extend(r,{phase:"after"}))},contextMenu:function(t,i){var r=this,u=r.get(t);t!=r.selected&&r.click(t),setTimeout(function(){var f=r.trigger({phase:"before",type:"contextMenu",target:t,originalEvent:i,object:u});if(f.isCancelled===!0)return!1;u.group||u.disabled||(r.menu.length>0&&n(r.box).find("#node_"+w2utils.escapeId(t)).w2menu(r.menu,{left:(i?i.offsetX||i.pageX:50)-25,select:function(n,i,u){r.menuClick(t,u,i)}}),r.trigger(n.extend(f,{phase:"after"})))},1)},menuClick:function(t,i,r){var u=this,f=u.trigger({phase:"before",type:"menuClick",target:t,originalEvent:r,menuIndex:i,menuItem:u.menu[i]});if(f.isCancelled===!0)return!1;u.trigger(n.extend(f,{phase:"after"}))},render:function(t){var i=this.trigger({phase:"before",type:"render",target:this.name,box:t});if(i.isCancelled===!0)return!1;(typeof t!="undefined"&&t!=null&&(n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),this.box=t),this.box)&&(n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-sidebar").html(''),n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.topHTML!=""&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px")),this.bottomHTML!=""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px")),this.trigger(n.extend(i,{phase:"after"})),this.refresh())},refresh:function(t){function h(n){var e="",f=n.img,i,u,t;for(f==null&&(f=this.img),i=n.icon,i==null&&(i=this.icon),t=n.parent,u=0;t&&t.parent!=null;)t.group&&u--,t=t.parent,u++;return typeof n.caption!="undefined"&&(n.text=n.caption),n.group?e='\t"+(!n.hidden&&n.expanded?w2utils.lang("Hide"):w2utils.lang("Show"))+"\t"+n.text+'':(n.selected&&!n.disabled&&(r.selected=n.id),t="",f&&(t=''),i&&(t=''),e='\t'+(n.nodes.length>0?n.expanded?"-":"+":n.plus?"+":"")+''+t+(n.count!==""?''+n.count+"":"")+''+n.text+''),e}var c=+new Date,s,r,i,f,o,u,e;if(window.getSelection&&window.getSelection().removeAllRanges(),s=this.trigger({phase:"before",type:"refresh",target:typeof t!="undefined"?t:this.name}),s.isCancelled===!0)return!1;if(this.topHTML!=""&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px")),this.bottomHTML!=""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px")),n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),r=this,typeof t=="undefined")i=this,f=".w2ui-sidebar-div";else{if(i=this.get(t),i==null)return;f="#node_"+w2utils.escapeId(i.id)+"_sub"}for(i!=this&&(o="#node_"+w2utils.escapeId(i.id),e=h(i),n(this.box).find(o).before(''),n(this.box).find(o).remove(),n(this.box).find(f).remove(),n("#sidebar_"+this.name+"_tmp").before(e),n("#sidebar_"+this.name+"_tmp").remove()),n(this.box).find(f).html(""),u=0;u div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),this.trigger(n.extend(t,{phase:"after"})),+new Date-i)},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled===!0)return!1;n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"}))},lock:function(t,i){var r=n(this.box).find("> div:first-child");w2utils.lock(r,t,i)},unlock:function(){w2utils.unlock(this.box)}},n.extend(t.prototype,w2utils.event),w2obj.sidebar=t}(jQuery),function(n){var t=new function(){this.customTypes=[]};n.fn.w2field=function(n){if(t[n])return t[n].apply(this,Array.prototype.slice.call(arguments,1));if(typeof n=="object")return t.init.apply(this,arguments);if(typeof n=="string")return t.init.apply(this,[{type:n}]);console.log("ERROR: Method "+n+" does not exist on jQuery.w2field")},n.extend(t,{init:function(i){var r=t;return n(this).each(function(){var l,s,y,f,h,o,c,a;if(typeof t.customTypes[i.type.toLowerCase()]=="function"){t.customTypes[i.type.toLowerCase()].call(this,i);return}l=i.type.toLowerCase();switch(l){case"clear":n(this).off("focus").off("blur").off("keypress").off("keydown").off("change").removeData(),n(this).prev().hasClass("w2ui-list")&&(n(this).prev().remove(),n(this).removeAttr("tabindex").css("border-color","").show()),n(this).prev().hasClass("w2ui-upload")&&(n(this).prev().remove(),n(this).removeAttr("tabindex").css("border-color","").show()),n(this).prev().hasClass("w2ui-field-helper")&&(n(this).css("padding-left",n(this).css("padding-top")),n(this).prev().remove()),n(this).next().hasClass("w2ui-field-helper")&&(n(this).css("padding-right",n(this).css("padding-top")),n(this).next().remove()),n(this).next().hasClass("w2ui-field-helper")&&n(this).next().remove();break;case"text":case"int":case"float":case"money":case"alphanumeric":case"hex":s=this,h={min:null,max:null,arrows:!1,keyboard:!0,suffix:"",prefix:""},i=n.extend({},h,i),["text","alphanumeric","hex"].indexOf(l)!=-1&&(i.arrows=!1,i.keyboard=!1);n(this).data("options",i).on("keypress",function(t){if(!t.metaKey&&!t.ctrlKey&&!t.altKey&&(t.charCode==t.keyCode||!(t.keyCode>0))){t.keyCode==13&&n(this).change();var i=String.fromCharCode(t.charCode);if(!v(i,!0))return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,!1}}).on("keydown",function(t,r){var e,u,o,f;if(i.keyboard){e=!1,u=n(s).val(),u=v(u)?parseFloat(u):i.min||0,o=t.keyCode||r.keyCode,f=1,(t.ctrlKey||t.metaKey)&&(f=10);switch(o){case 38:n(s).val(u+f<=i.max||i.max==null?u+f:i.max).change(),l=="money"&&n(s).val(Number(n(s).val()).toFixed(2)),e=!0;break;case 40:n(s).val(u-f>=i.min||i.min==null?u-f:i.min).change(),l=="money"&&n(s).val(Number(n(s).val()).toFixed(2)),e=!0}e&&(t.preventDefault(),setTimeout(function(){s.setSelectionRange(s.value.length,s.value.length)},0))}}).on("change",function(t){var r=n(s).val(),u=!1;if(i.min!=null&&r!=""&&ri.max&&(n(s).val(i.max).change(),u=!0),u)return t.stopPropagation(),t.preventDefault(),!1;this.value==""||v(this.value)||n(this).val(i.min!=null?i.min:"")});if(n(this).val()==""&&i.min!=null&&n(this).val(i.min),i.prefix!=""){n(this).before(''+i.prefix+""),o=n(this).prev();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":n(this).css("padding-left"),"padding-right":0,"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px","margin-left":0,"margin-right":0}).on("click",function(){n(this).next().focus()});n(this).css("padding-left",o.width()+parseInt(n(this).css("padding-left"))+5+"px")}if(c=parseInt(n(this).css("padding-right")),i.arrows!=""){n(this).after(' \t\t\t\t\t\t\t\t\t'),y=w2utils.getSize(this,"height"),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),height:n(this).height()+parseInt(n(this).css("padding-top"))+parseInt(n(this).css("padding-bottom"))+"px",padding:"0px","margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":"0px","border-left":"1px solid silver"}).css("margin-left","-"+(o.width()+parseInt(n(this).css("margin-right"))+12)+"px").on("mousedown",function(t){function r(){clearTimeout(n("body").data("_field_update_timer")),n("body").off("mouseup",r)}function i(t){n(s).focus().trigger(n.Event("keydown"),{keyCode:n(u.target).attr("type")=="up"?38:40}),t!==!1&&n("body").data("_field_update_timer",setTimeout(i,60))}var f=this,u=t;n("body").on("mouseup",r);n("body").data("_field_update_timer",setTimeout(i,700)),i(!1)});c+=o.width()+12,n(this).css("padding-right",c+"px")}if(i.suffix!=""){n(this).after(''+i.suffix+""),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":"3px","padding-right":n(this).css("padding-right"),"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px"}).on("click",function(){n(this).prev().focus()});o.css("margin-left","-"+(o.width()+parseInt(n(this).css("padding-right"))+5)+"px"),c+=o.width()+3,n(this).css("padding-right",c+"px")}function v(n,t){switch(l){case"int":return t&&["-"].indexOf(n)!=-1?!0:w2utils.isInt(n);case"float":return t&&["-","."].indexOf(n)!=-1?!0:w2utils.isFloat(n);case"money":return t&&["-",".","$","€","£","¥"].indexOf(n)!=-1?!0:w2utils.isMoney(n);case"hex":return w2utils.isHex(n);case"alphanumeric":return w2utils.isAlphaNumeric(n)}return!0}break;case"date":f=this,h={format:w2utils.settings.date_format,start:"",end:"",blocked:{},colored:{}},i=n.extend({},h,i);n(this).css({transition:"none","-webkit-transition":"none","-moz-transition":"none","-ms-transition":"none","-o-transition":"none"}).data("options",i).on("focus",function(){var e=parseFloat(n(f).offset().top)+parseFloat(f.offsetHeight),u=parseFloat(n(f).offset().left),t,r;clearInterval(n(f).data("mtimer")),n("#global_calendar_div").remove(),n("body").append(''),n("#global_calendar_div").html(n().w2field("calendar_get",f.value,i)).css({left:u+"px",top:e+"px"}).data("el",f).show(),t=n(window).width()+n(document).scrollLeft()-1,u+n("#global_calendar_div").width()>t&&n("#global_calendar_div").css("left",t-n("#global_calendar_div").width()+"px"),r=setInterval(function(){var i=n(window).width()+n(document).scrollLeft()-1,t=n(f).offset().left;if(t+n("#global_calendar_div").width()>i&&(t=i-n("#global_calendar_div").width()),n("#global_calendar_div").data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&n("#global_calendar_div").css({"-webkit-transition":".2s",left:t+"px",top:n(f).offset().top+f.offsetHeight+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(r),n("#global_calendar_div").remove();return}},100),n(f).data("mtimer",r)}).on("blur",function(){n(f).val(n.trim(n(f).val())),n.trim(n(f).val())==""||w2utils.isDate(n(f).val(),i.format)||n(this).w2tag(w2utils.lang("Not a valid date")+": "+i.format),clearInterval(n(f).data("mtimer")),n("#global_calendar_div").remove()}).on("keypress",function(){var r=this;setTimeout(function(){n("#global_calendar_div").html(n().w2field("calendar_get",r.value,i))},10)});setTimeout(function(){w2utils.isInt(f.value)&&(f.value=w2utils.formatDate(f.value,i.format))},1);break;case"time":break;case"datetime":break;case"color":f=this,h={prefix:"#",suffix:''},i=n.extend({},h,i);n(this).attr("maxlength",6).on("focus",function(){var u=parseFloat(n(f).offset().top)+parseFloat(f.offsetHeight),r=parseFloat(n(f).offset().left),t,i;clearInterval(n(f).data("mtimer")),n("#global_color_div").remove(),n("body").append(''),n("#global_color_div").html(n().w2field("getColorHTML",f.value)).css({left:r+"px",top:u+"px"}).data("el",f).show(),t=n(window).width()+n(document).scrollLeft()-1,r+n("#global_color_div").width()>t&&n("#global_color_div").css("left",t-n("#global_color_div").width()+"px"),i=setInterval(function(){var r=n(window).width()+n(document).scrollLeft()-1,t=n(f).offset().left;if(t+n("#global_color_div").width()>r&&(t=r-n("#global_color_div").width()),n("#global_color_div").data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&n("#global_color_div").css({"-webkit-transition":".2s",left:t+"px",top:n(f).offset().top+f.offsetHeight+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(i),n("#global_color_div").remove();return}},100),n(f).data("mtimer",i)}).on("click",function(){n(this).trigger("focus")}).on("blur",function(){n(f).val(n.trim(n(f).val())),clearInterval(n(f).data("mtimer")),n("#global_color_div").remove()}).on("keydown",function(t){if(t.keyCode==86&&(t.ctrlKey||t.metaKey)){var i=this;n(this).prop("maxlength",7),setTimeout(function(){var t=n(i).val();t.substr(0,1)=="#"&&(t=t.substr(1)),w2utils.isHex(t)||(t=""),n(i).val(t).prop("maxlength",6).change()},20)}}).on("keyup",function(t){t.keyCode==86&&(t.ctrlKey||t.metaKey)&&n(this).prop("maxlength",6)}).on("keypress",function(t){t.keyCode==13&&n(this).change();var i=String.fromCharCode(t.charCode);if(!w2utils.isHex(i,!0))return t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,!1}).on("change",function(){var i="#"+n(this).val();n(this).val().length!=6&&n(this).val().length!=3&&(i=""),n(this).next().find("div").css("background-color",i)});if(i.prefix!=""){n(this).before(''+i.prefix+""),o=n(this).prev();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":n(this).css("padding-left"),"padding-right":0,"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px","margin-left":0,"margin-right":0}).on("click",function(){n(this).next().focus()});n(this).css("padding-left",o.width()+parseInt(n(this).css("padding-left"))+2+"px")}if(i.suffix!=""){n(this).after(''+i.suffix+""),o=n(this).next();o.css({color:n(this).css("color"),"font-family":n(this).css("font-family"),"font-size":n(this).css("font-size"),"padding-top":n(this).css("padding-top"),"padding-bottom":n(this).css("padding-bottom"),"padding-left":"3px","padding-right":n(this).css("padding-right"),"margin-top":parseInt(n(this).css("margin-top"))+1+"px","margin-bottom":parseInt(n(this).css("margin-bottom"))+1+"px"}).on("click",function(){n(this).prev().focus()});o.css("margin-left","-"+(o.width()+parseInt(n(this).css("padding-right"))+4)+"px"),c=o.width()+parseInt(n(this).css("padding-right"))+4,n(this).css("padding-right",c+"px"),o.find("div").css("background-color","#"+n(f).val())}break;case"select":case"list":if(this.tagName!="SELECT"){console.log("ERROR: You can only apply $().w2field('list') to a SELECT element");return}var h={url:"",items:[],value:null,showNone:!0},f=this,e=n.extend({},h,i);n(f).data("settings",e),f.refresh=function(){var i=n(f).data("settings"),e="",r=t.cleanItems(i.items),u;i.showNone&&(e='- '+w2utils.lang("none")+" -");for(u in r)i.showNone||i.value!=null||(i.value=r[u].id),e+=''+r[u].text+"";n(f).html(e),n(f).val(i.value),n(f).val()!=i.value&&n(f).change()},e.url!=""?n.ajax({type:"GET",dataType:"text",url:e.url,complete:function(i,r){if(r=="success"){var e=n.parseJSON(i.responseText),u=n(f).data("settings");u.items=t.cleanItems(e.items),n(f).data("settings",u),f.refresh()}}}):f.refresh();break;case"enum":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('enum') to an INPUT element");return}var h={url:"",items:[],selected:[],max:0,maxHeight:172,showAll:!1,match:"begins with",render:null,maxCache:500,onShow:null,onHide:null,onAdd:null,onRemove:null,onItemOver:null,onItemOut:null,onItemClick:null},f=this,e=n.extend({},h,i);e.items=t.cleanItems(e.items),e.selected=t.cleanItems(e.selected),n(this).data("selected",e.selected),n(this).css({padding:"0px","border-color":"transparent","background-color":"transparent",outline:"none"}),this.add=function(t){var i,r,u;n(this).attr("readonly")||(i=n(this).data("selected"),r=n(this).data("settings"),typeof r.onAdd!="function"||(u=r.onAdd(t,r),u!==!1))&&(n.isArray(i)||(i=[]),r.max!=0&&r.max<=i.length&&i.splice(i.length-1,1),i.push(t),n(this).data("last_del",null),n(this).trigger("change"))},this.remove=function(i){var r=n(this).data("settings"),u;(typeof r.onRemove!="function"||(u=r.onRemove(i,r),u!==!1))&&(n(this).attr("readonly")||(n(this).data("selected").splice(i,1),n(this).parent().find("[title=Remove][index="+i+"]").remove(),this.refresh(),t.list_render.call(this),n(this).trigger("change")))},this.show=function(){var i,u,r;if(!n(this).attr("readonly")){if(i=n(this).data("settings"),n("#w2ui-global-items").length==0)n("body").append('');else return;u=n("#w2ui-global-items"),u.css({display:"block",left:n(f).offset().left+"px",top:n(f).offset().top+f.offsetHeight+3+"px"}).width(w2utils.getSize(f,"width")).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),t.list_render.call(f),r=function(){var i=n("#w2ui-global-items");if(n(f).length==0||n(f).offset().left==0&&n(f).offset().top==0){clearInterval(n(f).data("mtimer")),hide();return}i.data("position")!=n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)&&(i.css({"-webkit-transition":".2s",left:n(f).offset().left+"px",top:n(f).offset().top+f.offsetHeight+3+"px"}).data("position",n(f).offset().left+"x"+(n(f).offset().top+f.offsetHeight)),setTimeout(function(){t.list_render.call(f,n(f).data("last_search"))},200)),i.length>0&&n(f).data("mtimer",setTimeout(r,100))},n(f).data("mtimer",setTimeout(r,100)),typeof i.onShow=="function"&&i.onShow.call(this,i)}},this.hide=function(){var t=n(this).data("settings");clearTimeout(n(f).data("mtimer")),n("#w2ui-global-items").remove(),typeof t.onHide=="function"&&t.onHide.call(this,t)},this.refresh=function(){var r=this,i,t;n(n(this).data("div")).remove();var o="margin-top: "+n(this).css("margin-top")+"; margin-bottom: "+n(this).css("margin-bottom")+"; margin-left: "+n(this).css("margin-left")+"; margin-right: "+n(this).css("margin-right")+"; width: "+(w2utils.getSize(this,"width")-parseInt(n(this).css("margin-left"))-parseInt(n(this).css("margin-right")))+"px; ",u='',f=n(this).data("selected");for(i in f)u+='\t '+f[i].text+"";u+='\t',n(this).before(u),t=n(this).prev()[0],n(this).data("div",t);n(t).find("li").data("mouse","out").on("click",function(t){if(!n(t.target).hasClass("nomouse")){if(t.target.title==w2utils.lang("Remove")){r.remove(n(t.target).attr("index"));return}t.stopPropagation(),typeof e.onItemClick=="function"&&e.onItemClick.call(this,e)}}).on("mouseover",function(t){var i=t.target;(i.tagName!="LI"&&(i=i.parentNode),n(i).hasClass("nomouse"))||(n(i).data("mouse")=="out"&&typeof e.onItemOver=="function"&&e.onItemOver.call(this,e),n(i).data("mouse","over"))}).on("mouseout",function(t){var i=t.target;(i.tagName!="LI"&&(i=i.parentNode),n(i).hasClass("nomouse"))||(n(i).data("mouse","leaving"),setTimeout(function(){n(i).data("mouse")=="leaving"&&(n(i).data("mouse","out"),typeof e.onItemOut=="function"&&e.onItemOut.call(this,e))},0))});n(t).on("click",function(){n(this).find("input").focus()}).find("input").on("focus",function(i){n(t).css({outline:"auto 5px -webkit-focus-ring-color","outline-offset":"-2px"}),r.show(),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0}).on("blur",function(i){n(t).css("outline","none"),r.hide(),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0});r.resize()},this.resize=function(){var r=n(this).data("settings"),i=n(this).prev(),t=n(i).find(">div").height();t<23&&(t=23),t>r.maxHeight&&(t=r.maxHeight),n(i).height(t+(t%23==0?0:23-t%23)),i.length>0&&(i[0].scrollTop=1e3),n(this).height(t)},n(this).data("settings",e).attr("tabindex",-1),f.refresh();break;case"upload":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('upload') to an INPUT element");return}var h={url:"",base64:!0,hint:w2utils.lang("Attach files by dragging and dropping or Click to Select"),max:0,maxSize:0,maxFileSize:0,onAdd:null,onRemove:null,onItemClick:null,onItemDblClick:null,onItemOver:null,onItemOut:null,onProgress:null,onComplete:null},f=this,e=n.extend({},h,i);e.base64===!0&&(e.maxSize==0&&(e.maxSize=20971520),e.maxFileSize==0&&(e.maxFileSize=20971520)),a=e.selected,delete e.selected,n.isArray(a)||(a=[]),n(this).data("selected",a).data("settings",e).attr("tabindex",-1),t.upload_init.call(this),this.refresh=function(){var o=this,r=n(this).data("div"),i=n(this).data("settings"),c=n(this).data("selected"),h,t,s,l,e,f,u;n(r).find("li").remove(),n(r).find("> span:first-child").css("line-height",n(r).height()-w2utils.getSize(r,"+height")-8+"px");for(h in c){t=c[h],s=n(r).find(".file-list li").length,n(r).find("> span:first-child").remove(),n(r).find(".file-list").append('\t \t'+t.name+'\t - '+w2utils.size(t.size)+""),l=n(r).find(".file-list #file-"+s),e="",/image/i.test(t.type)&&(e='\t= h && w > 300) $(this).width(300);\t\t\tif (w < h && h > 300) $(this).height(300);"\t\tonerror="this.style.display = \'none\'"\t>'),f='style="padding: 3px; text-align: right; color: #777;"',u='style="padding: 3px"',e+='\t\tName:"+t.name+"\tSize:"+w2utils.size(t.size)+"\tType:\t\t'+t.type+"\t\tModified:"+w2utils.date(t.modified)+"\t";l.data("file",t).on("click",function(t){if(typeof i.onItemClick=="function"){var r=i.onItemClick.call(o,n(this).data("file"));if(r===!1)return}n(t.target).hasClass("file-delete")||t.stopPropagation()}).on("dblclick",function(t){if(typeof i.onItemDblClick=="function"){var r=i.onItemDblClick.call(o,n(this).data("file"));if(r===!1)return}t.stopPropagation(),document.selection?document.selection.empty():document.defaultView.getSelection().removeAllRanges()}).on("mouseover",function(){var u,r;(typeof i.onItemOver!="function"||(u=i.onItemOver.call(o,n(this).data("file")),u!==!1))&&(r=n(this).data("file"),n(this).w2overlay(e.replace("##FILE##",r.content?"data:"+r.type+";base64,"+r.content:""),{top:-4}))}).on("mouseout",function(){if(typeof i.onItemOut=="function"){var t=i.onItemOut.call(o,n(this).data("file"));if(t===!1)return}n(this).w2overlay()})}},this.refresh();break;case"slider":break;default:console.log('ERROR: w2field does not recognize "'+i.type+'" field type.')}})},addType:function(n,i){t.customTypes[String(n).toLowerCase()]=i},cleanItems:function(t){var e=[],f;for(f in t){var r="",u="",i=t[f];if(i!=null){if(n.isPlainObject(t))r=f,u=i;else if(typeof i=="object"&&(typeof i.id!="undefined"&&(r=i.id),typeof i.value!="undefined"&&(r=i.value),typeof i.txt!="undefined"&&(u=i.txt),typeof i.text!="undefined"&&(u=i.text)),typeof i=="string"){if(String(i)=="")continue;r=i,u=i,i={}}w2utils.isInt(r)&&(r=parseInt(r)),w2utils.isFloat(r)&&(r=parseFloat(r)),e.push(n.extend({},i,{id:r,text:u}))}}return e},upload_init:function(){var i=this,o=n(this).data("settings"),u=n(i).prev(),e,f,r;u.length>0&&u[0].tagName=="DIV"&&u.hasClass("w2ui-upload")&&u.remove(),e="margin-top: "+n(i).css("margin-top")+"; margin-bottom: "+n(i).css("margin-bottom")+"; margin-left: "+n(i).css("margin-left")+"; margin-right: "+n(i).css("margin-right")+"; width: "+(w2utils.getSize(i,"width")-parseInt(n(i).css("margin-left"))-parseInt(n(i).css("margin-right")))+"px; height: "+(w2utils.getSize(i,"height")-parseInt(n(i).css("margin-top"))-parseInt(n(i).css("margin-bottom")))+"px; ",f='\t'+o.hint+'\t\t',n(i).css({display1:"none","border-color":"transparent"}).before(f),n(i).data("div",n(i).prev()[0]),r=n(i).data("div");n(r).find(".file-input").off("change").on("change",function(){if(typeof this.files!="undefined")for(var n=0,r=this.files.length;ni.maxFileSize){r="Maximum file size is "+w2utils.size(i.maxFileSize),n(o).w2tag(r),console.log("ERROR: "+r);return}if(i.maxSize!=0&&l+f.size>i.maxSize){r="Maximum total size is "+w2utils.size(i.maxFileSize),n(o).w2tag(r),console.log("ERROR: "+r);return}if(i.max!=0&&a>=i.max){r="Maximum number of files is "+i.max,n(o).w2tag(r),console.log("ERROR: "+r);return}(typeof i.onAdd!="function"||(h=i.onAdd.call(u,f),h!==!1))&&(s.push(f),typeof FileReader!="undefined"&&i.base64===!0?(e=new FileReader,e.onload=function(){return function(t){var i=t.target.result,r=i.indexOf(",");f.content=i.substr(r+1),u.refresh(),n(u).trigger("change")}}(),e.readAsDataURL(t)):(u.refresh(),n(u).trigger("change")))},upload_remove:function(t){var r=this,s=n(r).data("div"),e=n(r).data("settings"),u=n(r).data("selected"),f=n(t).data("file"),o,i;if(typeof e.onRemove=="function"&&(o=e.onRemove.call(r,f),o===!1))return!1;for(i=u.length-1;i>=0;i--)u[i].name==f.name&&u[i].size==f.size&&u.splice(i,1);n(t).fadeOut("fast"),setTimeout(function(){n(t).remove(),u.length==0&&n(s).prepend(""+e.hint+""),r.refresh(),n(r).trigger("change")},300)},list_render:function(i){var r=this,e=n("#w2ui-global-items"),u=n(this).data("settings"),o=u.items,v=n(this).data("selected"),k,a,w,f,c,h,g,y;if(e.length!=0){typeof i=="undefined"&&(k="",k+='',e.html(k),i=""),n(this).data("last_search",i),(typeof n(r).data("last_index")=="undefined"||n(r).data("last_index")==null)&&n(r).data("last_index",0),typeof u.last_total=="undefined"&&(u.last_total=-1),typeof u.last_search_len=="undefined"&&(u.last_search_len=0),typeof u.last_search_match=="undefined"&&(u.last_search_match=-1),u.url!=""&&(o.length==0&&u.last_total!=0||i.length>u.last_search_len&&u.last_total>u.maxCache||i.length",d=[];for(f in v)d.push(w2utils.isInt(v[f].id)?parseInt(v[f].id):String(v[f].id));w="";for(f in o)if(c=o[f].id,h=o[f].text,n.inArray(w2utils.isInt(c)?parseInt(c):String(c),d)==-1||u.showAll===!0){var p=String(i).toLowerCase(),b=h.toLowerCase(),a=p.length<=b.length&&b.substr(0,p.length)==p;u.match.toLowerCase()=="contains"&&b.indexOf(p)!=-1&&(a=!0),a&&(typeof u.render=="function"&&(h=u.render(o[f],v)),h!==!1&&(typeof o[f].group!="undefined"&&o[f].group!=w&&(w=o[f].group,l+=''+w+""),l+='\n'+h+"",s==n(r).data("last_index")&&n(r).data("last_item",o[f]),s++))}l+="",s==0&&(l=''+w2utils.lang("No items found")+"",g=!0),e.find(".w2ui-items-list").html(l),n(this).data("last_max",s-1),e.find("li.selected").length>0&&e.find("li.selected")[0].scrollIntoView(!1),e.css({"-webkit-transition":"0s",height:"auto"}),y=parseInt(n(document).height())-parseInt(e.offset().top)-8,parseInt(e.height())>y&&(e.css({height:y-5+"px",overflow:"show"}),n(e).find(".w2ui-items-list").css({height:y-15+"px",overflow:"auto"}));n(e).off("mousedown").on("mousedown",function(i){var e=i.target,f,o;if(e.tagName!="LI"&&(e=n(e).parents("li")),f=n(e).attr("index"),f){if(o=u.items[f],typeof f=="undefined")if(i.preventDefault)i.preventDefault();else return!1;r.add(o),n(r).data("last_index",0),r.refresh(),t.list_render.call(r,"")}});n(r).prev().find("li > input").val(i).css("max-width",n(e).width()-25+"px").width((i.length+2)*6+"px").focus().on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0}).off("keyup").on("keyup",function(i){var u=this;setTimeout(function(){var f=n(r).data("last_index"),e;switch(i.keyCode){case 38:f--,f<0&&(f=0),n(r).data("last_index",f),i.preventDefault&&i.preventDefault();break;case 40:f++,f>n(r).data("last_max")&&(f=n(r).data("last_max")),n(r).data("last_index",f),i.preventDefault&&i.preventDefault();break;case 13:if(typeof n(r).data("last_item")=="undefined"||n(r).data("last_item")==null||g===!0)break;e=n(r).data("selected"),r.add(n(r).data("last_item")),f>n(r).data("last_max")-1&&(f=n(r).data("last_max")-1),n(r).data("last_index",f),n(r).data("last_item",null),n(u).val(""),r.refresh(),i.preventDefault&&i.preventDefault();break;case 8:String(u.value)==""&&(typeof n(r).data("last_del")=="undefined"||n(r).data("last_del")==null?(e=n(r).data("selected"),n.isArray(e)||(e=[]),n(r).data("last_del",e.length-1),r.refresh()):(e=n(r).data("selected"),r.remove(e.length-1)));break;default:n(r).data("last_index",0),n(r).data("last_del",null)}r.resize(),i.keyCode==8&&String(u.value)==""||(n(r).prev().find("li").css("opacity","1"),n(r).data("last_del",null)),n.inArray(i.keyCode,[16,91,37,39])==-1&&t.list_render.call(r,u.value)},10)})}},calendar_get:function(t,i){var e=new Date,s=Number(e.getMonth())+1+"/"+e.getDate()+"/"+(String(e.getYear()).length>3?e.getYear():e.getYear()+1900),o;(String(t)==""||String(t)=="undefined")&&(t=w2utils.formatDate(s,i.format)),w2utils.isDate(t,i.format)||(t=w2utils.formatDate(s,i.format));var r=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),f=i.format.replace(/-/g,"/").replace(/\./g,"/").toLowerCase(),u=new Date;return f=="mm/dd/yyyy"&&(u=new Date(r[0]+"/"+r[1]+"/"+r[2])),f=="m/d/yyyy"&&(u=new Date(r[0]+"/"+r[1]+"/"+r[2])),f=="dd/mm/yyyy"&&(u=new Date(r[1]+"/"+r[0]+"/"+r[2])),f=="d/m/yyyy"&&(u=new Date(r[1]+"/"+r[0]+"/"+r[2])),f=="yyyy/dd/mm"&&(u=new Date(r[2]+"/"+r[1]+"/"+r[0])),f=="yyyy/d/m"&&(u=new Date(r[2]+"/"+r[1]+"/"+r[0])),f=="yyyy/mm/dd"&&(u=new Date(r[1]+"/"+r[2]+"/"+r[0])),f=="yyyy/m/d"&&(u=new Date(r[1]+"/"+r[2]+"/"+r[0])),o=''+n().w2field("calendar_month",u.getMonth()+1,u.getFullYear(),i)+""},calendar_next:function(t){var f=String(t).split("/"),i=f[0],u=f[1],r;parseInt(i)<12?i=parseInt(i)+1:(i=1,u=parseInt(u)+1),r=n(n("#global_calendar_div.w2ui-calendar").data("el")).data("options"),n("#global_calendar_div.w2ui-calendar").html(n().w2field("calendar_get",w2utils.formatDate(i+"/1/"+u,r.format),r))},calendar_previous:function(t){var f=String(t).split("/"),i=f[0],u=f[1],r;parseInt(i)>1?i=parseInt(i)-1:(i=12,u=parseInt(u)-1),r=n(n("#global_calendar_div.w2ui-calendar").data("el")).data("options"),n("#global_calendar_div.w2ui-calendar").html(n().w2field("calendar_get",w2utils.formatDate(i+"/1/"+u,r.format),r))},calendar_month:function(t,i,r){var u=new Date,rt=w2utils.settings.fullmonths,et=w2utils.settings.fulldays,p=["31","28","31","30","31","30","31","31","30","31","30","31"],ft=Number(u.getMonth())+1+"/"+u.getDate()+"/"+(String(u.getYear()).length>3?u.getYear():u.getYear()+1900),c,g,e,s,f,v,o,h,l;i=Number(i),t=Number(t),(i===null||i==="")&&(i=String(u.getYear()).length>3?u.getYear():u.getYear()+1900),(t===null||t==="")&&(t=Number(u.getMonth())+1),t>12&&(t=t-12,i++),(t<1||t==0)&&(t=t+12,i--),p[1]=i/4==Math.floor(i/4)?"29":"28",i==null&&(i=u.getYear()),t==null&&(t=u.getMonth()-1),u=new Date,u.setDate(1),u.setMonth(t-1),u.setYear(i);var y=u.getDay(),nt=w2utils.settings.shortdays,d="";for(c=0,g=nt.length;c"+nt[c]+"";for(e='\t <- \t -> "+rt[t-1]+", "+i+'\t'+d+"\t",s=1,f=1;f<43;f++){if(y==0&&f==1){for(v=0;v<6;v++)e+=' ';f+=6}else if(fp[t-1]){e+=' ',f%7==0&&(e+="");continue}o=t+"/"+s+"/"+i,h="",f%7==6&&(h="w2ui-saturday"),f%7==0&&(h="w2ui-sunday"),o==ft&&(h+=" w2ui-today");var ut=s,b="",w="",a="";if(r.colored&&r.colored[o]!=undefined&&(tmp=r.colored[o].split(":"),w="background-color: "+tmp[0]+";",b="color: "+tmp[1]+";"),l=!1,r.start||r.end){var tt=new Date(r.start),it=new Date(r.end),k=new Date(o);(kit)&&(a=" w2ui-blocked-date",l=!0)}r.blocked&&n.inArray(o,r.blocked)!=-1&&(a=" w2ui-blocked-date",l=!0),e+='"+ut+"",(f%7==0||y==0&&f==1)&&(e+=""),s++}return e+=""},getColorHTML:function(n){for(var r='',u=[["000000","444444","666666","999999","CCCCCC","EEEEEE","F3F3F3","FFFFFF"],["FF011B","FF9838","FFFD59","01FD55","00FFFE","0424F3","9B24F4","FF21F5"],["F4CCCC","FCE5CD","FFF2CC","D9EAD3","D0E0E3","CFE2F3","D9D1E9","EAD1DC"],["EA9899","F9CB9C","FEE599","B6D7A8","A2C4C9","9FC5E8","B4A7D6","D5A6BD"],["E06666","F6B26B","FED966","93C47D","76A5AF","6FA8DC","8E7CC3","C27BA0"],["CC0814","E69138","F1C232","6AA84F","45818E","3D85C6","674EA7","A54D79"],["99050C","B45F17","BF901F","37761D","124F5C","0A5394","351C75","741B47"],["660205","783F0B","7F6011","274E12","0C343D","063762","20124D","4C1030"]],i,t=0;t<8;t++){for(r+="",i=0;i<8;i++)r+="\t\t\t'+(n==u[t][i]?"":" ")+"\t";r+="",t<2&&(r+='')}return r+=""}}),w2obj.field=t}(jQuery),function($){var w2form=function(n){this.name=null,this.header="",this.box=null,this.url="",this.formURL="",this.formHTML="",this.page=0,this.recid=0,this.fields=[],this.actions={},this.record={},this.original={},this.postData={},this.toolbar={},this.tabs={},this.style="",this.focus=0,this.msgNotJSON=w2utils.lang("Return data is not in JSON format."),this.msgRefresh=w2utils.lang("Refreshing..."),this.msgSaving=w2utils.lang("Saving..."),this.onRequest=null,this.onLoad=null,this.onValidate=null,this.onSubmit=null,this.onSave=null,this.onChange=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,this.onAction=null,this.onToolbar=null,this.onError=null,this.isGenerated=!1,this.last={xhr:null},$.extend(!0,this,w2obj.form,n)};$.fn.w2form=function(n){var s,u,i,r;if(typeof n!="object"&&n){if(w2ui[$(this).attr("name")])return r=w2ui[$(this).attr("name")],r[n].apply(r,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+n+" does not exist on jQuery.w2form")}else{if(r=this,!n||typeof n.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2form().');return}if(typeof w2ui[n.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+").");return}if(!w2utils.isAlphaNumeric(n.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var o=n.record,e=n.original,h=n.fields,c=n.toolbar,f=n.tabs,t=new w2form(n);if($.extend(t,{record:{},original:{},fields:[],tabs:{},toolbar:{},handlers:[]}),$.isArray(f)){$.extend(!0,t.tabs,{tabs:[]});for(s in f)u=f[s],typeof u=="object"?t.tabs.tabs.push(u):t.tabs.tabs.push({id:u,caption:u})}else $.extend(!0,t.tabs,f);$.extend(!0,t.toolbar,c);for(i in h)t.fields[i]=$.extend(!0,{},h[i]);for(i in o)t.record[i]=$.isPlainObject(o[i])?$.extend(!0,{},o[i]):o[i];for(i in e)t.original[i]=$.isPlainObject(e[i])?$.extend(!0,{},e[i]):e[i];return r.length>0&&(t.box=r[0]),t.formURL!=""?$.get(t.formURL,function(n){t.formHTML=n,t.isGenerated=!0,($(t.box).length!=0||n.length!=0)&&($(t.box).html(n),t.render(t.box))}):t.formHTML!=""||(t.formHTML=$(this).length!=0&&$.trim($(this).html())!=""?$(this).html():t.generateHTML()),w2ui[t.name]=t,t.formURL==""&&(String(t.formHTML).indexOf("w2ui-page")==-1&&(t.formHTML=''+t.formHTML+""),$(t.box).html(t.formHTML),t.isGenerated=!0,t.render(t.box)),t}},w2form.prototype={get:function(n,t){for(var i in this.fields)if(this.fields[i].name==n)return t===!0?i:this.fields[i];return null},set:function(n,t){for(var i in this.fields)if(this.fields[i].name==n)return $.extend(this.fields[i],t),this.refresh(),!0;return!1},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t&&this.recid!=0?this.request(n):(this.refresh(),typeof n=="function"&&n())},clear:function(){var n,t;this.recid=0,this.record={};for(n in this.fields)t=this.fields[n];$().w2tag(),this.refresh()},error:function(n){var i=this,t=this.trigger({target:this.name,type:"error",message:n,xhr:this.last.xhr});if(t.isCancelled===!0)return typeof callBack=="function"&&callBack(),!1;setTimeout(function(){w2alert(n,"Error")},1),this.trigger($.extend(t,{phase:"after"}))},validate:function(n){var i,e,t,u,r,o,f;typeof n=="undefined"&&(n=!0),i=[];for(e in this.fields){t=this.fields[e],this.record[t.name]==null&&(this.record[t.name]="");switch(t.type){case"int":this.record[t.name]&&!w2utils.isInt(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not an integer")});break;case"float":this.record[t.name]&&!w2utils.isFloat(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a float")});break;case"money":this.record[t.name]&&!w2utils.isMoney(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not in money format")});break;case"hex":this.record[t.name]&&!w2utils.isHex(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a hex number")});break;case"email":this.record[t.name]&&!w2utils.isEmail(this.record[t.name])&&i.push({field:t,error:w2utils.lang("Not a valid email")});break;case"checkbox":this.record[t.name]=this.record[t.name]==!0?1:0;break;case"date":this.record[t.name]&&!w2utils.isDate(this.record[t.name],t.options.format)&&i.push({field:t,error:w2utils.lang("Not a valid date")+": "+t.options.format})}u=this.record[t.name],t.required&&(u===""||$.isArray(u)&&u.length==0)&&i.push({field:t,error:w2utils.lang("Required field")}),t.equalto&&this.record[t.name]!=this.record[t.equalto]&&i.push({field:t,error:w2utils.lang("Field should be equal to ")+t.equalto})}if(r=this.trigger({phase:"before",target:this.name,type:"validate",errors:i}),r.isCancelled===!0)return i;if(n)for(o in r.errors)f=r.errors[o],$(f.field.el).w2tag(f.error,{"class":"w2ui-error"});return this.trigger($.extend(r,{phase:"after"})),i},request:function(postData,callBack){var obj=this,params,eventData,url;if(typeof postData=="function"&&(callBack=postData,postData=null),(typeof postData=="undefined"||postData==null)&&(postData={}),this.url&&(typeof this.url!="object"||this.url.get)){if((this.recid==null||typeof this.recid=="undefined")&&(this.recid=0),params={},params.cmd="get-record",params.name=this.name,params.recid=this.recid,$.extend(params,this.postData),$.extend(params,postData),eventData=this.trigger({phase:"before",type:"request",target:this.name,url:this.url,postData:params}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."}),!1;if(this.record={},this.original={},this.lock(this.msgRefresh),url=eventData.url,typeof eventData.url=="object"&&eventData.url.get&&(url=eventData.url.get),this.last.xhr)try{this.last.xhr.abort()}catch(e){}this.last.xhr=$.ajax({type:"GET",url:url,data:String($.param(eventData.postData,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",complete:function(xhr,status){var eventData,responseText,data;if(obj.unlock(),eventData=obj.trigger({phase:"before",target:obj.name,type:"load",xhr:xhr,status:status}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."}),!1;if(responseText=obj.last.xhr.responseText,status!="error"){if(typeof responseText!="undefined"&&responseText!=""){if(typeof responseText=="object")data=responseText;else try{eval("data = "+responseText)}catch(e){}typeof data=="undefined"&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),data.status=="error"?obj.error(data.message):(obj.record=$.extend({},data.record),obj.original=$.extend({},data.record))}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText);obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),typeof callBack=="function"&&callBack(data)}}),this.trigger($.extend(eventData,{phase:"after"}))}},submit:function(n,t){return this.save(n,t)},save:function(postData,callBack){var obj=this,errors;if(typeof postData=="function"&&(callBack=postData,postData=null),errors=obj.validate(!0),errors.length!==0){obj.goto(errors[0].field.page);return}if((typeof postData=="undefined"||postData==null)&&(postData={}),!obj.url||typeof obj.url=="object"&&!obj.url.save){console.log("ERROR: Form cannot be saved because no url is defined.");return}obj.lock(obj.msgSaving+' '),setTimeout(function(){var params={},f,field,tmp,dt,eventData,url;params.cmd="save-record",params.name=obj.name,params.recid=obj.recid,$.extend(params,obj.postData),$.extend(params,postData),params.record=$.extend(!0,{},obj.record);for(f in obj.fields){field=obj.fields[f];switch(String(field.type).toLowerCase()){case"date":dt=params.record[field.name],(field.options.format.toLowerCase()=="dd/mm/yyyy"||field.options.format.toLowerCase()=="dd-mm-yyyy"||field.options.format.toLowerCase()=="dd.mm.yyyy")&&(tmp=dt.replace(/-/g,"/").replace(/\./g,"/").split("/"),dt=new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0])),params.record[field.name]=w2utils.formatDate(dt,"yyyy-mm-dd")}}if(eventData=obj.trigger({phase:"before",type:"submit",target:obj.name,url:obj.url,postData:params}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Saving aborted."}),!1;if(url=eventData.url,typeof eventData.url=="object"&&eventData.url.save&&(url=eventData.url.save),obj.last.xhr)try{obj.last.xhr.abort()}catch(e){}obj.last.xhr=$.ajax({type:w2utils.settings.RESTfull?obj.recid==0?"POST":"PUT":"POST",url:url,data:String($.param(eventData.postData,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",xhr:function(){var n=new window.XMLHttpRequest;return n.upload.addEventListener("progress",function(n){if(n.lengthComputable){var t=Math.round(n.loaded/n.total*100);$("#"+obj.name+"_progress").text(""+t+"%")}},!1),n},complete:function(xhr,status){var eventData,responseText,data;if(obj.unlock(),eventData=obj.trigger({phase:"before",target:obj.name,type:"save",xhr:xhr,status:status}),eventData.isCancelled===!0)return typeof callBack=="function"&&callBack({status:"error",message:"Saving aborted."}),!1;if(responseText=xhr.responseText,status!="error"){if(typeof responseText!="undefined"&&responseText!=""){if(typeof responseText=="object")data=responseText;else try{eval("data = "+responseText)}catch(e){}typeof data=="undefined"&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),data.status=="error"?obj.error(data.message):obj.original=$.extend({},obj.record)}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText);obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),typeof callBack=="function"&&callBack(data)}}),obj.trigger($.extend(eventData,{phase:"after"}))},50)},lock:function(n,t){var i=$(this.box).find("> div:first-child");w2utils.lock(i,n,t)},unlock:function(){var n=this;setTimeout(function(){w2utils.unlock(n.box)},25)},goto:function(n){typeof n!="undefined"&&(this.page=n),$(this.box).data("auto-size")===!0&&$(this.box).height(0),this.refresh()},generateHTML:function(){var t=[],e,f,n,r,o,i,u;for(e in this.fields)f="",n=this.fields[e],typeof n.html=="undefined"&&(n.html={}),n.html=$.extend(!0,{caption:"",span:6,attr:"",text:"",page:0},n.html),n.html.caption==""&&(n.html.caption=n.name),r='",n.type=="list"&&(r='"),n.type=="checkbox"&&(r='"),n.type=="textarea"&&(r='"),f+='\n '+n.html.caption+':\n '+r+n.html.text+"",typeof t[n.html.page]=="undefined"&&(t[n.html.page]=''),t[n.html.page]+=f;for(o in t)t[o]+="\n";if(i="",!$.isEmptyObject(this.actions)){i+='\n';for(u in this.actions)i+='\n ';i+="\n"}return t.join("")+i},action:function(n,t){var i=this.trigger({phase:"before",target:n,type:"action",originalEvent:t});if(i.isCancelled===!0)return!1;typeof this.actions[n]=="function"&&this.actions[n].call(this,t),this.trigger($.extend(i,{phase:"after"}))},resize:function(){function o(){s.width($(n.box).width()).height($(n.box).height()),i.css("top",n.header!=""?w2utils.getSize(t,"height"):0),f.css("top",(n.header!=""?w2utils.getSize(t,"height"):0)+(n.toolbar.items.length>0?w2utils.getSize(i,"height"):0)),u.css("top",(n.header!=""?w2utils.getSize(t,"height"):0)+(n.toolbar.items.length>0?w2utils.getSize(i,"height")+5:0)+(n.tabs.tabs.length>0?w2utils.getSize(f,"height")+5:0)),u.css("bottom",r.length>0?w2utils.getSize(r,"height"):0)}var n=this,e=this.trigger({phase:"before",target:this.name,type:"resize"});if(e.isCancelled===!0)return!1;var s=$(this.box).find("> div"),t=$(this.box).find("> div .w2ui-form-header"),i=$(this.box).find("> div .w2ui-form-toolbar"),f=$(this.box).find("> div .w2ui-form-tabs"),u=$(this.box).find("> div .w2ui-page"),h=$(this.box).find("> div .w2ui-page.page-"+this.page),c=$(this.box).find("> div .w2ui-page.page-"+this.page+" > div"),r=$(this.box).find("> div .w2ui-buttons");o(),(parseInt($(this.box).height())==0||$(this.box).data("auto-size")===!0)&&($(this.box).height((t.length>0?w2utils.getSize(t,"height"):0)+(this.tabs.tabs.length>0?w2utils.getSize(f,"height"):0)+(this.toolbar.items.length>0?w2utils.getSize(i,"height"):0)+(u.length>0?w2utils.getSize(c,"height")+w2utils.getSize(h,"+height")+12:0)+(r.length>0?w2utils.getSize(r,"height"):0)),$(this.box).data("auto-size",!0)),o(),n.trigger($.extend(e,{phase:"after"}))},refresh:function(){var i=this,e,f,n,t,u,r;if(this.box&&this.isGenerated&&typeof $(this.box).html()!="undefined"){if($(this.box).find("input, textarea, select").each(function(n,t){var e=typeof $(t).attr("name")!="undefined"?$(t).attr("name"):$(t).attr("id"),f=i.get(e),u,r;if(f&&(u=$(t).parents(".w2ui-page"),u.length>0))for(r=0;r<100;r++)if(u.hasClass("page-"+r)){f.page=r;break}}),e=this.trigger({phase:"before",target:this.name,type:"refresh",page:this.page}),e.isCancelled===!0)return!1;$(this.box).find(".w2ui-page").hide(),$(this.box).find(".w2ui-page.page-"+this.page).show(),$(this.box).find(".w2ui-form-header").html(this.header),typeof this.tabs=="object"&&this.tabs.tabs.length>0?($("#form_"+this.name+"_tabs").show(),this.tabs.active=this.tabs.tabs[this.page].id,this.tabs.refresh()):$("#form_"+this.name+"_tabs").hide(),typeof this.toolbar=="object"&&this.toolbar.items.length>0?($("#form_"+this.name+"_toolbar").show(),this.toolbar.refresh()):$("#form_"+this.name+"_toolbar").hide();for(f in this.fields){n=this.fields[f],n.el=$(this.box).find('[name="'+String(n.name).replace(/\\/g,"\\\\")+'"]')[0],typeof n.el=="undefined"&&console.log('ERROR: Cannot associate field "'+n.name+'" with html control. Make sure html control exists with the same name.'),n.el&&(n.el.id=n.name);$(n.el).off("change").on("change",function(){var r=this.value,s=i.record[this.name]?i.record[this.name]:"",u=i.get(this.name),n,f,t;if((u.type=="enum"||u.type=="upload")&&$(this).data("selected")){var e=$(this).data("selected"),o=i.record[this.name],r=[],s=[];if($.isArray(e))for(n in e)r[n]=$.extend(!0,{},e[n]);if($.isArray(o))for(n in o)s[n]=$.extend(!0,{},o[n])}if(f=i.trigger({phase:"before",target:this.name,type:"change",value_new:r,value_previous:s}),f.isCancelled===!0)return $(this).val(i.record[this.name]),!1;t=this.value,this.type=="checkbox"&&(t=this.checked?!0:!1),this.type=="radio"&&(t=this.checked?!0:!1),u.type=="enum"&&(t=r),u.type=="upload"&&(t=r),i.record[this.name]=t,i.trigger($.extend(f,{phase:"after"}))});n.required?$(n.el).parent().addClass("w2ui-required"):$(n.el).parent().removeClass("w2ui-required")}$(this.box).find("button, input[type=button]").each(function(n,t){$(t).off("click").on("click",function(n){var t=this.value;this.name&&(t=this.name),this.id&&(t=this.id),i.action(t,n)})});for(f in this.fields)if(n=this.fields[f],t=typeof this.record[n.name]!="undefined"?this.record[n.name]:"",n.el)switch(String(n.type).toLowerCase()){case"email":case"text":case"textarea":n.el.value=t;break;case"date":n.options||(n.options={}),n.options.format||(n.options.format=w2utils.settings.date_format),n.el.value=t,this.record[n.name]=t,$(n.el).w2field($.extend({},n.options,{type:"date"}));break;case"int":n.el.value=t,$(n.el).w2field("int");break;case"float":n.el.value=t,$(n.el).w2field("float");break;case"money":n.el.value=t,$(n.el).w2field("money");break;case"hex":n.el.value=t,$(n.el).w2field("hex");break;case"alphanumeric":n.el.value=t,$(n.el).w2field("alphaNumeric");break;case"checkbox":this.record[n.name]==!0||this.record[n.name]==1||this.record[n.name]=="t"?$(n.el).prop("checked",!0):$(n.el).prop("checked",!1);break;case"password":n.el.value=t;break;case"select":case"list":$(n.el).w2field($.extend({},n.options,{type:"list",value:t}));break;case"enum":if(typeof n.options=="undefined"||typeof n.options.url=="undefined"&&typeof n.options.items=="undefined"){console.log("ERROR: (w2form."+i.name+") the field "+n.name+" defined as enum but not field.options.url or field.options.items provided.");break}this.record[n.name]=w2obj.field.cleanItems(t),t=this.record[n.name],$(n.el).w2field($.extend({},n.options,{type:"enum",selected:t}));break;case"upload":$(n.el).w2field($.extend({},n.options,{type:"upload",selected:t}));break;default:console.log('ERROR: field type "'+n.type+'" is not recognized.')}for(u=$(this.box).find(".w2ui-page"),r=0;r *").length>1&&$(u[r]).wrapInner("");this.trigger($.extend(e,{phase:"after"})),this.resize()}},render:function(n){function f(){var n=$(t.box).find("input, select, textarea");n.length>t.focus&&n[t.focus].focus()}var t=this,i,u,r;if(typeof n=="object"&&($(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),this.box=n),this.isGenerated){if(i=this.trigger({phase:"before",target:this.name,type:"render",box:typeof n!="undefined"?n:this.box}),i.isCancelled===!0)return!1;if(u=""+(this.header!=""?''+this.header+"":"")+'\t\t'+this.formHTML+"",$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-form").html(u),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),typeof this.toolbar.render=="undefined"){this.toolbar=$().w2toolbar($.extend({},this.toolbar,{name:this.name+"_toolbar",owner:this}));this.toolbar.on("click",function(n){var i=t.trigger({phase:"before",type:"toolbar",target:n.target,originalEvent:n});if(i.isCancelled===!0)return!1;t.trigger($.extend(i,{phase:"after"}))})}if(typeof this.toolbar=="object"&&typeof this.toolbar.render=="function"&&this.toolbar.render($("#form_"+this.name+"_toolbar")[0]),typeof this.tabs.render=="undefined"){this.tabs=$().w2tabs($.extend({},this.tabs,{name:this.name+"_tabs",owner:this}));this.tabs.on("click",function(n){t.goto(this.get(n.target,!0))})}if(typeof this.tabs=="object"&&typeof this.tabs.render=="function"&&this.tabs.render($("#form_"+this.name+"_tabs")[0]),this.trigger($.extend(i,{phase:"after"})),this.resize(),r=typeof this.url!="object"?this.url:this.url.get,r&&this.recid!=0?this.request():this.refresh(),$(".w2ui-layout").length==0){this.tmp_resize=function(){w2ui[t.name].resize()};$(window).off("resize","body").on("resize","body",this.tmp_resize)}setTimeout(function(){t.resize(),t.refresh()},150),this.focus>=0&&setTimeout(f,500)}},destroy:function(){var n=this.trigger({phase:"before",target:this.name,type:"destroy"});if(n.isCancelled===!0)return!1;typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),typeof this.tabs=="object"&&this.tabs.destroy&&this.tabs.destroy(),$(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),delete w2ui[this.name],this.trigger($.extend(n,{phase:"after"})),$(window).off("resize","body")}},$.extend(w2form.prototype,w2utils.event),w2obj.form=w2form}(jQuery); \ No newline at end of file +var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function i(n){var t=/^[-+]?[0-9]+$/;return t.test(n)}function r(n){return typeof n=="string"&&(n=n.replace(w2utils.settings.decimalSymbol,".")),(typeof n=="number"||typeof n=="string"&&n!=="")&&!isNaN(Number(n))}function u(n){var t=w2utils.settings,i=new RegExp("^"+(t.currencyPrefix?"\\"+t.currencyPrefix+"?":"")+"[-+]?[0-9]*[\\"+w2utils.settings.decimalSymbol+"]?[0-9]+"+(t.currencySuffix?"\\"+t.currencySuffix+"?":"")+"$","i");return(typeof n=="string"&&(n=n.replace(new RegExp(t.groupSymbol,"g"),"")),typeof n=="object"||n==="")?!1:i.test(n)}function f(n){return/^[a-fA-F0-9]+$/.test(n)}function e(n){return/^[a-zA-Z0-9_-]+$/.test(n)}function o(n){return/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(n)}function s(n,t,r){var h,f,e,o,c,a,l,u,s;if(!n)return!1;if(h="Invalid Date",t==null&&(t=w2utils.settings.date_format),typeof n.getUTCFullYear=="function"&&typeof n.getUTCMonth=="function"&&typeof n.getUTCDate=="function")o=n.getUTCFullYear(),f=n.getUTCMonth(),e=n.getUTCDate();else if(typeof n.getFullYear=="function"&&typeof n.getMonth=="function"&&typeof n.getDate=="function")o=n.getFullYear(),f=n.getMonth(),e=n.getDate();else{if(n=String(n),RegExp("mon","ig").test(t))for(t=t.replace(/month/ig,"m").replace(/mon/ig,"m").replace(/dd/ig,"d").replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),n=n.replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),c=0,a=w2utils.settings.fullmonths.length;c=0;f=s||t.indexOf("AM")>=0;o=f?12:24;t=t.replace("AM","").replace("PM","");t=n.trim(t);var r=t.split(":"),u=parseInt(r[0]||0),e=parseInt(r[1]||0);return(!f||r.length!==1)&&r.length!==2?!1:r[0]===""||u<0||u>o||!this.isInt(r[0])||r[0].length>2?!1:r.length===2&&(r[1]===""||e<0||e>59||!this.isInt(r[1])||r[1].length!==2)?!1:!f&&o===u&&e!==0?!1:f&&r.length===1&&u===0?!1:i===!0?(s&&(u+=12),{hours:u,minutes:e}):!0}function c(n){var u;if(n===""||n==null||(u=new Date(n),w2utils.isInt(n)&&(u=new Date(Number(n))),u==="Invalid Date"))return"";var f=new Date,t=(f.getTime()-u.getTime())/1e3,i="",r="";return t<0?(i='future<\/span>',r=""):t<60?(i=Math.floor(t),r="sec",t<0&&(i=0,r="sec")):t<3600?(i=Math.floor(t/60),r="min"):t<86400?(i=Math.floor(t/3600),r="hour"):t<2592e3?(i=Math.floor(t/86400),r="day"):t<365.25*86400?(i=Math.floor(t/365.25/8640)/10,r="month"):t>=365.25*86400&&(i=Math.floor(t/365.25/8640)/10,r="year"),i+" "+r+(i>1?"s":"")}function l(n){var t;if(n===""||n==null||(t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),t==="Invalid Date"))return"";var u=w2utils.settings.shortmonths,f=new Date,i=new Date;i.setTime(i.getTime()-864e5);var r=u[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),o=u[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),s=u[i.getMonth()]+" "+i.getDate()+", "+i.getFullYear(),h=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),c=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=r;return r===o&&(e=h),r===s&&(e=w2utils.lang("Yesterday")),''+e+"<\/span>"}function a(n){if(!w2utils.isFloat(n)||n==="")return"";if(n=parseFloat(n),n===0)return 0;var t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t===0?0:1)+" "+["Bt","KB","MB","GB","TB"][t]}function v(n,i,r){var u="";return i==null&&(i=w2utils.settings.groupSymbol||","),r==null&&(r=w2utils.settings.decimalSymbol||"."),(w2utils.isFloat(n)||w2utils.isInt(n)||w2utils.isMoney(n))&&(t=String(n).split("."),u=String(t[0]).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+i),t[1]!=null&&(u+=w2utils.settings.decimalSymbol+t[1])),u}function y(n,t){var e=w2utils.settings.shortmonths,o=w2utils.settings.fullmonths,i;if((t||(t=this.settings.date_format),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),i==="Invalid Date"))return"";var r=i.getFullYear(),f=i.getMonth(),u=i.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[f]).replace("mon",w2utils.settings.shortmonths[f]).replace(/yyyy/g,r).replace(/yyy/g,r).replace(/yy/g,r>2e3?100+parseInt(String(r).substr(2)):String(r).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+r).replace(/mm/g,(f+1<10?"0":"")+(f+1)).replace(/dd/g,(u<10?"0":"")+u).replace(/th/g,u==1?"st":"th").replace(/th/g,u==2?"nd":"th").replace(/th/g,u==3?"rd":"th").replace(/(^|[^a-z$])m/g,"$1"+(f+1)).replace(/(^|[^a-z$])d/g,"$1"+u)}function p(n,t){var h=w2utils.settings.shortmonths,c=w2utils.settings.fullmonths,i,o;if((t||(t=this.settings.time_format),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),w2utils.isTime(n)&&(o=w2utils.isTime(n,!0),i=new Date,i.setHours(o.hours),i.setMinutes(o.minutes)),i==="Invalid Date"))return"";var s="am",r=i.getHours(),e=i.getHours(),u=i.getMinutes(),f=i.getSeconds();return u<10&&(u="0"+u),f<10&&(f="0"+f),(t.indexOf("am")!==-1||t.indexOf("pm")!==-1)&&(r>=12&&(s="pm"),r>12&&(r=r-12)),t.toLowerCase().replace("am",s).replace("pm",s).replace("hhh",r<10?"0"+r:r).replace("hh24",e<10?"0"+e:e).replace("h24",e).replace("hh",r).replace("mm",u).replace("mi",u).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+r).replace(/(^|[^a-z$])m/g,"$1"+u).replace(/(^|[^a-z$])s/g,"$1"+f)}function w(n,t){var i;return n===""||n==null||typeof n=="object"&&!n.getMonth?"":(i=typeof t!="string"?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1]))}function b(t){if(t===null)return t;switch(typeof t){case"string":t=n.trim(String(t).replace(/(<([^>]+)>)/ig,""));break;case"object":for(var i in t)t[i]=this.stripTags(t[i])}return t}function k(n){if(n===null)return n;switch(typeof n){case"string":n=String(n).replace(/&/g,"&").replace(/>/g,">").replace(/\|\/? {}\\])/g,"\\$1")}function g(n){function l(n){for(var t,n=String(n).replace(/\r\n/g,"\n"),i="",r=0;r127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",o,t,i,h,c,s,r,u=0,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);u>2,c=(o&3)<<4|t>>4,s=(t&15)<<2|i>>6,r=i&63,isNaN(t)?s=r=64:isNaN(i)&&(r=64),e=e+f.charAt(h)+f.charAt(c)+f.charAt(s)+f.charAt(r);return e}function nt(n){function l(n){for(var r="",t=0,i=0,u,f;t191&&i<224?(u=n.charCodeAt(t+1),r+=String.fromCharCode((i&31)<<6|u&63),t+=2):(u=n.charCodeAt(t+1),f=n.charCodeAt(t+2),r+=String.fromCharCode((i&15)<<12|(u&63)<<6|f&63),t+=3);return r}var t="",o,s,h,c,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i>4,s=(f&15)<<4|r>>2,h=(r&3)<<6|e,t=t+String.fromCharCode(o),r!==64&&(t=t+String.fromCharCode(s)),e!==64&&(t=t+String.fromCharCode(h));return l(t)}function tt(t,i,r,u){function f(n,t,i){var r=!!window.webkitURL;return r||typeof i=="undefined"||(t=i),";"+n+": "+t+"; -webkit-"+n+": "+t+"; -moz-"+n+": "+t+"; -ms-"+n+": "+t+"; -o-"+n+": "+t+";"}var o=n(t).width(),s=n(t).height(),e=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+=f("perspective","700px")+"; overflow: hidden;";t.style.cssText+="; position: absolute; z-index: 1019; "+f("backface-visibility","hidden");i.style.cssText+="; position: absolute; z-index: 1020; "+f("backface-visibility","hidden");switch(r){case"slide-left":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)")},1);break;case"slide-right":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0px, 0, 0)","translate(0px, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)")},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; z-index: 0; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)")},1);break;case"slide-up":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateY(-180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(180deg)")},1);break;case"flip-right":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateY(180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(-180deg)")},1);break;case"flip-down":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateX(180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(-180deg)")},1);break;case"flip-up":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)");i.style.cssText+="overflow: hidden; "+f("transform","rotateX(-180deg)");n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)");t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(180deg)")},1);break;case"pop-in":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(.8)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1)")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")+";"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(1)")+"; opacity: 1;";i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)");i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;";t.style.cssText+=f("transition",e+"s")},1)}setTimeout(function(){r==="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020"));i&&n(i).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""});t&&(n(t).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t.parentNode&&n(t.parentNode).css({"-webkit-perspective":"","-moz-perspective":"","-ms-perspective":"","-o-perspective":""}));typeof u=="function"&&u()},e*1e3)}function it(t,i,r){var u={},f,e;typeof i=="object"?u=i:(u.msg=i,u.spinner=r);u.msg||u.msg===0||(u.msg="");w2utils.unlock(t);n(t).prepend('<\/div><\/div>');f=n(t).find(".w2ui-lock");e=n(t).find(".w2ui-lock-msg");u.msg||e.css({"background-color":"transparent",border:"0px"});u.spinner===!0&&(u.msg='<\/div>"+u.msg);u.opacity!=null&&f.css("opacity",u.opacity);typeof f.fadeIn=="function"?(f.fadeIn(200),e.html(u.msg).fadeIn(200)):(f.show(),e.html(u.msg).show(0));n().w2tag()}function rt(t){n(t).find(".w2ui-lock").remove();n(t).find(".w2ui-lock-msg").remove()}function ut(t,i){var r=n(t),u={left:parseInt(r.css("border-left-width"))||0,right:parseInt(r.css("border-right-width"))||0,top:parseInt(r.css("border-top-width"))||0,bottom:parseInt(r.css("border-bottom-width"))||0},f={left:parseInt(r.css("margin-left"))||0,right:parseInt(r.css("margin-right"))||0,top:parseInt(r.css("margin-top"))||0,bottom:parseInt(r.css("margin-bottom"))||0},e={left:parseInt(r.css("padding-left"))||0,right:parseInt(r.css("padding-right"))||0,top:parseInt(r.css("padding-top"))||0,bottom:parseInt(r.css("padding-bottom"))||0};switch(i){case"top":return u.top+f.top+e.top;case"bottom":return u.bottom+f.bottom+e.bottom;case"left":return u.left+f.left+e.left;case"right":return u.right+f.right+e.right;case"width":return u.left+u.right+f.left+f.right+e.left+e.right+parseInt(r.width());case"height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom+parseInt(r.height());case"+width":return u.left+u.right+f.left+f.right+e.left+e.right;case"+height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom}return 0}function ft(n){var t=this.settings.phrases[n];return t==null?n:t}function et(t){t||(t="en-us");t.length===5&&(t="locale/"+t+".json");n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(t){var i,r;w2utils.settings=n.extend(!0,w2utils.settings,t);i=w2obj.grid.prototype;for(r in i.buttons)i.buttons[r].caption=w2utils.lang(i.buttons[r].caption),i.buttons[r].hint=w2utils.lang(i.buttons[r].hint);i.msgDelete=w2utils.lang(i.msgDelete);i.msgNotJSON=w2utils.lang(i.msgNotJSON);i.msgRefresh=w2utils.lang(i.msgRefresh)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function ot(){if(t.scrollBarSize)return t.scrollBarSize;return n("body").append(' 1<\/div><\/div>'),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}function st(n,t){return!n||typeof n.name=="undefined"?(console.log('ERROR: The parameter "name" is required but not supplied in $().'+t+"()."),!1):typeof w2ui[n.name]!="undefined"?(console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+")."),!1):w2utils.isAlphaNumeric(n.name)?!0:(console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '),!1)}function ht(t,i,r,u){n.isArray(i)||(i=[i]);for(var f=0;f=0;e--)if(t=this.handlers[e],(t.event.type===n.type||t.event.type==="*")&&(t.event.target===n.target||t.event.target===null)&&(t.event.execute===n.phase||t.event.execute==="*"||t.event.phase==="*")&&(n=jQuery.extend({},t.event,n),i=[],r=RegExp(/\((.*?)\)/).exec(t.handler),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;return(f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase==="before"&&typeof this[f]=="function"&&(u=this[f],i=[],r=RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0))?n:n.object!=null&&n.phase==="before"&&typeof n.object[f]=="function"&&(u=n.object[f],i=[],r=RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)?n:(n.phase==="after"&&typeof n.onComplete=="function"&&n.onComplete.call(this,n),n)}};w2utils.keyboard=function(n){function i(){jQuery(document).on("keydown",r);jQuery(document).on("mousedown",u)}function r(n){var i=n.target.tagName;jQuery.inArray(i,["INPUT","SELECT","TEXTAREA"])===-1&&jQuery(n.target).prop("contenteditable")!=="true"&&t&&w2ui[t]&&typeof w2ui[t].keydown=="function"&&w2ui[t].keydown.call(w2ui[t],n)}function u(n){var u=n.target.tagName,r=jQuery(n.target).parents(".w2ui-reset"),i;r.length>0&&(i=r.attr("name"),w2ui[i]&&w2ui[i].keyboard&&(t=i))}function f(n){return typeof n!="undefined"&&(t=n),t}function e(){t=null}var t=null;return n.active=f,n.clear=e,i(),n}({}),function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))};n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name"));typeof n=="string"&&w2ui[n]&&w2ui[n].destroy();typeof n=="object"&&n.destroy()};n.fn.w2marker=function(t){return t===""||t==null?n(this).each(function(n,t){t.innerHTML=t.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1")}):n(this).each(function(n,i){function e(n){return''+n+"<\/span>"}var u,r,f;typeof t=="string"&&(t=[t]);i.innerHTML=i.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1");for(u in t)r=t[u],typeof r!="string"&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(//g,"<"),f=new RegExp(r+"(?!([^<]+)?>)","gi"),i.innerHTML=i.innerHTML.replace(f,e)})};n.fn.w2tag=function(t,i){if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),typeof i["class"]=="undefined"&&(i["class"]=""),n(this).length===0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");r==null&&(r={});n(n(i).data("taged-el")).removeClass(r["class"]);clearInterval(n(i).data("timer"));n(i).remove()});return}return n(this).each(function(r,u){var h=u.id,f=w2utils.escapeId(u.id),s,o;if(t===""||t==null)n("#w2ui-tag-"+f).css("opacity",0),setTimeout(function(){clearInterval(n("#w2ui-tag-"+f).data("timer"));n("#w2ui-tag-"+f).remove()},300);else{clearInterval(n("#w2ui-tag-"+f).data("timer"));n("#w2ui-tag-"+f).remove();n("body").append('0?"w2ui-tag-popup":"")+'" style=""><\/div>');s=setInterval(function(){if(n(u).length===0||n(u).offset().left===0&&n(u).offset().top===0){clearInterval(n("#w2ui-tag-"+f).data("timer"));e();return}n("#w2ui-tag-"+f).data("position")!==n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top&&n("#w2ui-tag-"+f).css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top)},100);setTimeout(function(){n(u).offset()&&(n("#w2ui-tag-"+f).css({opacity:"1",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).html(' '+t+"<\/div> <\/div>").data("text",t).data("taged-el",u).data("options",i).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top).data("timer",s),n(u).off("keypress",e).on("keypress",e).off("change",e).on("change",e).css(i.css).addClass(i["class"]),typeof i.onShow=="function"&&i.onShow())},1);o="";n(u).length>0&&(o=n(u)[0].style.cssText);function e(){($tag=n("#w2ui-tag-"+f),$tag.length<=0)||(clearInterval($tag.data("timer")),$tag.remove(),n(u).off("keypress",e).removeClass(i["class"]),n(u).length>0&&(n(u)[0].style.cssText=o),typeof i.onHide=="function"&&i.onHide())}}})};n.fn.w2overlay=function(t,i){function l(){var t=n("#w2ui-overlay"+r),i;t.data("element")===u[0]&&t.length!==0&&(i=n(u).offset().left+"x"+n(u).offset().top,t.data("position")!==i?s():setTimeout(l,250))}function s(){var t=n("#w2ui-overlay"+r),u;if(t.data("keepOpen")===!0){t.removeData("keepOpen");return}(typeof i.onHide=="function"&&(u=i.onHide()),u!==!1)&&(t.remove(),n(document).off("click",s),clearInterval(t.data("timer")))}function h(){var o=n("#w2ui-overlay"+r),t=o.find(" > div"),e,l;if(o.length>0){t.height("auto").width("auto");var a=!1,s=t.height(),f=t.width();i.width&&i.widtht.find("div.menu > table").height()&&t.find("div.menu").css("overflow-y","hidden")},1),setTimeout(function(){t.find("div.menu").css("overflow-y","auto")},10));i.tmp.contentWidth&&(f=i.tmp.contentWidth,t.width(f),setTimeout(function(){t.width()>t.find("div.menu > table").width()&&t.find("div.menu").css("overflow-x","hidden")},1),setTimeout(function(){t.find("div.menu").css("overflow-y","auto")},10));switch(i.align){case"both":i.left=17;i.width===0&&(i.width=w2utils.getSize(n(u),"width"));break;case"left":i.left=17;break;case"right":i.tipLeft=f-45;i.left=w2utils.getSize(n(u),"width")-f+10}var v=(f-17)/2,p=i.left,y=i.width,c=i.tipLeft;y=f!==30||y?i.width?i.width:"auto":30;v<25&&(p=25-v,c=Math.floor(v));o.css({top:u.offset().top+w2utils.getSize(u,"height")+i.top+7+"px",left:(u.offset().left>25?u.offset().left:25)+p+"px","min-width":y,"min-height":i.height?i.height:"auto"});e=window.innerHeight+n(document).scrollTop()-t.offset().top-7;l=window.innerWidth+n(document).scrollLeft()-t.offset().left-7;e>-50&&e<210||i.openAbove===!0?(e=t.offset().top-n(document).scrollTop()-7,i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),s>e&&(a=!0,t.height(e).width(f).css({"overflow-y":"auto"}),s=e),o.css("top",n(u).offset().top-s-24+i.top+"px"),o.find(">style").html("#w2ui-overlay"+r+":before { display: none; margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { display: block; margin-left: "+parseInt(c)+"px; }")):(i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),s>e&&(a=!0,t.height(e).width(f).css({"overflow-y":"auto"})),o.find(">style").html("#w2ui-overlay"+r+":before { display: block; margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { display: none; margin-left: "+parseInt(c)+"px; }"));f=t.width();l=window.innerWidth+n(document).scrollLeft()-t.offset().left-7;i.maxWidth&&l>i.maxWidth&&(l=i.maxWidth);f>l&&i.align!=="both"&&(i.align="right",setTimeout(function(){h()},1));a&&!1&&t.width(f+w2utils.scrollBarSize()+2)}}var u=this,r="",f,e,c,o;if(arguments.length==1&&(i=typeof t=="object"?t:{html:t}),arguments.length==2&&(i.html=t),n.isPlainObject(i)||(i={}),i=n.extend({},{name:null,html:"",align:"none",left:0,top:0,tipLeft:30,width:0,height:0,maxWidth:null,maxHeight:null,style:"","class":"",onShow:null,onHide:null,openAbove:!1,tmp:{}},i),i.name&&(r="-"+i.name),this.length===0||i.html===""||i.html==null)return n("#w2ui-overlay"+r).length>0?(f=n("#w2ui-overlay"+r)[0].hide,typeof f=="function"&&f()):n("#w2ui-overlay"+r).remove(),n(this);n("#w2ui-overlay"+r).length>0&&(f=n("#w2ui-overlay"+r)[0].hide,n(document).off("click",f),typeof f=="function"&&f());n("body").append('0?"w2ui-overlay-popup":"")+'">
Error("+i.code+"): "+i.message+"<\/p>").addClass("error").delay(3e3).fadeOut(1e3,function(){n(this).remove()})}}});uf.init();n("#adv_nick").combogrid({url:w+"?action=load_combo_data",datatype:"json",munit:"px",alternate:!0,colModel:i.comboGrid,select:function(t,i){return n("#adv_nick").val(i.item.slug),n("#adv_name").val(i.item.title),n("#adv_mail").val(i.item.email),!1}});n("#add-file-button").click(function(){var t=u.url+n("select#files_list option:selected").val();return n("#ad_img").val(t),!1});e("ctt-grid",fi,su,"slug",i.customTaxes,kt.cTax);e("x-ctt-grid",ei,hu,"slug",i.customTaxes,kt.cTax);e("cust-grid",pi,du,"slug",i.customs,kt.customs);e("x-cust-grid",wi,gu,"slug",i.customs,kt.customs);nr=w+"?action=load_posts&cstr="+samEditorOptions.data.custList+"&sp="+nf+"&spg="+tf+"&limit=10000";ar("posts-grid",oi,cu,"id",i.posts,nr);ar("x-posts-grid",si,au,"id",i.posts,nr);n("#tabs").tabs({activate:function(t,i){var r=i.newPanel[0].id;r=="tabs-1"&&w2ui["posts-grid"]&&oi.w2render("posts-grid");r=="tabs-2"&&(vt.is(":visible")&&w2ui["ctt-grid"]&&fi.w2render("ctt-grid"),rt.is(":visible")&&w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid"),g.is(":visible")&&w2ui["x-posts-grid"]&&si.w2render("x-posts-grid"),at.is(":visible")&&w2ui["cats-grid"]&&hi.w2render("cats-grid"),tt.is(":visible")&&w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid"),yt.is(":visible")&&w2ui["auth-grid"]&&li.w2render("auth-grid"),ft.is(":visible")&&w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid"),pt.is(":visible")&&w2ui["tags-grid"]&&vi.w2render("tags-grid"),ot.is(":visible")&&w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid"),wt.is(":visible")&&w2ui["cust-grid"]&&pi.w2render("cust-grid"),ht.is(":visible")&&w2ui["xcust-grid"]&&wi.w2render("x-cust-grid"));r=="tabs-3"&&ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid");r=="tabs-5"&&o&&(o.destroy(),o=n.jqplot("graph",b,dt))}});n(window).resize(function(){o&&(o.destroy(),o=n.jqplot("graph",b,dt))});n("#code_mode_false").click(function(){ur.show("blind",{direction:"vertical"},500);fr.hide("blind",{direction:"vertical"},500)});n("#code_mode_true").click(function(){ur.hide("blind",{direction:"vertical"},500);fr.show("blind",{direction:"vertical"},500)});2==n("input:radio[name=view_type]:checked").val()&&(f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)),f.attr("disabled",!0));n("input:radio[name=view_type]").click(function(){var t=n("input:radio[name=view_type]:checked").val();switch(t){case"0":s.is(":hidden")&&s.show("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"1":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":visible")&&h.hide("blind",{direction:"vertical"},500);f.attr("disabled",!1);break;case"2":s.is(":visible")&&s.hide("blind",{direction:"vertical"},500);h.is(":hidden")&&(h.show("blind",{direction:"vertical"},500,function(){w2ui["posts-grid"]&&oi.w2render("posts-grid")}),f.is(":checked")&&(f.attr("checked",!1),g.hide("blind",{direction:"vertical"},500)));f.attr("disabled",!0)}});vr=n.ajax({url:w,data:{action:"load_authors",level:3},type:"POST"});vr.done(function(n){tr=n;e("auth-grid",li,pu,"slug",i.authors,tr);e("x-auth-grid",ai,wu,"slug",i.authors,tr)});yr=n.ajax({url:w,data:{action:"load_users",subscriber:encodeURI(u.subscriber),contributor:encodeURI(u.contributor),author:encodeURI(u.author),editor:encodeURI(u.editor),admin:encodeURI(u.admin),sadmin:encodeURI(u.superAdmin)},type:"POST"});yr.done(function(n){pr=n;e("users-grid",lt,lu,"slug",i.users,pr)});wr=n.ajax({url:w,data:{action:"load_cats",level:3},type:"POST"});wr.done(function(n){ir=n;e("cats-grid",hi,vu,"slug",i.cats,ir);e("x-cats-grid",ci,yu,"slug",i.cats,ir)});br=n.ajax({url:w,data:{action:"load_tags",level:3},type:"POST"});br.done(function(n){rr=n;e("tags-grid",vi,bu,"slug",i.tags,rr);e("x-tags-grid",yi,ku,"slug",i.tags,rr)});f.click(function(){f.is(":checked")?2==n("input:radio[name=view_type]:checked").val()?f.attr("checked",!1):g.show("blind",{direction:"vertical"},500,function(){w2ui["x-posts-grid"]&&si.w2render("x-posts-grid")}):g.hide("blind",{direction:"vertical"},500)});n("input:radio[name=ad_users]").click(function(){var t=n("input:radio[name=ad_users]:checked").val();t=="0"?bt.is(":visible")&&bt.hide("blind",{direction:"vertical"},500):bt.is(":hidden")&&bt.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")})});er.click(function(){er.is(":checked")?or.show("blind",{direction:"vertical"},500,function(){ct.is(":visible")&&w2ui["users-grid"]&<.w2render("users-grid")}):or.hide("blind",{direction:"vertical"},500)});sr.click(function(){sr.is(":checked")?ct.show("blind",{direction:"vertical"},500,function(){w2ui["users-grid"]&<.w2render("users-grid")}):ct.hide("blind",{direction:"vertical"},500)});n("#ad_swf").click(function(){n("#ad_swf").is(":checked")?n("#swf-params").show("blind",{direction:"vertical"},500):n("#swf-params").hide("blind",{direction:"vertical"},500)});nt.is(":checked")&&c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500));nt.click(function(){nt.is(":checked")?(at.show("blind",{direction:"vertical"},500,function(){w2ui["cats-grid"]&&hi.w2render("cats-grid")}),ni.show("blind",{direction:"vertical"},500),c.is(":checked")&&(c.attr("checked",!1),tt.hide("blind",{direction:"vertical"},500))):(at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))});c.click(function(){c.is(":checked")?(tt.show("blind",{direction:"vertical"},500,function(){w2ui["x-cats-grid"]&&ci.w2render("x-cats-grid")}),nt.is(":checked")&&(nt.attr("checked",!1),at.hide("blind",{direction:"vertical"},500),ni.hide("blind",{direction:"vertical"},500))):tt.hide("blind",{direction:"vertical"},500)});it.is(":checked")&&l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500));it.click(function(){it.is(":checked")?(vt.show("blind",{direction:"vertical"},500,function(){w2ui["ctt-grid"]&&fi.w2render("ctt-grid")}),ti.show("blind",{direction:"vertical"},500),l.is(":checked")&&(l.attr("checked",!1),rt.hide("blind",{direction:"vertical"},500))):(vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))});l.click(function(){l.is(":checked")?(rt.show("blind",{direction:"vertical"},500,function(){w2ui["x-ctt-grid"]&&ei.w2render("x-ctt-grid")}),it.is(":checked")&&(it.attr("checked",!1),vt.hide("blind",{direction:"vertical"},500),ti.hide("blind",{direction:"vertical"},500))):rt.hide("blind",{direction:"vertical"},500)});ut.is(":checked")&&a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500));ut.click(function(){ut.is(":checked")?(yt.show("blind",{direction:"vertical"},500,function(){w2ui["auth-grid"]&&li.w2render("auth-grid")}),ii.show("blind",{direction:"vertical"},500),a.is(":checked")&&(a.attr("checked",!1),ft.hide("blind",{direction:"vertical"},500))):(yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))});a.click(function(){a.is(":checked")?(ft.show("blind",{direction:"vertical"},500,function(){w2ui["x-auth-grid"]&&ai.w2render("x-auth-grid")}),ut.is(":checked")&&(ut.attr("checked",!1),yt.hide("blind",{direction:"vertical"},500),ii.hide("blind",{direction:"vertical"},500))):ft.hide("blind",{direction:"vertical"},500)});et.is(":checked")&&v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500));et.click(function(){et.is(":checked")?(pt.show("blind",{direction:"vertical"},500,function(){w2ui["tags-grid"]&&vi.w2render("tags-grid")}),ri.show("blind",{direction:"vertical"},500),v.is(":checked")&&(v.attr("checked",!1),ot.hide("blind",{direction:"vertical"},500))):(pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))});v.click(function(){v.is(":checked")?(ot.show("blind",{direction:"vertical"},500,function(){w2ui["x-tags-grid"]&&yi.w2render("x-tags-grid")}),et.is(":checked")&&(et.attr("checked",!1),pt.hide("blind",{direction:"vertical"},500),ri.hide("blind",{direction:"vertical"},500))):ot.hide("blind",{direction:"vertical"},500)});st.is(":checked")&&y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500));st.click(function(){st.is(":checked")?(wt.show("blind",{direction:"vertical"},500,function(){w2ui["cust-grid"]&&pi.w2render("cust-grid")}),ui.show("blind",{direction:"vertical"},500),y.is(":checked")&&(y.attr("checked",!1),ht.hide("blind",{direction:"vertical"},500))):(wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))});y.click(function(){y.is(":checked")?(ht.show("blind",{direction:"vertical"},500,function(){w2ui["x-cust-grid"]&&wi.w2render("x-cust-grid")}),st.is(":checked")&&(st.attr("checked",!1),wt.hide("blind",{direction:"vertical"},500),ui.hide("blind",{direction:"vertical"},500))):ht.hide("blind",{direction:"vertical"},500)});n("#ad_start_date, #ad_end_date").datepicker({dateFormat:"yy-mm-dd",showButtonPanel:!0});n("#ad_schedule").click(function(){n("#ad_schedule").is(":checked")?n("#rc-sc").show("blind",{direction:"vertical"},500):n("#rc-sc").hide("blind",{direction:"vertical"},500)});n("#limit_hits").click(function(){n("#limit_hits").is(":checked")?n("#rc-hl").show("blind",{direction:"vertical"},500):n("#rc-hl").hide("blind",{direction:"vertical"},500)});n("#limit_clicks").click(function(){n("#limit_clicks").is(":checked")?n("#rc-cl").show("blind",{direction:"vertical"},500):n("#rc-cl").hide("blind",{direction:"vertical"},500)});p=samEditorOptions.ads;p.pointer="ads";(p.enabled||""==gt.val())&>.pointer({content:"
"+p.content+"<\/p>",position:"top",close:function(){n.ajax({url:ajaxurl,data:{action:"close_pointer",pointer:p.pointer},async:!0})}}).pointer("open");var k=n("#is_singular"),kr=n("#is_single"),dr=n("#is_page"),gr=n("#is_attachment"),nu=n("#is_posttype");k.click(function(){k.is(":checked")&&n("#is_single, #is_page, #is_attachment, #is_posttype").attr("checked",!0)});n("#is_single, #is_page, #is_attachment, #is_posttype").click(function(){!k.is(":checked")||kr.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&nu.is(":checked")?!k.is(":checked")&&kr.is(":checked")&&nu.is(":checked")&&dr.is(":checked")&&gr.is(":checked")&&k.attr("checked",!0):k.attr("checked",!1)});var d=n("#is_archive"),tu=n("#is_tax"),iu=n("#is_category"),ru=n("#is_tag"),uu=n("#is_author"),fu=n("#is_date"),eu=n("#is_posttype_archive"),ou=n("#is_tax, #is_category, #is_tag, #is_author, #is_date, #is_posttype_archive");return d.click(function(){d.is(":checked")&&ou.attr("checked",!0)}),ou.click(function(){!d.is(":checked")||tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")?!d.is(":checked")&&tu.is(":checked")&&iu.is(":checked")&&eu.is(":checked")&&ru.is(":checked")&&uu.is(":checked")&&fu.is(":checked")&&d.attr("checked",!0):d.attr("checked",!1)}),n("#stats_month").change(function(){bi=n(this).val();n.post(cr,{action:"load_item_stats",id:lr,sm:bi}).done(function(t){n("#total_hits").text(t.total.hits);n("#total_clicks").text(t.total.clicks);b=[t.hits,t.clicks];o&&(o.destroy(),o=n.jqplot("graph",b,dt))})}),!1})})(jQuery) \ No newline at end of file diff --git a/js/sam-layout.js b/js/sam-layout.js index 028272d..876c68e 100644 --- a/js/sam-layout.js +++ b/js/sam-layout.js @@ -19,8 +19,8 @@ wc: samAjax.clauses, level: samAjax.level }, - type: 'POST', - crossDomain: true + type: 'POST'/*, + crossDomain: true*/ }).done(function(data) { $(el).replaceWith(data.ad); $.post(samAjax.ajaxurl, { diff --git a/js/sam-layout.min.js b/js/sam-layout.min.js index aa627e2..62deb23 100644 --- a/js/sam-layout.min.js +++ b/js/sam-layout.min.js @@ -1 +1 @@ -(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST",crossDomain:!0}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file +(function(n){n(document).ready(function(){samAjax.load?(samAjax.mailer&&n.post(samAjax.ajaxurl,{action:"sam_maintenance"}),n("div.sam-place").each(function(t,i){var r=n(i).data("sam");"undefined"==typeof r&&(r=0);var u=this.id.split("_"),f=u[1],e=u[2];n.ajax({url:samAjax.loadurl,data:{action:"load_place",id:f,pid:e,codes:r,wc:samAjax.clauses,level:samAjax.level},type:"POST"}).done(function(t){n(i).replaceWith(t.ad);n.post(samAjax.ajaxurl,{action:"sam_hit",id:t.id,pid:t.pid,level:samAjax.level});n("#"+t.cid).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:t.id,pid:t.pid,level:samAjax.level})})})}),n("div.sam-ad").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})):n("div.sam-container").each(function(t,i){var r=this.id.split("_"),u=r[1],f=r[2];n.post(samAjax.ajaxurl,{action:"sam_hit",id:u,pid:f,level:samAjax.level});n(i).find("a").bind("click",function(){n.post(samAjax.ajaxurl,{action:"sam_click",id:u,pid:f,level:samAjax.level})})})})})(jQuery) \ No newline at end of file diff --git a/js/w2ui.js b/js/w2ui.js index 6edd7fd..6e4bc6d 100644 --- a/js/w2ui.js +++ b/js/w2ui.js @@ -1,6938 +1,8478 @@ +/* w2ui 1.4.1 (c) http://w2ui.com, vitmalina@gmail.com */ var w2ui = w2ui || {}; var w2obj = w2obj || {}; // expose object to be able to overwrite default functions /************************************************ - * Library: Web 2.0 UI for jQuery - * - Following objects are defines - * - w2ui - object that will contain all widgets - * - w2obj - object with widget prototypes - * - w2utils - basic utilities - * - $().w2render - common render - * - $().w2destroy - common destroy - * - $().w2marker - marker plugin - * - $().w2tag - tag plugin - * - $().w2overlay - overlay plugin - * - $().w2menu - menu plugin - * - w2utils.event - generic event object - * - w2utils.keyboard - object for keyboard navigation - * - Dependencies: jQuery - * - * == NICE TO HAVE == - * - date has problems in FF new Date('yyyy-mm-dd') breaks - * - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter - * - overlay should be displayed where more space (on top or on bottom) - * - write and article how to replace certain framework functions - * - format date and time is buggy - * - onComplete should pass widget as context (this) - * - ************************************************/ +* Library: Web 2.0 UI for jQuery +* - Following objects are defines +* - w2ui - object that will contain all widgets +* - w2obj - object with widget prototypes +* - w2utils - basic utilities +* - $().w2render - common render +* - $().w2destroy - common destroy +* - $().w2marker - marker plugin +* - $().w2tag - tag plugin +* - $().w2overlay - overlay plugin +* - $().w2menu - menu plugin +* - w2utils.event - generic event object +* - w2utils.keyboard - object for keyboard navigation +* - Dependencies: jQuery +* +* == NICE TO HAVE == +* - date has problems in FF new Date('yyyy-mm-dd') breaks +* - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter +* - overlay should be displayed where more space (on top or on bottom) +* - write and article how to replace certain framework functions +* - format date and time is buggy +* - onComplete should pass widget as context (this) +* - add maxHeight for the w2menu +* - user localization from another lib (make it generic), https://github.com/jquery/globalize#readme +* - hidden and disabled in menus +* - isTime should support seconds +* - TEST On IOS +* +************************************************/ var w2utils = (function ($) { - var tmp = {}; // for some temp variables - var obj = { - settings : { - "locale" : "en-us", - "date_format" : "m/d/yyyy", - "date_display" : "Mon d, yyyy", - "time_format" : "hh:mi pm", - "currency" : "^[\$\€\£\¥]?[-]?[0-9]*[\.]?[0-9]+$", - "currencySymbol": "$", - "float" : "^[-]?[0-9]*[\.]?[0-9]+$", - "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], - "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], - "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], - "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], - "RESTfull" : false, - "phrases" : {} // empty object for english phrases - }, - isInt : isInt, - isFloat : isFloat, - isMoney : isMoney, - isHex : isHex, - isAlphaNumeric : isAlphaNumeric, - isEmail : isEmail, - isDate : isDate, - isTime : isTime, - age : age, - date : date, - size : size, - formatNumber : formatNumber, - formatDate : formatDate, - formatTime : formatTime, - formatDateTime : formatDateTime, - stripTags : stripTags, - encodeTags : encodeTags, - escapeId : escapeId, - base64encode : base64encode, - base64decode : base64decode, - transition : transition, - lock : lock, - unlock : unlock, - lang : lang, - locale : locale, - getSize : getSize, - scrollBarSize : scrollBarSize - } - return obj; - - function isInt (val) { - var re = /^[-]?[0-9]+$/; - return re.test(val); - } - - function isFloat (val) { - var re = new RegExp(w2utils.settings["float"]); - return re.test(val); - } - - function isMoney (val) { - var re = new RegExp(w2utils.settings.currency); - return re.test(val); - } - - function isHex (val) { - var re = /^[a-fA-F0-9]+$/; - return re.test(val); - } - - function isAlphaNumeric (val) { - var re = /^[a-zA-Z0-9_-]+$/; - return re.test(val); - } - - function isEmail (val) { - var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; - return email.test(val); - } - - function isDate (val, format, retDate) { - if (!val) return false; - if (!format) format = w2utils.settings.date_format; - // format date - var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/'); - var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase(); - var dt = 'Invalid Date'; - var month, day, year; - if (tmp2 == 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; } - if (tmp2 == 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; } - if (tmp2 == 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; } - if (tmp2 == 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - if (tmp2 == 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; } - dt = new Date(month + '/' + day + '/' + year); - // do checks - if (typeof month == 'undefined') return false; - if (dt == 'Invalid Date') return false; - if ((dt.getMonth()+1 != month) || (dt.getDate() != day) || (dt.getFullYear() != year)) return false; - if (retDate === true) return dt; else return true; - } - - function isTime (val) { - // Both formats 10:20pm and 22:20 - if (String(val) == 'undefined') return false; - var max; - // -- process american foramt - val = val.toUpperCase(); - if (val.indexOf('PM') >= 0 || val.indexOf('AM') >= 0) max = 12; else max = 23; - val = $.trim(val.replace('AM', '')); - val = $.trim(val.replace('PM', '')); - // --- - var tmp = val.split(':'); - if (tmp.length != 2) { return false; } - if (tmp[0] == '' || parseInt(tmp[0]) < 0 || parseInt(tmp[0]) > max || !this.isInt(tmp[0])) { return false; } - if (tmp[1] == '' || parseInt(tmp[1]) < 0 || parseInt(tmp[1]) > 59 || !this.isInt(tmp[1])) { return false; } - return true; - } - - function age (timeStr) { - if (timeStr == '' || typeof timeStr == 'undefined' || timeStr == null) return ''; - if (w2utils.isInt(timeStr)) timeStr = Number(timeStr); // for unix timestamps - - var d1 = new Date(timeStr); - if (w2utils.isInt(timeStr)) d1 = new Date(Number(timeStr)); // for unix timestamps - var tmp = String(timeStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(timeStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Time') return ''; - - var d2 = new Date(); - var sec = (d2.getTime() - d1.getTime()) / 1000; - var amount = ''; - var type = ''; - - if (sec < 60) { - amount = Math.floor(sec); - type = 'sec'; - if (sec < 0) { amount = 0; type = 'sec' } - } else if (sec < 60*60) { - amount = Math.floor(sec/60); - type = 'min'; - } else if (sec < 24*60*60) { - amount = Math.floor(sec/60/60); - type = 'hour'; - } else if (sec < 30*24*60*60) { - amount = Math.floor(sec/24/60/60); - type = 'day'; - } else if (sec < 12*30*24*60*60) { - amount = Math.floor(sec/30/24/60/60*10)/10; - type = 'month'; - } else if (sec >= 12*30*24*60*60) { - amount = Math.floor(sec/12/30/24/60/60*10)/10; - type = 'year'; - } - return amount + ' ' + type + (amount > 1 ? 's' : ''); - } - - function date (dateStr) { - var months = w2utils.settings.shortmonths; - if (dateStr == '' || typeof dateStr == 'undefined' || dateStr == null) return ''; - if (w2utils.isInt(dateStr)) dateStr = Number(dateStr); // for unix timestamps - - var d1 = new Date(dateStr); - if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (d1 == 'Invalid Date') return ''; - - var d2 = new Date(); // today - var d3 = new Date(); - d3.setTime(d3.getTime() - 86400000); // yesterday - - var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear(); - var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear(); - var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear(); - - var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am'); - var dsp = dd1; - if (dd1 == dd2) dsp = time; - if (dd1 == dd3) dsp = w2utils.lang('Yesterday'); - - return ''+ dsp +''; - } - - function size (sizeStr) { - if (!w2utils.isFloat(sizeStr) || sizeStr == '') return ''; - sizeStr = parseFloat(sizeStr); - if (sizeStr == 0) return 0; - var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB']; - var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) ); - return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i == 0 ? 0 : 1) + ' ' + sizes[i]; - } - - function formatNumber (val) { - var ret = ''; - // check if this is a number - if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) { - ret = String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); - } - return ret; - } - - function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.date_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - var tmp = String(dateStr).split('-'); - if (tmp.length == 3) dt = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd - var tmp = String(dateStr).split('/'); - if (tmp.length == 3) dt = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy - if (dt == 'Invalid Date') return ''; - - var year = dt.getFullYear(); - var month = dt.getMonth(); - var date = dt.getDate(); - return format.toLowerCase() - .replace('month', w2utils.settings.fullmonths[month]) - .replace('mon', w2utils.settings.shortmonths[month]) - .replace(/yyyy/g, year) - .replace(/yyy/g, year) - .replace(/yy/g, String(year).substr(2)) - .replace(/(^|[^a-z$])y/g, '$1'+year) // only y's that are not preceeded by a letter - .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1)) - .replace(/dd/g, (date < 10 ? '0' : '') + date) - .replace(/(^|[^a-z$])m/g, '$1'+ (month + 1)) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter - } - - - function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String - var months = w2utils.settings.shortmonths; - var fullMonths = w2utils.settings.fullmonths; - if (typeof format == 'undefined') format = this.settings.time_format; - if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return ''; - - var dt = new Date(dateStr); - if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps - if (dt == 'Invalid Date') return ''; - - var type = 'am'; - var hour = dt.getHours(); - var h24 = dt.getHours(); - var min = dt.getMinutes(); - var sec = dt.getSeconds(); - if (min < 10) min = '0' + min; - if (sec < 10) sec = '0' + sec; - if (format.indexOf('am') != -1 || format.indexOf('pm') != -1) { - if (hour >= 12) type = 'pm'; - if (hour > 12) hour = hour - 12; - } - return format.toLowerCase() - .replace('am', type) - .replace('pm', type) - .replace('hh', hour) - .replace('h24', h24) - .replace('mm', min) - .replace('mi', min) - .replace('ss', sec) - .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter - .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter - } - - function formatDateTime(dateStr, format) { - var fmt; - if (typeof format != 'string') { - var fmt = [this.settings.date_format, this.settings.time_format]; - } else { - var fmt = format.split('|'); - } - return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]); - } - - function stripTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = $.trim(String(html).replace(/(<([^>]+)>)/ig, "")); - break; - case 'object': - for (var a in html) html[a] = this.stripTags(html[a]); - break; - } - return html; - } - - function encodeTags (html) { - if (html == null) return html; - switch (typeof html) { - case 'number': - break; - case 'string': - html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/\|\/? {}\\])/g, '\\$1'); - } - - function base64encode (input) { - var output = ""; - var chr1, chr2, chr3, enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = utf8_encode(input); - - while (i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); + var tmp = {}; // for some temp variables + var obj = { + version : '1.4.1', + settings : { + "locale" : "en-us", + "date_format" : "m/d/yyyy", + "date_display" : "Mon d, yyyy", + "time_format" : "hh:mi pm", + "currencyPrefix" : "$", + "currencySuffix" : "", + "currencyPrecision" : 2, + "groupSymbol" : ",", + "decimalSymbol" : ".", + "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + "shortdays" : ["M", "T", "W", "T", "F", "S", "S"], + "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], + "dataType" : 'HTTP', // can be HTTP, RESTFULL, JSON (case sensative) + "phrases" : {} // empty object for english phrases + }, + isInt : isInt, + isFloat : isFloat, + isMoney : isMoney, + isHex : isHex, + isAlphaNumeric : isAlphaNumeric, + isEmail : isEmail, + isDate : isDate, + isTime : isTime, + age : age, + date : date, + size : size, + formatNumber : formatNumber, + formatDate : formatDate, + formatTime : formatTime, + formatDateTime : formatDateTime, + stripTags : stripTags, + encodeTags : encodeTags, + escapeId : escapeId, + base64encode : base64encode, + base64decode : base64decode, + transition : transition, + lock : lock, + unlock : unlock, + lang : lang, + locale : locale, + getSize : getSize, + scrollBarSize : scrollBarSize, + checkName : checkName, + checkUniqueId : checkUniqueId, + parseRoute : parseRoute, + // some internal variables + isIOS : ((navigator.userAgent.toLowerCase().indexOf('iphone') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipod') != -1 || + navigator.userAgent.toLowerCase().indexOf('ipad') != -1) + ? true : false), + isIE : ((navigator.userAgent.toLowerCase().indexOf('msie') != -1 || + navigator.userAgent.toLowerCase().indexOf('trident') != -1 ) + ? true : false) + }; + return obj; + + function isInt (val) { + var re = /^[-+]?[0-9]+$/; + return re.test(val); } - function utf8_encode (string) { - var string = String(string).replace(/\r\n/g,"\n"); - var utftext = ""; - - for (var n = 0; n < string.length; n++) { - var c = string.charCodeAt(n); - if (c < 128) { - utftext += String.fromCharCode(c); - } - else if((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } - else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - } - return utftext; + function isFloat (val) { + if (typeof val == 'string') val = val.replace(w2utils.settings.decimalSymbol, '.'); + return (typeof val === 'number' || (typeof val === 'string' && val !== '')) && !isNaN(Number(val)); } - return output; - } - - function base64decode (input) { - var output = ""; - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; - var i = 0; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - - while (i < input.length) { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - output = output + String.fromCharCode(chr1); - if (enc3 != 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 != 64) { - output = output + String.fromCharCode(chr3); - } - } - output = utf8_decode(output); - - function utf8_decode (utftext) { - var string = ""; - var i = 0; - var c = 0, c1 = 0, c2 = 0; - - while ( i < utftext.length ) { - c = utftext.charCodeAt(i); - if (c < 128) { - string += String.fromCharCode(c); - i++; - } - else if((c > 191) && (c < 224)) { - c2 = utftext.charCodeAt(i+1); - string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); - i += 2; + function isMoney (val) { + var se = w2utils.settings; + var re = new RegExp('^'+ (se.currencyPrefix ? '\\' + se.currencyPrefix + '?' : '') +'[-+]?[0-9]*[\\'+ w2utils.settings.decimalSymbol +']?[0-9]+'+ (se.currencySuffix ? '\\' + se.currencySuffix + '?' : '') +'$', 'i'); + if (typeof val === 'string') { + val = val.replace(new RegExp(se.groupSymbol, 'g'), ''); } - else { - c2 = utftext.charCodeAt(i+1); - c3 = utftext.charCodeAt(i+2); - string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); - i += 3; - } - } - - return string; + if (typeof val === 'object' || val === '') return false; + return re.test(val); } - return output; - } - - function transition (div_old, div_new, type, callBack) { - var width = $(div_old).width(); - var height = $(div_old).height(); - var time = 0.5; - - if (!div_old || !div_new) { - console.log('ERROR: Cannot do transition when one of the divs is null'); - return; + function isHex (val) { + var re = /^[a-fA-F0-9]+$/; + return re.test(val); } - div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;'; - div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden'); - div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden'); - - switch (type) { - case 'slide-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - }, 1); - break; - - case 'slide-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)'); - }, 1); - break; - - case 'slide-down': - // init divs - div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - }, 1); - break; - - case 'slide-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - }, 1); - break; - - case 'flip-left': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('-transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)'); - }, 1); - break; - - case 'flip-right': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)'); - }, 1); - break; - - case 'flip-down': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)'); - }, 1); - break; - - case 'flip-up': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)'); - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)'); - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)'); - }, 1); - break; - - case 'pop-in': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +';'; - }, 1); - break; - - case 'pop-out': - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;'; - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;'; - }, 1); - break; - - default: - // init divs - div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)'); - div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;'; - $(div_new).show(); - // -- need a timing function because otherwise not working - window.setTimeout(function() { - div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;'; - div_old.style.cssText += cross('transition', time +'s'); - }, 1); - break; + function isAlphaNumeric (val) { + var re = /^[a-zA-Z0-9_-]+$/; + return re.test(val); } - setTimeout(function () { - if (type == 'slide-down') { - $(div_old).css('z-index', '1019'); - $(div_new).css('z-index', '1020'); - } - if (div_new) { - $(div_new).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - } - if (div_old) { - $(div_old).css({ - 'opacity': '1', - '-webkit-transition': '', - '-moz-transition': '', - '-ms-transition': '', - '-o-transition': '', - '-webkit-transform': '', - '-moz-transform': '', - '-ms-transform': '', - '-o-transform': '', - '-webkit-backface-visibility': '', - '-moz-backface-visibility': '', - '-ms-backface-visibility': '', - '-o-backface-visibility': '' - }); - if (div_old.parentNode) $(div_old.parentNode).css({ - '-webkit-perspective': '', - '-moz-perspective': '', - '-ms-perspective': '', - '-o-perspective': '' - }); - } - if (typeof callBack == 'function') callBack(); - }, time * 1000); - - function cross(property, value, none_webkit_value) { - var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR - if (!isWebkit && typeof none_webkit_value != 'undefined') value = none_webkit_value; - return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+ - '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';'; - } - } - - function lock (box, msg, showSpinner) { - if (!msg && msg != 0) msg = ''; - w2utils.unlock(box); - $(box).find('>:first-child').before( - '