Forráskód Böngészése

added ajax task to fetch values - Zaliczka

Piotr Labudda 9 éve
szülő
commit
177e7bc8fe
1 módosított fájl, 28 hozzáadás és 1 törlés
  1. 28 1
      SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

+ 28 - 1
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

@@ -56,7 +56,24 @@ function zaliczkaFetchData(query, fieldType, resultCallback) {
     }
     switch (fieldType['@namespace']) {
       case 'default_db/IN7_DZIENNIK_KORESP': {
-				
+				superagent
+					.post('<?= Request::getPathUri(); ?>/index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=fetchDataAjax')
+					.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;
+						if (err || !res.ok || 'application/json' !== res.type) {
+							payload = {type: 'warning', msg: res.body.msg || 'Request error', body: res.body};
+						} else {
+							payload = {type: 'success', msg: res.body.msg || '', body: res.body};
+						}
+						jQuery(document).trigger('DBG:notify', payload);
+						resultCallback(payload.body.options);
+					});
         console.warn("TODO: fetch by ajax default_db:IN7_DZIENNIK_KORESP");
         var options = [
           { id: 65432, title: 'testowa koresp 1', kategoriaKosztu: 'KOSZT1' },
@@ -111,6 +128,16 @@ function syncZaliczkaState(state, updates, stateSyncSyccessCallback, stateSyncEr
 		UI::tag('script', ['src'=>'static/zaliczka/main.js' . (V::get('DBG', '', $_GET) ? '?_ts=' . time() : ''), 'type'=>'text/javascript']);
 	}
 
+	public function fetchDataAjaxAction() {
+		$reqBody = Request::getRequestBody();
+		// var_dump($reqBody);
+		die(json_encode([
+			[ 'id' => 100, 'nrBudowy' => 'Budowa 100/2016' ],
+			[ 'id' => 101, 'nrBudowy' => 'Budowa 101/2016' ],
+			[ 'id' => 102, 'nrBudowy' => 'Budowa 102/2016' ],
+		]));
+	}
+
 	public function fetchDataBySchema($schema, $idUser, $primaryKey = null) {// if $primaryKey is null then search for last row
 		return [// TODO: fetch data from DB
 			'id' => 123,