mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
checklist field
This commit is contained in:
35
application/Espo/Core/FieldValidators/ChecklistType.php
Normal file
35
application/Espo/Core/FieldValidators/ChecklistType.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM 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.
|
||||
*
|
||||
* EspoCRM 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 EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\FieldValidators;
|
||||
|
||||
class ChecklistType extends ArrayType
|
||||
{
|
||||
|
||||
}
|
||||
@@ -131,6 +131,7 @@
|
||||
"map": "Map",
|
||||
"number": "Number (auto-increment)",
|
||||
"colorpicker": "Color Picker",
|
||||
"checklist": "Checklist",
|
||||
"jsonArray": "Json Array",
|
||||
"jsonObject": "Json Object"
|
||||
},
|
||||
|
||||
51
application/Espo/Resources/metadata/fields/checklist.json
Normal file
51
application/Espo/Resources/metadata/fields/checklist.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"params": [
|
||||
{
|
||||
"name": "required",
|
||||
"type": "bool",
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "options",
|
||||
"type": "array",
|
||||
"view": "views/admin/field-manager/fields/options",
|
||||
"noEmptyString": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name":"isSorted",
|
||||
"type":"bool"
|
||||
},
|
||||
{
|
||||
"name": "translation",
|
||||
"type": "varchar",
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "maxCount",
|
||||
"type": "int",
|
||||
"min": 1
|
||||
},
|
||||
{
|
||||
"name": "audited",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "readOnly",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"validationList": [
|
||||
"required",
|
||||
"maxCount"
|
||||
],
|
||||
"filter": true,
|
||||
"notCreatable": false,
|
||||
"notSortable": true,
|
||||
"fieldDefs": {
|
||||
"type":"jsonArray",
|
||||
"storeArrayValues": true
|
||||
},
|
||||
"translatedOptions": true,
|
||||
"personalData": true
|
||||
}
|
||||
7
client/res/templates/fields/checklist/detail.tpl
Normal file
7
client/res/templates/fields/checklist/detail.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
{{#each optionDataList}}
|
||||
<div class="checklist-item-container">
|
||||
<input type="checkbox" data-name="{{dataName}}" id="{{id}}" {{#if isChecked}} checked{{/if}} disabled="disabled">
|
||||
<label for="{{id}}" class="checklist-label">{{label}}</label>
|
||||
</div>
|
||||
{{/each}}
|
||||
7
client/res/templates/fields/checklist/edit.tpl
Normal file
7
client/res/templates/fields/checklist/edit.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
{{#each optionDataList}}
|
||||
<div class="checklist-item-container">
|
||||
<input type="checkbox" data-name="{{dataName}}" id="{{id}}" {{#if isChecked}} checked{{/if}}>
|
||||
<label for="{{id}}" class="checklist-label">{{label}}</label>
|
||||
</div>
|
||||
{{/each}}
|
||||
135
client/src/views/fields/checklist.js
Normal file
135
client/src/views/fields/checklist.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM 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.
|
||||
*
|
||||
* EspoCRM 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 EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
define('views/fields/checklist', ['views/fields/array'], function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
type: 'checklist',
|
||||
|
||||
listTemplate: 'fields/array/list',
|
||||
|
||||
detailTemplate: 'fields/checklist/detail',
|
||||
|
||||
editTemplate: 'fields/checklist/edit',
|
||||
|
||||
isInversed: false,
|
||||
|
||||
events: {
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return _.extend({
|
||||
optionDataList: this.getOptionDataList(),
|
||||
}, Dep.prototype.data.call(this));
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
this.params.options = this.params.options || [];
|
||||
},
|
||||
|
||||
afterRender: function () {
|
||||
if (this.mode == 'search') {
|
||||
this.renderSearch();
|
||||
}
|
||||
|
||||
if (this.isEditMode()) {
|
||||
this.$el.find('input').on('change', function () {
|
||||
this.trigger('change');
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
getOptionDataList: function () {
|
||||
var valueList = this.model.get(this.name) || [];
|
||||
var list = [];
|
||||
|
||||
this.params.options.forEach(function (item) {
|
||||
var isChecked = ~valueList.indexOf(item);
|
||||
var dataName = 'checklistItem-' + this.name + '-' + item;
|
||||
var id = 'checklist-item-' + this.name + '-' + item;
|
||||
|
||||
if (this.isInversed) isChecked = !isChecked;
|
||||
list.push({
|
||||
name: item,
|
||||
isChecked: isChecked,
|
||||
dataName: dataName,
|
||||
id: id,
|
||||
label: this.translatedOptions[item] || item,
|
||||
});
|
||||
}, this);
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
fetch: function () {
|
||||
var list = [];
|
||||
|
||||
this.params.options.forEach(function (item) {
|
||||
var $item = this.$el.find('input[data-name="checklistItem-' + this.name + '-' + item + '"]');
|
||||
var isChecked = $item.get(0) && $item.get(0).checked;
|
||||
if (this.isInversed)
|
||||
isChecked = !isChecked;
|
||||
if (isChecked)
|
||||
list.push(item);
|
||||
}, this);
|
||||
|
||||
var data = {};
|
||||
data[this.name] = list;
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
validateRequired: function () {
|
||||
if (this.isRequired()) {
|
||||
var value = this.model.get(this.name);
|
||||
if (!value || value.length == 0) {
|
||||
var msg = this.translate('fieldIsRequired', 'messages').replace('{field}', this.getLabelText());
|
||||
this.showValidationMessage(msg, '.checklist-item-container:last-child input');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
validateMaxCount: function () {
|
||||
if (this.params.maxCount) {
|
||||
var itemList = this.model.get(this.name) || [];
|
||||
if (itemList.length > this.params.maxCount) {
|
||||
var msg =
|
||||
this.translate('fieldExceedsMaxCount', 'messages')
|
||||
.replace('{field}', this.getLabelText())
|
||||
.replace('{maxCount}', this.params.maxCount.toString());
|
||||
this.showValidationMessage(msg, '.checklist-item-container:last-child input');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -1025,6 +1025,20 @@ ul.dropdown-menu > li.checkbox:last-child {
|
||||
}
|
||||
}
|
||||
|
||||
.field {
|
||||
.checklist-label {
|
||||
color: @text-color;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.checklist-item-container {
|
||||
margin-bottom: 2px;
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter > .form-group .field {
|
||||
.link-container {
|
||||
font-size: @font-size-small;
|
||||
|
||||
Reference in New Issue
Block a user