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();
|
||||||
@ -4503,25 +4503,17 @@ class Form
|
|||||||
* @param string $htmlname Name of html select area
|
* @param string $htmlname Name of html select area
|
||||||
* @param string $url Url
|
* @param string $url Url
|
||||||
* @param string $id Preselected key
|
* @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 string $moreparam Add more parameters onto the select tag
|
||||||
* @param int $translate Translate and encode value
|
* @param string $moreparamtourl Add more parameters onto the Ajax called URL
|
||||||
* @param int $maxlen Length maximum for labels
|
|
||||||
* @param int $disabled Html select box is disabled
|
* @param int $disabled Html select box is disabled
|
||||||
* @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort
|
* @param int $minimumInputLength Minimum Input Length
|
||||||
* @param string $morecss Add more class to css styles
|
* @param string $morecss Add more class to css styles
|
||||||
* @param int $addjscombo Add js combo
|
|
||||||
* @return string HTML select string.
|
* @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 = '';
|
$out = '';
|
||||||
|
|
||||||
// Add code for jquery to use select2
|
|
||||||
if ($addjscombo && empty($conf->dol_use_jmobile))
|
|
||||||
{
|
|
||||||
$tmpplugin='select2';
|
$tmpplugin='select2';
|
||||||
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -4532,37 +4524,46 @@ class Form
|
|||||||
url: "'.$url.'",
|
url: "'.$url.'",
|
||||||
dataType: \'json\',
|
dataType: \'json\',
|
||||||
delay: 250,
|
delay: 250,
|
||||||
data: function (params) {
|
data: function (searchTerm, pageNumber, context) {
|
||||||
return {
|
return {
|
||||||
q: params.term, // search term
|
q: searchTerm, // search term
|
||||||
page: params.page
|
page: pageNumber
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
processResults: function (data, page) {
|
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.
|
// parse the results into the format expected by Select2.
|
||||||
// since we are using custom formatting functions we do not need to
|
// since we are using custom formatting functions we do not need to
|
||||||
// alter the remote JSON data
|
// alter the remote JSON data
|
||||||
|
console.log(data);
|
||||||
return {
|
return {
|
||||||
results: data.items
|
results: data.items
|
||||||
};
|
};
|
||||||
},
|
},*/
|
||||||
cache: true
|
cache: true
|
||||||
},
|
},
|
||||||
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
||||||
minimumInputLength: 0,
|
minimumInputLength: '.$minimumInputLength.',
|
||||||
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||||
//templateSelection: formatRepoSelection // 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>';
|
</script>';
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO get all values from $url into $array
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$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;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -748,3 +748,4 @@ ShortSaturday=S
|
|||||||
ShortSunday=S
|
ShortSunday=S
|
||||||
SelectMailModel=Select email template
|
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";
|
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);
|
$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";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test4: a select
|
// Test4a: a select
|
||||||
print "Test 4a: a select<br>\n";
|
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.');
|
$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;
|
$selected=3;
|
||||||
@ -73,20 +64,29 @@ print $form->selectarray('selectarray',$array);
|
|||||||
|
|
||||||
print '<br><br>'."\n";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test4d: form->select_thirdparty
|
print "Test 4d: a select with ajax refresh<br>\n";
|
||||||
print "Test 4d: Select thirdparty<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 $form->select_company(0,'thirdpartytest');
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test4e: form->select_product
|
// Test5b: form->select_product
|
||||||
print "Test 4e: Select product (using ajax)<br>\n";
|
print "Test 5b: Select product (using ajax)<br>\n";
|
||||||
$form->select_produits(0,'producttest');
|
$form->select_produits(0,'producttest');
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test5: a multiselect
|
// Test5c: a multiselect
|
||||||
print "Test 5: a multiselect<br>\n";
|
print "Test 5c: a multiselect<br>\n";
|
||||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
||||||
$arrayselected=array(1,3);
|
$arrayselected=array(1,3);
|
||||||
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);
|
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user