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

Implemented dynamic editing UI for admin page with slidepanel #57

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
101 changes: 101 additions & 0 deletions modules/formulize/admin/admin_editor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

$ele_name = $_GET['ele_name'];
$preg_array = explode('_', $ele_name);
$_GET = array();
$_GET['ele_id'] = array_pop($preg_array);
$_GET['page'] ='element';
$_GET['aid'] = 0;

// initialize the ImpressCMS admin page template
include_once("admin_header.php");
define('_FORMULIZE_UI_PHP_INCLUDED', 1);

// include necessary Formulize files/functions
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";

global $xoopsTpl;

if(!isset($xoopsTpl)) {
global $xoopsOption, $xoopsConfig, $xoopsModule;

$xoopsOption['theme_use_smarty'] = 1;

// include Smarty template engine and initialize it
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';

if ( @$xoopsOption['template_main'] ) {
if ( false === strpos( $xoopsOption['template_main'], ':' ) ) {
$xoopsOption['template_main'] = 'db:' . $xoopsOption['template_main'];
}
}
$xoopsThemeFactory = new xos_opal_ThemeFactory();
$xoopsThemeFactory->allowedThemes = $xoopsConfig['theme_set_allowed'];
$xoopsThemeFactory->defaultTheme = $xoopsConfig['theme_set'];

$xoTheme =& $xoopsThemeFactory->createInstance( array(
'contentTemplate' => @$xoopsOption['template_main'],
) );
$xoopsTpl =& $xoTheme->template;

//$xoTheme->addScript( '/include/xoops.js', array( 'type' => 'text/javascript' ) );
//$xoTheme->addScript( '/include/linkexternal.js', array( 'type' => 'text/javascript' ) );
}

// handle any operations requested as part of this page load
// sets up a template variable with the results of the op, called opResults
include_once "op.php";

// create the contents that we want to display for the currently selected page
// the included php files create the values for $adminPage that are used for this page
$adminPage = array();
switch($_GET['page']) {
case "application":
include "application.php";
break;
case "form":
include "form.php";
break;
case "screen":
include "screen.php";
break;
case "relationship":
include "relationship.php";
break;
case "element":
include "element.php";
break;
case "advanced-calculation":
include "advanced_calculation.php";
break;
default:
case "home":
include "home.php";
break;

}
//$adminPage['logo'] = "/modules/formulize/images/formulize-logo.png";

// assign the default selected tab, if any:
if(isset($_GET['tab']) AND (!isset($_POST['tabs_selected']) OR $_POST['tabs_selected'] === "")) {
foreach($adminPage['tabs'] as $selected=>$tabData) {
if(strtolower($tabData['name']) == $_GET['tab']) {
$adminPage['tabselected'] = $selected-1;
break;
}
}
} elseif($_POST['tabs_selected'] !== "") {
$adminPage['tabselected'] = intval($_POST['tabs_selected']);
}


// assign the contents to the template and display
$adminPage['formulizeModId'] = getFormulizeModId();
$xoopsTpl->assign('adminPage', $adminPage);
$xoopsTpl->assign('breadcrumbtrail', $breadcrumbtrail);
$xoopsTpl->assign('scrollx', intval($_POST['scrollx']));
$accordion_active = (isset($_POST['accordion_active']) AND $_POST['accordion_active'] !== "" AND $_POST['accordion_active'] !== "false") ? intval($_POST['accordion_active']) : "false";
$xoopsTpl->assign('accordion_active', $accordion_active);
$xoopsTpl->display("db:admin/ui.html");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is where it dynamically generates the markup from php.

Then within the markup it directs the save.php at formulize/ instead of /admin

4 changes: 4 additions & 0 deletions modules/formulize/class/elementrenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ function constructElement($form_ele_id, $ele_value, $entry, $isDisabled=false, $
}
}
$ele_value[0] = $this->formulize_replaceCurlyBracketVariables($ele_value[0], $entry, $id_form);

include_once XOOPS_ROOT_PATH."/modules/formulize/include/formdisplay.php";
$ele_value[0] .= formulize_themeForm::addFrontsideEditButton($form_ele_id);
$form_ele = $ele_value; // an array, item 0 is the contents of the break, item 1 is the class of the table cell (for when the form is table rendered)
break;
case 'text':
Expand Down Expand Up @@ -255,6 +258,7 @@ function constructElement($form_ele_id, $ele_value, $entry, $isDisabled=false, $
$ele_caption,
$ele_value[0]
);
$form_ele->setName($form_ele_id);
break;

case 'select':
Expand Down
69 changes: 65 additions & 4 deletions modules/formulize/include/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@

// NEED TO USE OUR OWN VERSION OF THE CLASS, TO GET ELEMENT NAMES IN THE TR TAGS FOR EACH ROW
class formulize_themeForm extends XoopsThemeForm {

var $form_id = "";

/**
* Insert an empty row in the table to serve as a seperator.
*
Expand Down Expand Up @@ -79,12 +82,31 @@ public function render() {
. "' method='" . $this->getMethod()
. "' onsubmit='return xoopsFormValidate_" . $ele_name . "();'" . $this->getExtra() . ">
<div class='xo-theme-form'>
<head>
<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js\"></script>
<script type=\"text/javascript\" src=\"../../plugins/slidepanel/js/jquery.slidepanel.js\"></script>
<link rel=\"stylesheet\" type=\"text/css\" href=\"../../plugins/slidepanel/css/jquery.slidepanel.css\">
</head>
<table width='100%' class='outer' cellspacing='1'>
<tr><th colspan='2'>" . $this->getTitle() . "</th></tr>
";
$hidden = '';
list($ret, $hidden) = $this->_drawElements($this->getElements(), $ret, $hidden);
$ret .= "</table>\n$hidden\n</div>\n</form>\n";
$ret .= '
<html lang="en">
<script type="text/javascript">
$(document).ready(function(){
$("[data-slidepanel]").slidepanel({
orientation: "right",
mode: "push"
});
});
</script>

</body>
</html>
';
$ret .= $this->renderValidationJS(true);
return $ret;
}
Expand Down Expand Up @@ -128,7 +150,21 @@ function _drawElements($elements, $ret, $hidden) {
if (($desc = $ele->getDescription()) != '') {
$ret .= "<div class='xoops-form-element-help'>{$desc}</div>";
}
$ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
$ret .= "</td><td class='$class'>" . $ele->render();
$element_name = trim($ele->getName());
//print "name: ".$element_name.'<br />';
switch ($element_name) {
case 'control_buttons':
case 'proxyuser':
// Do nothing
break;
default:
include_once XOOPS_ROOT_PATH."/modules/formulize/include/formdisplay.php";
$ret .= formulize_themeForm::addFrontsideEditButton($element_name);
break;
}

$ret .= "</td></tr>\n";
} else {
$hidden .= $ele->render();
}
Expand Down Expand Up @@ -159,6 +195,29 @@ function _drawValidationJS($skipConditionalCheck) {

return $fullJs;
}

function addFrontsideEditButton ($thisEleName) {
global $xoopsUser;
$groups = $xoopsUser ? $xoopsUser->getGroups() : array(0=>XOOPS_GROUP_ANONYMOUS);
$uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
$mid = getFormulizeModId();
$gperm_handler = xoops_gethandler('groupperm');
$isAdmin = $gperm_handler->checkRight("edit_form", $this->form_id, $groups, $mid);

if (!$isAdmin) {
return;
}

$editButton = 'edit_' . $thisEleName;
//$returnButton = '<a href="../../plugins/slidepanel/external.html" data-slidepanel="panel"><input type="button" class="formulize_adminEditButton" name="editx" id="' . $editButton . '" value="Edit" onclick="javascript:adminEdit(' . $thisEleName . ');"></a>';
//$returnButton = '<a href="../../modules/formulize/templates/admin/ui.html" data-slidepanel="panel"><input type="button" class="formulize_adminEditButton" name="editx" id="' . $editButton . '" value="Edit" onclick="javascript:adminEdit(' . $thisEleName . ');"></a>';
$returnButton = '<a href="../../modules/formulize/admin/admin_editor.php?' . 'ele_name=' . $thisEleName . '" data-slidepanel="panel"><input type="button" class="formulize_adminEditButton" name="editx" id="' . $editButton . '" value="Edit"></a>';

//$returnButton = '<a href="../../modules/formulize/admin/ui.php?ele_id=1&aid=0&page=element" data-slidepanel="panel"><input type="button" class="formulize_adminEditButton" name="editx" id="' . $editButton . '" value="Edit"></a>';


return $returnButton;
}

}

Expand Down Expand Up @@ -718,6 +777,7 @@ function displayForm($formframe, $entry="", $mainform="", $done_dest="", $button
// necessary to trigger the proper reloading of the form page, until Done is called and that form does not have this flag.
$form->addElement (new XoopsFormHidden ('ventry', $settings['ventry']));
}
$form->form_id = $this_fid;
$form->setExtra("enctype='multipart/form-data'"); // impératif!

if(is_array($settings)) {
Expand Down Expand Up @@ -1138,7 +1198,7 @@ function addSubmitButton($form, $subButtonText, $go_back="", $currentURL, $butto

$currentPage = "";
$screenid = "";
if($screen) {
if($screen) {
$screenid = $screen->getVar('sid');
// check for a current page setting
if(isset($settings['formulize_currentPage'])) {
Expand Down Expand Up @@ -1168,6 +1228,7 @@ function addSubmitButton($form, $subButtonText, $go_back="", $currentURL, $butto

$trayElements = $buttontray->getElements();
if(count($trayElements) > 0 OR $nosubforms) {
$buttontray->setName("control_buttons");
$form->addElement($buttontray);
}
return $form;
Expand Down Expand Up @@ -1355,9 +1416,9 @@ function drawSubLinks($subform_id, $sub_entries, $uid, $groups, $frid, $mid, $fi
// get the title of this subform
// help text removed for F4.0 RC2, this is an experiment
$subtitle = q("SELECT desc_form FROM " . $xoopsDB->prefix("formulize_id") . " WHERE id_form = $subform_id");
$col_one = "<p id=\"subform-caption-f$fid-sf$subform_id\" class=\"subform-caption\"><b>" . trans($subtitle[0]['desc_form']) . "</b></p>"; // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
$col_one = "<p class=\"subform-caption\"><b>" . trans($subtitle[0]['desc_form']) . "</b></p>"; // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
} else {
$col_one = "<p id=\"subform-caption-f$fid-sf$subform_id\" class=\"subform-caption\"><b>" . trans($customCaption) . "</b></p>"; // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
$col_one = "<p class=\"subform-caption\"><b>" . trans($customCaption) . "</b></p>"; // <p style=\"font-weight: normal;\">" . _formulize_ADD_HELP;
}

/*if(intval($sub_entries[$subform_id][0]) != 0 OR $sub_entry_new OR is_array($sub_entry_written)) {
Expand Down
25 changes: 24 additions & 1 deletion modules/formulize/libraries/formulize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// formulize.js
//

if (typeof xoopsGetElementById != 'function') {
// the 'xoopsGetElementById' function is included with xoops, so when it is missing, Formulize is embedded in another CMS
Expand All @@ -25,3 +24,27 @@ jQuery(document).ready(function() {
formulizechanged = 1;
});
});

function adminEdit(thisElement) {
var editButtons = document.getElementsByClassName('formulize_adminEditButton');
//console.log(editButtons);
/*
for (var i = 0; i<editButtons.length; i++) {
editButtons[i].hidden = 'true';
}
*/
//console.log(editButtons);

var url_link = '../formulize/admin/renderhtml.php?ele_name=';
url_link = url_link.concat(thisElement.name);

$.ajax({
url: url_link,
dataType: 'json',
success: function(data){
// No need to return anything
}
});

}

2 changes: 1 addition & 1 deletion modules/formulize/templates/admin/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h1><{$adminPage.pagetitle}></h1>

function sendFormData(thisformdata, ele_id) {
if(!ele_id) { ele_id = 0 }
$.post("save.php?ele_id="+ele_id, $(thisformdata).serialize(), function(data) {
$.post("<{$xoops_url}>/save.php?ele_id="+ele_id, $(thisformdata).serialize(), function(data) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing this line, when re-testing on browser, it continues to generate the following page source:

function sendFormData(thisformdata, ele_id) {
if(!ele_id) { ele_id = 0 }
$.post("save.php?ele_id="+ele_id, $(thisformdata).serialize(), function(data) {

-already cleared all cache, but still persists.

saveCounter = saveCounter + 1;
if(data) {
if(data.substr(0,10)=="/* eval */") {
Expand Down
Loading