-
Notifications
You must be signed in to change notification settings - Fork 14
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
user can rearrange the elements of a form from the form screen #50
base: master
Are you sure you want to change the base?
Changes from all commits
b3f4231
83f37f2
8cf1b6c
38151db
fd122f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
############################################################################### | ||
## Formulize - ad hoc form creation and reporting module for XOOPS ## | ||
## Copyright (c) 2010 Freeform Solutions ## | ||
############################################################################### | ||
## This program is free software; you can redistribute it and/or modify ## | ||
## it under the terms of the GNU General Public License as published by ## | ||
## the Free Software Foundation; either version 2 of the License, or ## | ||
## (at your option) any later version. ## | ||
## ## | ||
## You may not change or alter any portion of this comment or credits ## | ||
## of supporting developers from this source code or any supporting ## | ||
## source code which is considered copyrighted (c) material of the ## | ||
## original comment or credit authors. ## | ||
## ## | ||
## This program is distributed in the hope that it will be useful, ## | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of ## | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## | ||
## GNU General Public License for more details. ## | ||
## ## | ||
## You should have received a copy of the GNU General Public License ## | ||
## along with this program; if not, write to the Free Software ## | ||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## | ||
############################################################################### | ||
## Author of this file: Freeform Solutions ## | ||
## URL: http://www.freeformsolutions.ca/formulize ## | ||
## Project: Formulize ## | ||
############################################################################### | ||
|
||
// This file will re order elements from the entry screen | ||
|
||
include_once "../../../mainfile.php"; | ||
ob_end_clean(); | ||
ob_end_clean(); // in some cases there appears to be two buffers active?! So we must try to end twice. | ||
global $xoopsUser; | ||
global $xoopsDB; | ||
|
||
if(!$xoopsUser) { | ||
print "Error: you are not logged in"; | ||
return; | ||
} | ||
$gperm_handler = xoops_gethandler('groupperm'); | ||
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php"; | ||
include_once XOOPS_ROOT_PATH ."/modules/formulize/class/forms.php"; | ||
$groups = $xoopsUser->getGroups(); | ||
$mid = getFormulizeModId(); | ||
$permissionToCheck = "module_admin"; | ||
$itemToCheck = $mid; | ||
$moduleToCheck = 1; // system module | ||
if(!$gperm_handler->checkRight($permissionToCheck, $itemToCheck, $groups, $moduleToCheck)) { | ||
print "Error: you do not have permission to save this data"; | ||
return; | ||
} | ||
|
||
|
||
$formulizeForm = new formulizeForm(); | ||
|
||
//error_log($_POST["ele_id"]." ".$_POST["ele_order"]); | ||
$return=$formulizeForm->reorderElements($_POST["ele_id"],$_POST["ele_order"]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ | |
|
||
//THIS FILE HANDLES THE DISPLAY OF FORMS. FUNCTIONS CAN BE CALLED FROM ANYWHERE (INTENDED FOR PAGEWORKS MODULE) | ||
|
||
global $xoopsDB, $xoopsUser; | ||
|
||
|
||
|
||
global $xoopsConfig; | ||
// load the formulize language constants if they haven't been loaded already | ||
if ( file_exists(XOOPS_ROOT_PATH."/modules/formulize/language/".$xoopsConfig['language']."/main.php") ) { | ||
|
@@ -46,6 +50,7 @@ | |
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; | ||
include_once XOOPS_ROOT_PATH . "/include/functions.php"; | ||
|
||
|
||
// 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 { | ||
/** | ||
|
@@ -72,6 +77,15 @@ public function insertBreakFormulize($extra = '', $class= '', $name, $element_ha | |
* @return string | ||
*/ | ||
public function render() { | ||
|
||
global $xoopsUser, $gperm_handler; | ||
//Check if user is an admin | ||
$groups = $xoopsUser->getGroups(); | ||
$mid = getFormulizeModId(); | ||
$permissionToCheck = "module_admin"; | ||
$itemToCheck = $mid; | ||
$moduleToCheck = 1; // system module | ||
$isAdmin=$gperm_handler->checkRight($permissionToCheck, $itemToCheck, $groups, $moduleToCheck); | ||
$ele_name = $this->getName(); | ||
$ret = "<form id='" . $ele_name | ||
. "' name='" . $ele_name | ||
|
@@ -85,6 +99,60 @@ public function render() { | |
$hidden = ''; | ||
list($ret, $hidden) = $this->_drawElements($this->getElements(), $ret, $hidden); | ||
$ret .= "</table>\n$hidden\n</div>\n</form>\n"; | ||
#some javascript for updating the elements in the table | ||
#only allow the user to reorganize if user is an admin | ||
if($isAdmin){ | ||
$ret .= '<html lang="en"> | ||
|
||
<script type=\'text/javascript\'> | ||
|
||
var fixHelperModified = function(e, tr) { | ||
|
||
var $originals = tr.children(); | ||
var $helper = tr.clone(); | ||
$helper.children().each(function(index) { | ||
$(this).width($originals.eq(index).width()); | ||
}); | ||
return $helper; | ||
}, | ||
updateIndex = function(e, ui) { | ||
$(\'td.index\', ui.item.parent()).each(function (i) { | ||
$(this).html(i + 1); | ||
}); | ||
}; | ||
updateTable = function(){ | ||
var table = document.getElementById(\'entryTable\'); | ||
var rowLength = table.rows.length; | ||
for(var i=2; i<rowLength-2; i+=1){ | ||
var row = table.rows[i]; | ||
row.setAttribute("rowIndex",i-1); | ||
$.ajax( | ||
{ | ||
type:"POST", | ||
url:"admin/reorder_entry_elements.php", | ||
data:{"ele_id":row.getAttribute("rowId"),"ele_order":row.getAttribute("rowIndex")}, | ||
success:function(response){ | ||
} | ||
}); | ||
|
||
|
||
} | ||
}; | ||
|
||
$("#entryTable tbody").sortable({ | ||
|
||
items: \'tr:gt(2):lt(-2)\', | ||
helper: fixHelperModified, | ||
stop: updateIndex, | ||
update: updateTable | ||
}).disableSelection(); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> | ||
'; | ||
} | ||
$ret .= $this->renderValidationJS(true); | ||
return $ret; | ||
} | ||
|
@@ -103,7 +171,6 @@ public function renderValidationJS( $withtags = true, $skipConditionalCheck = fa | |
} | ||
return $js; | ||
} | ||
|
||
function _drawElements($elements, $ret, $hidden) { | ||
$class ='even'; | ||
|
||
|
@@ -166,6 +233,8 @@ function _drawElements($elements, $ret, $hidden) { | |
return array($ret, $hidden); | ||
} | ||
|
||
|
||
|
||
// need to check whether the element is a standard element, if if so, add the check for whether its row exists or not | ||
function _drawValidationJS($skipConditionalCheck) { | ||
$fullJs = ""; | ||
|
@@ -2790,9 +2859,14 @@ function drawJavascriptForConditionalElements($conditionalElements, $governingEl | |
|
||
print " | ||
<script type='text/javascript'> | ||
|
||
<src>//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css</scr> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
<src>//code.jquery.com/jquery-2.0.2.js</src> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you've commented out these lines, so they should be deleted entirely? |
||
<src>//code.jquery.com/ui/1.10.4/jquery-ui.js</src> | ||
var conditionalHTML = new Array(); // needs to be global! | ||
|
||
$(\"#entryTable tbody\").sortable().disableSelection(); | ||
$(\"#sort3\").sortable().disableSelection(); | ||
|
||
jQuery(window).load(function() { | ||
|
||
// preload the current state of the HTML for any conditional elements that are currently displayed, so we can compare against what we get back when their conditions change | ||
|
@@ -2955,6 +3029,7 @@ function ShowHideTableRow(rowSelector, show, speed, callback) | |
|
||
|
||
|
||
|
||
</script>"; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
<input type="hidden" name="reload_elements" value=""> | ||
<input type="hidden" name="aid" value="<{$content.aid}>"> | ||
<input type="hidden" name="elementorder" value=""> | ||
|
||
|
||
|
||
<div class="accordion-box"> | ||
<h2><{$smarty.const._AM_ELE_ADDINGTOFORM}></h2> | ||
<p><{$smarty.const._AM_ELE_CLICKTOADD}></p> | ||
|
@@ -110,7 +111,7 @@ <h2><{$smarty.const._AM_ELE_MANAGINGELEFORM}></h2> | |
}); | ||
|
||
$(".savebutton").click(function () { | ||
$("[name=elementorder]").val($("#accordion-2").sortable('serialize')); | ||
// $("[name=elementorder]").val($("#accordion-2").sortable('serialize')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be commented? |
||
}); | ||
|
||
$("#accordion-2").bind( "sortupdate", function(event, ui) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to see this code in action...but I wonder if we need some kind of check for whether the user is an admin? It appears as if this code will be present always, and anyone can drag the order of the elements? Ideally, we would want the draggable handles to be visible only when the mouse hovers on a row, the same as the "edit" link/button that is in Joseph's branch.