Skip to content

Commit

Permalink
added new render target RENDER_TARGET_NONE_AND_CLOSE
Browse files Browse the repository at this point in the history
added new response receiver attribute
removed login custom bg images
added warmup after setup
  • Loading branch information
brainfoolong committed Apr 9, 2024
1 parent 5f929d5 commit c66521e
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 112 deletions.
17 changes: 17 additions & 0 deletions appdata/modules/Framelix/dev/web-types/web-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"default-icon": "icon.png",
"contributions": {
"html": {
"attributes": [
{
"name": "title",
"description": "Displays the content as a tooltip. Accepts a language key as well."
},
{
"name": "data-toolip",
"description": "Alias for 'title'"
},
{
"name": "data-request-response-receiver",
"description": "If set, this container will receive the request response if a child container does make an async request.",
"value": {
"kind": "no-value"
}
}
],
"elements": [
{
"name": "framelix-button",
Expand Down
27 changes: 12 additions & 15 deletions appdata/modules/Framelix/js/form/framelix-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FramelixForm {
* The target to render the submit response to
* @type {FramelixTypeDefJsRequestOptions}
*/
requestOptions = { url: '', renderTarget: 'currentcontext' }
requestOptions = { url: null, renderTarget: FramelixTypeDefJsRequestOptions.RENDER_TARGET_CURRENT_CONTEXT }

/**
* Submit the form async
Expand All @@ -110,12 +110,6 @@ class FramelixForm {
*/
submitAsyncRaw = true

/**
* Execute the javascript code after form submit
* @var {string|null}
*/
executeAfterAsyncSubmit = null

/**
* Submit the form with enter key
* @type {boolean}
Expand Down Expand Up @@ -818,7 +812,9 @@ class FramelixForm {
}
}
this.hideValidationMessage()
let submitUrl = this.submitUrl
const requestOptions = this.requestOptions ? this.requestOptions : { url: null, renderTarget: 'currentcontext' }
let submitUrl = this.submitUrl || requestOptions.url
// if no submit url is defined, try to use the current tab context url
if (!submitUrl) {
const tabContent = this.form.closest('.framelix-tab-content')
if (tabContent.length) {
Expand All @@ -845,6 +841,13 @@ class FramelixForm {

// if request does handle anything itself, do not proceed handling the request
const responseCheckHeadersStatus = await request.checkHeaders()

// handling closing modals, no matter what happen later
if (requestOptions && requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixModal.destroyAll()
FramelixPopup.destroyAll()
}

if (responseCheckHeadersStatus !== 0) {
return true
}
Expand Down Expand Up @@ -884,13 +887,7 @@ class FramelixForm {
}

if (typeof responseData.buffer === 'string' && responseData.buffer.length) {
FramelixRequest.renderResponse(responseData.buffer, this.requestOptions, this.container[0])
}

if (this.executeAfterAsyncSubmit) {
await new Promise(function (resolve) {
eval('(async function(){' + self.executeAfterAsyncSubmit + ' resolve();})()')
})
FramelixRequest.renderResponse(responseData.buffer, requestOptions, this.container[0])
}
return true
}
Expand Down
59 changes: 41 additions & 18 deletions appdata/modules/Framelix/js/framelix-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,36 +209,59 @@ class FramelixRequest {
return null
}
initiatorElement = $(initiatorElement)
let parentCell = initiatorElement.closest('td')
let parentPopup = initiatorElement.closest('.framelix-popup')
let parentModal = initiatorElement.closest('.framelix-modal')
let parentTab = initiatorElement.closest('.framelix-tab-content')
let validTarget = false
if (!validTarget) {
let responseReceiver = initiatorElement.closest('td')
if (responseReceiver.length) {
validTarget = true
requestOptions.renderTarget = { elementSelector: responseReceiver }
}
}

if (!validTarget) {
let responseReceiver = initiatorElement.closest('.framelix-popup')
if (responseReceiver.length) {
validTarget = true
requestOptions.renderTarget = { popupOptions: responseReceiver[0].framelixPopupInstance.options }
initiatorElement = responseReceiver[0].framelixPopupInstance.target
}
}

if (parentCell.length) {
requestOptions.renderTarget = { elementSelector: parentCell }
} else if (parentPopup.length) {
requestOptions.renderTarget = { popupOptions: parentPopup[0].framelixPopupInstance.options }
initiatorElement = parentPopup[0].framelixPopupInstance.target
} else if (parentModal.length) {
const modal = FramelixModal.instances[parentModal.attr('data-instance-id')]
if (modal) {
requestOptions.renderTarget = { modalOptions: { instance: modal } }
if (!validTarget) {
let responseReceiver = initiatorElement.closest('.framelix-modal')
if (responseReceiver.length) {
validTarget = true
const modal = FramelixModal.instances[responseReceiver.attr('data-instance-id')]
if (modal) {
requestOptions.renderTarget = { modalOptions: { instance: modal } }
}
}
} else if (parentTab.length) {
const modal = FramelixModal.instances[parentModal.attr('data-instance-id')]
if (modal) {
requestOptions.renderTarget = { modalOptions: { instance: modal } }
}

if (!validTarget) {
let responseReceiver = initiatorElement.closest('[data-request-response-receiver]')
if (responseReceiver.length) {
validTarget = true
requestOptions.renderTarget = { elementSelector: responseReceiver }
}
}
}
}
console.log(requestOptions)
const isFixedResponse = !(request instanceof FramelixRequest)
if (!requestOptions.renderTarget) {
if (!requestOptions.renderTarget || requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
if (!isFixedResponse) {
Framelix.showProgressBar(1)
request.checkHeaders().then(function () {
Framelix.showProgressBar(null)
if (requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixPopup.destroyAll()
FramelixModal.destroyAll()
}
})
} else if (requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixPopup.destroyAll()
FramelixModal.destroyAll()
}
} else if (requestOptions.renderTarget.modalOptions) {
let options = requestOptions.renderTarget.modalOptions
Expand Down
22 changes: 12 additions & 10 deletions appdata/modules/Framelix/public/dist/js/form.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ class FramelixForm {
submitMethod = 'post';
submitUrl = null;
requestOptions = {
url: '',
renderTarget: 'currentcontext'
url: null,
renderTarget: FramelixTypeDefJsRequestOptions.RENDER_TARGET_CURRENT_CONTEXT
};
submitAsync = true;
submitAsyncRaw = true;
executeAfterAsyncSubmit = null;
submitWithEnter = true;
autocomplete = false;
stickyFormButtons = false;
Expand Down Expand Up @@ -530,7 +529,11 @@ class FramelixForm {
}
}
this.hideValidationMessage();
let submitUrl = this.submitUrl;
const requestOptions = this.requestOptions ? this.requestOptions : {
url: null,
renderTarget: 'currentcontext'
};
let submitUrl = this.submitUrl || requestOptions.url;
if (!submitUrl) {
const tabContent = this.form.closest('.framelix-tab-content');
if (tabContent.length) {
Expand All @@ -556,6 +559,10 @@ class FramelixForm {
}
self.hideValidationMessage();
const responseCheckHeadersStatus = await request.checkHeaders();
if (requestOptions && requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixModal.destroyAll();
FramelixPopup.destroyAll();
}
if (responseCheckHeadersStatus !== 0) {
return true;
}
Expand Down Expand Up @@ -587,12 +594,7 @@ class FramelixForm {
FramelixToast.showNext();
}
if (typeof responseData.buffer === 'string' && responseData.buffer.length) {
FramelixRequest.renderResponse(responseData.buffer, this.requestOptions, this.container[0]);
}
if (this.executeAfterAsyncSubmit) {
await new Promise(function (resolve) {
eval('(async function(){' + self.executeAfterAsyncSubmit + ' resolve();})()');
});
FramelixRequest.renderResponse(responseData.buffer, requestOptions, this.container[0]);
}
return true;
}
Expand Down
72 changes: 46 additions & 26 deletions appdata/modules/Framelix/public/dist/js/general.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1628,47 +1628,66 @@ class FramelixRequest {
return null;
}
initiatorElement = $(initiatorElement);
let parentCell = initiatorElement.closest('td');
let parentPopup = initiatorElement.closest('.framelix-popup');
let parentModal = initiatorElement.closest('.framelix-modal');
let parentTab = initiatorElement.closest('.framelix-tab-content');
if (parentCell.length) {
requestOptions.renderTarget = {
elementSelector: parentCell
};
} else if (parentPopup.length) {
requestOptions.renderTarget = {
popupOptions: parentPopup[0].framelixPopupInstance.options
};
initiatorElement = parentPopup[0].framelixPopupInstance.target;
} else if (parentModal.length) {
const modal = FramelixModal.instances[parentModal.attr('data-instance-id')];
if (modal) {
let validTarget = false;
if (!validTarget) {
let responseReceiver = initiatorElement.closest('td');
if (responseReceiver.length) {
validTarget = true;
requestOptions.renderTarget = {
modalOptions: {
instance: modal
}
elementSelector: responseReceiver
};
}
} else if (parentTab.length) {
const modal = FramelixModal.instances[parentModal.attr('data-instance-id')];
if (modal) {
}
if (!validTarget) {
let responseReceiver = initiatorElement.closest('.framelix-popup');
if (responseReceiver.length) {
validTarget = true;
requestOptions.renderTarget = {
modalOptions: {
instance: modal
}
popupOptions: responseReceiver[0].framelixPopupInstance.options
};
initiatorElement = responseReceiver[0].framelixPopupInstance.target;
}
}
if (!validTarget) {
let responseReceiver = initiatorElement.closest('.framelix-modal');
if (responseReceiver.length) {
validTarget = true;
const modal = FramelixModal.instances[responseReceiver.attr('data-instance-id')];
if (modal) {
requestOptions.renderTarget = {
modalOptions: {
instance: modal
}
};
}
}
}
if (!validTarget) {
let responseReceiver = initiatorElement.closest('[data-request-response-receiver]');
if (responseReceiver.length) {
validTarget = true;
requestOptions.renderTarget = {
elementSelector: responseReceiver
};
}
}
}
}
console.log(requestOptions);
const isFixedResponse = !(request instanceof FramelixRequest);
if (!requestOptions.renderTarget) {
if (!requestOptions.renderTarget || requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
if (!isFixedResponse) {
Framelix.showProgressBar(1);
request.checkHeaders().then(function () {
Framelix.showProgressBar(null);
if (requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixPopup.destroyAll();
FramelixModal.destroyAll();
}
});
} else if (requestOptions.renderTarget === FramelixTypeDefJsRequestOptions.RENDER_TARGET_NONE_AND_CLOSE) {
FramelixPopup.destroyAll();
FramelixModal.destroyAll();
}
} else if (requestOptions.renderTarget.modalOptions) {
let options = requestOptions.renderTarget.modalOptions;
Expand Down Expand Up @@ -3048,6 +3067,7 @@ class FramelixTypeDefJsRequestOptions extends FramelixBaseTypeDef {
static RENDER_TARGET_MODAL_NEW = "modalnew";
static RENDER_TARGET_POPUP = "popup";
static RENDER_TARGET_CURRENT_CONTEXT = "currentcontext";
static RENDER_TARGET_NONE_AND_CLOSE = "none-close";
static toAttrValue(data) {
return super.toAttrValue(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class FramelixTypeDefJsRequestOptions extends FramelixBaseTypeDef {
*/
static RENDER_TARGET_CURRENT_CONTEXT = "currentcontext"

/**
* Same as "null", makes the request, but not render it, additionally it destroys all modals and popups to get back
* to the pages context
*/
static RENDER_TARGET_NONE_AND_CLOSE = "none-close"

/**
* @param {FramelixTypeDefJsRequestOptions|Object} data
* @return {string}
Expand All @@ -41,7 +47,7 @@ class FramelixTypeDefJsRequestOptions extends FramelixBaseTypeDef {
* The render target for the request
* If null, it will make the request but not render it anywhere
* Require any of the class constants starting with RENDER_TARGET_
* @type {FramelixTypeDefJsRenderTarget|Object|null|("modalnew", "popup", "currentcontext")}
* @type {FramelixTypeDefJsRenderTarget|Object|null|("modalnew", "popup", "currentcontext", "none-close")}
*/
renderTarget = null

Expand Down
19 changes: 11 additions & 8 deletions appdata/modules/Framelix/src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Framelix\Framelix\Form;

use Framelix\Framelix\Enums\ButtonColor;
use Framelix\Framelix\Form\Field\File;
use Framelix\Framelix\Html\HtmlAttributes;
use Framelix\Framelix\Html\PhpToJsData;
use Framelix\Framelix\Html\TypeDefs\ElementColor;
use Framelix\Framelix\Html\TypeDefs\JsRequestOptions;
use Framelix\Framelix\Lang;
use Framelix\Framelix\Network\Request;
use Framelix\Framelix\Network\Response;
Expand Down Expand Up @@ -69,11 +69,20 @@ class Form implements JsonSerializable

/**
* The url to submit to
* If null then it is the current url
* If null then it is the current url or current tag
* @var Url|View|string|null
*/
public Url|View|string|null $submitUrl = null;

/**
* The request options instead of submitUrl
* @var JsRequestOptions|array|null
*/
public JsRequestOptions|array|null $requestOptions = [
'url' => null,
'renderTarget' => JsRequestOptions::RENDER_TARGET_CURRENT_CONTEXT,
];

/**
* Submit the form async
* If false then the form will be submitted with native form submit features (new page load)
Expand All @@ -89,12 +98,6 @@ class Form implements JsonSerializable
*/
public bool $submitAsyncRaw = false;

/**
* Execute the javascript code after form submit
* @var string|null
*/
public ?string $executeAfterAsyncSubmit = null;

/**
* Validation message to show in the frontend
* @var string|null
Expand Down
Loading

0 comments on commit c66521e

Please sign in to comment.