|
@@ -15,7 +15,7 @@ Lib::loadClass('UserProfile');
|
|
|
|
|
|
class Route_ViewTableAjax extends RouteBase {
|
|
|
|
|
|
- public function getTableAjaxWidget($acl, $backRefFilter = [], $childRefFilter = []) {
|
|
|
+ function getTableAjaxWidget($acl, $backRefFilter = [], $childRefFilter = []) {
|
|
|
$syncUrl = $this->getLink('', [ 'namespace' => $acl->getNamespace() ]);
|
|
|
$tbl = new TableAjax($acl);
|
|
|
$tbl->setRootUrl($syncUrl);
|
|
@@ -64,353 +64,356 @@ class Route_ViewTableAjax extends RouteBase {
|
|
|
return $tbl;
|
|
|
}
|
|
|
|
|
|
- public function defaultAction() {
|
|
|
+ function defaultAction() {
|
|
|
UI::gora();
|
|
|
UI::menu();
|
|
|
try {
|
|
|
- $namespace = V::get('namespace', '', $_GET, 'word');
|
|
|
- if (!$namespace) {
|
|
|
- $typeName = V::get('typeName', '', $_GET, 'word');
|
|
|
- if (!$typeName) throw new Exception("Wrong param typeName");
|
|
|
- $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
|
|
|
+ $this->defaultView();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ UI::startContainer();
|
|
|
+ UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
|
|
|
+ UI::endContainer();
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ UI::dol();
|
|
|
+ }
|
|
|
+ function defaultView() {
|
|
|
+ $namespace = V::get('namespace', '', $_GET, 'word');
|
|
|
+ if (!$namespace) {
|
|
|
+ $typeName = V::get('typeName', '', $_GET, 'word');
|
|
|
+ if (!$typeName) throw new Exception("Wrong param typeName");
|
|
|
+ $namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
|
|
|
+ }
|
|
|
+ $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
|
|
|
+
|
|
|
+ $forceFilterInit = array();
|
|
|
+ $requestDataFilters = array();
|
|
|
+ $filterInit = new stdClass();
|
|
|
+ $filterInit->currSortCol = $acl->getPrimaryKeyField();
|
|
|
+ $filterInit->currSortFlip = 'desc';
|
|
|
+ foreach ($_REQUEST as $k => $v) {
|
|
|
+ if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
|
|
|
+ $requestDataFilters[$k] = $v;
|
|
|
+ $filterInit->$k = $v;
|
|
|
}
|
|
|
- $acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
|
|
|
-
|
|
|
- $forceFilterInit = array();
|
|
|
- $requestDataFilters = array();
|
|
|
- $filterInit = new stdClass();
|
|
|
- $filterInit->currSortCol = $acl->getPrimaryKeyField();
|
|
|
- $filterInit->currSortFlip = 'desc';
|
|
|
- foreach ($_REQUEST as $k => $v) {
|
|
|
- if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
|
|
|
- $requestDataFilters[$k] = $v;
|
|
|
- $filterInit->$k = $v;
|
|
|
- }
|
|
|
- else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
|
|
|
- $requestDataFilters[$k] = $v;
|
|
|
- $filterInit->$k = $v;
|
|
|
- }
|
|
|
- else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
|
|
|
- $fldName = substr($k, 3);
|
|
|
- $forceFilterInit[$fldName] = $v;
|
|
|
- }
|
|
|
+ else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
|
|
|
+ $requestDataFilters[$k] = $v;
|
|
|
+ $filterInit->$k = $v;
|
|
|
}
|
|
|
-
|
|
|
- $backRefFilter = [
|
|
|
- 'namespace' => V::get('backRefNS', '', $_GET),
|
|
|
- 'primaryKey' => V::get('backRefPK', '', $_GET),
|
|
|
- 'fieldName' => V::get('backRefField', '', $_GET),
|
|
|
- ];
|
|
|
- $childRefFilter = [
|
|
|
- 'namespace' => V::get('childRefNS', '', $_GET),
|
|
|
- 'primaryKey' => V::get('childRefPK', '', $_GET),
|
|
|
- ];
|
|
|
- $tbl = $this->getTableAjaxWidget($acl, $backRefFilter, $childRefFilter);
|
|
|
- $lastDataFilters = $tbl->getFilters();
|
|
|
- DBG::log([
|
|
|
- '$requestDataFilters' => $requestDataFilters,
|
|
|
- '$lastDataFilters' => $lastDataFilters,
|
|
|
- ], 'array', "TODO:BUG?:filters");
|
|
|
- if (empty($lastDataFilters) && empty($requestDataFilters)) {
|
|
|
- DBG::log(['TODO: run setFilterInit', [
|
|
|
- 'currSortCol' => $acl->getPrimaryKeyField(),
|
|
|
- 'currSortFlip' => 'desc',
|
|
|
- ]], 'array', "TODO:BUG?:filters");
|
|
|
- $tbl->setFilterInit([
|
|
|
- 'currSortCol' => $acl->getPrimaryKeyField(),
|
|
|
- 'currSortFlip' => 'desc',
|
|
|
- ]);
|
|
|
- } else if (!empty($requestDataFilters)) {
|
|
|
- $tbl->setFilterInit($filterInit);
|
|
|
+ else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
|
|
|
+ $fldName = substr($k, 3);
|
|
|
+ $forceFilterInit[$fldName] = $v;
|
|
|
}
|
|
|
- if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
|
|
|
- if (V::get('DBG_INST', '', $_GET)) { // TODO: TEST namespace
|
|
|
- $siblings = ACL::getNamespaceSiblings($namespace);
|
|
|
- DBG::nicePrint($siblings, '$siblings');
|
|
|
- $filtrInstance = V::get('f_instance', [], $_POST, 'array');
|
|
|
- DBG::nicePrint($filtrInstance, '$filtrInstance');
|
|
|
- $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} YES");
|
|
|
- $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} NO");
|
|
|
-
|
|
|
- $_ = array(UI, 'h');
|
|
|
- echo $_('form', ['method' => "POST", 'style' => "width:600px; border:1px solid #ddd; border-radius:2px"], [
|
|
|
- $_('div', ['style' => "background-color:#ddd"], "Test Filtr instancji"),
|
|
|
- $_('div', ['style' => "padding:8px"], array_map(function ($sibling) use ($filtrInstance, $_) {
|
|
|
- return $_('div', [], [
|
|
|
- $_('label', ['style' => "margin:0 8px"], [
|
|
|
- $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
|
|
|
- " TAK "
|
|
|
- ]),
|
|
|
- $_('label', ['style' => "margin:0 8px"], [
|
|
|
- $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
|
|
|
- " NIE "
|
|
|
- ]),
|
|
|
- $_('label', ['style' => "margin:0 8px"], [
|
|
|
- $_('input', ['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'x']),
|
|
|
- " pomiń "
|
|
|
- ]),
|
|
|
- // $_('button', ['onClick'=>"this.form.f_instance['{$sibling}'].value = ''; return false"], "odznacz"),
|
|
|
- $_('button', ['onClick'=>"console.log(this.form.elements['f_instance[{$sibling}]']); this.form.elements['f_instance[{$sibling}]'].value = 'x'; return false"], "odznacz"),
|
|
|
- " - {$sibling}"
|
|
|
- ]);
|
|
|
- }, $siblings)),
|
|
|
- $_('div', [], [
|
|
|
- $_('input', ['type'=>"hidden", 'name'=>'_route', 'value'=>"ViewObject"]),
|
|
|
- $_('input', ['type'=>"hidden", 'name'=>'namespace', 'value'=>$namespace]),
|
|
|
- $_('input', ['type'=>"submit", 'value'=>"Filtruj - TEST"]),
|
|
|
- ]),
|
|
|
- ]);
|
|
|
- DBG::nicePrint($_POST, '$_POST');
|
|
|
- {
|
|
|
- $args = $_POST;
|
|
|
- $fIsInstance = [];
|
|
|
- $fIsNotInstance = [];
|
|
|
- if (!empty($args['f_instance'])) {
|
|
|
- foreach ($args['f_instance'] as $inst => $selected) {
|
|
|
- if ('YES' === $selected) {
|
|
|
- $fIsInstance[] = $inst;
|
|
|
- } else if ('NO' === $selected) {
|
|
|
- $fIsNotInstance[] = $inst;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ $backRefFilter = [
|
|
|
+ 'namespace' => V::get('backRefNS', '', $_GET),
|
|
|
+ 'primaryKey' => V::get('backRefPK', '', $_GET),
|
|
|
+ 'fieldName' => V::get('backRefField', '', $_GET),
|
|
|
+ ];
|
|
|
+ $childRefFilter = [
|
|
|
+ 'namespace' => V::get('childRefNS', '', $_GET),
|
|
|
+ 'primaryKey' => V::get('childRefPK', '', $_GET),
|
|
|
+ ];
|
|
|
+ $tbl = $this->getTableAjaxWidget($acl, $backRefFilter, $childRefFilter);
|
|
|
+ $lastDataFilters = $tbl->getFilters();
|
|
|
+ DBG::log([
|
|
|
+ '$requestDataFilters' => $requestDataFilters,
|
|
|
+ '$lastDataFilters' => $lastDataFilters,
|
|
|
+ ], 'array', "TODO:BUG?:filters");
|
|
|
+ if (empty($lastDataFilters) && empty($requestDataFilters)) {
|
|
|
+ DBG::log(['TODO: run setFilterInit', [
|
|
|
+ 'currSortCol' => $acl->getPrimaryKeyField(),
|
|
|
+ 'currSortFlip' => 'desc',
|
|
|
+ ]], 'array', "TODO:BUG?:filters");
|
|
|
+ $tbl->setFilterInit([
|
|
|
+ 'currSortCol' => $acl->getPrimaryKeyField(),
|
|
|
+ 'currSortFlip' => 'desc',
|
|
|
+ ]);
|
|
|
+ } else if (!empty($requestDataFilters)) {
|
|
|
+ $tbl->setFilterInit($filterInit);
|
|
|
+ }
|
|
|
+ if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
|
|
|
+ if (V::get('DBG_INST', '', $_GET)) { // TODO: TEST namespace
|
|
|
+ $siblings = ACL::getNamespaceSiblings($namespace);
|
|
|
+ DBG::nicePrint($siblings, '$siblings');
|
|
|
+ $filtrInstance = V::get('f_instance', [], $_POST, 'array');
|
|
|
+ DBG::nicePrint($filtrInstance, '$filtrInstance');
|
|
|
+ $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} YES");
|
|
|
+ $sibling = 'default_db/CRM_PROCES/PROCES_INIT'; DBG::nicePrint(array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : []), "merge {$sibling} NO");
|
|
|
+
|
|
|
+ $_ = array(UI, 'h');
|
|
|
+ echo $_('form', ['method' => "POST", 'style' => "width:600px; border:1px solid #ddd; border-radius:2px"], [
|
|
|
+ $_('div', ['style' => "background-color:#ddd"], "Test Filtr instancji"),
|
|
|
+ $_('div', ['style' => "padding:8px"], array_map(function ($sibling) use ($filtrInstance, $_) {
|
|
|
+ return $_('div', [], [
|
|
|
+ $_('label', ['style' => "margin:0 8px"], [
|
|
|
+ $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'YES'], ('YES' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
|
|
|
+ " TAK "
|
|
|
+ ]),
|
|
|
+ $_('label', ['style' => "margin:0 8px"], [
|
|
|
+ $_('input', array_merge(['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'NO'], ('NO' === V::get($sibling, '', $filtrInstance)) ? ['checked' => "checked"] : [])),
|
|
|
+ " NIE "
|
|
|
+ ]),
|
|
|
+ $_('label', ['style' => "margin:0 8px"], [
|
|
|
+ $_('input', ['type'=>"radio", 'name'=>"f_instance[{$sibling}]", 'value'=>'x']),
|
|
|
+ " pomiń "
|
|
|
+ ]),
|
|
|
+ // $_('button', ['onClick'=>"this.form.f_instance['{$sibling}'].value = ''; return false"], "odznacz"),
|
|
|
+ $_('button', ['onClick'=>"console.log(this.form.elements['f_instance[{$sibling}]']); this.form.elements['f_instance[{$sibling}]'].value = 'x'; return false"], "odznacz"),
|
|
|
+ " - {$sibling}"
|
|
|
+ ]);
|
|
|
+ }, $siblings)),
|
|
|
+ $_('div', [], [
|
|
|
+ $_('input', ['type'=>"hidden", 'name'=>'_route', 'value'=>"ViewObject"]),
|
|
|
+ $_('input', ['type'=>"hidden", 'name'=>'namespace', 'value'=>$namespace]),
|
|
|
+ $_('input', ['type'=>"submit", 'value'=>"Filtruj - TEST"]),
|
|
|
+ ]),
|
|
|
+ ]);
|
|
|
+ DBG::nicePrint($_POST, '$_POST');
|
|
|
+ {
|
|
|
+ $args = $_POST;
|
|
|
+ $fIsInstance = [];
|
|
|
+ $fIsNotInstance = [];
|
|
|
+ if (!empty($args['f_instance'])) {
|
|
|
+ foreach ($args['f_instance'] as $inst => $selected) {
|
|
|
+ if ('YES' === $selected) {
|
|
|
+ $fIsInstance[] = $inst;
|
|
|
+ } else if ('NO' === $selected) {
|
|
|
+ $fIsNotInstance[] = $inst;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $queryFeatures = $acl->buildQuery([
|
|
|
- // TODO: 'propertyName' => "*,@instance",
|
|
|
- 'f_is_instance' => $fIsInstance,
|
|
|
- 'f_is_not_instance' => $fIsNotInstance,
|
|
|
- '@instances' => '1',
|
|
|
- 'limit' => 10
|
|
|
- ]);
|
|
|
- // $total = $queryFeatures->getTotal();
|
|
|
- $items = $queryFeatures->getItems();
|
|
|
-
|
|
|
- $rootNamespace = $acl->getRootNamespace();
|
|
|
- DBG::nicePrint($rootNamespace, '$rootNamespace');
|
|
|
- $jsRenderFunName = 'render_dropdown_instances_' . substr(md5(time()), 0, 6);
|
|
|
- DBG::nicePrint($jsRenderFunName, '$jsRenderFunName');
|
|
|
- UI::table([
|
|
|
- 'rows' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
|
|
|
- return [
|
|
|
- 'ID' => $row['ID'],
|
|
|
- 'DESC' => $row['DESC'],
|
|
|
- 'TYPE' => $row['TYPE'],
|
|
|
- 'Typ' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [
|
|
|
- UI::h('button', [
|
|
|
- // 'onClick' => "p5UI__dropdown(event, this, 'left bottom')",
|
|
|
- 'onClick' => "p5UI__dropdown(event, this, 'left bottom', {$jsRenderFunName}({$row['ID']}))",
|
|
|
- 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"
|
|
|
- ], [
|
|
|
- UI::h('i', ['class' => "glyphicon glyphicon-tags", 'title' => "Ustaw typ danych (instancje)"]),
|
|
|
- ]),
|
|
|
- UI::h('div', ['class' => "p5UI__dropdown-content"]
|
|
|
- , array_merge(
|
|
|
- [
|
|
|
- UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_ViewObject_instances_filterInput(this)"], null),
|
|
|
- ]
|
|
|
- , array_map(function ($sibling) use ($row, $namespace, $rootNamespace) {
|
|
|
- return UI::h('div', ['label'=>$sibling, 'style'=>"padding:4px 0"], [
|
|
|
- UI::h('button', array_merge(['class' => "btn btn-xs btn-default",
|
|
|
- 'style' => "margin:0 4px 0 0",
|
|
|
- 'title' => "Ustaw instancje '{$sibling}'",
|
|
|
- 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'yes')"],
|
|
|
- (in_array($sibling, explode(',', $row['@instances']))) ? ['disabled' => "disabled"] : []
|
|
|
- ), "+"),
|
|
|
- UI::h('button', ['class' => "btn btn-xs btn-default",
|
|
|
- 'style' => "margin:0 4px 0 0",
|
|
|
- 'title' => "Usuń instancje '{$sibling}'",
|
|
|
- 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'no')"], "-"),
|
|
|
- UI::h('span', [], substr($sibling, strlen($rootNamespace) + 1)),
|
|
|
- ]);
|
|
|
- }, $siblings)
|
|
|
- )
|
|
|
- )
|
|
|
+ }
|
|
|
+ $queryFeatures = $acl->buildQuery([
|
|
|
+ // TODO: 'propertyName' => "*,@instance",
|
|
|
+ 'f_is_instance' => $fIsInstance,
|
|
|
+ 'f_is_not_instance' => $fIsNotInstance,
|
|
|
+ '@instances' => '1',
|
|
|
+ 'limit' => 10
|
|
|
+ ]);
|
|
|
+ // $total = $queryFeatures->getTotal();
|
|
|
+ $items = $queryFeatures->getItems();
|
|
|
+
|
|
|
+ $rootNamespace = $acl->getRootNamespace();
|
|
|
+ DBG::nicePrint($rootNamespace, '$rootNamespace');
|
|
|
+ $jsRenderFunName = 'render_dropdown_instances_' . substr(md5(time()), 0, 6);
|
|
|
+ DBG::nicePrint($jsRenderFunName, '$jsRenderFunName');
|
|
|
+ UI::table([
|
|
|
+ 'rows' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
|
|
|
+ return [
|
|
|
+ 'ID' => $row['ID'],
|
|
|
+ 'DESC' => $row['DESC'],
|
|
|
+ 'TYPE' => $row['TYPE'],
|
|
|
+ 'Typ' => UI::h('div', ['class'=>"p5UI__dropdown-wrap"], [
|
|
|
+ UI::h('button', [
|
|
|
+ // 'onClick' => "p5UI__dropdown(event, this, 'left bottom')",
|
|
|
+ 'onClick' => "p5UI__dropdown(event, this, 'left bottom', {$jsRenderFunName}({$row['ID']}))",
|
|
|
+ 'class' => "btn btn-xs btn-default p5UI__dropdown-btn"
|
|
|
+ ], [
|
|
|
+ UI::h('i', ['class' => "glyphicon glyphicon-tags", 'title' => "Ustaw typ danych (instancje)"]),
|
|
|
]),
|
|
|
- 'instancesList' => implode(', ', ACL::getFeatureNamespaces($namespace, $row['ID'])),
|
|
|
+ UI::h('div', ['class' => "p5UI__dropdown-content"]
|
|
|
+ , array_merge(
|
|
|
+ [
|
|
|
+ UI::h('input', ['type' => "text", 'placeholder' => "Search..", 'class' => "p5UI__dropdown-input", 'onkeyup' => "p5_ViewObject_instances_filterInput(this)"], null),
|
|
|
+ ]
|
|
|
+ , array_map(function ($sibling) use ($row, $namespace, $rootNamespace) {
|
|
|
+ return UI::h('div', ['label'=>$sibling, 'style'=>"padding:4px 0"], [
|
|
|
+ UI::h('button', array_merge(['class' => "btn btn-xs btn-default",
|
|
|
+ 'style' => "margin:0 4px 0 0",
|
|
|
+ 'title' => "Ustaw instancje '{$sibling}'",
|
|
|
+ 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'yes')"],
|
|
|
+ (in_array($sibling, explode(',', $row['@instances']))) ? ['disabled' => "disabled"] : []
|
|
|
+ ), "+"),
|
|
|
+ UI::h('button', ['class' => "btn btn-xs btn-default",
|
|
|
+ 'style' => "margin:0 4px 0 0",
|
|
|
+ 'title' => "Usuń instancje '{$sibling}'",
|
|
|
+ 'onClick' => "return p5_ViewObject_instance_set(this, '{$row['ID']}', '{$sibling}', 'no')"], "-"),
|
|
|
+ UI::h('span', [], substr($sibling, strlen($rootNamespace) + 1)),
|
|
|
+ ]);
|
|
|
+ }, $siblings)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ]),
|
|
|
+ 'instancesList' => implode(', ', ACL::getFeatureNamespaces($namespace, $row['ID'])),
|
|
|
+ ];
|
|
|
+ }, $items)
|
|
|
+ ]);
|
|
|
+ echo UI::h('style', ['type' => "text/css"], "
|
|
|
+ .p5UI__dropdown-content { min-width:400px; border:1px solid #ccc; background-color: #fff; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
|
|
|
+ .p5UI__dropdown-content .p5UI__dropdown-item { display:block; color:#000; padding:4px; text-decoration:none }
|
|
|
+ .p5UI__dropdown-content .p5UI__dropdown-item:hover { background-color:#ebebeb }
|
|
|
+ ");
|
|
|
+ echo UI::h('script', ['src'=>"static/vendor.js?v=816e859d", 'type'=>"text/javascript"]);
|
|
|
+ $jsArgs = [
|
|
|
+ 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
|
|
|
+ 'NAMESPACE' => $namespace,
|
|
|
+ 'DBG' => DBG::isActive() ? 'true' : 'false',
|
|
|
+ ];
|
|
|
+
|
|
|
+ UI::inlineJS(__FILE__ . '.instancesDropdown.js', [
|
|
|
+ 'JS_GLOBAL_FUNCTION_NAME' => $jsRenderFunName,
|
|
|
+ 'NAMESPACE' => $namespace,
|
|
|
+ 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
|
|
|
+ 'DBG' => DBG::isActive() ? 1 : 0,
|
|
|
+ 'INITIAL_DROPDOWN_DATA' => [
|
|
|
+ // 'allowed_instances' => $siblings,
|
|
|
+ 'allowed_instances' => array_map(function ($sibling) use ($rootNamespace) {
|
|
|
+ return [
|
|
|
+ 'namespace' => $sibling,
|
|
|
+ 'label' => substr($sibling, strlen($rootNamespace) + 1)
|
|
|
+ ];
|
|
|
+ }, $siblings),
|
|
|
+ 'items' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
|
|
|
+ return [
|
|
|
+ 'pk' => $row['ID'], // TODO: $primaryKeyField
|
|
|
+ 'instances' => explode(',', $row['@instances']),
|
|
|
];
|
|
|
}, $items)
|
|
|
- ]);
|
|
|
- echo UI::h('style', ['type' => "text/css"], "
|
|
|
- .p5UI__dropdown-content { min-width:400px; border:1px solid #ccc; background-color: #fff; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
|
|
|
- .p5UI__dropdown-content .p5UI__dropdown-item { display:block; color:#000; padding:4px; text-decoration:none }
|
|
|
- .p5UI__dropdown-content .p5UI__dropdown-item:hover { background-color:#ebebeb }
|
|
|
- ");
|
|
|
- echo UI::h('script', ['src'=>"static/vendor.js?v=816e859d", 'type'=>"text/javascript"]);
|
|
|
- $jsArgs = [
|
|
|
- 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
|
|
|
- 'NAMESPACE' => $namespace,
|
|
|
- 'DBG' => DBG::isActive() ? 'true' : 'false',
|
|
|
- ];
|
|
|
-
|
|
|
- UI::inlineJS(__FILE__ . '.instancesDropdown.js', [
|
|
|
- 'JS_GLOBAL_FUNCTION_NAME' => $jsRenderFunName,
|
|
|
- 'NAMESPACE' => $namespace,
|
|
|
- 'SET_INSTANCE_URL' => $this->getLink('setInstanceAjax'),
|
|
|
- 'DBG' => DBG::isActive() ? 1 : 0,
|
|
|
- 'INITIAL_DROPDOWN_DATA' => [
|
|
|
- // 'allowed_instances' => $siblings,
|
|
|
- 'allowed_instances' => array_map(function ($sibling) use ($rootNamespace) {
|
|
|
- return [
|
|
|
- 'namespace' => $sibling,
|
|
|
- 'label' => substr($sibling, strlen($rootNamespace) + 1)
|
|
|
- ];
|
|
|
- }, $siblings),
|
|
|
- 'items' => array_map(function($row) use ($namespace, $siblings, $rootNamespace, $jsRenderFunName) {
|
|
|
- return [
|
|
|
- 'pk' => $row['ID'], // TODO: $primaryKeyField
|
|
|
- 'instances' => explode(',', $row['@instances']),
|
|
|
- ];
|
|
|
- }, $items)
|
|
|
- ],
|
|
|
- ]);
|
|
|
- echo UI::h('script', [], "
|
|
|
- var SET_INSTANCE_URL = '{$jsArgs['SET_INSTANCE_URL']}'
|
|
|
- var NAMESPACE = '{$jsArgs['NAMESPACE']}'
|
|
|
- function p5_ViewObject_instance_set(n, pk, sibling, toConnect) {
|
|
|
- console.log('p5_ViewObject_instance_set pk('+pk+'), sibling('+sibling+'), toConnect('+toConnect+'), n', n);
|
|
|
- window.fetch(SET_INSTANCE_URL, {
|
|
|
- method: 'POST',
|
|
|
- headers: { 'Content-Type': 'application/json' },
|
|
|
- credentials: 'same-origin',
|
|
|
- body: JSON.stringify({
|
|
|
- namespace: NAMESPACE,
|
|
|
- primaryKey: pk,
|
|
|
- instance: sibling,
|
|
|
- toConnect: toConnect,
|
|
|
- })
|
|
|
- }).then(function (response) {
|
|
|
- return response.json()
|
|
|
- }).then(function (response) {
|
|
|
- p5UI__notifyAjaxCallback(response)
|
|
|
- console.log(response) // TODO: render list
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+ echo UI::h('script', [], "
|
|
|
+ var SET_INSTANCE_URL = '{$jsArgs['SET_INSTANCE_URL']}'
|
|
|
+ var NAMESPACE = '{$jsArgs['NAMESPACE']}'
|
|
|
+ function p5_ViewObject_instance_set(n, pk, sibling, toConnect) {
|
|
|
+ console.log('p5_ViewObject_instance_set pk('+pk+'), sibling('+sibling+'), toConnect('+toConnect+'), n', n);
|
|
|
+ window.fetch(SET_INSTANCE_URL, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ namespace: NAMESPACE,
|
|
|
+ primaryKey: pk,
|
|
|
+ instance: sibling,
|
|
|
+ toConnect: toConnect,
|
|
|
})
|
|
|
- }
|
|
|
- ");
|
|
|
- echo UI::h('script', [], "
|
|
|
- function p5_ViewObject_instances_filterInput(n) {
|
|
|
- var input, filter, ul, li, a, i, div;
|
|
|
- input = n // .id-myInput
|
|
|
- filter = input.value.toUpperCase()
|
|
|
- div = n.parentNode // .id-myDropdown
|
|
|
- a = div.getElementsByTagName('div')
|
|
|
- for (i = 0; i < a.length; i++) {
|
|
|
- if (a[i].getAttribute('label') && a[i].getAttribute('label').toUpperCase().indexOf(filter) > -1) {
|
|
|
- a[i].style.display = 'block'
|
|
|
- } else {
|
|
|
- a[i].style.display = 'none'
|
|
|
- }
|
|
|
+ }).then(function (response) {
|
|
|
+ return response.json()
|
|
|
+ }).then(function (response) {
|
|
|
+ p5UI__notifyAjaxCallback(response)
|
|
|
+ console.log(response) // TODO: render list
|
|
|
+ })
|
|
|
+ }
|
|
|
+ ");
|
|
|
+ echo UI::h('script', [], "
|
|
|
+ function p5_ViewObject_instances_filterInput(n) {
|
|
|
+ var input, filter, ul, li, a, i, div;
|
|
|
+ input = n // .id-myInput
|
|
|
+ filter = input.value.toUpperCase()
|
|
|
+ div = n.parentNode // .id-myDropdown
|
|
|
+ a = div.getElementsByTagName('div')
|
|
|
+ for (i = 0; i < a.length; i++) {
|
|
|
+ if (a[i].getAttribute('label') && a[i].getAttribute('label').toUpperCase().indexOf(filter) > -1) {
|
|
|
+ a[i].style.display = 'block'
|
|
|
+ } else {
|
|
|
+ a[i].style.display = 'none'
|
|
|
}
|
|
|
}
|
|
|
- ");
|
|
|
- echo '<hr style="margin-top:300px">';
|
|
|
- exit;
|
|
|
- }
|
|
|
- echo $tbl->render();
|
|
|
-
|
|
|
- if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
|
|
|
- Lib::loadClass('DebugExecutionTime');
|
|
|
- $dbgExecTime = new DebugExecutionTime();
|
|
|
- $dbgExecTime->activate();
|
|
|
- $dbgExecTime->log('start');
|
|
|
- UI::startContainer(['style'=>'border:1px solid red']);
|
|
|
- UI::tag('p', null, "TEST - load perms from db");
|
|
|
- $idTable = $acl->getID();
|
|
|
- UI::tag('p', null, "DBG idTable({$idTable})");
|
|
|
- if ($idTable > 0) {
|
|
|
- $dbgExecTime->log('before sql');
|
|
|
- $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
|
|
|
- $dbgExecTime->log('after sql', ['sql']);
|
|
|
- UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
|
|
|
- $csvIdProces = array();
|
|
|
- foreach ($aclTableRows as $row) {
|
|
|
- if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
|
|
|
- }
|
|
|
}
|
|
|
+ ");
|
|
|
+ echo '<hr style="margin-top:300px">';
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ echo $tbl->render();
|
|
|
+
|
|
|
+ if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
|
|
|
+ Lib::loadClass('DebugExecutionTime');
|
|
|
+ $dbgExecTime = new DebugExecutionTime();
|
|
|
+ $dbgExecTime->activate();
|
|
|
+ $dbgExecTime->log('start');
|
|
|
+ UI::startContainer(['style'=>'border:1px solid red']);
|
|
|
+ UI::tag('p', null, "TEST - load perms from db");
|
|
|
+ $idTable = $acl->getID();
|
|
|
+ UI::tag('p', null, "DBG idTable({$idTable})");
|
|
|
+ if ($idTable > 0) {
|
|
|
+ $dbgExecTime->log('before sql');
|
|
|
+ $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
|
|
|
+ $dbgExecTime->log('after sql', ['sql']);
|
|
|
+ UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
|
|
|
+ $csvIdProces = array();
|
|
|
+ foreach ($aclTableRows as $row) {
|
|
|
+ if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $tableName = $acl->getName();
|
|
|
- $databaseName = DB::getPDO()->getDatabaseName();
|
|
|
- UI::table([
|
|
|
- 'caption' => "Cell to process",
|
|
|
- 'rows' => array_map(
|
|
|
- function ($row) use ($aclTableRows, $idTable) {
|
|
|
- $row['proces'] = array();
|
|
|
- $row['id_zasob'] = 0;
|
|
|
- $row['PERM_R'] = 0;
|
|
|
- $row['PERM_W'] = 0;
|
|
|
- $row['PERM_X'] = 0;
|
|
|
- $row['PERM_C'] = 0;
|
|
|
- $row['PERM_S'] = 0;
|
|
|
- $row['PERM_O'] = 0;
|
|
|
- $row['PERM_V'] = 0;
|
|
|
- $row['PERM_E'] = 0;
|
|
|
- foreach ($aclTableRows as $aclInfo) {
|
|
|
- if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
|
|
|
- $row['proces'][] = $aclInfo['ID_PROCES'];
|
|
|
- $row['id_zasob'] = $aclInfo['ID_CELL'];
|
|
|
- $row['PERM_R'] += $aclInfo['PERM_R'];
|
|
|
- $row['PERM_W'] += $aclInfo['PERM_W'];
|
|
|
- $row['PERM_X'] += $aclInfo['PERM_X'];
|
|
|
- $row['PERM_C'] += $aclInfo['PERM_C'];
|
|
|
- $row['PERM_S'] += $aclInfo['PERM_S'];
|
|
|
- $row['PERM_O'] += $aclInfo['PERM_O'];
|
|
|
- $row['PERM_V'] += $aclInfo['PERM_V'];
|
|
|
- $row['PERM_E'] += $aclInfo['PERM_E'];
|
|
|
- }
|
|
|
+ $tableName = $acl->getName();
|
|
|
+ $databaseName = DB::getPDO()->getDatabaseName();
|
|
|
+ UI::table([
|
|
|
+ 'caption' => "Cell to process",
|
|
|
+ 'rows' => array_map(
|
|
|
+ function ($row) use ($aclTableRows, $idTable) {
|
|
|
+ $row['proces'] = array();
|
|
|
+ $row['id_zasob'] = 0;
|
|
|
+ $row['PERM_R'] = 0;
|
|
|
+ $row['PERM_W'] = 0;
|
|
|
+ $row['PERM_X'] = 0;
|
|
|
+ $row['PERM_C'] = 0;
|
|
|
+ $row['PERM_S'] = 0;
|
|
|
+ $row['PERM_O'] = 0;
|
|
|
+ $row['PERM_V'] = 0;
|
|
|
+ $row['PERM_E'] = 0;
|
|
|
+ foreach ($aclTableRows as $aclInfo) {
|
|
|
+ if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
|
|
|
+ $row['proces'][] = $aclInfo['ID_PROCES'];
|
|
|
+ $row['id_zasob'] = $aclInfo['ID_CELL'];
|
|
|
+ $row['PERM_R'] += $aclInfo['PERM_R'];
|
|
|
+ $row['PERM_W'] += $aclInfo['PERM_W'];
|
|
|
+ $row['PERM_X'] += $aclInfo['PERM_X'];
|
|
|
+ $row['PERM_C'] += $aclInfo['PERM_C'];
|
|
|
+ $row['PERM_S'] += $aclInfo['PERM_S'];
|
|
|
+ $row['PERM_O'] += $aclInfo['PERM_O'];
|
|
|
+ $row['PERM_V'] += $aclInfo['PERM_V'];
|
|
|
+ $row['PERM_E'] += $aclInfo['PERM_E'];
|
|
|
}
|
|
|
- $row['proces'] = (empty($row['proces']))
|
|
|
- ? "<i style=\"color:red\">Brak</i>"
|
|
|
- : implode(", ", $row['proces']);
|
|
|
- if (!$row['id_zasob']) $row['id_zasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$row['COLUMN_NAME']}' and PARENT_ID = {$idTable} limit 1");
|
|
|
- return $row;
|
|
|
- }, DB::getPDO()->fetchAll("
|
|
|
- select t.TABLE_NAME, t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
|
|
|
- from `information_schema`.`COLUMNS` t
|
|
|
- where t.TABLE_SCHEMA = '{$databaseName}'
|
|
|
- and t.TABLE_NAME like '{$tableName}'
|
|
|
- ")
|
|
|
- )
|
|
|
- ]);
|
|
|
-
|
|
|
- if (!empty($csvIdProces)) {
|
|
|
- $csvIdProces = implode(",", $csvIdProces);
|
|
|
- UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
|
|
|
- $userLogin = User::getLogin();
|
|
|
- $dbgExecTime->log('before sql');
|
|
|
- $rows = DB::getPDO()->fetchAll("select ID_PROCES from `CRM_PROCES_idx_USER_to_PROCES_VIEW` where ADM_ACCOUNT = '{$userLogin}' and ID_PROCES in({$csvIdProces}) group by ID_PROCES");
|
|
|
- $dbgExecTime->log('after sql', ['sql']);
|
|
|
- UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]);
|
|
|
- $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
|
|
|
- $userTablePerms = array();
|
|
|
- foreach ($aclTableRows as $row) {
|
|
|
- if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
|
|
|
- if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
|
|
|
- } else {
|
|
|
- $userTablePerms[ $row['CELL_NAME'] ] = $row;
|
|
|
- unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
|
|
|
- unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
|
|
|
- unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
|
|
|
}
|
|
|
+ $row['proces'] = (empty($row['proces']))
|
|
|
+ ? "<i style=\"color:red\">Brak</i>"
|
|
|
+ : implode(", ", $row['proces']);
|
|
|
+ if (!$row['id_zasob']) $row['id_zasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$row['COLUMN_NAME']}' and PARENT_ID = {$idTable} limit 1");
|
|
|
+ return $row;
|
|
|
+ }, DB::getPDO()->fetchAll("
|
|
|
+ select t.TABLE_NAME, t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
|
|
|
+ from `information_schema`.`COLUMNS` t
|
|
|
+ where t.TABLE_SCHEMA = '{$databaseName}'
|
|
|
+ and t.TABLE_NAME like '{$tableName}'
|
|
|
+ ")
|
|
|
+ )
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!empty($csvIdProces)) {
|
|
|
+ $csvIdProces = implode(",", $csvIdProces);
|
|
|
+ UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
|
|
|
+ $userLogin = User::getLogin();
|
|
|
+ $dbgExecTime->log('before sql');
|
|
|
+ $rows = DB::getPDO()->fetchAll("select ID_PROCES from `CRM_PROCES_idx_USER_to_PROCES_VIEW` where ADM_ACCOUNT = '{$userLogin}' and ID_PROCES in({$csvIdProces}) group by ID_PROCES");
|
|
|
+ $dbgExecTime->log('after sql', ['sql']);
|
|
|
+ UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]);
|
|
|
+ $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
|
|
|
+ $userTablePerms = array();
|
|
|
+ foreach ($aclTableRows as $row) {
|
|
|
+ if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
|
|
|
+ if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
|
|
|
+ } else {
|
|
|
+ $userTablePerms[ $row['CELL_NAME'] ] = $row;
|
|
|
+ unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
|
|
|
+ unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
|
|
|
+ unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
|
|
|
}
|
|
|
- UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]);
|
|
|
- } else UI::alert('warning', "brak \$csvIdProces");
|
|
|
- $dbgExecTime->printDebug();
|
|
|
- UI::endContainer();
|
|
|
- }
|
|
|
- } catch (Exception $e) {
|
|
|
- UI::startContainer();
|
|
|
- UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
|
|
|
+ }
|
|
|
+ UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]);
|
|
|
+ } else UI::alert('warning', "brak \$csvIdProces");
|
|
|
+ $dbgExecTime->printDebug();
|
|
|
UI::endContainer();
|
|
|
- DBG::log($e);
|
|
|
}
|
|
|
- UI::dol();
|
|
|
}
|
|
|
|
|
|
public function setInstanceAjaxAction() {
|