Selaa lähdekoodia

added createForm action in ViewTableAjax

Piotr Labudda 8 vuotta sitten
vanhempi
commit
44a7fe7a1b
2 muutettua tiedostoa jossa 61 lisäystä ja 13 poistoa
  1. 28 2
      SE/se-lib/Route/ViewTableAjax.php
  2. 33 11
      SE/se-lib/TableAjax.php

+ 28 - 2
SE/se-lib/Route/ViewTableAjax.php

@@ -403,7 +403,33 @@ class Route_ViewTableAjax extends RouteBase {
 		return $response;
 	}
 
-	public function editFormAction() {// namespace, _hash, _primaryKey
+	public function createFormAction() {// TODO: move to createFormJsonAction
+		try {
+			$args = $_REQUEST;
+			$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);
+			$tbl->sendAjaxCreate();
+		} catch (Exception $e) {
+			DBG::log($e);
+			throw $e;
+		}
+	}
+	public function createFormJsonAction() {
+		Response::sendTryCatchJson(array($this, 'createFormJson'), $args = $_REQUEST);
+	}
+	public function createFormJson($args) { // namespace, _hash, _primaryKey
+		throw new Exception("TODO: ...");
+	}
+	public function createSaveAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'createSaveAjax'), $args = 'JSON_FROM_REQUEST_BODY');
+	}
+	public function createSaveAjax($args) {
+		throw new Exception("TODO: ...");
+	}
+
+	public function editFormAction() { // TODO: not used - moved to editFormJsonAction
 		try {
 			$args = $_REQUEST;
 			$id = V::get('_primaryKey', 0, $args, 'int');
@@ -421,7 +447,7 @@ class Route_ViewTableAjax extends RouteBase {
 	public function editFormJsonAction() {
 		Response::sendTryCatchJson(array($this, 'editFormJson'), $args = $_REQUEST);
 	}
-	public function editFormJson($args) {// namespace, _hash, _primaryKey
+	public function editFormJson($args) { // namespace, _hash, _primaryKey
 		$id = V::get('_primaryKey', 0, $args, 'int');
 		if ($id <= 0) throw new HttpException("Bad Request - missing primaryKey", 400);
 		$namespace = V::get('namespace', '', $args, 'word');

+ 33 - 11
SE/se-lib/TableAjax.php

@@ -3840,9 +3840,35 @@ jQuery(document).ready(function(){
 						});
 					}
 
+					// TODO: replace jQuery.ajax
+					// window.fetch('<?= $this->syncUrl; ?>&_hash=<?= $this->_htmlID; ?>&_task=createFormJson', {
+					// 	method: 'GET',
+					// 	credentials: 'same-origin',
+					// }).then(function(response) {
+					// 	return response.json()
+					// }).then(function __route_edit_payload(payload) {
+					// 	taskCnt.removeClass('AjaxTable-loading');
+					// 	// console.log('editFormJson :: payload', payload)
+					// 	if ('success' == payload.type) {
+					// 		var node = document.createElement('div')
+					// 		taskCnt.get(0).appendChild(node)
+					// 		p5UI__buildDom(payload.body.reactNode, node)
+					// 		initDateTimePicker(jQuery(node));
+					// 		// console.log('editFormJson :: dom loaded - TODO: add action on save - P5UI__FeatureEditForm')
+					// 	} else {
+					// 		console.log('editFormJson :: ERROR payload', payload)
+					// 	}
+					// }).catch(function __route_edit_catch(e) {
+					// 	taskCnt.removeClass('AjaxTable-loading');
+					// 	console.log('editFormJson :: ERROR', e)
+					// 	p5UI__notifyAjaxCallback({
+					// 		type: 'error',
+					// 		msg: 'Request error ' + e
+					// 	});
+					// });
+
 					jQuery.ajax({
-						url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE',// TODO: mv to ViewTableAjax route
-						// TODO: url: 'index.php?_route=ViewTableAjax&_task=createForm&namespace=<?= $acl->getNamespace(); ?>&_hash=<?php echo $this->_htmlID; ?>',
+						url: 'index.php?_route=ViewTableAjax&_task=createForm&namespace=<?= $acl->getNamespace(); ?>&_hash=<?php echo $this->_htmlID; ?>',
 						type: 'GET',
 						dataType: 'text',
 						data: reqData,
@@ -4069,11 +4095,7 @@ function hidePopover() {
 				$this->sendAjaxResponseJson('ajaxCopy', $_REQUEST);
 				break;
 			}
-			case 'CREATE': {
-				$this->sendAjaxCreate($_REQUEST);
-				break;
-			}
-			case 'CREATE_SAVE': {
+			case 'CREATE_SAVE': { // TODO: mv to _route = ViewTableAjax & _task = createSaveAjax
 				$this->sendAjaxResponseJson('ajaxCreateSave', $_REQUEST);
 				break;
 			}
@@ -4289,7 +4311,7 @@ function hidePopover() {
 		return $response;
 	}
 
-	public function sendAjaxEdit($id, $args) {
+	public function sendAjaxEdit($id, $args) { // TODO: not used @see ViewTableAjax::editFormAction
 		header("Content-type: text/plain");
 		$acl = $this->_acl;
 
@@ -4538,7 +4560,7 @@ jQuery(document).ready(function(){
 		exit;
 	}
 
-	private function sendAjaxCreate($args) {
+	public function sendAjaxCreate($args = []) {
 		$acl = $this->_acl;
 		header("Content-type: text/plain");
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
@@ -4598,8 +4620,8 @@ jQuery(document).ready(function(){
 				<?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
 					<?php if ($this->_acl->canCreateField($vCol['name'])) : ?>
 						<div class="form-group">
-							<label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
-								<i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
+							<label class="control-label" for="<?php echo "f{$kID}"; ?>"><?= V::get('label', $vCol['name'], $vCol); ?>
+								<i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars(V::get('opis', '', $vCol)); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
 							</label>
 							<div>
 								<?php