|
@@ -420,7 +420,123 @@ class Route_ViewTableAjax extends RouteBase {
|
|
Response::sendTryCatchJson(array($this, 'createFormJson'), $args = $_REQUEST);
|
|
Response::sendTryCatchJson(array($this, 'createFormJson'), $args = $_REQUEST);
|
|
}
|
|
}
|
|
public function createFormJson($args) { // namespace, _hash, _primaryKey
|
|
public function createFormJson($args) { // namespace, _hash, _primaryKey
|
|
- throw new Exception("TODO: ...");
|
|
|
|
|
|
+ $namespace = V::get('namespace', '', $args, 'word');
|
|
|
|
+ if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
|
|
|
|
+ $acl = Core_AclHelper::getAclByNamespace($namespace);
|
|
|
|
+ $tbl = $this->getTableAjaxWidget($acl);
|
|
|
|
+
|
|
|
|
+ if (!Core_AclHelper::hasCreatePerms($acl)) {
|
|
|
|
+ return [
|
|
|
|
+ 'type' => "success",
|
|
|
|
+ 'msg' => "Dodaj nowy rekord",
|
|
|
|
+ 'body' => [
|
|
|
|
+ 'reactNode' => [ 'div', [ 'class' => "alert alert-danger" ], "Brak uprawnień do utworzenia nowego rekordu." ]
|
|
|
|
+ ],
|
|
|
|
+ ];
|
|
|
|
+ // throw new Exception("Brak uprawnień do utworzenia nowego rekordu.");
|
|
|
|
+ }
|
|
|
|
+ $fieldsList = array();
|
|
|
|
+ foreach ($acl->getFieldListByIdZasob() as $kID => $fieldName) {
|
|
|
|
+ if ($fieldName == 'ID') continue;
|
|
|
|
+ $field['name'] = $fieldName;
|
|
|
|
+ $field['opis'] = $acl->getFieldOpis($fieldName);
|
|
|
|
+ $field['label'] = $acl->getFieldLabel($fieldName);
|
|
|
|
+ if (empty($field['label'])) $field['label'] = str_replace('_', ' ', $fieldName);
|
|
|
|
+ $fieldsList[$kID] = $field;
|
|
|
|
+ }
|
|
|
|
+ $cols = array();
|
|
|
|
+ $forceFilterInit = array();
|
|
|
|
+ $defaultAclGroup = User::getDefaultAclGroup();
|
|
|
|
+ if ($defaultAclGroup) {
|
|
|
|
+ $forceFilterInit['A_ADM_COMPANY'] = $defaultAclGroup;
|
|
|
|
+ $forceFilterInit['A_CLASSIFIED'] = $defaultAclGroup;
|
|
|
|
+ }
|
|
|
|
+ foreach ($_GET as $k => $v) { // TODO: read from $args ?
|
|
|
|
+ if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
|
|
|
|
+ $fldName = substr($k, 3);
|
|
|
|
+ $forceFilterInit[$fldName] = $v;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ foreach ($fieldsList as $kID => $field) {
|
|
|
|
+ $defaultValue = '';
|
|
|
|
+ if (!empty($forceFilterInit[$field['name']])) {
|
|
|
|
+ $defaultValue = $forceFilterInit[$field['name']];
|
|
|
|
+ }
|
|
|
|
+ $cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
|
|
|
|
+ }
|
|
|
|
+ $tsValues = array();
|
|
|
|
+ $featureFunctions = [
|
|
|
|
+ // 'edit' => [ 'href' => '#EDIT/{0}', 'ico' => 'glyphicon glyphicon-pencil', 'title' => "Edytuj rekord"],
|
|
|
|
+ 'hist' => [ 'href' => '#HIST/{0}', 'ico' => 'glyphicon glyphicon-book', 'title' => "Historia" ],
|
|
|
|
+ 'files' => [ 'href' => '#FILES/{0}', 'ico' => 'glyphicon glyphicon-folder-open', 'title' => "Pliki" ],
|
|
|
|
+ // 'cp' => [ 'href' => '#', 'ico' => 'glyphicon glyphicon-plus-sign', 'title' => "Kopiuj rekord", 'onclick' => 'return tableAjaxCopy({0});' ],
|
|
|
|
+ 'msgs' => [ 'href' => "index.php?_route=TableMsgs&_task=tableRow&idTable=".$acl->getID()."&idRow={0}", 'ico' => 'glyphicon glyphicon-envelope', 'title' => "Wiadomości" ],
|
|
|
|
+ ];
|
|
|
|
+ $jsFields = [];
|
|
|
|
+ $tabindex = 0;
|
|
|
|
+ foreach ($fieldsList as $kID => $vCol) {
|
|
|
|
+ $fieldName = $vCol['name'];
|
|
|
|
+ DBG::log(['$fieldName'=>$fieldName, 'canCreate'=>$acl->canCreateField($fieldName)], 'array', "form field");
|
|
|
|
+ if ($acl->canCreateField($fieldName)) {
|
|
|
|
+ DBG::log("editFormJson::field({$fieldName})");
|
|
|
|
+ $fieldParams = [ 'appendBack' => true, 'tabindex' => (++$tabindex), 'maxGrid' => 8 ];
|
|
|
|
+ if (!empty($tsValues[$kID])) $fieldParams['typespecialValue'] = $tsValues[$kID];
|
|
|
|
+
|
|
|
|
+ $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
|
|
|
|
+ [ 'label', [ 'class' => "control-label", 'for' => "f{$kID}" ], [
|
|
|
|
+ [ 'span', [ 'style' => ['padding-right'=>'4px'] ], $vCol['label'] ],
|
|
|
|
+ [ 'i', [ 'class' => "glyphicon glyphicon-info-sign frm-help", 'data-toggle' => "popover", 'data-trigger' => "hover", 'title' => "", 'data-content' => htmlspecialchars($vCol['opis']), 'data-original-title' => "[{$kID}] {$fieldName}" ] ],
|
|
|
|
+ ] ],
|
|
|
|
+ [ 'div', [ 'class' => "" ], [
|
|
|
|
+ UI::hGetFormItem($acl, $fieldName, 'C', $kID, "f{$kID}", $cols[$kID], $fieldParams),
|
|
|
|
+ ] ]
|
|
|
|
+ ] ];
|
|
|
|
+ // } else {
|
|
|
|
+ // $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
|
|
|
|
+ // "TODO: SKIP field ({$fieldName}) - ! canWriteObjectField && ! canReadObjectField"
|
|
|
|
+ // ]];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $jsFields[] = [ 'div', [ 'class' => "form-group" ], [
|
|
|
|
+ [ 'div', [ 'class' => "" ], [
|
|
|
|
+ ['button', [ 'type' => "submit", 'class' => "btn btn-primary", 'tabindex' => ++$tabindex ], "Zapisz" ]
|
|
|
|
+ ] ]
|
|
|
|
+ ] ];
|
|
|
|
+
|
|
|
|
+ $tblLabel = $acl->getNamespace();
|
|
|
|
+ if ('default_db' == $acl->getSourceName()) {
|
|
|
|
+ $tblLabel = array();
|
|
|
|
+ $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
|
|
|
|
+ if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
|
|
|
|
+ if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
|
|
|
|
+ if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS;
|
|
|
|
+ $tblLabel = implode(" - ", $tblLabel);
|
|
|
|
+ }
|
|
|
|
+ $syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace();
|
|
|
|
+
|
|
|
|
+ $jsGui = [
|
|
|
|
+ 'reactNode' => [ 'div', [ 'class' => "container AjaxFrmHorizontalEdit", 'style' => [ "max-width" => "940px" ] ], [
|
|
|
|
+ [ 'h4', [ 'style' => [ "padding-bottom" => "3px", "border-bottom" => "1px solid #ddd" ] ], [
|
|
|
|
+ "Dodaj nowy rekord",
|
|
|
|
+ ] ],
|
|
|
|
+ [ 'P5UI__FeatureCreateForm', [
|
|
|
|
+ 'class' => "", 'action' => "", 'method' => "post",
|
|
|
|
+ 'id' => "CREATE_FRM_{$this->_htmlID}", // TODO: rm - use React nodes // TODO: $this->_htmlID not exists!
|
|
|
|
+ 'ajaxSaveUrl' => "{$syncUrl}&_task=createSaveAjax", // TODO:? &_hash={$this->_htmlID}
|
|
|
|
+ 'ajaxSaveLegacyUrl' => "{$syncUrl}&_task=createSaveLegacy", // TODO: Legacy RM
|
|
|
|
+ 'namespace' => $acl->getNamespace(),
|
|
|
|
+ 'tableLabelHtml' => $tblLabel,
|
|
|
|
+ '_htmlID' => $acl->getName(),
|
|
|
|
+ ], [
|
|
|
|
+ [ 'fieldset', [ 'style' => [ "padding-bottom" => "100px" ] ], $jsFields ] // fieldset
|
|
|
|
+ ] ] // form
|
|
|
|
+ ] ] // .container
|
|
|
|
+ ];
|
|
|
|
+ return [
|
|
|
|
+ 'type' => "success",
|
|
|
|
+ 'msg' => "Dodaj nowy rekord",
|
|
|
|
+ 'body' => $jsGui, // TODO: action for GUI: array to render by function h, js to trigger
|
|
|
|
+ ];
|
|
}
|
|
}
|
|
public function createSaveAjaxAction() {
|
|
public function createSaveAjaxAction() {
|
|
Response::sendTryCatchJson(array($this, 'createSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
|
|
Response::sendTryCatchJson(array($this, 'createSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
|
|
@@ -428,6 +544,48 @@ class Route_ViewTableAjax extends RouteBase {
|
|
public function createSaveAjax($args) {
|
|
public function createSaveAjax($args) {
|
|
throw new Exception("TODO: ...");
|
|
throw new Exception("TODO: ...");
|
|
}
|
|
}
|
|
|
|
+ public function createSaveLegacyAction() { // TODO: Legacy RM
|
|
|
|
+ $args = [
|
|
|
|
+ 'namespace' => V::get('namespace', '', $_GET),
|
|
|
|
+ 'body' => Request::getRequestJson(),
|
|
|
|
+ ];
|
|
|
|
+ DBG::log($args, 'array', 'createSaveLegacyAction');
|
|
|
|
+ Response::sendTryCatchJson(array($this, 'createSaveLegacy'), $args);
|
|
|
|
+ }
|
|
|
|
+ public function createSaveLegacy($args) { // TODO: Legacy RM
|
|
|
|
+ $namespace = V::get('namespace', '', $args, 'word');
|
|
|
|
+ if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
|
|
|
|
+ $body = V::get('body', null, $args);
|
|
|
|
+ if (!$body) throw new HttpException("Bad Request - missing body", 400);
|
|
|
|
+ $acl = Core_AclHelper::getAclByNamespace($namespace);
|
|
|
|
+ $tbl = $this->getTableAjaxWidget($acl);
|
|
|
|
+ DBG::log($args, 'array', "ajaxCreateSave");
|
|
|
|
+ $createdId = null;
|
|
|
|
+ try {
|
|
|
|
+ $item = $acl->convertObjectFromUserInput($body, $type = 'array_by_id', $prefix = 'f');
|
|
|
|
+ $createdId = $acl->addItem($item);
|
|
|
|
+ if ($createdId) {
|
|
|
|
+ return [
|
|
|
|
+ 'type' => 'success',
|
|
|
|
+ 'msg' => "Utworzono pomyślnie rekord nr {$createdId}",
|
|
|
|
+ 'id' => $createdId,
|
|
|
|
+ 'record' => $acl->buildQuery([])->getItem($createdId),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return [
|
|
|
|
+ 'type' => 'error',
|
|
|
|
+ 'msg' => "Nie udało się utworzyć nowego rekordu!",
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception $e) {
|
|
|
|
+ return [
|
|
|
|
+ 'type' => 'error',
|
|
|
|
+ 'msg' => $e->getMessage(),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public function editFormAction() { // TODO: not used - moved to editFormJsonAction
|
|
public function editFormAction() { // TODO: not used - moved to editFormJsonAction
|
|
try {
|
|
try {
|