Piotr Labudda před 7 roky
revize
b78f90e84b

+ 0 - 0
schema/ant-object/.gitkeep


+ 39 - 0
theme/base.php

@@ -0,0 +1,39 @@
+<?php
+
+// TODO: file and class name must have the same name as project
+
+class Theme_base extends ThemeDefault {
+
+	// function head() { // TODO: echo 'html tag inside <head>'
+	// }
+
+	// function top() { // TODO: first tag after body: top menu or header
+	// 	include dirname(__FILE__) . '/Bocian/top.php';
+	// }
+
+	// function footer() { // TODO: before </body>
+	// 	include dirname(__FILE__) . '/view/footer.php';
+	// }
+
+	// function login($data) { // TODO: login view
+	// 	if (is_array($data) && !empty($data)) {
+	// 		extract($data);
+	// 	}
+	// 	include dirname(__FILE__) . '/view/login.php';
+	// }
+
+	// function logout($data) { // TODO: logout view
+	// 	if (is_array($data) && !empty($data)) {
+	// 		extract($data);
+	// 	}
+	// 	include dirname(__FILE__) . '/view/logout.php';
+	// }
+
+	// function home($data) { // TODO: home page view
+	// 	if (is_array($data) && !empty($data)) {
+	// 		extract($data);
+	// 	}
+	// 	include dirname(__FILE__) . '/view/home.php';
+	// }
+
+}

+ 42 - 0
tools/ExampleTool.php

@@ -0,0 +1,42 @@
+<?php
+
+Lib::loadClass('RouteToolBase');
+Lib::loadClass('UI');
+Lib::loadClass('Response');
+Lib::loadClass('Theme');
+
+// class name must have the same name as file
+// index.php?_route=UrlAction_BraveCare  - uruchamia defaultAction
+class ExampleTool extends RouteToolBase {
+
+	public function defaultAction() {
+		UI::gora();
+		Theme::top();
+		echo '<h1>Example Tool</h1>';
+		UI::inlineJS(__FILE__ . '.example.js', [
+			'URL_TEST_AJAX_ACTION' => $this->getLink('testAjax'),
+		]);
+		UI::dol();
+	}
+
+	public function testAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'testAjax'), $_REQUEST); // args from request
+		// Response::sendTryCatchJson(array($this, 'testAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // args from json request
+	}
+	public function testAjax($args) { // args given by sendTryCatchJson
+		$items = [
+			[ 'ID' => 1, 'name' => 'x', 'desc' => 'a' ],
+			[ 'ID' => 2, 'name' => 'y', 'desc' => 'b' ],
+			[ 'ID' => 3, 'name' => 'z',  'desc' => 'c' ],
+		];
+
+		return [
+			'type' => 'success',
+			'msg' => 'OK',
+			'body' => [
+				'items' => $items,
+			]
+		];
+	}
+
+}

+ 15 - 0
tools/ExampleTool.php.example.js

@@ -0,0 +1,15 @@
+console.log('URL_TEST_AJAX_ACTION:', URL_TEST_AJAX_ACTION)
+
+if (!URL_TEST_AJAX_ACTION) {
+	throw "Brak zmiennej URL_TEST_AJAX_ACTION"
+}
+
+global.fetch(URL_TEST_AJAX_ACTION, { // @doc https://github.com/github/fetch
+	credentials: 'same-origin', // or 'include' for CORS
+}).then(function (response) {
+	return response.json()
+}).then(function (data) {
+	console.log('data', data)
+}).catch(function (e) {
+	console.warn('Error', e)
+})