Quellcode durchsuchen

added schema objects in Storage; fixed p5UI button ajax namespace

Piotr Labudda vor 9 Jahren
Ursprung
Commit
dde0c1592a

+ 20 - 0
SE/schema/gui/core/default_db-admin_users.json

@@ -0,0 +1,20 @@
+{
+  "name": "admin_users",
+  "label": "Użytkownik",
+  "list_label": "Użytkownicy",
+  "fields": {
+    "ID": { "label": "Nr", "type": "int" },
+    "ADM_ACCOUNT": { "label": "Login", "type": "string", "restrictions": { "maxLength": 20 } },
+    "ADM_NAME": { "label": "Imię i nazwisko", "type": "string", "restrictions": { "maxLength": 255 } }
+  },
+  "keys": {
+    "PRIMARY": {
+      "fields": "ID",
+      "auto_increment": true
+    },
+    "uniq_adm_account": {
+      "fields": ["ADM_ACCOUNT"],
+      "type": "UNIQUE"
+    }
+  }
+}

+ 16 - 0
SE/schema/gui/core/default_db-crm_lista_zasobow.json

@@ -0,0 +1,16 @@
+{
+  "name": "crm_lista_zasobow",
+  "label": "Zasób",
+  "list_label": "Zasoby",
+  "fields": {
+    "ID": { "label": "Nr", "type": "int" },
+    "DESC": { "label": "Cecha", "type": "string", "restrictions": { "maxLength": 255 } },
+    "OPIS": { "label": "OPIS", "type": "string", "restrictions": { "maxLength": 255 } }
+  },
+  "keys": {
+    "PRIMARY": {
+      "fields": "ID",
+      "auto_increment": true
+    }
+  }
+}

+ 22 - 0
SE/schema/gui/core/default_db-local_email.json

@@ -0,0 +1,22 @@
+{
+  "name": "local_email",
+  "label": "Lokalny adres email",
+  "list_label": "Lokalne adresy email",
+  "fields": {
+    "ID": {"label": "Nr", "type": "int" },
+    "EMAIL": { "label": "Login", "type": "string", "restrictions": { "maxLength": 20 } },
+    "ID_USER": { "label": "Nr użytkownika", "type": "int", "nullable": true },
+    "ID_GROUP": { "label": "Nr grupy", "type": "int", "nullable": true },
+    "REMOTE_TYPE": { "label": "Przypisane do", "type": "enumeration", "restrictions": { "enumeration": ["ADMIN_USERS", "CRM_LISTA_ZASOBOW"] } }
+  },
+  "keys": {
+    "PRIMARY": {
+      "fields": "ID",
+      "auto_increment": true
+    },
+    "uniq_remote": {
+      "fields": ["REMOTE_TYPE", "ID_USER", "ID_USER"],
+      "type": "UNIQUE"
+    }
+  }
+}

+ 27 - 0
SE/schema/gui/core/group.json

@@ -0,0 +1,27 @@
+{
+  "name": "group",
+  "label": "Grupa",
+  "list_label": "Grupy",
+  "parent_object": "zasob",
+  "fields": {
+    "ID": {},
+    "DESC": {},
+    "OPIS": {},
+    "ref_LOCAL_EMAIL": {
+      "label": "Adresy email lokalnej poczty",
+      "type": "ref",
+      "ref_config": {
+        "name": "group__ref__local_email",
+        "target": "local_email",
+        "default_db_cache_fields": {
+          "target": "remote",
+          "from": "ID",
+          "to": "ID_GROUP"
+        }
+      },
+      "remote_fields": {
+        "EMAIL": {}
+      }
+    }
+  }
+}

+ 13 - 0
SE/schema/gui/core/local_email.json

@@ -0,0 +1,13 @@
+{
+  "name": "local_email",
+  "label": "Lokalny adres email",
+  "list_label": "Lokalne adresy email",
+  "parent_object": "default_db/local_email",
+  "fields": {
+    "ID": {},
+    "EMAIL": {},
+    "ID_USER": {},
+    "ID_GROUP": {},
+    "REMOTE_TYPE": {}
+  }
+}

+ 15 - 0
SE/schema/gui/core/stanowisko.json

@@ -0,0 +1,15 @@
+{
+  "name": "stanowisko",
+  "label": "Stanowisko",
+  "list_label": "Stanowiska",
+  "parent_object": "group",
+  "fields": {
+    "ID": {},
+    "DESC": {},
+    "OPIS": {},
+    "ref_LOCAL_EMAIL": {}
+  },
+  "default_db_cache_fields": {
+    "TYPE": "STANOWISKO"
+  }
+}

+ 14 - 0
SE/schema/gui/core/user.json

@@ -0,0 +1,14 @@
+{
+  "name": "user",
+  "label": "Użytkownik",
+  "list_label": "Użytkownicy",
+  "parent_object": "default_db/admin_users",
+  "fields": {
+    "ID": {},
+    "ADM_ACCOUNT": {},
+    "ADM_NAME": {}
+  },
+  "default_db_cache_fields": {
+    "EMPLOYEE_TYPE": "Kontakt"
+  }
+}

+ 27 - 0
SE/schema/gui/core/worker.json

@@ -0,0 +1,27 @@
+{
+  "name": "worker",
+  "label": "Pracownik",
+  "list_label": "Pracownicy",
+  "parent_object": "user",
+  "fields": {
+    "ID": {},
+    "ADM_ACCOUNT": {},
+    "ADM_NAME": {},
+    "ref_LOCAL_EMAIL": {
+      "label": "Adresy email lokalnej poczty",
+      "type": "ref",
+      "ref_config": {
+        "name": "user__ref__local_email",
+        "target": "local_email",
+        "default_db_cache_fields": {
+          "target": "remote",
+          "from": "ID",
+          "to": "ID_ADMIN_USERS"
+        }
+      }
+    }
+  },
+  "default_db_cache_fields": {
+    "EMPLOYEE_TYPE": "Pracownik"
+  }
+}

+ 16 - 0
SE/schema/gui/core/worker_active.json

@@ -0,0 +1,16 @@
+{
+  "name": "worker_active",
+  "label": "Aktywny Pracownik",
+  "list_label": "Aktywni Pracownicy",
+  "parent_object": "worker",
+  "fields": {
+    "ID": {},
+    "ADM_ACCOUNT": {},
+    "ADM_NAME": {},
+    "ref_LOCAL_EMAIL": {}
+  },
+  "default_db_cache_fields": {
+    "EMPLOYEE_TYPE": "Pracownik",
+    "A_STATUS": "NORMAL"
+  }
+}

+ 16 - 0
SE/schema/gui/core/worker_inctive.json

@@ -0,0 +1,16 @@
+{
+  "name": "worker_inctive",
+  "label": "Nieaktywny Pracownik",
+  "list_label": "Nieaktywni Pracownicy",
+  "parent_object": "worker",
+  "fields": {
+    "ID": {},
+    "ADM_ACCOUNT": {},
+    "ADM_NAME": {},
+    "ref_LOCAL_EMAIL": {}
+  },
+  "default_db_cache_fields": {
+    "EMPLOYEE_TYPE": "Pracownik",
+    "A_STATUS": "OFF_SOFT"
+  }
+}

+ 11 - 0
SE/schema/gui/core/zasob.json

@@ -0,0 +1,11 @@
+{
+  "name": "zasob",
+  "label": "Zasób",
+  "list_label": "Zasoby",
+  "parent_object": "default_db/crm_lista_zasobow",
+  "fields": {
+    "ID": {},
+    "DESC": {},
+    "OPIS": {}
+  }
+}

+ 179 - 45
SE/se-lib/Route/Storage.php

@@ -4,6 +4,7 @@
 Lib::loadClass('RouteBase');
 Lib::loadClass('Schema_TableFactory');
 Lib::loadClass('Response');
+Lib::loadClass('UI');
 
 /*
 # Storage:
@@ -23,8 +24,9 @@ class Route_Storage extends RouteBase {
 	}
 
 	public function defaultAction() {
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
+		$this->navView();
 		try {
 			$storageList = $this->getStorageList();
 			if (empty($storageList)) throw new Exception("No storage defined");
@@ -40,25 +42,128 @@ class Route_Storage extends RouteBase {
 				$menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
 				$storageMenu[] = $menuItem;
 			}
-			$this->navView();
+			{// core object list
+				$menuItem = array();
+				//$menuItem['id'] = 'Obiekty';
+				$menuItem['nazwa'] = 'Obiekty podstawowe';
+				$menuItem['typ'] = 'OBJECTS';
+				$menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=coreObjectList">' . "obiekty" . '</a>';
+				//$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
+				//$menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=objectRawInfo">' . "raw info" . '</a>';
+				// TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
+				$storageMenu[] = $menuItem;
+			}
+			{// object list - for current company
+				$hostName = $_SERVER['SERVER_NAME'];
+				$cleanHostName = str_replace(array(".", "-"), '_', $hostName);
+				$menuItem = array();
+				//$menuItem['id'] = 'Obiekty';
+				$menuItem['nazwa'] = "Obiekty dla domeny '{$cleanHostName}'";
+				$menuItem['typ'] = 'OBJECTS';
+				$menuItem['tabele i widoki'] = '<a href="index.php?_route=Storage&_task=objectList">' . "obiekty" . '</a>';
+				//$menuItem['views'] = '<a href="index.php?_route=Storage&_task=viewList&idStorage=' . $id . '">' . "views" . '</a>';
+				//$menuItem['raw info'] = '<a href="index.php?_route=Storage&_task=objectRawInfo">' . "raw info" . '</a>';
+				// TODO: $menuItem['xsd'] = '<a href="index.php?_route=Storage&_task=xsd&idStorage=' . $id . '" target="_blank">' . "xsd" . '</a>';
+				$storageMenu[] = $menuItem;
+			}
 			DBG::table("storageMenu", $storageMenu, __CLASS__, __FUNCTION__, __LINE__);
 		} catch (Exception $e) {
-			SE_Layout::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
+	}
+
+	public function getCoreObjectFromFile($objectName) {
+		if ('default_db/' === substr($objectName, 0, 11)) {
+			return array('name' => substr($objectName, 11));
+		}
+
+		$filePath = APP_PATH_SCHEMA . "/gui/core/{$objectName}.json";
+		if (!file_exists($filePath)) throw new Exception("File not exists", 404);
+
+		$json = file_get_contents($filePath);
+		DBG::_('DBG', '>1', "{$objectName} filePath", $filePath, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::_('DBG', '>1', "{$objectName} file content", $json, __CLASS__, __FUNCTION__, __LINE__);
+		$json = @json_decode($json, $assoc = true);
+		DBG::_('DBG', '>1', "{$objectName} json_last_error()", json_last_error(), __CLASS__, __FUNCTION__, __LINE__);
+		if (null == $json && 0 !== json_last_error()) throw new Exception("Parse json error for object '{$objectName}': " . json_last_error());
+		$jsonParent = array();
+		$parent = (is_array($json['parent_object']))? end($json['parent_object']) : $json['parent_object'];
+		$jsonParent = $this->getCoreObjectFromFile($parent);
+		return array_merge_recursive($jsonParent, $json);
+	}
+
+	public function coreObjectStructAction() {
+		UI::gora();
+		UI::menu();
+		$this->navView();
+		try {
+
+			$object = V::get('object', '', $_REQUEST, 'word');
+			if (empty($object)) throw new Exception("Missing Object name");
+			$json = $this->getCoreObjectFromFile($object);
+			DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
+
+
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}
-		SE_Layout::dol();
+		UI::dol();
+	}
+
+	public function coreObjectListAction() {
+		UI::gora();
+		UI::menu();
+		$this->navView();
+		try {
+			$files = glob(APP_PATH_SCHEMA . "/gui/core/*.json", GLOB_NOSORT);
+			//DBG::_(true, true, "files", $files);
+			$objectList = array();
+			foreach ($files as $filePath) {
+				$objItem = array();
+				$fileName = basename($filePath);
+				$objName = substr($fileName, 0, -5);// remove ext '.json'
+				$objItem['name'] = $objName;
+				$objItem['file_name'] = $fileName;
+				$objItem['label'] = "";// TODO: read from json
+				$objItem['struktura'] = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . $objName . '">' . "struct" . '</a>';
+				$objectList[] = $objItem;
+			}
+			usort($objectList, function($rowA, $rowB) {
+				$a = $rowA['nazwa']; $b = $rowB['nazwa'];
+				if ($a == $b) return 0;
+				return ($a < $b) ? -1 : 1;
+			});
+
+			DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
+	}
+
+	public function objectListAction() {
+		UI::gora();
+		UI::menu();
+		try {
+
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
 	}
 
 	public function tableListAction() {
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
+		$this->navView();
 		try {
 			$idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
 			if (empty($idStorage)) throw new Exception("No id storage");
 			$storageList = $this->getStorageList();
 			if (empty($storageList)) throw new Exception("No storage defined");
-			if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
+			if (!array_key_exists($idStorage, $storageList)) throw new Exception("Storage id='{$idStorage}' not exists");
 
-			$this->navView();
 			$storagePdo = DB::getStorage($idStorage);
 			$viewRealList = $storagePdo->getViewList();
 			$tableRealList = $storagePdo->getTableList();
@@ -72,14 +177,13 @@ class Route_Storage extends RouteBase {
 			}
 
 			$emptyItem = array();
-			$emptyItem['nazwa'] = '';//->urlTblStruct = $this->buildActionUrl('tableStruct', array('storageId'=>$storageId, 'tblName'=>$tblName));
+			$emptyItem['nazwa'] = '';
 			$emptyItem['type'] = '';
-			$emptyItem['dodaj zasób'] = '';//->urlTblAddToZasoby = $this->buildAjaxActionUrl('addTableToZasoby', $urlParams);
-			$emptyItem['struktura'] = '';//->urlTblRawStruct = $this->buildActionUrl('tableStructRaw', array('storageId'=>$storageId, 'tblName'=>$tblName));
-			$emptyItem['objectTest'] = '';//->urlObjectTest = $this->buildActionUrl('objectTest', array('storageId'=>$storageId, 'tblName'=>$tblName));
-			$emptyItem['xsd'] = '';//->urlTableXsd = $this->buildActionUrl('tableXsd', array('storageId'=>$storageId, 'tblName'=>$tblName, 'HEADER_NOT_INIT'=>'YES'));
-			$emptyItem['id_zasob'] = '';//->zasobId = $zasobTableId;
-			$emptyItem['isHist'] = '';//->isHistTable = ('_HIST' == substr($tblName, -5)) ? true : false;
+			$emptyItem['id_zasob'] = '';
+			$emptyItem['struktura'] = '';
+			$emptyItem['objectTest'] = '';
+			$emptyItem['xsd'] = '';
+			$emptyItem['isHist'] = '';
 			$emptyItem['uwagi'] = '';
 
 			$tableList = array();
@@ -100,8 +204,8 @@ class Route_Storage extends RouteBase {
 				} else {
 					$tblItem['uwagi'] .= 'TODO: ADD ZASOB';
 					$ajaxAddZasobLink = Request::getUriDirName() . "/index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}";
-					$onClick = "return p5UI__ButtonAjax(this, { href: '{$ajaxAddZasobLink}' })";
-					$tblItem['dodaj zasób'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
+					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addToZasoby', { href: '{$ajaxAddZasobLink}' })";
+					$tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
 				}
 				$tableList[] = $tblItem;
 			}
@@ -118,7 +222,7 @@ class Route_Storage extends RouteBase {
 					$tblItem['id_zasob'] = $tblZasob['ID'];
 				} else {
 					$tblItem['uwagi'] .= 'TODO: ADD ZASOB';
-					$tblItem['dodaj zasób'] = '<a href="#">TODO: ADD ZASOB</a>';
+					$tblItem['id_zasob'] = 'TODO: ADD ZASOB';
 				}
 				$tableList[] = $tblItem;
 			}
@@ -132,31 +236,40 @@ class Route_Storage extends RouteBase {
 					$tableList[] = $tblItem;
 				}
 			}
+			usort($tableList, function($rowA, $rowB) {
+				$a = $rowA['nazwa']; $b = $rowB['nazwa'];
+				if ($a == $b) return 0;
+				$a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
+				if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
+					return ($a1 < $b1) ? 1 : -1;
+				}
+				return ($a < $b) ? -1 : 1;
+			});
 			DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
 			?>
 <script>
-jQuery(document).on('p5UI__ButtonAjax:click', function(e, n, payload) {
-	console.log('event p5UI__ButtonAjax:click', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:click', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addToZasoby:click', n, payload);
 });
-jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
-	console.log('event p5UI__ButtonAjax:ajaxLoaded', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', n, payload);
 	if ('success' == payload.type && payload.body && payload.body.id > 0) {
-		jQuery(n).parents('td').next('td').next('td').next('td').next('td').text(payload.body.id);
-		jQuery(n).remove();
+		jQuery(n).parents('td').text(payload.body.id);
 	}
 	jQuery.notify(payload.msg, payload.type);
 });
 </script>
 			<?php
 		} catch (Exception $e) {
-			SE_Layout::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 	public function rawInfoAction() {
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
+		$this->navView();
 		try {
 			$idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
 			if (empty($idStorage)) throw new Exception("No id storage");
@@ -164,19 +277,19 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 			if (empty($storageList)) throw new Exception("No storage defined");
 			if (!array_key_exists($idStorage, $storageList)) throw new Exception("No id storage not exists");
 
-			$this->navView();
 			$storagePdo = DB::getStorage($idStorage);
 			$rawInfo = $storagePdo->getTableListWithInfo();
 			DBG::table("rawInfo", $rawInfo, __CLASS__, __FUNCTION__, __LINE__);
 		} catch (Exception $e) {
-			SE_Layout::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 	public function tableStructAction() {
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
+		$this->navView();
 		try {
 			$idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
 			if (empty($idStorage)) throw new Exception("No id storage");
@@ -186,13 +299,12 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 			$tblName = V::get('table', '', $_REQUEST, 'word');
 			if (empty($tblName)) throw new Exception("No table name");
 
-			$this->navView();
 			$storagePdo = DB::getStorage($idStorage);
 			$tblStruct = $storagePdo->getTableStruct($tblName);
 
 			$idTable = $this->fetchTableId($idStorage, $tblName);
 			if ($idTable <= 0) {
-				SE_Layout::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
+				UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
 				DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
 				throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
 			}
@@ -208,7 +320,6 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 
 			$emptyItem = array();
 			$emptyItem['name'] = '';
-			$emptyItem['dodaj zasób'] = '';
 			$emptyItem['id_zasob'] = '';
 			$emptyItem['uwagi'] = '';
 
@@ -241,8 +352,8 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 				} else {
 					$tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB';
 					$ajaxAddZasobLink = Request::getUriDirName() . "/index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}";
-					$onClick = "return p5UI__ButtonAjax(this, { href: '{$ajaxAddZasobLink}' })";
-					$tblItem['dodaj zasób'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
+					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addToZasoby', { href: '{$ajaxAddZasobLink}' })";
+					$tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
 				}
 				$tableList[] = $tblItem;
 			}
@@ -255,14 +366,25 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 					$tableList[] = $tblItem;
 				}
 			}
+			usort($tableList, function($rowA, $rowB) {
+				$a = $rowA['name']; $b = $rowB['name'];
+				if ('ID' == $a) return -1;
+				if ('ID' == $b) return 1;
+				if ($a == $b) return 0;
+				$a1 = substr($a, 0, 1); $b1 = substr($b, 0, 1);
+				if (('_' == $a1 || '_' == $b1) && $a1 != $b1) {
+					return ($a1 < $b1) ? 1 : -1;
+				}
+				return ($a < $b) ? -1 : 1;
+			});
 			DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
 			?>
 <script>
-jQuery(document).on('p5UI__ButtonAjax:click', function(e, n, payload) {
-	console.log('event p5UI__ButtonAjax:click', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:click', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addToZasoby:click', n, payload);
 });
-jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
-	console.log('event p5UI__ButtonAjax:ajaxLoaded', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', n, payload);
 	if ('success' == payload.type && payload.body && payload.body.id > 0) {
 		jQuery(n).parents('td').next('td').text(payload.body.id);
 		jQuery(n).remove();
@@ -274,9 +396,9 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 <?php
 
 		} catch (Exception $e) {
-			SE_Layout::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 	public function xsdAction() {
@@ -516,6 +638,7 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 			$backDisabled = false;
 			$idStorage = V::get('idStorage', 0, $_REQUEST, 'int');
 			$tblName = V::get('table', '', $_REQUEST, 'word');
+			$objName = V::get('object', '', $_REQUEST, 'word');
 			switch ($task) {
 				case 'tableList':
 				case 'viewList':
@@ -529,12 +652,21 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 					$backLink = "index.php?_route=Storage&_task=tableList&idStorage={$idStorage}";
 					$currentLink = "index.php?_route=Storage&_task={$task}&idStorage={$idStorage}&table={$tblName}";
 					break;
+				case 'objectStruct': break;
+				case 'coreObjectStruct':
+					$backLabel = "Obiekty podstawowe";
+					$backLink = "index.php?_route=Storage&_task=coreObjectList";
+					$currentLink = "index.php?_route=Storage&_task={$task}&object={$objName}";
+					break;
 			}
 			switch ($task) {
 				case 'tableList': $currentLabel = "Tabele [{$idStorage}]"; break;
 				case 'viewList':  $currentLabel = "Widoki [{$idStorage}]"; break;
 				case 'rawInfo':   $currentLabel = "Raw info [{$idStorage}]"; break;
 				case 'tableStruct': $currentLabel = "Struktura tabeli '{$tblName}'"; break;
+				case 'coreObjectList': $currentLabel = "Obiekty podstawowe"; break;
+				case 'coreObjectStruct': $currentLabel = "Obiekt '{$objName}'"; break;
+				case 'objectList': $currentLabel = "Obiekty z aktualnej domeny"; break;// TODO: domain from $_GET
 			}
 		}
 		?>
@@ -589,6 +721,7 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 	public function addTableToZasobyAction() {// sends JSON
 		$response = new stdClass();
 		try {
+			$response->id = 123; throw new AlertSuccessException("TEST: Utworzono pomyślnie rekord nr 123");
 			$idStorage = V::get('storageId', '', $_GET);
 			$tblName = V::get('tblName', '', $_GET, 'word');
 			if (empty($tblName)) throw new HttpException("Wrong table name");
@@ -661,6 +794,7 @@ jQuery(document).on('p5UI__ButtonAjax:ajaxLoaded', function(e, n, payload) {
 	public function addCellToZasobyAction() {// sends JSON
 		$response = new stdClass();
 		try {
+			$response->id = 123; throw new AlertSuccessException("TEST: Utworzono pomyślnie rekord nr 123");
 			$idStorage = V::get('storageId', '', $_GET);
 			$tblName = V::get('tblName', '', $_GET, 'word');
 			$cellName = V::get('cellName', '', $_GET, 'word');

+ 1 - 1
SE/se-lib/bootstrap.php

@@ -2,7 +2,7 @@
 
 define('DS', DIRECTORY_SEPARATOR);
 define('APP_PATH_LIB', dirname(__FILE__));
-define('APP_PATH_ROOT', APP_PATH_LIB . DS . '..');
+define('APP_PATH_ROOT', realpath(APP_PATH_LIB . DS . '..'));
 define('APP_PATH_WWW', APP_PATH_ROOT);
 define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
 define('APP_PATH_SCHEMA', APP_PATH_ROOT . DS . 'schema');

+ 4 - 3
SE/se-lib/tmpl/_layout_gora.php

@@ -74,14 +74,15 @@
 		</script>
 	<?php endif; ?>
 <script>
-function p5UI__ButtonAjax(n, props) {
+function p5UI__ButtonAjax(n, eventNamespace, props) {
 	var dbg = <?php echo (DBG::isActive())? 1 : 0; ?>;
+	var eventNamespace = eventNamespace || 'p5UI__ButtonAjax';
 	var $n = jQuery(n);
 	var state = {
 		baseCssClassNames: n.className,
 		href: props.href
 	};
-	jQuery(document).trigger('p5UI__ButtonAjax:click', [n, state]);
+	jQuery(document).trigger(eventNamespace+':click', [n, state]);
 	if ($n.hasClass('disabled')) {// bootstrap already prevent this action
 		if(dbg)console.log('WARNING: btn disabled - waiting for response - Cancel?');
 		return false;
@@ -105,7 +106,7 @@ function p5UI__ButtonAjax(n, props) {
 					return;
 				}
 				jQuery(document).trigger('DBG:notify', {type: 'success', msg: 'res.status:' + res.status + '. res.body:' + JSON.stringify(res.body)});
-				jQuery(document).trigger('p5UI__ButtonAjax:ajaxLoaded', [n, {type: 'success', msg: res.body.msg, body: res.body}]);
+				jQuery(document).trigger(eventNamespace+':ajaxLoaded', [n, {type: 'success', msg: res.body.msg, body: res.body}]);
 			}
 			req = null;
 		});