1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Chnages to make batch processing common code reusable - moved setting up of drop down list to form handler, made JavaScript unobtrusive

First stab at a datepicker function for form handler - very basic
Some tidying up in download plugin
This commit is contained in:
bugrain
2009-08-14 23:22:38 +00:00
parent 0527a8a02a
commit 3816e3ba55
7 changed files with 162 additions and 123 deletions

View File

@@ -10,9 +10,9 @@
* Administration Area - Users
*
* $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $
* $Revision: 1.51 $
* $Date: 2009-08-10 15:34:28 $
* $Author: e107coders $
* $Revision: 1.52 $
* $Date: 2009-08-14 23:22:36 $
* $Author: bugrain $
*
*/
require_once ('../class2.php');
@@ -1111,40 +1111,30 @@ class users
function show_batch_options()
{
$text = "<span class='f-left' style='padding-left:15px'><img src='".e_IMAGE."generic/branchbottom.gif' alt='' />
<select class='tbox' name='execute_batch' onchange='this.form.submit()'>
<option value=''>With selected...</option>
<option value='ban_selected'>".USRLAN_30."</option>
<option value='unban_selected'>".USRLAN_33."</option>
<option value='activate_selected'>".USRLAN_32."</option>
<option value='delete_selected'>".LAN_DELETE."</option>
<optgroup label='Assign Userclass..'>
";
$frm = new e_form();
$classes = get_userclass_list();
$assignClasses = array(); // Userclass list of userclasses that can be assigned
foreach ($classes as $key => $val)
{
if ($key < 240 && $key!=0)
{
$text .= "<option value='userclass_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n";
$assignClasses[$key] = $classes[$key];
}
}
$text .= "
</optgroup>
<optgroup label='Remove Userclass..'>
";
foreach ($classes as $key => $val)
{
if ($key < 240 && $key!=0)
{
$text .= "<option value='remuserclass_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n";
}
}
$text .= "<option value='userclass_selected_0'>".USRLAN_220."</option>
</optgroup>
</select></span><span class='clear'>&nbsp;</span>";
return $text;
$removeClasses = $assignClasses; // Userclass list of userclasses that can be removed
$removeClasses[0] = array('userclass_name'=>array('userclass_id'=>0, 'userclass_name'=>USRLAN_220));
return $frm->batchoptions(
array(
'ban_selected' =>USRLAN_30,
'unban_selected' =>USRLAN_33,
'activate_selected' =>USRLAN_32,
'delete_selected' =>LAN_DELETE
),
array(
'userclass' =>array('Assign Userclass...',$assignClasses),
'remuserclass' =>array('Remove Userclass..', $removeClasses)
)
);
}
@@ -1755,15 +1745,28 @@ class users
function user_remuserclass($userid,$uclass)
{
global $sql,$sql2;
$eu = new e_userclass;
if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1"))
$emessage = &eMessage::getInstance();
if ($uclass[0] == 0)
{
$row = $sql->db_Fetch();
$eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class']));
if($sql->db_Update("user","user_class='' WHERE user_id={$userid}")===TRUE)
{
$emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated;
}
else
{
$emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated;
}
}
else
{
$eu = new e_userclass;
if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1"))
{
$row = $sql->db_Fetch();
$eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class']));
}
$emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated;
}
$emessage = &eMessage::getInstance();
$emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated;
}
// Set userclass for user(s).

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_files/e_css.php,v $
| $Revision: 1.1 $
| $Date: 2009-08-06 22:41:35 $
| $Revision: 1.2 $
| $Date: 2009-08-14 23:22:36 $
| $Author: bugrain $
+---------------------------------------------------------------+
*/
@@ -45,7 +45,8 @@ echo "
display: block;
}
a.e-hide-if-js,
span.e-hide-if-js {
span.e-hide-if-js,
button.e-hide-if-js {
display: inline;
}
</style>

View File

@@ -8,9 +8,9 @@
* e107 Javascript API
*
* $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $
* $Revision: 1.33 $
* $Date: 2009-07-21 10:27:26 $
* $Author: secretr $
* $Revision: 1.34 $
* $Date: 2009-08-14 23:22:36 $
* $Author: bugrain $
*
*/
@@ -873,6 +873,21 @@ Object.extend(e107Helper, {
});
},
/**
*
*
*/
executeBatch: function(event) {
var element = event.memo['element'] ? $(event.memo.element) : $$('body')[0];
Element.select(element, 'select.e-execute-batch').invoke('observe', 'change', function(e) {
var frm = e.element().up('form');
if (frm) {
frm.submit();
e.stop();
}
});
},
/**
* added as Element method below
*/
@@ -1158,7 +1173,7 @@ e107Helper.BB = {
if (!this.__selectedInputArea) {
return; //[SecretR] TODO - alert the user
}
var eField = this.__selectedInputArea,
var eField = this.__selectedInputArea,
tags = this.parse(text, emote),
scrollPos, sel, newStart;
if(this.insertIE(eField, text, tags)) return;
@@ -2670,6 +2685,6 @@ function sendInfo(handler, container, form) {
/*
* Core Auto-load
*/
$w('autoExternalLinks autoNoHistory autoHide toggleObserver toggleManyObserver scrollToObserver').each( function(f) {
$w('autoExternalLinks autoNoHistory autoHide toggleObserver toggleManyObserver scrollToObserver executeBatch').each( function(f) {
e107.runOnLoad(e107Helper[f], null, true);
});

View File

@@ -9,9 +9,9 @@
* Form Handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
* $Revision: 1.37 $
* $Date: 2009-07-21 16:05:10 $
* $Author: e107coders $
* $Revision: 1.38 $
* $Date: 2009-08-14 23:22:37 $
* $Author: bugrain $
*
*/
@@ -65,7 +65,7 @@ class e_form
var $_tabindex_counter = 0;
var $_tabindex_enabled = true;
var $_cached_attributes = array();
/**
* @var user_class
*/
@@ -108,6 +108,35 @@ class e_form
return $ret;
}
/**
* Date field with popup calendar
* @param name => string - the name of the field
* @param datestamp => UNIX timestamp - default value of the field
**/
function datepicker($name, $datestamp=false)
{
global $pref;
//TODO can some of these values be set in an admin section somewhere so they are set per site?
//TODO allow time option ?
$cal = new DHTML_Calendar(true);
$cal_options['showsTime'] = false;
$cal_options['showOthers'] = false;
$cal_options['weekNumbers'] = false;
//TODO use $prefs values for format?
$cal_options['ifFormat'] = $pref['inputdate'];
$cal_options['timeFormat'] = "24";
$cal_attrib['class'] = "tbox";
$cal_attrib['size'] = "12";
$cal_attrib['name'] = $name;
if ($datestamp)
{
//TODO use $prefs values for format?
$cal_attrib['value'] = date("d/m/Y H:i:s", $datestamp);
$cal_attrib['value'] = date("d/m/Y", $datestamp);
}
return $cal->make_input_field($cal_options, $cal_attrib);
}
function file($name, $options = array())
{
$options = $this->format_options('file', $name, $options);
@@ -260,7 +289,7 @@ class e_form
{
if($classnum == e_UC_BLANK)
return $this->option('&nbsp;', '');
$tmp = explode(',', $current_value);
if($nest_level == 0)
{
@@ -277,7 +306,7 @@ class e_form
$prefix = '&nbsp;&nbsp;'.str_repeat('--', $nest_level - 1).'&gt;';
$style = '';
}
return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), "style={$style}")."\n";
return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), array("style"=>"{$style}"))."\n";
}
function optgroup_open($label, $disabled)
@@ -492,7 +521,7 @@ class e_form
}
/**
* Get default options array based on the filed type
* Get default options array based on the field type
*
* @param string $type
* @return array default options
@@ -580,10 +609,10 @@ class e_form
function columnSelector($columnsArray,$columnsDefault='',$id='column_options')
{
$text = "<div style='position:relative;float:right;'>
<a href='#".$id."' class='e-expandit' style='height:16px' title='Click to select columns to display'>
<a href='#".$id."' class='e-show-if-js e-expandit' title='Click to select columns to display'>
<img class='middle' src='".e_IMAGE_ABS."admin_images/select_columns_16.png' alt='select columns' /></a>
<div id='".$id."' class='e-hideme col-selection'>\n";
<div id='".$id."' class='e-show-if-js e-hideme col-selection'>\n";
unset($columnsArray['options']);
foreach($columnsArray as $key=>$fld)
@@ -732,6 +761,48 @@ class e_form
}
// This needs to be dynamic for the various form types, and be loaded via ajax.
}
/**
* Generates a batch options select component
* This component is generally associated with a table of items where one or more rows in the table can be selected (using checkboxes).
* The list options determine some processing that wil lbe applied to all checked rows when the form is submitted.
* @param options => array - associative array of option elements, keyed on the option value
* @param ucOptions => array - associative array of userclass option groups to display, keyed on the option value prefix
* @return the HTML for the form component
*/
function batchoptions($options, $ucOptions=null) {
$text = "
<div class='f-left'>
<img src='".e_IMAGE."generic/branchbottom.gif' alt='' class='TODO' />
<select class='tbox e-execute-batch' name='execute_batch'>
<option value=''>With selected...</option>";
foreach ($options as $key => $val)
{
$text .= "<option value='".$key."'>".$val."</option>";
}
if ($ucOptions)
{
foreach ($ucOptions as $ucKey => $ucVal)
{
$text .= "<optgroup label='".$ucVal[0]."'>";
foreach ($ucVal[1] as $key => $val)
{
$text .= "<option value='".$ucKey."_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n";
}
$text .= "</optgroup>";
}
}
$text .= "
</select>
<button class='update e-hide-if-js' type='submit'><span>Go</span></button>
</div>
<span class='clear'>&nbsp;</span>";
return $text;
}
}
class form {

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $
| $Revision: 1.10 $
| $Date: 2009-08-06 22:36:17 $
| $Revision: 1.11 $
| $Date: 2009-08-14 23:22:37 $
| $Author: bugrain $
+----------------------------------------------------------------------------+
*/
@@ -834,12 +834,5 @@ function admin_download_adminmenu($parms)
$var['mirror']['text'] = DOWLAN_128;
$var['mirror']['link'] = e_SELF."?mirror";
e_admin_menu(DOWLAN_32, $action, $var);
unset($var);
if ($action == "" || $action == "main") {
$var['1']['text'] = "//TODO";
$var['1']['link'] = "";
e_admin_menu(DOWLAN_184, $subAction, $var);
}
}
?>

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $
| $Revision: 1.15 $
| $Date: 2009-08-06 22:41:34 $
| $Revision: 1.16 $
| $Date: 2009-08-14 23:22:37 $
| $Author: bugrain $
|
+----------------------------------------------------------------------------+
@@ -60,30 +60,6 @@ class adminDownload extends download
// Search field
$text .= "
<script type='text/javascript'>
e107.runOnLoad(function(){
var el = $('download-search-text');
el.e107PreviousValue = el.getValue();
el.observe('keyup', function(e) {
var el = e.element();
e.stop();
if (el.getValue() != el.e107PreviousValue) {
if (el.e107Timeout) {
window.clearTimeout(el.e107Timeout);
}
el.e107PreviousValue = el.getValue();
el.e107Timeout = window.setTimeout(function () {
new e107Ajax.Updater('downloads-list', '{$url}', {
method: 'post',
parameters: { //send query parameters here
'download_filter_list': 1,
'download-search-text': el.getValue()
},
overlayPage: $(document.body)
});
}, 500);
}
});
}, document, false);
</script>
<form method='post' action='".e_SELF."' class='e-show-if-js'>
<div id='download_search'>
@@ -456,7 +432,7 @@ class adminDownload extends download
{
$parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]";
$text .= "<div class='buttons-bar center nextprev'>".$this->batch_options().
$tp->parseTemplate("{NEXTPREV={$parms}}")."</div>";
$tp->parseTemplate("{NEXTPREV={$parms}}")."</div>";
}
$text .= "</form></fieldset>";
@@ -465,37 +441,17 @@ class adminDownload extends download
}
// ---------------------------------------------------------------------------
function batch_options()
function batch_options()
{
$text = "<span class='f-left' style='padding-left:15px'><img src='".e_IMAGE."generic/branchbottom.gif' alt='' />
<select class='tbox' name='execute_batch' onchange='this.form.submit()'>
<option value=''>With selected...</option>";
$text .= "<option value='delete_selected'>".LAN_DELETE."</option>";
$text .= "
<optgroup label='Assign Userclass..'>
";
$classes = get_userclass_list();
foreach ($classes as $key => $val)
{
$text .= "<option value='userclass_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n";
}
$text .= "
</optgroup>
<optgroup label='Assign Visibility..'>
";
$classes = get_userclass_list();
foreach ($classes as $key => $val)
{
$text .= "<option value='visibility_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n";
}
$text .= "
</optgroup>
</select></span><span class='clear'>&nbsp;</span>";
return $text;
$frm = new e_form();
$classes = get_userclass_list();
return $frm->batchoptions(
array('delete_selected'=>LAN_DELETE),
array(
'userclass' =>array('Assign userclass...',$classes),
'visibility'=>array('Assign Visibility..',$classes)
)
);
}

View File

@@ -4,8 +4,8 @@
| e107 website system - Language File.
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/download/languages/English/admin_download.php,v $
| $Revision: 1.6 $
| $Date: 2009-07-18 19:04:04 $
| $Revision: 1.7 $
| $Date: 2009-08-14 23:22:38 $
| $Author: bugrain $
+----------------------------------------------------------------------------+
*/
@@ -185,7 +185,7 @@ define("DOWLAN_180", "File size (database/disk)");
define("DOWLAN_181", "Not readable");
define("DOWLAN_182", "Timestamp");
define("DOWLAN_183", "Advanced search");
define("DOWLAN_184", "Batch options");
define("DOWLAN_184", "");
define("DOWLAN_185", "Files referenced multiple times in the database");
define("DOWLAN_186", "Files not referenced in the database");
define("DOWLAN_187", "Database entries referencing non-existent files");