1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 13:47:31 +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 * Administration Area - Users
* *
* $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $ * $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $
* $Revision: 1.51 $ * $Revision: 1.52 $
* $Date: 2009-08-10 15:34:28 $ * $Date: 2009-08-14 23:22:36 $
* $Author: e107coders $ * $Author: bugrain $
* *
*/ */
require_once ('../class2.php'); require_once ('../class2.php');
@@ -1111,40 +1111,30 @@ class users
function show_batch_options() function show_batch_options()
{ {
$frm = new e_form();
$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..'>
";
$classes = get_userclass_list(); $classes = get_userclass_list();
$assignClasses = array(); // Userclass list of userclasses that can be assigned
foreach ($classes as $key => $val) foreach ($classes as $key => $val)
{ {
if ($key < 240 && $key!=0) 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 .= " $removeClasses = $assignClasses; // Userclass list of userclasses that can be removed
</optgroup> $removeClasses[0] = array('userclass_name'=>array('userclass_id'=>0, 'userclass_name'=>USRLAN_220));
<optgroup label='Remove Userclass..'> return $frm->batchoptions(
"; array(
foreach ($classes as $key => $val) 'ban_selected' =>USRLAN_30,
{ 'unban_selected' =>USRLAN_33,
if ($key < 240 && $key!=0) 'activate_selected' =>USRLAN_32,
{ 'delete_selected' =>LAN_DELETE
$text .= "<option value='remuserclass_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n"; ),
} array(
} 'userclass' =>array('Assign Userclass...',$assignClasses),
'remuserclass' =>array('Remove Userclass..', $removeClasses)
$text .= "<option value='userclass_selected_0'>".USRLAN_220."</option> )
</optgroup> );
</select></span><span class='clear'>&nbsp;</span>";
return $text;
} }
@@ -1755,16 +1745,29 @@ class users
function user_remuserclass($userid,$uclass) function user_remuserclass($userid,$uclass)
{ {
global $sql,$sql2; global $sql,$sql2;
$emessage = &eMessage::getInstance();
if ($uclass[0] == 0)
{
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; $eu = new e_userclass;
if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1")) if($sql->db_Select("user","user_id,user_class","user_id={$userid} LIMIT 1"))
{ {
$row = $sql->db_Fetch(); $row = $sql->db_Fetch();
$eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class'])); $eu->class_remove($uclass[0], array($row['user_id']=>$row['user_class']));
} }
$emessage = &eMessage::getInstance();
$emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated; $emessage->add(UCSLAN_9, E_MESSAGE_SUCCESS); // classes updated;
} }
}
// Set userclass for user(s). // Set userclass for user(s).
function user_userclass($userid,$uclass,$append=FALSE) function user_userclass($userid,$uclass,$append=FALSE)

View File

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

View File

@@ -8,9 +8,9 @@
* e107 Javascript API * e107 Javascript API
* *
* $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $ * $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $
* $Revision: 1.33 $ * $Revision: 1.34 $
* $Date: 2009-07-21 10:27:26 $ * $Date: 2009-08-14 23:22:36 $
* $Author: secretr $ * $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 * added as Element method below
*/ */
@@ -2670,6 +2685,6 @@ function sendInfo(handler, container, form) {
/* /*
* Core Auto-load * 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); e107.runOnLoad(e107Helper[f], null, true);
}); });

View File

@@ -9,9 +9,9 @@
* Form Handler * Form Handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
* $Revision: 1.37 $ * $Revision: 1.38 $
* $Date: 2009-07-21 16:05:10 $ * $Date: 2009-08-14 23:22:37 $
* $Author: e107coders $ * $Author: bugrain $
* *
*/ */
@@ -108,6 +108,35 @@ class e_form
return $ret; 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()) function file($name, $options = array())
{ {
$options = $this->format_options('file', $name, $options); $options = $this->format_options('file', $name, $options);
@@ -277,7 +306,7 @@ class e_form
$prefix = '&nbsp;&nbsp;'.str_repeat('--', $nest_level - 1).'&gt;'; $prefix = '&nbsp;&nbsp;'.str_repeat('--', $nest_level - 1).'&gt;';
$style = ''; $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) 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 * @param string $type
* @return array default options * @return array default options
@@ -580,10 +609,10 @@ class e_form
function columnSelector($columnsArray,$columnsDefault='',$id='column_options') function columnSelector($columnsArray,$columnsDefault='',$id='column_options')
{ {
$text = "<div style='position:relative;float:right;'> $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> <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']); unset($columnsArray['options']);
foreach($columnsArray as $key=>$fld) 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. // 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 { class form {

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $
| $Revision: 1.10 $ | $Revision: 1.11 $
| $Date: 2009-08-06 22:36:17 $ | $Date: 2009-08-14 23:22:37 $
| $Author: bugrain $ | $Author: bugrain $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -834,12 +834,5 @@ function admin_download_adminmenu($parms)
$var['mirror']['text'] = DOWLAN_128; $var['mirror']['text'] = DOWLAN_128;
$var['mirror']['link'] = e_SELF."?mirror"; $var['mirror']['link'] = e_SELF."?mirror";
e_admin_menu(DOWLAN_32, $action, $var); 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). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $
| $Revision: 1.15 $ | $Revision: 1.16 $
| $Date: 2009-08-06 22:41:34 $ | $Date: 2009-08-14 23:22:37 $
| $Author: bugrain $ | $Author: bugrain $
| |
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
@@ -60,30 +60,6 @@ class adminDownload extends download
// Search field // Search field
$text .= " $text .= "
<script type='text/javascript'> <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> </script>
<form method='post' action='".e_SELF."' class='e-show-if-js'> <form method='post' action='".e_SELF."' class='e-show-if-js'>
<div id='download_search'> <div id='download_search'>
@@ -467,35 +443,15 @@ 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='' /> $frm = new e_form();
<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(); $classes = get_userclass_list();
foreach ($classes as $key => $val) return $frm->batchoptions(
{ array('delete_selected'=>LAN_DELETE),
$text .= "<option value='userclass_selected_".$val['userclass_name']['userclass_id']."'>".$val['userclass_name']['userclass_name']."</option>\n"; array(
} 'userclass' =>array('Assign userclass...',$classes),
$text .= " 'visibility'=>array('Assign Visibility..',$classes)
</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;
} }

View File

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