Work on a new widget
This commit is contained in:
parent
6318b12aeb
commit
06d19a5a40
48
htdocs/core/ajax/selectsearchbox.php
Normal file
48
htdocs/core/ajax/selectsearchbox.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/ajax/selectsearchbox.php
|
||||
* \ingroup core
|
||||
* \brief This script returns content of possible search
|
||||
*/
|
||||
|
||||
|
||||
// This script is called with a POST method.
|
||||
// Directory to scan (full path) is inside POST['dir'].
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
|
||||
$res=@include '../../main.inc.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
|
||||
|
||||
|
||||
$search_boxvalue=GETPOST('q');
|
||||
|
||||
$arrayresult=array('a'=>'aaaa', 'b'=>'bbbb');
|
||||
|
||||
if ($conf->projet->enabled)
|
||||
{
|
||||
$arrayresult['searchintoproject']=$langs->trans("SearchIntoProject", $search_boxvalue);
|
||||
}
|
||||
print dol_json_encode($arrayresult);
|
||||
|
||||
if (is_object($db)) $db->close();
|
||||
@ -4500,70 +4500,71 @@ class Form
|
||||
* Return a HTML select string, built from an array of key+value but content returned into select come from an Ajax call of an URL.
|
||||
* Note: Do not apply langs->trans function on returned content, content may be entity encoded twice.
|
||||
*
|
||||
* @param string $htmlname Name of html select area
|
||||
* @param string $url Url
|
||||
* @param string $id Preselected key
|
||||
* @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' ').
|
||||
* @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value"
|
||||
* @param int $value_as_key 1 to use value as key
|
||||
* @param string $moreparam Add more parameters onto the select tag
|
||||
* @param int $translate Translate and encode value
|
||||
* @param int $maxlen Length maximum for labels
|
||||
* @param int $disabled Html select box is disabled
|
||||
* @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort
|
||||
* @param string $morecss Add more class to css styles
|
||||
* @param int $addjscombo Add js combo
|
||||
* @return string HTML select string.
|
||||
* @param string $htmlname Name of html select area
|
||||
* @param string $url Url
|
||||
* @param string $id Preselected key
|
||||
* @param string $moreparam Add more parameters onto the select tag
|
||||
* @param string $moreparamtourl Add more parameters onto the Ajax called URL
|
||||
* @param int $disabled Html select box is disabled
|
||||
* @param int $minimumInputLength Minimum Input Length
|
||||
* @param string $morecss Add more class to css styles
|
||||
* @return string HTML select string.
|
||||
*/
|
||||
static function selectArrayAjax($htmlname, $url, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0)
|
||||
static function selectArrayAjax($htmlname, $url, $id='', $moreparam='', $moreparamtourl='', $disabled=0, $minimumInputLength=1, $morecss='')
|
||||
{
|
||||
$out = '';
|
||||
|
||||
// Add code for jquery to use select2
|
||||
if ($addjscombo && empty($conf->dol_use_jmobile))
|
||||
{
|
||||
$tmpplugin='select2';
|
||||
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$(".'.$htmlname.'").select2({
|
||||
ajax: {
|
||||
dir: "ltr",
|
||||
url: "'.$url.'",
|
||||
dataType: \'json\',
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
q: params.term, // search term
|
||||
page: params.page
|
||||
};
|
||||
},
|
||||
processResults: function (data, page) {
|
||||
// parse the results into the format expected by Select2.
|
||||
// since we are using custom formatting functions we do not need to
|
||||
// alter the remote JSON data
|
||||
return {
|
||||
results: data.items
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
||||
minimumInputLength: 0,
|
||||
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO get all values from $url into $array
|
||||
$tmpplugin='select2';
|
||||
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$(".'.$htmlname.'").select2({
|
||||
ajax: {
|
||||
dir: "ltr",
|
||||
url: "'.$url.'",
|
||||
dataType: \'json\',
|
||||
delay: 250,
|
||||
data: function (searchTerm, pageNumber, context) {
|
||||
return {
|
||||
q: searchTerm, // search term
|
||||
page: pageNumber
|
||||
};
|
||||
},
|
||||
results: function (remoteData, pageNumber, query) {
|
||||
console.log(remoteData);
|
||||
return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
|
||||
//return {results:[remoteData], more:false}
|
||||
},
|
||||
/*processResults: function (data, page) {
|
||||
// parse the results into the format expected by Select2.
|
||||
// since we are using custom formatting functions we do not need to
|
||||
// alter the remote JSON data
|
||||
console.log(data);
|
||||
return {
|
||||
results: data.items
|
||||
};
|
||||
},*/
|
||||
cache: true
|
||||
},
|
||||
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
||||
minimumInputLength: '.$minimumInputLength.',
|
||||
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
||||
});
|
||||
|
||||
$(".'.$htmlname.'").change(function() {
|
||||
alert(\'eee\');
|
||||
$(".'.$htmlname.'").select2.clearSearch();
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
</script>';
|
||||
|
||||
$out.=self::selectarray('.'.$htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, '', $translate, $maxlen, $disabled, $sort, '', 0);
|
||||
|
||||
$out.='<input type="text" class="'.$htmlname.($morecss?' '.$morecss:'').'" '.($moreparam?$moreparam.' ':'').'name="'.$htmlname.'">';
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
@ -747,4 +747,5 @@ ShortFriday=F
|
||||
ShortSaturday=S
|
||||
ShortSunday=S
|
||||
SelectMailModel=Select email template
|
||||
SetRef=Set ref
|
||||
SetRef=Set ref
|
||||
SearchIntoProject=Search %s into projects
|
||||
@ -45,18 +45,9 @@ print '<br><br>'."\n";
|
||||
print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)<br>\n";
|
||||
$form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0);
|
||||
|
||||
/*print '<br><br>'."\n";
|
||||
|
||||
print "Test 4c: a select with ajax refresh<br>\n";
|
||||
//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz');
|
||||
$array=array();
|
||||
$selected=-1;
|
||||
print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selecsearchbox.php', $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
||||
*/
|
||||
|
||||
print '<br><br>'."\n";
|
||||
|
||||
// Test4: a select
|
||||
// Test4a: a select
|
||||
print "Test 4a: a select<br>\n";
|
||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3 ith a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.');
|
||||
$selected=3;
|
||||
@ -73,20 +64,29 @@ print $form->selectarray('selectarray',$array);
|
||||
|
||||
print '<br><br>'."\n";
|
||||
|
||||
// Test4d: form->select_thirdparty
|
||||
print "Test 4d: Select thirdparty<br>\n";
|
||||
print "Test 4d: a select with ajax refresh<br>\n";
|
||||
//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz');
|
||||
$array=array();
|
||||
$selected=-1;
|
||||
print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, 'style="min-width: 250px;"', '', 0, 1, '');
|
||||
|
||||
|
||||
print '<br><br>'."\n";
|
||||
|
||||
// Test5a: form->select_thirdparty
|
||||
print "Test 5a: Select thirdparty<br>\n";
|
||||
print $form->select_company(0,'thirdpartytest');
|
||||
|
||||
print '<br><br>'."\n";
|
||||
|
||||
// Test4e: form->select_product
|
||||
print "Test 4e: Select product (using ajax)<br>\n";
|
||||
// Test5b: form->select_product
|
||||
print "Test 5b: Select product (using ajax)<br>\n";
|
||||
$form->select_produits(0,'producttest');
|
||||
|
||||
print '<br><br>'."\n";
|
||||
|
||||
// Test5: a multiselect
|
||||
print "Test 5: a multiselect<br>\n";
|
||||
// Test5c: a multiselect
|
||||
print "Test 5c: a multiselect<br>\n";
|
||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
||||
$arrayselected=array(1,3);
|
||||
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user