Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE/Remote-Inclusion #374

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions modules/formulize/include/entriesdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -3336,15 +3336,15 @@ function addNew(flag) {
} else {
window.document.controls.ventry.value = 'addnew';
}
window.document.controls.submit();
submitControls();
}

function goDetails(viewentry, screen) {
window.document.controls.ventry.value = viewentry;
if(screen>0) {
window.document.controls.overridescreen.value = screen;
}
window.document.controls.submit();
submitControls();
}

function cancelCalcs() {
Expand Down Expand Up @@ -3423,7 +3423,15 @@ function showLoading() {
}
?>
window.document.controls.ventry.value = '';
window.document.controls.submit();
submitControls();
}

function submitControls() {
if (window.formulize_remoteSubmitList) {
window.formulize_remoteSubmitList();
} else {
window.document.controls.submit();
}
}

function showLoadingReset() {
Expand Down
10 changes: 9 additions & 1 deletion modules/formulize/include/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,11 @@ function validateAndSubmit(leave) {
if (leave=='leave') {
jQuery('#save_and_leave').val(1);
}
window.document.formulize_mainform.submit();
if (window.formulize_remoteSubmitForm) {
window.formulize_remoteSubmitForm();
} else {
window.document.formulize_mainform.submit();
}
} else {
hideSavingGraphic();
}
Expand Down Expand Up @@ -3583,6 +3587,9 @@ function formulize_javascriptForAfterRemovingLocks(action) {
if(action == 'submitGoParent') {
window.document.go_parent.submit();
} else if(action == 'rewritePage') {
if (window.formulize_remoteSubmitForm) {
window.formulize_remoteSubmitForm();
} else {
var formAction = jQuery('form[name=formulize_mainform]').attr('action');
var formData = jQuery('form[name=formulize_mainform]').serialize();
jQuery.ajax({
Expand All @@ -3598,6 +3605,7 @@ function formulize_javascriptForAfterRemovingLocks(action) {
});
}
}
}

<?php

Expand Down
12 changes: 12 additions & 0 deletions modules/formulize/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
require_once "../../mainfile.php";
}

// ajax request from a different server, so set $formulize_screen_id now, and we won't use the theme to render the contents of the page
if(!strstr($_SERVER['HTTP_REFERER'], XOOPS_URL)
AND isset($_SERVER['HTTP_FORMULIZE_REMOTE_INCLUDE'])
AND isset($_GET['sid'])
AND intval($_GET['sid'])) {
$formulize_screen_id = $_GET['sid'];
}

// need to declare the allowable CORS locations -- must be configurable
header('Access-Control-Allow-Origin: https://polygon.red');
header('Access-Control-Allow-Headers: formulize-remote-include, x-requested-with, Content-Type, referer');

include_once XOOPS_ROOT_PATH.'/header.php';

include_once XOOPS_ROOT_PATH.'/modules/formulize/include/common.php';
Expand Down
5 changes: 5 additions & 0 deletions modules/formulize/templates/css/formulize-icons/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
19 changes: 19 additions & 0 deletions remote.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Formulize remote include test</title>
<script id='formulize.remote.js' src='https://julian.formulize.net/remote.js'></script>
</head>

<body>

<div id='formulize'></div>

<script>
window.onload = function() {
formulize_remoteRenderScreen(2, 'formulize');
}
</script>

</body>
</html>
78 changes: 78 additions & 0 deletions remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Formulize remote include javascript library
* Copyright the Formulize Project 2023
*/

var formulize = {url:''};
formulize.url = document.getElementById('formulize.remote.js').getAttribute('src').replace('/remote.js', '');
if (formulize.url == '') {
console.log('Formulize Remote Error: could not determine url for your Formulize instance. Check that the <script> tag that includes the remote.js file has the id "formulize.remote.js".');
}

if(typeof window.jQuery == 'undefined') {
var dochead = document.getElementsByTagName('head')[0];
const formulize_jQueryScript = document.createElement('script');
formulize_jQueryScript.src = 'https://code.jquery.com/jquery-1.12.4.js';
formulize_jQueryScript.crossorigin = 'anonymous';
dochead.appendChild(formulize_jQueryScript);
const formulize_jQueryUIScript = document.createElement('script');
formulize_jQueryUIScript.src = 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js';
formulize_jQueryUIScript.crossorigin = 'anonymous';
dochead.appendChild(formulize_jQueryUIScript);
const formulize_moduleCSS = document.createElement('link');
formulize_moduleCSS.rel = 'stylesheet';
formulize_moduleCSS.href = formulize.url+'/modules/formulize/templates/css/formulize.css';
formulize_moduleCSS.type = 'text/css';
dochead.appendChild(formulize_moduleCSS);
const formulize_themeCSS = document.createElement('link');
formulize_themeCSS.rel = 'stylesheet';
formulize_themeCSS.href = formulize.url+'/themes/Anari/css/style.css';
formulize_themeCSS.type = 'text/css';
dochead.appendChild(formulize_themeCSS);
const poppinsFont = document.createElement('link');
poppinsFont.rel = 'stylesheet';
poppinsFont.href = 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap';
poppinsFont.type = 'text/css';
dochead.appendChild(poppinsFont);

}

var lastLoadedScreenId = 0;
var lastUsedDomTarget = '';
function formulize_remoteRenderScreen(screen_id, dom_id, formData='') {
lastLoadedScreenId = parseInt(screen_id);
lastUsedDomTarget = dom_id;
jQuery.ajax({
type: "POST",
data: formData,
url: formulize.url+'/modules/formulize/index.php?sid='+screen_id,
headers: { 'formulize-remote-include': 1 },
success: function(html) {
jQuery('#'+dom_id).empty();
jQuery('#'+dom_id).append(html).ready(function() {
jQuery('body').show(200, function() {
jQuery('.formulizeThemeForm').each(function() {
jQuery(this).show();
});
jQuery(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
formulize_remoteSubmitList();
}
return true;
});
var formulize_pageShown = new CustomEvent('formulize_pageShown');
window.dispatchEvent(formulize_pageShown);
});
});
}
});
}

function formulize_remoteSubmitList() {
formulize_remoteRenderScreen(lastLoadedScreenId, lastUsedDomTarget, jQuery('#controls').serialize());
}

function formulize_remoteSubmitForm() {
formulize_remoteRenderScreen(lastLoadedScreenId, lastUsedDomTarget, jQuery('#formulize_mainform').serialize());
}