* [story#68579,doing,1.5h] add remote options for filter in preview.
This commit is contained in:
@@ -107,4 +107,68 @@ class pivot extends control
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noletter');
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: 获取系统数据下拉选项。
|
||||
* AJAX: get sys options.
|
||||
*
|
||||
* @param int $pivotID
|
||||
* @param string $field
|
||||
* @param string $saveAs
|
||||
* @param string $values
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetSysOptions(int|string $pivotID, string $field = '', string $saveAs = '', string $values = '', string $search = '', int $limit = 100)
|
||||
{
|
||||
if(!empty($field))
|
||||
{
|
||||
$pivot = $this->pivot->getByID($pivotID);
|
||||
$fieldSetting = $pivot->fieldSettings->$field;
|
||||
$options = $this->pivot->getSysOptions($fieldSetting->type, $fieldSetting->object, $fieldSetting->field, $pivot->sql, $saveAs);
|
||||
}
|
||||
else
|
||||
{
|
||||
$typeOption = $pivotID;
|
||||
$options = $this->pivot->getSysOptions($typeOption);
|
||||
}
|
||||
|
||||
/* 根据关键字过滤选项。*/
|
||||
/* Filter options by keywords. */
|
||||
$limitOptions = $options;
|
||||
if(!empty($search))
|
||||
{
|
||||
foreach($limitOptions as $key => $text)
|
||||
{
|
||||
if(strpos($text, $search) === false) unset($limitOptions[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/* 根据限制数量过滤选项。*/
|
||||
/* Filter options by limit. */
|
||||
$limitOptions = array_slice($limitOptions, 0, $limit, true);
|
||||
|
||||
/* 添加默认值到选项列表。*/
|
||||
/* Add default value to options. */
|
||||
if(!empty($values))
|
||||
{
|
||||
$values = explode(',', $values);
|
||||
foreach($values as $value)
|
||||
{
|
||||
if(!isset($limitOptions[$value])) $limitOptions[$value] = $options[$value];
|
||||
}
|
||||
}
|
||||
|
||||
/* 转换为value text格式。*/
|
||||
/* Convert to value text format. */
|
||||
$valueTextList = array();
|
||||
foreach($limitOptions as $value => $text)
|
||||
{
|
||||
$valueTextList[] = array('value' => $value, 'text' => $text);
|
||||
}
|
||||
|
||||
echo json_encode($valueTextList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,27 +23,23 @@ $fnGenerateFilters = function() use($pivot, $showOrigin, $lang)
|
||||
$options = array();
|
||||
foreach($pivot->filters as $filter)
|
||||
{
|
||||
$type = $filter['type'];
|
||||
$name = $filter['name'];
|
||||
$field = $filter['field'];
|
||||
$value = zget($filter, 'default', '');
|
||||
$from = zget($filter, 'from');
|
||||
$type = $filter['type'];
|
||||
$name = $filter['name'];
|
||||
$field = $filter['field'];
|
||||
$value = zget($filter, 'default', '');
|
||||
$from = zget($filter, 'from');
|
||||
$values = is_array($value) ? implode(',', $value) : $value;
|
||||
if($from == 'query')
|
||||
{
|
||||
$typeOption = $filter['typeOption'];
|
||||
if(strpos($type, 'select') !== false && !isset($options[$typeOption])) $options[$typeOption] = $this->pivot->getSysOptions($typeOption);
|
||||
|
||||
$filters[] = filter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => zget($options, $typeOption, array()), 'multiple' => $type == 'multipleselect' ? true : false)));
|
||||
$optionUrl = createLink('pivot', 'ajaxGetSysOptions', "typeOption=$typeOption&field=&saveAs=&values=$values&search={search}");
|
||||
$filters[] = filter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => $optionUrl, 'multiple' => $type == 'multipleselect' ? true : false)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if($type == 'select' && !isset($options[$field]))
|
||||
{
|
||||
$fieldSetting = $pivot->fieldSettings->$field;
|
||||
$options[$field] = $this->pivot->getSysOptions($fieldSetting->type, $fieldSetting->object, $fieldSetting->field, $pivot->sql, zget($filter, 'saveAs', ''));
|
||||
}
|
||||
|
||||
$filters[] = resultFilter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => zget($options, $field, array()))));
|
||||
$saveAs = zget($filter, 'saveAs', $field);
|
||||
$optionUrl = createLink('pivot', 'ajaxGetSysOptions', "pivotID=$pivot->id&field=$field&saveAs=$saveAs&values=$values&search={search}");
|
||||
$filters[] = resultFilter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => $optionUrl)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user