filters refactor
This commit is contained in:
@@ -210,8 +210,17 @@ class Base
|
||||
if (!empty($item['value'])) {
|
||||
$methodName = 'apply' . ucfirst($type);
|
||||
|
||||
if (method_exists($this, $methodName)) {;
|
||||
$this->$methodName($item['field'], $item['value'], $result);
|
||||
if (method_exists($this, $methodName)) {
|
||||
$attribute = null;
|
||||
if (isset($item['field'])) {
|
||||
$attribute = $item['field'];
|
||||
}
|
||||
if (isset($item['attribute'])) {
|
||||
$attribute = $item['attribute'];
|
||||
}
|
||||
if ($attribute) {
|
||||
$this->$methodName($attribute, $item['value'], $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -689,13 +698,20 @@ class Base
|
||||
protected function checkWhere($where)
|
||||
{
|
||||
foreach ($where as $w) {
|
||||
$attribute = null;
|
||||
if (isset($w['field'])) {
|
||||
$attribute = $w['field'];
|
||||
}
|
||||
if (isset($w['attribute'])) {
|
||||
$attribute = $w['attribute'];
|
||||
}
|
||||
if ($attribute) {
|
||||
if (isset($w['type']) && $w['type'] === 'linkedWith') {
|
||||
if (in_array($w['field'], $this->getAcl()->getScopeForbiddenFieldList($this->getEntityType()))) {
|
||||
if (in_array($attribute, $this->getAcl()->getScopeForbiddenFieldList($this->getEntityType()))) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
} else {
|
||||
if (in_array($w['field'], $this->getAcl()->getScopeForbiddenAttributeList($this->getEntityType()))) {
|
||||
if (in_array($attribute, $this->getAcl()->getScopeForbiddenAttributeList($this->getEntityType()))) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
@@ -728,7 +744,15 @@ class Base
|
||||
$value = null;
|
||||
$timeZone = 'UTC';
|
||||
|
||||
if (empty($item['field'])) {
|
||||
$attribute = null;
|
||||
if (isset($item['field'])) {
|
||||
$attribute = $item['field'];
|
||||
}
|
||||
if (isset($item['attribute'])) {
|
||||
$attribute = $item['attribute'];
|
||||
}
|
||||
|
||||
if (!$attribute) {
|
||||
return null;
|
||||
}
|
||||
if (empty($item['type'])) {
|
||||
@@ -741,14 +765,13 @@ class Base
|
||||
$timeZone = $item['timeZone'];
|
||||
}
|
||||
$type = $item['type'];
|
||||
$field = $item['field'];
|
||||
|
||||
if (empty($value) && in_array($type, array('on', 'before', 'after'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$where = array();
|
||||
$where['field'] = $field;
|
||||
$where['attribute'] = $attribute;
|
||||
|
||||
$dt = new \DateTime('now', new \DateTimeZone($timeZone));
|
||||
|
||||
@@ -875,8 +898,16 @@ class Base
|
||||
{
|
||||
$part = array();
|
||||
|
||||
if (!empty($item['field']) && !empty($item['type'])) {
|
||||
$methodName = 'getWherePart' . ucfirst($item['field']) . ucfirst($item['type']);
|
||||
$attribute = null;
|
||||
if (!empty($item['field'])) { // for backward compatibility
|
||||
$attribute = $item['field'];
|
||||
}
|
||||
if (!empty($item['attribute'])) {
|
||||
$attribute = $item['attribute'];
|
||||
}
|
||||
|
||||
if (!empty($attribute) && !empty($item['type'])) {
|
||||
$methodName = 'getWherePart' . ucfirst($attribute) . ucfirst($item['type']);
|
||||
if (method_exists($this, $methodName)) {
|
||||
$value = null;
|
||||
if (!empty($item['value'])) {
|
||||
@@ -909,74 +940,74 @@ class Base
|
||||
}
|
||||
break;
|
||||
case 'like':
|
||||
$part[$item['field'] . '*'] = $item['value'];
|
||||
$part[$attribute . '*'] = $item['value'];
|
||||
break;
|
||||
case 'equals':
|
||||
case 'on':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
$part[$attribute . '='] = $item['value'];
|
||||
break;
|
||||
case 'startsWith':
|
||||
$part[$item['field'] . '*'] = $item['value'] . '%';
|
||||
$part[$attribute . '*'] = $item['value'] . '%';
|
||||
break;
|
||||
case 'endsWith':
|
||||
$part[$item['field'] . '*'] = '%' . $item['value'];
|
||||
$part[$attribute . '*'] = '%' . $item['value'];
|
||||
break;
|
||||
case 'contains':
|
||||
$part[$item['field'] . '*'] = '%' . $item['value'] . '%';
|
||||
$part[$attribute . '*'] = '%' . $item['value'] . '%';
|
||||
break;
|
||||
case 'notEquals':
|
||||
case 'notOn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
$part[$attribute . '!='] = $item['value'];
|
||||
break;
|
||||
case 'greaterThan':
|
||||
case 'after':
|
||||
$part[$item['field'] . '>'] = $item['value'];
|
||||
$part[$attribute . '>'] = $item['value'];
|
||||
break;
|
||||
case 'lessThan':
|
||||
case 'before':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
$part[$attribute . '<'] = $item['value'];
|
||||
break;
|
||||
case 'greaterThanOrEquals':
|
||||
$part[$item['field'] . '>='] = $item['value'];
|
||||
$part[$attribute . '>='] = $item['value'];
|
||||
break;
|
||||
case 'lessThanOrEquals':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
$part[$attribute . '<'] = $item['value'];
|
||||
break;
|
||||
case 'in':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
$part[$attribute . '='] = $item['value'];
|
||||
break;
|
||||
case 'notIn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
$part[$attribute . '!='] = $item['value'];
|
||||
break;
|
||||
case 'isNull':
|
||||
$part[$item['field'] . '='] = null;
|
||||
$part[$attribute . '='] = null;
|
||||
break;
|
||||
case 'isNotNull':
|
||||
case 'ever':
|
||||
$part[$item['field'] . '!='] = null;
|
||||
$part[$attribute . '!='] = null;
|
||||
break;
|
||||
case 'isTrue':
|
||||
$part[$item['field'] . '='] = true;
|
||||
$part[$attribute . '='] = true;
|
||||
break;
|
||||
case 'isFalse':
|
||||
$part[$item['field'] . '='] = false;
|
||||
$part[$attribute . '='] = false;
|
||||
break;
|
||||
case 'today':
|
||||
$part[$item['field'] . '='] = date('Y-m-d');
|
||||
$part[$attribute . '='] = date('Y-m-d');
|
||||
break;
|
||||
case 'past':
|
||||
$part[$item['field'] . '<'] = date('Y-m-d');
|
||||
$part[$attribute . '<'] = date('Y-m-d');
|
||||
break;
|
||||
case 'future':
|
||||
$part[$item['field'] . '>='] = date('Y-m-d');
|
||||
$part[$attribute . '>='] = date('Y-m-d');
|
||||
break;
|
||||
case 'lastSevenDays':
|
||||
$dt1 = new \DateTime();
|
||||
$dt2 = clone $dt1;
|
||||
$dt2->modify('-7 days');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt2->format('Y-m-d'),
|
||||
$item['field'] . '<=' => $dt1->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt2->format('Y-m-d'),
|
||||
$attribute . '<=' => $dt1->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastXDays':
|
||||
@@ -986,8 +1017,8 @@ class Base
|
||||
|
||||
$dt2->modify('-'.$number.' days');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt2->format('Y-m-d'),
|
||||
$item['field'] . '<=' => $dt1->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt2->format('Y-m-d'),
|
||||
$attribute . '<=' => $dt1->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'nextXDays':
|
||||
@@ -996,22 +1027,22 @@ class Base
|
||||
$number = strval(intval($item['value']));
|
||||
$dt2->modify('+'.$number.' days');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt1->format('Y-m-d'),
|
||||
$item['field'] . '<=' => $dt2->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt1->format('Y-m-d'),
|
||||
$attribute . '<=' => $dt2->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of this month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->modify('first day of this month')->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of last month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->modify('first day of last month')->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentQuarter':
|
||||
@@ -1019,8 +1050,8 @@ class Base
|
||||
$quarter = ceil($dt->format('m') / 3);
|
||||
$dt->modify('first day of January this year');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastQuarter':
|
||||
@@ -1033,29 +1064,29 @@ class Base
|
||||
$dt->sub('P1Y');
|
||||
}
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
$attribute . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'),
|
||||
$attribute . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'between':
|
||||
if (is_array($item['value'])) {
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $item['value'][0],
|
||||
$item['field'] . '<=' => $item['value'][1],
|
||||
$attribute . '>=' => $item['value'][0],
|
||||
$attribute . '<=' => $item['value'][1],
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -87,7 +87,7 @@ class Meeting extends \Espo\Core\SelectManagers\Base
|
||||
{
|
||||
$result['whereClause'][] = $this->convertDateTimeWhere(array(
|
||||
'type' => 'today',
|
||||
'field' => 'dateStart',
|
||||
'attribute' => 'dateStart',
|
||||
'timeZone' => $this->getUserTimeZone()
|
||||
));
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ class Task extends \Espo\Core\SelectManagers\Base
|
||||
'OR' => array(
|
||||
$this->convertDateTimeWhere(array(
|
||||
'type' => 'past',
|
||||
'field' => 'dateStart',
|
||||
'attribute' => 'dateStart',
|
||||
'timeZone' => $this->getUserTimeZone()
|
||||
)),
|
||||
$this->convertDateTimeWhere(array(
|
||||
'type' => 'today',
|
||||
'field' => 'dateStart',
|
||||
'attribute' => 'dateStart',
|
||||
'timeZone' => $this->getUserTimeZone()
|
||||
))
|
||||
)
|
||||
@@ -91,7 +91,7 @@ class Task extends \Espo\Core\SelectManagers\Base
|
||||
$result['whereClause'][] = [
|
||||
$this->convertDateTimeWhere(array(
|
||||
'type' => 'past',
|
||||
'field' => 'dateEnd',
|
||||
'attribute' => 'dateEnd',
|
||||
'timeZone' => $this->getUserTimeZone()
|
||||
)),
|
||||
[
|
||||
@@ -106,7 +106,7 @@ class Task extends \Espo\Core\SelectManagers\Base
|
||||
{
|
||||
$result['whereClause'][] = $this->convertDateTimeWhere(array(
|
||||
'type' => 'today',
|
||||
'field' => 'dateEnd',
|
||||
'attribute' => 'dateEnd',
|
||||
'timeZone' => $this->getUserTimeZone()
|
||||
));
|
||||
}
|
||||
@@ -118,16 +118,22 @@ class Task extends \Espo\Core\SelectManagers\Base
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
$field = $item['field'];
|
||||
$attribute = null;
|
||||
if (!empty($item['field'])) { // for backward compatibility
|
||||
$attribute = $item['field'];
|
||||
}
|
||||
if (!empty($item['attribute'])) {
|
||||
$attribute = $item['attribute'];
|
||||
}
|
||||
|
||||
if ($field != 'dateStart' && $field != 'dateEnd') {
|
||||
if ($attribute != 'dateStart' && $attribute != 'dateEnd') {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$fieldDate = $field . 'Date';
|
||||
$attributeDate = $attribute . 'Date';
|
||||
|
||||
$dateItem = array(
|
||||
'field' => $fieldDate,
|
||||
'attribute' => $attributeDate,
|
||||
'type' => $item['type']
|
||||
);
|
||||
if (!empty($item['value'])) {
|
||||
@@ -138,7 +144,7 @@ class Task extends \Espo\Core\SelectManagers\Base
|
||||
'OR' => array(
|
||||
'AND' => [
|
||||
$result,
|
||||
$fieldDate . '=' => null
|
||||
$attributeDate . '=' => null
|
||||
],
|
||||
$this->getWherePart($dateItem)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
<select class="form-control search-type input-sm" name="{{name}}-type">
|
||||
{{options searchData.typeOptions searchType field='dateSearchRanges'}}
|
||||
{{options searchTypeList searchType field='dateSearchRanges'}}
|
||||
</select>
|
||||
<div class="input-group primary">
|
||||
<input class="main-element form-control input-sm" type="text" name="{{name}}" value="{{searchData.dateValue}}" autocomplete="off">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
<select class="form-control search-type input-sm" name="{{name}}-type">
|
||||
{{options searchData.typeOptions searchType field='intSearchRanges'}}
|
||||
{{options searchTypeList searchType field='intSearchRanges'}}
|
||||
</select>
|
||||
<input type="text" class="form-control input-sm hidden" name="{{name}}" value="{{searchParams.value1}}" pattern="[\-]?[0-9]*" {{#if params.maxLength}} maxlength="{{params.maxLength}}"{{/if}} placeholder="{{translate 'Value'}}">
|
||||
<input type="text" class="form-control{{#ifNotEqual searchParams.type 'between'}} hidden{{/ifNotEqual}} additional input-sm" name="{{name}}-additional" value="{{searchParams.value2}}" pattern="[\-]?[0-9]*" {{#if params.maxLength}} maxlength="{{params.maxLength}}"{{/if}} placeholder="{{translate 'Value'}}">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<select class="form-control search-type input-sm" name="{{name}}-type">
|
||||
{{options searchData.typeOptions searchParams.typeFront field='searchRanges'}}
|
||||
{{options searchTypeList searchType field='searchRanges'}}
|
||||
</select>
|
||||
<div class="primary">
|
||||
<select class="form-control input-sm" name="{{typeName}}">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<select class="form-control search-type input-sm" name="{{name}}-type">
|
||||
{{options searchData.typeOptions searchParams.typeFront field='searchRanges'}}
|
||||
{{options searchTypeList searchType field='searchRanges'}}
|
||||
</select>
|
||||
<div class="primary">
|
||||
<div class="input-group">
|
||||
@@ -23,5 +23,3 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<select class="form-control search-type input-sm" name="{{name}}-type">
|
||||
{{options searchData.typeOptions searchParams.typeFront field='searchRanges'}}
|
||||
{{options searchTypeList searchType field='searchRanges'}}
|
||||
</select>
|
||||
<div class="primary">
|
||||
<div class="input-group">
|
||||
|
||||
@@ -122,7 +122,7 @@ Espo.define('search-manager', [], function () {
|
||||
},
|
||||
|
||||
getWherePart: function (name, defs) {
|
||||
var field = name;
|
||||
var attribute = name;
|
||||
|
||||
if ('where' in defs) {
|
||||
return defs.where;
|
||||
@@ -140,13 +140,16 @@ Espo.define('search-manager', [], function () {
|
||||
value: a
|
||||
};
|
||||
}
|
||||
if ('field' in defs) {
|
||||
field = defs.field;
|
||||
if ('field' in defs) { // for backward compatibility
|
||||
attribute = defs.field;
|
||||
}
|
||||
if ('attribute' in defs) {
|
||||
attribute = defs.attribute;
|
||||
}
|
||||
if (defs.dateTime) {
|
||||
return {
|
||||
type: type,
|
||||
field: field,
|
||||
attribute: attribute,
|
||||
value: defs.value,
|
||||
dateTime: true,
|
||||
timeZone: this.dateTime.timeZone || 'UTC'
|
||||
@@ -155,8 +158,8 @@ Espo.define('search-manager', [], function () {
|
||||
value = defs.value;
|
||||
return {
|
||||
type: type,
|
||||
field: field,
|
||||
value: value,
|
||||
attribute: attribute,
|
||||
value: value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +159,7 @@ Espo.define('views/fields/base', 'view', function (Dep) {
|
||||
data.searchData = this.searchData;
|
||||
data.searchValues = this.getSearchValues();
|
||||
data.searchType = this.getSearchType();
|
||||
data.searchTypeList = this.getSearchTypeList();
|
||||
}
|
||||
return data;
|
||||
},
|
||||
@@ -300,12 +301,20 @@ Espo.define('views/fields/base', 'view', function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
getSearchParamsData: function () {
|
||||
return this.searchParams.data || {};
|
||||
},
|
||||
|
||||
getSearchValues: function () {
|
||||
return (this.searchParams.data || {}).values || {};
|
||||
return this.getSearchParamsData().values || {};
|
||||
},
|
||||
|
||||
getSearchType: function () {
|
||||
return (this.searchParams.data || {}).type || this.searchParams.type;
|
||||
return this.getSearchParamsData().type || this.searchParams.type;
|
||||
},
|
||||
|
||||
getSearchTypeList: function () {
|
||||
return this.searchTypeList;
|
||||
},
|
||||
|
||||
initInlineEdit: function () {
|
||||
|
||||
@@ -38,7 +38,7 @@ Espo.define('views/fields/date', 'views/fields/base', function (Dep) {
|
||||
|
||||
validations: ['required', 'date', 'after', 'before'],
|
||||
|
||||
searchTypeOptions: ['lastSevenDays', 'ever', 'isEmpty', 'currentMonth', 'lastMonth', 'currentQuarter', 'lastQuarter', 'currentYear', 'lastYear', 'today', 'past', 'future', 'lastXDays', 'nextXDays', 'on', 'after', 'before', 'between'],
|
||||
searchTypeList: ['lastSevenDays', 'ever', 'isEmpty', 'currentMonth', 'lastMonth', 'currentQuarter', 'lastQuarter', 'currentYear', 'lastYear', 'today', 'past', 'future', 'lastXDays', 'nextXDays', 'on', 'after', 'before', 'between'],
|
||||
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
@@ -49,13 +49,11 @@ Espo.define('views/fields/date', 'views/fields/base', function (Dep) {
|
||||
if (this.mode === 'search') {
|
||||
this.searchData.dateValue = this.getDateTime().toDisplayDate(this.searchParams.dateValue);
|
||||
this.searchData.dateValueTo = this.getDateTime().toDisplayDate(this.searchParams.dateValueTo);
|
||||
data.searchType = this.searchParams.typeFront || this.searchParams.type;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
setupSearch: function () {
|
||||
this.searchData.typeOptions = this.searchTypeOptions;
|
||||
this.events = _.extend({
|
||||
'change select.search-type': function (e) {
|
||||
var type = $(e.currentTarget).val();
|
||||
@@ -250,8 +248,10 @@ Espo.define('views/fields/date', 'views/fields/base', function (Dep) {
|
||||
};
|
||||
} else if (type === 'isEmpty') {
|
||||
data = {
|
||||
typeFront: type,
|
||||
type: 'isNull'
|
||||
type: 'isNull',
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data = {
|
||||
@@ -261,6 +261,10 @@ Espo.define('views/fields/date', 'views/fields/base', function (Dep) {
|
||||
return data;
|
||||
},
|
||||
|
||||
getSearchType: function () {
|
||||
return this.getSearchParamsData().type || this.searchParams.typeFront || this.searchParams.type;
|
||||
},
|
||||
|
||||
validateRequired: function () {
|
||||
if (this.isRequired()) {
|
||||
if (this.model.get(this.name) === null) {
|
||||
|
||||
@@ -36,7 +36,7 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
validations: ['required', 'datetime', 'after', 'before'],
|
||||
|
||||
searchTypeOptions: ['lastSevenDays', 'ever', 'isEmpty', 'currentMonth', 'lastMonth', 'currentQuarter', 'lastQuarter', 'currentYear', 'lastYear', 'today', 'past', 'future', 'lastXDays', 'nextXDays', 'on', 'after', 'before', 'between'],
|
||||
searchTypeList: ['lastSevenDays', 'ever', 'isEmpty', 'currentMonth', 'lastMonth', 'currentQuarter', 'lastQuarter', 'currentYear', 'lastYear', 'today', 'past', 'future', 'lastXDays', 'nextXDays', 'on', 'after', 'before', 'between'],
|
||||
|
||||
timeFormatMap: {
|
||||
'HH:mm': 'H:i',
|
||||
|
||||
@@ -42,6 +42,8 @@ Espo.define('views/fields/int', 'views/fields/base', function (Dep) {
|
||||
|
||||
thousandSeparator: ',',
|
||||
|
||||
searchTypeList: ['isNotEmpty', 'isEmpty', 'equals', 'notEquals', 'greaterThan', 'lessThan', 'greaterThanOrEquals', 'lessThanOrEquals', 'between'],
|
||||
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
this.defineMaxLength();
|
||||
@@ -74,9 +76,6 @@ Espo.define('views/fields/int', 'views/fields/base', function (Dep) {
|
||||
if (this.model.get(this.name) !== null && typeof this.model.get(this.name) !== 'undefined') {
|
||||
data.isNotEmpty = true;
|
||||
}
|
||||
if (this.mode === 'search') {
|
||||
data.searchType = this.searchParams.typeFront || this.searchParams.type;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -98,7 +97,6 @@ Espo.define('views/fields/int', 'views/fields/base', function (Dep) {
|
||||
},
|
||||
|
||||
setupSearch: function () {
|
||||
this.searchData.typeOptions = [, 'isNotEmpty', 'isEmpty', 'equals', 'notEquals', 'greaterThan', 'lessThan', 'greaterThanOrEquals', 'lessThanOrEquals', 'between'];
|
||||
this.events = _.extend({
|
||||
'change select.search-type': function (e) {
|
||||
this.handleSearchType($(e.currentTarget).val());
|
||||
@@ -247,6 +245,10 @@ Espo.define('views/fields/int', 'views/fields/base', function (Dep) {
|
||||
return data;
|
||||
},
|
||||
|
||||
getSearchType: function () {
|
||||
return this.searchParams.typeFront || this.searchParams.type;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
|
||||
createDisabled: false,
|
||||
|
||||
searchTypeList: ['is', 'isEmpty', 'isNotEmpty'],
|
||||
|
||||
data: function () {
|
||||
return _.extend({
|
||||
idName: this.idName,
|
||||
@@ -142,7 +144,6 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
},
|
||||
|
||||
setupSearch: function () {
|
||||
this.searchData.typeOptions = ['is', 'isEmpty', 'isNotEmpty'];
|
||||
|
||||
this.events = _.extend({
|
||||
'change select.search-type': function (e) {
|
||||
@@ -301,15 +302,19 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
if (type == 'isEmpty') {
|
||||
var data = {
|
||||
type: 'isNull',
|
||||
typeFront: type,
|
||||
field: this.idName
|
||||
field: this.idName,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
} else if (type == 'isNotEmpty') {
|
||||
var data = {
|
||||
type: 'isNotNull',
|
||||
typeFront: type,
|
||||
field: this.idName
|
||||
field: this.idName,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
}
|
||||
@@ -326,7 +331,6 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
var data;
|
||||
if (entityId) {
|
||||
data = {
|
||||
frontType: 'is',
|
||||
type: 'and',
|
||||
field: this.idName,
|
||||
|
||||
@@ -345,10 +349,12 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
valueId: entityId,
|
||||
valueName: entityName,
|
||||
valueType: entityType,
|
||||
data: {
|
||||
type: 'is'
|
||||
}
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
frontType: 'is',
|
||||
type: 'and',
|
||||
field: this.idName,
|
||||
value: [
|
||||
@@ -362,10 +368,17 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) {
|
||||
value: entityType,
|
||||
}
|
||||
],
|
||||
valueType: entityType
|
||||
valueType: entityType,
|
||||
data: {
|
||||
type: 'is'
|
||||
}
|
||||
};
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
getSearchType: function () {
|
||||
return this.getSearchParamsData().type || this.searchParams.typeFront;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,6 +54,8 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
|
||||
createDisabled: false,
|
||||
|
||||
searchTypeList: ['is', 'isEmpty', 'isNotEmpty', 'isOneOf'],
|
||||
|
||||
data: function () {
|
||||
return _.extend({
|
||||
idName: this.idName,
|
||||
@@ -161,7 +163,6 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
},
|
||||
|
||||
setupSearch: function () {
|
||||
this.searchData.typeOptions = ['is', 'isEmpty', 'isNotEmpty', 'isOneOf'];
|
||||
this.searchData.oneOfIdList = this.searchParams.oneOfIdList || [];
|
||||
this.searchData.oneOfNameHash = this.searchParams.oneOfNameHash || {};
|
||||
|
||||
@@ -395,25 +396,31 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
if (type == 'isEmpty') {
|
||||
var data = {
|
||||
type: 'isNull',
|
||||
typeFront: type,
|
||||
field: this.idName
|
||||
field: this.idName,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
} else if (type == 'isNotEmpty') {
|
||||
var data = {
|
||||
type: 'isNotNull',
|
||||
typeFront: type,
|
||||
field: this.idName
|
||||
field: this.idName,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
} else if (type == 'isOneOf') {
|
||||
var data = {
|
||||
type: 'in',
|
||||
typeFront: type,
|
||||
field: this.idName,
|
||||
value: this.searchData.oneOfIdList,
|
||||
oneOfIdList: this.searchData.oneOfIdList,
|
||||
oneOfNameHash: this.searchData.oneOfNameHash
|
||||
oneOfNameHash: this.searchData.oneOfNameHash,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
|
||||
@@ -423,14 +430,21 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
}
|
||||
var data = {
|
||||
type: 'equals',
|
||||
typeFront: type,
|
||||
field: this.idName,
|
||||
value: value,
|
||||
valueName: this.$el.find('[name="' + this.nameName + '"]').val(),
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
}
|
||||
},
|
||||
|
||||
getSearchType: function () {
|
||||
return this.getSearchParamsData().type || this.searchParams.typeFront || this.searchParams.frontType;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ Espo.define('views/fields/user', 'views/fields/link', function (Dep) {
|
||||
setupSearch: function () {
|
||||
Dep.prototype.setupSearch.call(this);
|
||||
|
||||
this.searchData.typeOptions.push('isFromTeams');
|
||||
this.searchTypeList = Espo.Utils.clone(this.searchTypeList);
|
||||
this.searchTypeList.push('isFromTeams');
|
||||
|
||||
this.searchData.teamIdList = this.searchParams.teamIdList || [];
|
||||
this.searchData.teamNameHash = this.searchParams.teamNameHash || {};
|
||||
|
||||
@@ -177,11 +179,13 @@ Espo.define('views/fields/user', 'views/fields/link', function (Dep) {
|
||||
if (type == 'isFromTeams') {
|
||||
var data = {
|
||||
type: 'isUserFromTeams',
|
||||
typeFront: type,
|
||||
field: this.name,
|
||||
value: this.searchData.teamIdList,
|
||||
teamIdList: this.searchData.teamIdList,
|
||||
teamNameHash: this.searchData.teamNameHash
|
||||
teamNameHash: this.searchData.teamNameHash,
|
||||
data: {
|
||||
type: type
|
||||
}
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user