|
|
@@ -655,7 +655,7 @@ class Route_Storage_AclStruct extends RouteBase {
|
|
|
])
|
|
|
]);
|
|
|
|
|
|
- $thisGetLink = [Router::getRoute('Storage'), 'getLink'];
|
|
|
+ $thisGetLink = [ $this, 'getLink' ];
|
|
|
{ // not installed ref
|
|
|
$refFields = array_filter($item['field'], function ($field) {
|
|
|
return 'ref:' === substr($field['xsdType'], 0, 4);
|
|
|
@@ -685,7 +685,7 @@ class Route_Storage_AclStruct extends RouteBase {
|
|
|
// 'xsdType' => $field['xsdType'], // always === "ref:{$field['fieldNamespace']}"
|
|
|
'ref object' => UI::h('a', [
|
|
|
'class' => "btn btn-xs btn-link",
|
|
|
- 'href' => $thisGetLink('objectStruct', [ 'namespace' => $refNamespace ])
|
|
|
+ 'href' => $thisGetLink('', [ 'namespace' => $refNamespace ])
|
|
|
], "objectStruct ({$refNamespace})"),
|
|
|
'ref source' => UI::h('div', [],
|
|
|
(null === $refSource)
|
|
|
@@ -722,6 +722,7 @@ class Route_Storage_AclStruct extends RouteBase {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ $thisGetLink = [ $this, 'getLink' ];
|
|
|
UI::table([
|
|
|
'__html_id' => 'struct_table',
|
|
|
'caption' => UI::h('span', [], [
|
|
|
@@ -951,4 +952,59 @@ class Route_Storage_AclStruct extends RouteBase {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public function addFieldToZasobyAjaxAction() {
|
|
|
+ DBG::log($_REQUEST, 'array', '$_REQUEST');
|
|
|
+ Response::sendTryCatchJson(array($this, 'addFieldToZasobyAjax'), $_REQUEST);
|
|
|
+ }
|
|
|
+ public function addFieldToZasobyAjax($args) {
|
|
|
+ $namespace = V::get('namespace', '', $args);
|
|
|
+ if (empty($namespace)) throw new HttpException("Missing namespace");
|
|
|
+ $fieldNamespace = V::get('fieldNamespace', '', $args);
|
|
|
+ if (empty($fieldNamespace)) throw new HttpException("Missing fieldNamespace");
|
|
|
+ $fieldItem = SchemaFactory::loadDefaultObject('SystemObjectField')->getItem($fieldNamespace);
|
|
|
+ if (!$fieldItem) throw new HttpException("Field not found '{$fieldNamespace}'", 404);
|
|
|
+ DBG::log($fieldItem, 'array', "\$fieldItem");
|
|
|
+ if ($fieldItem['idZasob'] > 0) throw (new AlertSuccessException("Field already added to Zasoby '{$fieldItem['idZasob']}'"))->setBody([ 'id' => $fieldItem['idZasob'] ]);
|
|
|
+ $objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace);
|
|
|
+ if (!$objectItem) throw new HttpException("Object not found '{$namespace}'", 404);
|
|
|
+ DBG::log($objectItem, 'array', "\$objectItem");
|
|
|
+ if (!$objectItem['idZasob']) throw new Exception("Missing Object idZasob");
|
|
|
+ $zasobItem = DB::getPDO()->fetchFirst("
|
|
|
+ select zField.ID, zField.`DESC`, zField.`TYPE`, zField.PARENT_ID
|
|
|
+ from CRM_LISTA_ZASOBOW as zField
|
|
|
+ join CRM_LISTA_ZASOBOW as zTable on(zTable.ID = zField.PARENT_ID)
|
|
|
+ where zTable.`ID` = '{$objectItem['idZasob']}'
|
|
|
+ and zTable.`TYPE` = 'TABELA'
|
|
|
+ and zField.`DESC` = '{$fieldItem['fieldNamespace']}'
|
|
|
+ and zField.`TYPE` = 'KOMORKA'
|
|
|
+ ");
|
|
|
+ if ($zasobItem) {
|
|
|
+ SchemaFactory::loadDefaultObject('SystemObjectField')->updateItem([
|
|
|
+ 'namespace' => $fieldItem['namespace'],
|
|
|
+ 'idZasob' => $zasobItem['ID']
|
|
|
+ ]);
|
|
|
+ throw (new AlertSuccessException("Zasob już istnieje"))->setBody([ 'id' => $zasobItem['ID'] ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $newFieldItem = [
|
|
|
+ 'PARENT_ID' => $objectItem['idZasob'],
|
|
|
+ 'TYPE' => 'KOMORKA',
|
|
|
+ 'DESC' => $fieldItem['fieldNamespace'],
|
|
|
+ 'DESC_PL' => $fieldItem['fieldNamespace'],
|
|
|
+ ];
|
|
|
+ DBG::log($newFieldItem, 'array', "add new field item");
|
|
|
+ try {
|
|
|
+ $acl = User::getAcl()->getObjectAcl('default_db', 'crm_lista_zasobow');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ throw new Exception("Brak dostępu do tabeli Zasoby");
|
|
|
+ }
|
|
|
+ $createdId = $acl->addItem($newFieldItem);
|
|
|
+ if (!$createdId) throw new Exception("Nie udało się utworzyć nowego rekordu!");
|
|
|
+ SchemaFactory::loadDefaultObject('SystemObjectField')->updateItem([
|
|
|
+ 'namespace' => $fieldItem['namespace'],
|
|
|
+ 'idZasob' => $createdId
|
|
|
+ ]);
|
|
|
+ throw (new AlertSuccessException("Utworzono pomyślnie rekord nr {$createdId}"))->setBody([ 'id' => $createdId ]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|