Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multicheck control] #4529

Merged
merged 11 commits into from
Dec 6, 2017
2,578 changes: 1,289 additions & 1,289 deletions frappe/core/doctype/docfield/docfield.json

Large diffs are not rendered by default.

94 changes: 49 additions & 45 deletions frappe/core/doctype/domain_settings/domain_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,62 @@
// For license information, please see license.txt

frappe.ui.form.on('Domain Settings', {
onload: function(frm) {
let domains = $('<div class="domain-editor">')
.appendTo(frm.fields_dict.domains_html.wrapper);

if(!frm.domain_editor) {
frm.domain_editor = new frappe.DomainsEditor(domains, frm);
before_load: function(frm) {
if(!frm.domains_multicheck) {
frm.domains_multicheck = frappe.ui.form.make_control({
parent: frm.fields_dict.domains_html.$wrapper,
df: {
fieldname: "domains_multicheck",
fieldtype: "MultiCheck",
get_data: () => {
let active_domains = (frm.doc.active_domains || []).map(row => row.domain);
return frappe.boot.all_domains.map(domain => {
return {
label: domain,
value: domain,
checked: active_domains.includes(domain)
};
});
}
},
render_input: true
});
frm.domains_multicheck.refresh_input();
}

frm.domain_editor.show();
},

validate: function(frm) {
if(frm.domain_editor) {
frm.domain_editor.set_items_in_table();
}
frm.trigger('set_options_in_table');
},
});

frappe.DomainsEditor = frappe.CheckboxEditor.extend({
init: function(wrapper, frm) {
var opts = {};
$.extend(opts, {
wrapper: wrapper,
frm: frm,
field_mapper: {
child_table_field: "active_domains",
item_field: "domain",
cdt: "Has Domain"
},
attribute: 'data-domain',
checkbox_selector: false,
get_items: this.get_all_domains,
editor_template: this.get_template()
set_options_in_table: function(frm) {
let selected_options = frm.domains_multicheck.get_value();
let unselected_options = frm.domains_multicheck.options
.map(option => option.value)
.filter(value => {
return !selected_options.includes(value);
});

let map = {}, list = [];
(frm.doc.active_domains || []).map(row => {
map[row.domain] = row.name;
list.push(row.domain);
});

this._super(opts);
},
unselected_options.map(option => {
if(list.includes(option)) {
frappe.model.clear_doc("Has Domain", map[option]);
}
});

get_template: function() {
return `
<div class="checkbox" data-domain="{{item}}">
<label>
<input type="checkbox">
<span class="label-area small">{{ __(item) }}</span>
</label>
</div>
`;
},
selected_options.map(option => {
if(!list.includes(option)) {
frappe.model.clear_doc("Has Domain", map[option]);
let row = frappe.model.add_child(frm.doc, "Has Domain", "active_domains");
row.domain = option;
}
});

get_all_domains: function() {
// return all the domains available in the system
this.items = frappe.boot.all_domains;
this.render_items();
},
});
refresh_field('active_domains');
}
});
10 changes: 5 additions & 5 deletions frappe/core/doctype/domain_settings/domain_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "domains",
"fieldname": "active_domains_sb",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
Expand All @@ -27,7 +27,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Domains",
"label": "Active Domains",
"length": 0,
"no_copy": 0,
"permlevel": 0,
Expand Down Expand Up @@ -57,7 +57,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Domains",
"label": "Domains HTML",
"length": 0,
"no_copy": 0,
"permlevel": 0,
Expand Down Expand Up @@ -95,7 +95,7 @@
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
Expand All @@ -114,7 +114,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2017-05-12 17:01:18.615000",
"modified": "2017-12-05 17:36:46.842134",
"modified_by": "Administrator",
"module": "Core",
"name": "Domain Settings",
Expand Down
15 changes: 7 additions & 8 deletions frappe/desk/page/setup_wizard/setup_wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ frappe.setup = {
events: {},
data: {},
utils: {},
domains: [],

on: function(event, fn) {
if(!frappe.setup.events[event]) {
Expand All @@ -26,7 +27,8 @@ frappe.setup = {
}

frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
var requires = (frappe.boot.setup_wizard_requires || []);
let requires = (frappe.boot.setup_wizard_requires || []);


frappe.require(requires, function() {
frappe.call({
Expand Down Expand Up @@ -216,10 +218,10 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides {
get_setup_slides_filtered_by_domain() {
var filtered_slides = [];
frappe.setup.slides.forEach(function(slide) {
if(frappe.setup.domain) {
var domains = slide.domains;
if (domains.indexOf('all') !== -1 ||
domains.indexOf(frappe.setup.domain.toLowerCase()) !== -1) {
if(frappe.setup.domains) {
let active_domains = frappe.setup.domains;
if (!slide.domains ||
slide.domains.filter(d => active_domains.includes(d)).length > 0) {
filtered_slides.push(slide);
}
} else {
Expand Down Expand Up @@ -311,7 +313,6 @@ frappe.setup.slides_settings = [
{
// Welcome (language) slide
name: "welcome",
domains: ["all"],
title: __("Hello!"),
icon: "fa fa-world",
// help: __("Let's prepare the system for first use."),
Expand Down Expand Up @@ -344,7 +345,6 @@ frappe.setup.slides_settings = [
{
// Region slide
name: 'region',
domains: ["all"],
title: __("Select Your Region"),
icon: "fa fa-flag",
// help: __("Select your Country, Time Zone and Currency"),
Expand Down Expand Up @@ -376,7 +376,6 @@ frappe.setup.slides_settings = [
{
// Profile slide
name: 'user',
domains: ["all"],
title: __("The First User: You"),
icon: "fa fa-user",
fields: [
Expand Down
7 changes: 4 additions & 3 deletions frappe/public/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"public/js/frappe/form/controls/autocomplete.js",
"public/js/frappe/form/controls/barcode.js",
"public/js/frappe/form/controls/geolocation.js",
"public/js/frappe/form/controls/multiselect.js"
"public/js/frappe/form/controls/multiselect.js",
"public/js/frappe/form/controls/multicheck.js"
],
"js/dialog.min.js": [
"public/js/frappe/dom.js",
Expand Down Expand Up @@ -120,7 +121,8 @@
"public/css/desktop.css",
"public/css/form.css",
"public/css/mobile.css",
"public/css/kanban.css"
"public/css/kanban.css",
"public/css/controls.css"
],
"css/frappe-rtl.css": [
"public/css/bootstrap-rtl.css",
Expand Down Expand Up @@ -168,7 +170,6 @@
"public/js/frappe/socketio_client.js",
"public/js/frappe/router.js",
"public/js/frappe/defaults.js",
"public/js/frappe/checkbox_editor.js",
"public/js/frappe/roles_editor.js",
"public/js/lib/microtemplate.js",

Expand Down
6 changes: 6 additions & 0 deletions frappe/public/css/controls.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.unit-checkbox {
color: #36414c;
}
.frappe-control .select-all {
margin-right: 5px;
}
140 changes: 0 additions & 140 deletions frappe/public/js/frappe/checkbox_editor.js

This file was deleted.

1 change: 1 addition & 0 deletions frappe/public/js/frappe/form/controls/base_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
} else {
this.label_area = this.label_span = this.$wrapper.find("label").get(0);
this.input_area = this.$wrapper.find(".control-input").get(0);
this.$input_wrapper = this.$wrapper.find(".control-input-wrapper");
// keep a separate display area to rendered formatted values
// like links, currencies, HTMLs etc.
this.disp_area = this.$wrapper.find(".control-value").get(0);
Expand Down