From 39e9b14cf61a0d485ed120248c599a81e48ad82f Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 5 Feb 2013 16:39:48 -0800 Subject: [PATCH] userpicker() functioning correctly with jquery --- e107_handlers/form_handler.php | 22 +++++++++++++++------- e107_plugins/pm/pm.php | 27 +++++++++++++++++++-------- e107_plugins/pm/pm_shortcodes.php | 1 + e107_web/js/core/all.jquery.js | 23 +++++++++++++++++++++++ user.php | 5 +++-- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index a90ccac61..c490c55f2 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -208,12 +208,11 @@ class e_form if(vartrue($options['typeahead'])) { - $options['data-provide'] ="typeahead"; if(vartrue($options['typeahead']) == 'users') { - $options['data-source'] = e_BASE."user.php"; - } - + $options['data-source'] = e_BASE."user.php"; + $options['class'] .= " e-typeahead"; + } } $options = $this->format_options('text', $name, $options); @@ -642,6 +641,14 @@ class e_form function userpicker($name_fld, $id_fld, $default_name, $default_id, $options = array()) { if(!is_array($options)) parse_str($options, $options); + + //TODO Auto-calculate $name_fld from $id_fld ie. append "_usersearch" here ? + + return $this->text($name_fld,$default_name,20, "typeahead=users&readonly=".vartrue($options['readonly'])) + .$this->hidden($id_fld,$default_id, array('id' => $this->name2id($id_fld)))." id# ".$default_id; + + + /* $label_fld = str_replace('_', '-', $name_fld).'-upicker-lable'; @@ -657,9 +664,9 @@ class e_form
'; - // FIXME - switch to external JS, jQuery support + e107::getJs()->requireCoreLib('scriptaculous/controls.js', 2); - //TODO - external JS + e107::getJs()->footerInline(" //autocomplete fields \$\$('input[name={$name_fld}]').each(function(el) { @@ -695,7 +702,7 @@ class e_form }); "); return $ret; - + */ } @@ -1045,6 +1052,7 @@ class e_form $name = (strpos($name, '[') === false) ? $name.'[]' : $name; if(!is_array($selected)) $selected = explode(",",$selected); } + $text = $this->select_open($name, $options)."\n"; if(isset($options['default'])) diff --git a/e107_plugins/pm/pm.php b/e107_plugins/pm/pm.php index e9f6844ec..819038877 100755 --- a/e107_plugins/pm/pm.php +++ b/e107_plugins/pm/pm.php @@ -137,7 +137,11 @@ class pm_extended extends private_message $tpl_file = THEME.'pm_template.php'; include_once(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); $enc = (check_class($this->pmPrefs['attach_class']) ? "enctype='multipart/form-data'" : ''); - setScVar('pm_handler_shortcodes','pmInfo', $pm_info); + // setScVar('pm_handler_shortcodes','pmInfo', $pm_info); + + $sc = e107::getScBatch('pm',TRUE); + $sc->setVars($pm_info); + $text = "
". $this->e107->tp->parseTemplate($PM_SEND_PM, TRUE). @@ -155,35 +159,39 @@ class pm_extended extends private_message function show_inbox($start = 0) { + $tp = e107::getParser(); + $tpl_file = THEME.'pm_template.php'; include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); + $pm_blocks = $this->block_get(); $pmlist = $this->pm_get_inbox(USERID, $start, $this->pmPrefs['perpage']); + // setScVar('pm_handler_shortcodes', 'pmNextPrev', array('start' => $start, 'total' => $pmlist['total_messages'])); $sc = e107::getScBatch('pm',TRUE); $sc->pmNextPrev = array('start' => $start, 'total' => $pmlist['total_messages']); $txt = ""; - $txt .= $this->e107->tp->parseTemplate($PM_INBOX_HEADER, true); + $txt .= $tp->parseTemplate($PM_INBOX_HEADER, true); + if($pmlist['total_messages']) { foreach($pmlist['messages'] as $rec) { if(trim($rec['pm_subject']) == '') { $rec['pm_subject'] = '['.LAN_PM_61.']'; } - // setScVar('pm_handler_shortcodes','pmInfo', $rec); $sc->setVars($rec); - - - $txt .= $this->e107->tp->parseTemplate($PM_INBOX_TABLE, true); + $txt .= $tp->parseTemplate($PM_INBOX_TABLE, true); } } else { - $txt .= $this->e107->tp->parseTemplate($PM_INBOX_EMPTY, true); + $txt .= $tp->parseTemplate($PM_INBOX_EMPTY, true); } - $txt .= $this->e107->tp->parseTemplate($PM_INBOX_FOOTER, true); + + $txt .= $tp->parseTemplate($PM_INBOX_FOOTER, true); $txt .= ""; + return $txt; } @@ -324,6 +332,9 @@ class pm_extended extends private_message */ function post_pm() { + print_a($_POST); + + if(!check_class($this->pmPrefs['pm_class'])) { return LAN_PM_12; diff --git a/e107_plugins/pm/pm_shortcodes.php b/e107_plugins/pm/pm_shortcodes.php index 5b3bd558a..c4ca02636 100755 --- a/e107_plugins/pm/pm_shortcodes.php +++ b/e107_plugins/pm/pm_shortcodes.php @@ -112,6 +112,7 @@ class pm_shortcodes extends e_shortcode else { $frm = e107::getForm(); + //TODO Use $frm->userpicker(); return $frm->text('pm_to','',10,'typeahead=users'); $ret = $us->select_form($type, 'pm_to', '', $this->pmPrefs['pm_class']); diff --git a/e107_web/js/core/all.jquery.js b/e107_web/js/core/all.jquery.js index 431fefee0..70a966d79 100644 --- a/e107_web/js/core/all.jquery.js +++ b/e107_web/js/core/all.jquery.js @@ -12,6 +12,29 @@ $(document).ready(function() $(".e-expandit").show(); // $(".e-spinner").spinner(); //FIXME breaks tooltips + + $('.e-typeahead').each(function() { + + var id = $(this).attr("id"); + var name = '#' + id.replace('-usersearch', ''); + var newval = $(this).attr("data-value"); + $(this).typeahead({ + source: $(this).attr("data-source"), + updater: function(text, type){ + if(type == 'value') + { + $(name).val(text); + } + return text; + } + }) + }); + + + + + + //check all $("#check-all").click(function(event){ diff --git a/user.php b/user.php index d6ad42897..4b321e21c 100644 --- a/user.php +++ b/user.php @@ -26,11 +26,12 @@ if(e_AJAX_REQUEST) if(vartrue($_GET['q'])) { $q = filter_var($_GET['q'], FILTER_SANITIZE_STRING); - if($sql->select("user", "user_name", "user_name LIKE '". $q."%' ORDER BY user_name LIMIT 15")) + if($sql->select("user", "user_id,user_name", "user_name LIKE '". $q."%' ORDER BY user_name LIMIT 15")) { while($row = $sql->db_Fetch()) { - $data[] = $row['user_name']; + $id = $row['user_id']; + $data[$id] = $row['user_name']; } if(count($data))