AJAX work on create/update

This commit is contained in:
Deon George 2010-03-13 20:45:40 +11:00
parent f713afc8d1
commit 2e8e9625d6
10 changed files with 160 additions and 30 deletions

View File

@ -107,6 +107,9 @@ if (count($ldap['attrs']['need']) > 0) {
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=objectclass', $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=objectclass',
$app['server']->getIndex(),rawurlencode($request['dn'])); $app['server']->getIndex(),rawurlencode($request['dn']));
if (get_request('meth','REQUEST') == 'ajax')
$href .= '&meth=ajax';
header(sprintf('Location: %s',$href)); header(sprintf('Location: %s',$href));
die(); die();
} }

View File

@ -32,7 +32,7 @@ if ($request['attribute']->isReadOnly())
*/ */
# Render the form # Render the form
if (get_request('meth','REQUEST') != 'ajax') { if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST') != 'ajax') {
# Render the form. # Render the form.
$request['page']->drawTitle(sprintf('%s <b>%s</b> %s <b>%s</b>',_('Add new'),$request['attr'],_('value to'),get_rdn($request['dn']))); $request['page']->drawTitle(sprintf('%s <b>%s</b> %s <b>%s</b>',_('Add new'),$request['attr'],_('value to'),get_rdn($request['dn'])));
$request['page']->drawSubTitle(); $request['page']->drawSubTitle();
@ -113,7 +113,9 @@ if (get_request('meth','REQUEST') != 'ajax') {
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>';
echo '<br />'; echo '<br />';
printf('<input id="save_button" type="submit" value="%s" />',_('Add new ObjectClass')); printf('<input id="save_button" type="submit" value="%s" %s />',
_('Add new ObjectClass'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'entry_form\'),\'%s\');"',_('Updating Object')) : ''));
echo '</td></tr></table>'; echo '</td></tr></table>';
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';

View File

@ -60,7 +60,7 @@ if (count($request['template']->getLDAPadd(true))) {
echo '</div>'; echo '</div>';
echo "\n\n"; echo "\n\n";
echo '<form action="cmd.php" method="post">'; echo '<form action="cmd.php" method="post" id="create_form">';
echo '<div>'; echo '<div>';
echo '<input type="hidden" name="cmd" value="create" />'; echo '<input type="hidden" name="cmd" value="create" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
@ -111,19 +111,32 @@ if (count($request['template']->getLDAPadd(true))) {
echo '<div style="text-align: center;">'; echo '<div style="text-align: center;">';
echo '<br />'; echo '<br />';
printf('<input type="submit" value="%s" />',_('Commit'));
printf('<input type="submit" name="cancel" value="%s" />',_('Cancel')); printf('<input type="submit" value="%s" %s/>',
_('Commit'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'create_form\'),\'%s\');"',_('Updating Object')) : ''));
printf('<input type="submit" name="cancel" value="%s" %s/>',
_('Cancel'),
(isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&container=%s\',\'%s\');"',$app['server']->getIndex(),$request['template']->getContainer(),_('Retrieving DN')) : ''));
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
echo '<br />'; echo '<br />';
} else { } else {
echo '<div style="text-align: center;">'; $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',
echo _('You made no changes');
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',
$app['server']->getIndex(),rawurlencode($request['dn'])); $app['server']->getIndex(),rawurlencode($request['dn']));
printf(' <a href="%s">%s</a>.',htmlspecialchars($href),_('Go back')); echo '<div style="text-align: center;">';
echo _('You made no changes');
if (isAjaxEnabled())
printf(' <a href="cmd.php?%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');">%s</a>.',
htmlspecialchars($href),htmlspecialchars($href),_('Retrieving DN'),_('Go back'));
else
printf(' <a href="cmd.php?%s">%s</a>.',htmlspecialchars($href),_('Go back'));
echo '</div>'; echo '</div>';
} }
?> ?>

View File

@ -67,11 +67,14 @@ if (count($request['children'])) {
echo '<tr>'; echo '<tr>';
echo '<td style="width: 50%; text-align: center;">'; echo '<td style="width: 50%; text-align: center;">';
echo '<form action="cmd.php" method="post">'; echo '<form action="cmd.php" method="post" id="delete_form">';
echo '<input type="hidden" name="cmd" value="rdelete" />'; echo '<input type="hidden" name="cmd" value="rdelete" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn'])); printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
printf('<input type="submit" value="%s" />',sprintf(_('Delete all %s objects'),count($request['search']))); //@todo need to refresh the tree after a delete
printf('<input type="submit" value="%s" %s />',
sprintf(_('Delete all %s objects'),count($request['search'])),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'delete_form\'),\'%s\');"',_('Deleting Object(s)')) : ''));
echo '</form>'; echo '</form>';
echo '</td>'; echo '</td>';
@ -80,7 +83,9 @@ if (count($request['children'])) {
echo '<input type="hidden" name="cmd" value="template_engine" />'; echo '<input type="hidden" name="cmd" value="template_engine" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn'])); printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
printf('<input type="submit" name="submit" value="%s" />',_('Cancel')); printf('<input type="submit" name="submit" value="%s" %s />',
_('Cancel'),
(isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&dn=%s\',\'%s\');"',$app['server']->getIndex(),htmlspecialchars($request['dn']),_('Retrieving DN')) : ''));
echo '</form>'; echo '</form>';
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
@ -114,11 +119,14 @@ if (count($request['children'])) {
echo '<tr>'; echo '<tr>';
echo '<td colspan="2" style="width: 50%; text-align: center;">'; echo '<td colspan="2" style="width: 50%; text-align: center;">';
echo '<form action="cmd.php" method="post">'; echo '<form action="cmd.php" method="post" id="delete_form">';
echo '<input type="hidden" name="cmd" value="delete" />'; echo '<input type="hidden" name="cmd" value="delete" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn'])); printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
printf('<input type="submit" name="submit" value="%s" />',_('Delete')); //@todo need to refresh the tree after a delete
printf('<input type="submit" name="submit" value="%s" %s />',
_('Delete'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'delete_form\'),\'%s\');"',_('Deleting Object(s)')) : ''));
echo '</form>'; echo '</form>';
echo '</td>'; echo '</td>';
@ -128,7 +136,9 @@ if (count($request['children'])) {
echo '<input type="hidden" name="cmd" value="template_engine" />'; echo '<input type="hidden" name="cmd" value="template_engine" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn'])); printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
printf('<input type="submit" name="submit" value="%s" />',_('Cancel')); printf('<input type="submit" name="submit" value="%s" %s />',
_('Cancel'),
(isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&dn=%s\',\'%s\');"',$app['server']->getIndex(),htmlspecialchars($request['dn']),_('Retrieving DN')) : ''));
echo '</form>'; echo '</form>';
echo '</td>'; echo '</td>';

View File

@ -10,9 +10,27 @@ var http_request = null;
var http_request_success_callback = ''; var http_request_success_callback = '';
var http_request_error_callback = ''; var http_request_error_callback = '';
function ajDISPLAY(div,urlParameters,display) { function ajSUBMIT(div,obj,display) {
var pageDiv = getDiv(div); var pageDiv = getDiv(div);
window.scrollTo(0,95);
if (pageDiv)
includeHTML(pageDiv,'<img src="images/ajax-progress.gif"><br><small>'+display+'...</small>');
else
return true;
makeHttpRequest('cmd.php',getParameters(obj.parentNode)+'meth=ajax','POST','alertAJ','cancelAJ',div);
return false;
}
function ajDISPLAY(div,urlParameters,display,ns) {
var pageDiv = getDiv(div);
if (! ns)
window.scrollTo(0,95);
if (pageDiv) if (pageDiv)
includeHTML(pageDiv,'<img src="images/ajax-progress.gif"><br><small>'+display+'...</small>'); includeHTML(pageDiv,'<img src="images/ajax-progress.gif"><br><small>'+display+'...</small>');
else else
@ -190,3 +208,46 @@ function makeHttpRequest(url,parameters,meth,successCallbackFunctionName,errorCa
if (meth == 'GET') parameters = null; if (meth == 'GET') parameters = null;
http_request.send(parameters); http_request.send(parameters);
} }
function getParameters(obj) {
var elements = ['input','select','textarea'];
var getstr = '';
for (var j in elements) {
for (i=0; i<obj.getElementsByTagName(elements[j]).length; i++) {
// Ignore submit variables
if (obj.getElementsByTagName(elements[j])[i].type == 'submit') {
} else if (obj.getElementsByTagName(elements[j])[i].type == 'text') {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=' + encodeURIComponent(obj.getElementsByTagName(elements[j])[i].value) + '&';
} else if (obj.getElementsByTagName(elements[j])[i].type == 'checkbox') {
if (obj.getElementsByTagName(elements[j])[i].checked) {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=' + encodeURIComponent(obj.getElementsByTagName(elements[j])[i].value) + '&';
} else {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=&';
}
} else if (obj.getElementsByTagName(elements[j])[i].type == 'radio') {
if (obj.getElementsByTagName(elements[j])[i].checked) {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=' + encodeURIComponent(obj.getElementsByTagName(elements[j])[i].value) + '&';
}
} else if (obj.getElementsByTagName(elements[j])[i].tagName == 'SELECT') {
var sel = obj.getElementsByTagName(elements[j])[i];
getstr += sel.name + '=' + encodeURIComponent(sel.options[sel.selectedIndex].value) + '&';
} else if (obj.getElementsByTagName(elements[j])[i].tagName == 'INPUT') {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=' + encodeURIComponent(obj.getElementsByTagName(elements[j])[i].value) + '&';
} else if (obj.getElementsByTagName(elements[j])[i].tagName == 'TEXTAREA') {
getstr += obj.getElementsByTagName(elements[j])[i].name + '=' + encodeURIComponent(obj.getElementsByTagName(elements[j])[i].value) + '&';
} else {
alert('UNTRAPPED FORM tag:'+elements[j]+', n: '+obj.getElementsByTagName(elements[j])[i].tagName+', t:'+obj.getElementsByTagName(elements[j])[i].type);
}
}
}
return getstr;
}

View File

@ -69,6 +69,9 @@ if ($result) {
foreach ($request['template']->getLDAPmodify() as $attr => $junk) foreach ($request['template']->getLDAPmodify() as $attr => $junk)
$redirect_url .= sprintf('&modified_attrs[]=%s',$attr); $redirect_url .= sprintf('&modified_attrs[]=%s',$attr);
if (get_request('meth','REQUEST') == 'ajax')
$redirect_url .= '&meth=ajax';
header("Location: $redirect_url"); header("Location: $redirect_url");
die(); die();
} }

View File

@ -38,7 +38,7 @@ if (count($request['template']->getLDAPmodify(true))) {
echo '</div>'; echo '</div>';
echo "\n\n"; echo "\n\n";
echo '<form action="cmd.php" method="post">'; echo '<form action="cmd.php" method="post" id="update_form">';
echo '<div>'; echo '<div>';
echo '<input type="hidden" name="cmd" value="update" />'; echo '<input type="hidden" name="cmd" value="update" />';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex()); printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
@ -187,14 +187,20 @@ if (count($request['template']->getLDAPmodify(true))) {
echo '<div style="text-align: center;">'; echo '<div style="text-align: center;">';
echo '<br />'; echo '<br />';
printf('<input type="submit" value="%s" />',_('Commit')); printf('<input type="submit" value="%s" %s/>',
printf('<input type="submit" name="cancel" value="%s" />',_('Cancel')); _('Commit'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'update_form\'),\'%s\');"',_('Updating Object')) : ''));
printf('<input type="submit" name="cancel" value="%s" %s/>',
_('Cancel'),
(isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&dn=%s\',\'%s\');"',htmlspecialchars($request['dn']),_('Retrieving DN')) : ''));
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
echo '<br />'; echo '<br />';
if (count($request['template']->getForceDeleteAttrs()) > 0) { if (count($request['template']->getForceDeleteAttrs()) > 0) {
echo '<table class="result_table"><tr>'; echo '<table class="result_table" style="margin-left: auto; margin-right: auto;"><tr>';
printf('<td class="heading">%s:</td>',_('The deletion of objectClass(es)')); printf('<td class="heading">%s:</td>',_('The deletion of objectClass(es)'));
printf('<td class="value"><b>%s</b></td>',implode('</b>, <b>',$request['template']->getAttribute('objectclass')->getRemovedValues())); printf('<td class="value"><b>%s</b></td>',implode('</b>, <b>',$request['template']->getAttribute('objectclass')->getRemovedValues()));
echo '</tr><tr>'; echo '</tr><tr>';
@ -212,12 +218,18 @@ if (count($request['template']->getLDAPmodify(true))) {
} }
} else { } else {
echo '<div style="text-align: center;">'; $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',
echo _('You made no changes');
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',
$app['server']->getIndex(),rawurlencode($request['dn'])); $app['server']->getIndex(),rawurlencode($request['dn']));
printf(' <a href="%s">%s</a>.',htmlspecialchars($href),_('Go back')); echo '<div style="text-align: center;">';
echo _('You made no changes');
if (isAjaxEnabled())
printf(' <a href="cmd.php?%s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');">%s</a>.',
htmlspecialchars($href),htmlspecialchars($href),_('Retrieving DN'),_('Go back'));
else
printf(' <a href="cmd.php?%s">%s</a>.',htmlspecialchars($href),_('Go back'));
echo '</div>'; echo '</div>';
} }

View File

@ -343,7 +343,7 @@ class Template extends xmlTemplate {
continue; continue;
# If _REQUEST['skip_array'] with this attr set, we'll ignore this new_value # If _REQUEST['skip_array'] with this attr set, we'll ignore this new_value
if (isset($_REQUEST['skip_array'][$attr])) if (isset($_REQUEST['skip_array'][$attr]) && $_REQUEST['skip_array'][$attr] == 'on')
continue; continue;
# Prune out entries with a blank value. # Prune out entries with a blank value.

View File

@ -1408,7 +1408,10 @@ class TemplateRender extends PageRender {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
if (! $this->template->isReadOnly()) if (! $this->template->isReadOnly())
printf('<tr><td colspan="2" style="text-align: center;"><input type="submit" id="create_button" name="submit" value="%s" /></td></tr>',_('Update Object')); printf('<tr><td colspan="2" style="text-align: center;"><input type="submit" id="create_button" name="submit" value="%s" %s/></td></tr>',
_('Update Object'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'entry_form\'),\'%s\');"',_('Updating DN')) : ''),
_('Update Object'));
} }
/** STEP FORM METHODS **/ /** STEP FORM METHODS **/
@ -1504,7 +1507,9 @@ class TemplateRender extends PageRender {
if ($page < $this->pagelast) if ($page < $this->pagelast)
printf('<td>&nbsp;</td><td><input type="submit" id="create_button" value="%s" /></td>',_('Proceed &gt;&gt;')); printf('<td>&nbsp;</td><td><input type="submit" id="create_button" value="%s" /></td>',_('Proceed &gt;&gt;'));
else else
printf('<td style="text-align: center;"><input type="submit" id="create_button" name="submit" value="%s" /></td>',_('Create Object')); printf('<td style="text-align: center;"><input type="submit" id="create_button" name="submit" value="%s" %s /></td>',
_('Create Object'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'entry_form\'),\'%s\');"',_('Creating Object')) : ''));
echo '</tr>'; echo '</tr>';
} }
@ -2012,7 +2017,7 @@ function fillRec(id,value) {
$this->getServerID(),rawurlencode($this->template->getDN()),rawurlencode($attribute->getName(false)))); $this->getServerID(),rawurlencode($this->template->getDN()),rawurlencode($attribute->getName(false))));
if (isAjaxEnabled()) if (isAjaxEnabled())
return sprintf('(<a href="cmd.php?%s" title="%s %s" onclick="return ajDISPLAY(\'ADDVALUE%s\',\'%s&amp;raw=1\',\'%s\');">%s</a>)', return sprintf('(<a href="cmd.php?%s" title="%s %s" onclick="return ajDISPLAY(\'ADDVALUE%s\',\'%s&amp;raw=1\',\'%s\',1);">%s</a>)',
$href_parm,_('Add an additional value to attribute'),$attribute->getName(false),$attribute->getName(), $href_parm,_('Add an additional value to attribute'),$attribute->getName(false),$attribute->getName(),
$href_parm,_('Add Value to Attribute'),_('add value')); $href_parm,_('Add Value to Attribute'),_('add value'));
else else
@ -2020,6 +2025,24 @@ function fillRec(id,value) {
$href_parm,_('Add an additional value to attribute'),$attribute->getName(false),_('add value')); $href_parm,_('Add an additional value to attribute'),$attribute->getName(false),_('add value'));
} }
protected function getAddValueMenuItemObjectClassAttribute($attribute) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$href_parm = htmlspecialchars(sprintf('cmd=add_value_form&server_id=%s&dn=%s&attr=%s',
$this->getServerID(),rawurlencode($this->template->getDN()),rawurlencode($attribute->getName(false))));
if (isAjaxEnabled())
return sprintf('(<a href="cmd.php?%s" title="%s %s" onclick="return ajDISPLAY(\'BODY\',\'%s\',\'%s\');">%s</a>)',
$href_parm,_('Add an additional value to attribute'),$attribute->getName(false),
$href_parm,_('Add Value to Attribute'),_('add value'));
else
return sprintf('(<a href="cmd.php?%s" title="%s %s">%s</a>)',
$href_parm,_('Add an additional value to attribute'),$attribute->getName(false),_('add value'));
}
protected function getModifyMemberMenuItemAttribute($attribute) { protected function getModifyMemberMenuItemAttribute($attribute) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);

View File

@ -107,8 +107,11 @@ class page {
printf('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); printf('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
if (isset($_SESSION[APPCONFIG])) if (isset($_SESSION[APPCONFIG]))
printf('<title>%s (%s) - %s</title>', printf('<title>%s (%s) - %s%s</title>',
$this->_app['title'],app_version(),$_SESSION[APPCONFIG]->getValue('appearance','page_title')); $this->_app['title'],
app_version(),
(get_request('dn','REQUEST') ? htmlspecialchars(get_request('dn','REQUEST')).' ' : ''),
$_SESSION[APPCONFIG]->getValue('appearance','page_title'));
else else
printf('<title>%s - %s</title>',$this->_app['title'],app_version()); printf('<title>%s - %s</title>',$this->_app['title'],app_version());