فهرست منبع

use UI::inlineJS in Zaliczka

Piotr Labudda 9 سال پیش
والد
کامیت
9f03f64798

+ 11 - 72
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

@@ -155,6 +155,7 @@ class Route_UrlAction_UserProNetMediaZaliczka extends RouteBase {// TODO: UrlAct
 					$editLink = Request::getPathUri() . "index.php?_route=UrlAction_UserProNetMediaZaliczka&idUser={$idUser}&idZaliczka={$row['ID']}";
 					$editLabel = ($isFirst) ? "Rozlicz / Podgląd" : "Podgląd";
 					if ($isFirst) $isFirst = false;
+					$histLink = Request::getPathUri() . "index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=hist&idUser={$idUser}&idZaliczka={$row['ID']}";
 					return [
 						'Nr' => $row['ID'],
 						'Status' => $row['A_STATUS'],
@@ -162,7 +163,8 @@ class Route_UrlAction_UserProNetMediaZaliczka extends RouteBase {// TODO: UrlAct
 						'L_APPOITMENT_USER' => $row['L_APPOITMENT_USER'],
 						'KWOTA' => $row['KWOTA'],
 						'NIEROZLICZONA_KWOTA' => $row['NIEROZLICZONA_KWOTA'],
-						'#' => '<a href="' . $editLink . '">' . $editLabel . '</a>'
+						'#' => '<a href="' . $editLink . '">' . $editLabel . '</a>',
+						'DBG' => '<a href="' . $histLink . '">' . "DBG HIST" . '</a>'
 					];
 				},
 				DB::getPDO()->fetchAll("
@@ -321,77 +323,14 @@ window.location.href='{$redirectUrl}';
 
 		DBG::nicePrint($zaliczkaData, '$zaliczkaData');// TODO: DBG
 
-		?>
-<script>
-function zaliczkaFetchData(query, fieldType, resultCallback) {
-  console.warn('TODO: zaliczkaFetchData(query, fieldType, resultCallback)  query('+query+') fieldType:', fieldType);
-
-  // fieldType: Object {"@baseTypeName": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
-  if ('object' === typeof fieldType) {
-    if (!fieldType['@namespace']) {
-      // TODO: log error
-      console.error("BUG: Missing typeName in fieldType");
-      return;
-    }
-    switch (fieldType['@namespace']) {
-			case 'default_db/IN7_MK_BAZA_DYSTRYBUCJI':
-      case 'default_db/IN7_DZIENNIK_KORESP':
-			{
-				superagent
-					.post('<?= Request::getPathUri(); ?>/index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=fetchDataAjax&idUser=<?= $idUser; ?>&idZaliczka=<?= $idZaliczka; ?>')
-					.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
-					.send({
-						schema: fieldType,
-						query: query
-					})
-					.set('Accept', 'application/json')
-					.end(function(err, res) {
-						var payload = (err || !res.ok || 'application/json' !== res.type)
-							? {type: 'warning', msg: (res.body && res.body.msg) ? res.body.msg : 'Request error', body: res.body}
-							: {type: 'success', msg: res.body.msg || '', body: res.body}
-						jQuery(document).trigger('DBG:notify', payload)
-						console.log('F.fetchDataAjax res.body', res.body)
-						console.log('F.fetchDataAjax payload', payload)
-						jQuery.notify(payload.msg, payload.type)
-						resultCallback(payload.body)
-					});
-			}
-      break;
-      default: {
-        console.log("BUG: Unsupported type namespace '" + fieldType['@baseTypeName'] + "'");
-      }
-    }
-  } else {
-    console.log("BUG: Unsupported type '" + fieldType + "'");
-    return;
-  }
-}
-
-function syncZaliczkaState(state, updates, stateSyncSyccessCallback, stateSyncErrorCallback) {
-  // TODO: if ajax success then stateSyncSyccessCallback(Response.data)
-  // TODO: if ajax fail then stateSyncErrorCallback(Response.data)
-  console.log('====== TODO: syncZaliczkaState updates:', updates, 'state:', state);
-	superagent
-		.post('<?= Request::getPathUri(); ?>/index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=syncStataAjax&idUser=<?= $idUser; ?>&idZaliczka=<?= $idZaliczka; ?>') // TODO: add idUser & idZaliczka
-		.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
-		.send({
-			updates: updates,
-		})
-		.set('Accept', 'application/json')
-		.end(function(err, res) {
-			var payload = (err || !res.ok || 'application/json' !== res.type)
-				? {type: 'warning', msg: (res.body && res.body.msg) ? res.body.msg : 'Request error', body: res.body}
-				: {type: 'success', msg: res.body.msg || '', body: res.body}
-			jQuery(document).trigger('DBG:notify', payload)
-			console.log('F.syncZaliczkaState res.body', res.body)
-			console.log('F.syncZaliczkaState payload', payload)
-			jQuery.notify(payload.msg, payload.type)
-			stateSyncSyccessCallback({data: payload.body})
-		});
-}
-
-</script>
-<?php
+		UI::inlineJS(__FILE__ . '.fetchData.js', [
+			'_initData' => $initData,
+			'syncUrl' => Request::getPathUri() . "index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=fetchDataAjax&idUser={$idUser}&idZaliczka={$idZaliczka}"
+		]);
+		UI::inlineJS(__FILE__ . '.syncState.js', [
+			'_initData' => $initData,
+			'syncUrl' => Request::getPathUri() . "index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=syncStataAjax&idUser={$idUser}&idZaliczka={$idZaliczka}"
+		]);
 		UI::tag('script', ['src'=>'static/vendor.js' . (V::get('DBG', '', $_GET) ? '?_ts=' . time() : ''), 'type'=>'text/javascript']);
 		UI::tag('script', ['src'=>'static/zaliczka/main.js' . (V::get('DBG', '', $_GET) ? '?_ts=' . time() : ''), 'type'=>'text/javascript']);
 	}

+ 47 - 0
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php.fetchData.js

@@ -0,0 +1,47 @@
+// @require var syncUrl = ''
+
+function zaliczkaFetchData(query, fieldType, resultCallback) {
+  console.warn('TODO: zaliczkaFetchData(query, fieldType, resultCallback)  query('+query+') fieldType:', fieldType);
+
+  // fieldType: Object {"@baseTypeName": "default_db:IN7_DZIENNIK_KORESP", id: "xsd:integer", title: "xsd:string", kategoriaKosztu: "xsd:string"}
+  if ('object' === typeof fieldType) {
+    if (!fieldType['@namespace']) {
+      // TODO: log error
+      console.error("BUG: Missing typeName in fieldType");
+      return;
+    }
+    switch (fieldType['@namespace']) {
+			case 'default_db/IN7_MK_BAZA_DYSTRYBUCJI':
+      case 'default_db/IN7_DZIENNIK_KORESP':
+			{
+				superagent
+					.post(syncUrl)
+					.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
+					.send({
+						schema: fieldType,
+						query: query
+					})
+					.set('Accept', 'application/json')
+					.end(function(err, res) {
+						var payload = (err || !res.ok || 'application/json' !== res.type)
+							? {type: 'warning', msg: (res.body && res.body.msg) ? res.body.msg : 'Request error', body: res.body}
+							: {type: 'success', msg: res.body.msg || '', body: res.body}
+						jQuery(document).trigger('DBG:notify', payload)
+						console.log('F.fetchDataAjax res.body', res.body)
+						console.log('F.fetchDataAjax payload', payload)
+						jQuery.notify(payload.msg, payload.type)
+						resultCallback(payload.body)
+					});
+			}
+      break;
+      default: {
+        console.log("BUG: Unsupported type namespace '" + fieldType['@baseTypeName'] + "'");
+      }
+    }
+  } else {
+    console.log("BUG: Unsupported type '" + fieldType + "'");
+    return;
+  }
+}
+
+global.zaliczkaFetchData = zaliczkaFetchData

+ 26 - 0
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php.syncState.js

@@ -0,0 +1,26 @@
+// @require var syncUrl = ''
+
+function syncZaliczkaState(state, updates, stateSyncSyccessCallback, stateSyncErrorCallback) {
+  // TODO: if ajax success then stateSyncSyccessCallback(Response.data)
+  // TODO: if ajax fail then stateSyncErrorCallback(Response.data)
+  console.log('====== TODO: syncZaliczkaState updates:', updates, 'state:', state);
+	superagent
+		.post(syncUrl)
+		.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
+		.send({
+			updates: updates,
+		})
+		.set('Accept', 'application/json')
+		.end(function(err, res) {
+			var payload = (err || !res.ok || 'application/json' !== res.type)
+				? {type: 'warning', msg: (res.body && res.body.msg) ? res.body.msg : 'Request error', body: res.body}
+				: {type: 'success', msg: res.body.msg || '', body: res.body}
+			jQuery(document).trigger('DBG:notify', payload)
+			console.log('F.syncZaliczkaState res.body', res.body)
+			console.log('F.syncZaliczkaState payload', payload)
+			jQuery.notify(payload.msg, payload.type)
+			stateSyncSyccessCallback({data: payload.body})
+		});
+}
+
+global.syncZaliczkaState = syncZaliczkaState

+ 1 - 1
SE/se-lib/Schema/DefaultDb/zaliczka/ZaliczkaStorageAcl.php

@@ -11,7 +11,7 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
       '@namespace' => 'default_db/ZALICZKA/Zaliczka',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
       '@implements' => 'default_types/Infrastructure',
       'id' => 'xsd:integer',
-      'created' => 'xsd:date',
+      'created' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_CREATE_DATE' ],
       'worker' => [ '@ref' => 'default_objects/AccessOwner' ],// 'alias_ref:default_objects:AccessOwner'
       // 'worker' => [ '@ref' => 'Worker' ],
       'kwota' => [ '@type' => 'xsd:decimal', '@totalDigits' => 16, '@fractionDigits' => 2 ],

+ 2 - 0
SE/se-lib/UI.php

@@ -232,10 +232,12 @@ class UI {
 	public static function inlineJS($jsFile, $jsonVars = []) {
 		if (!file_exists($jsFile)) throw new Exception("js file '" . basename($jsFile) . "' not exists!");
 		UI::startTag('script', [], "\n");
+		echo "(function (global) {" . "\n";
 		foreach ($jsonVars as $name => $var) {
 			echo "var {$name} = " . json_encode($var) . ";\n";
 		}
 		include $jsFile;
+		echo "})(window)" . "\n";
 		UI::endTag('script', "\n");
 	}