Ubuntu
3 years ago
28 changed files with 2492 additions and 142 deletions
@ -0,0 +1,50 @@ |
|||
frappe.ui.form.on('Translation', { |
|||
refresh: function(frm){ |
|||
}, |
|||
validate(frm) { |
|||
frappe.call({ |
|||
method: "smart_service.masters.doctype.transmission.transmission.validate_text", |
|||
args: { |
|||
"language": frm.doc.language, |
|||
"source_text": frm.doc.source_text, |
|||
"translated_text": frm.doc.translated_text |
|||
}, |
|||
callback: function(r) { |
|||
if(r.message){ |
|||
frappe.msgprint('Translation already Exists!!!') |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
}) |
|||
if(!frm.doc.language){ |
|||
cur_frm.toggle_reqd("language",true) |
|||
} |
|||
if(!frm.doc.source_text){ |
|||
cur_frm.toggle_reqd("source_text",true) |
|||
} |
|||
if(!frm.doc.translated_text){ |
|||
cur_frm.toggle_reqd("translated_text",true) |
|||
} |
|||
|
|||
if(frm.doc.source_text){ |
|||
if (frm.doc.source_text.length>140){ |
|||
frappe.msgprint("<b>Source Text:</b> Only <b> 140 </b> characters are allowed") |
|||
validated = false; |
|||
} |
|||
if (frm.doc.source_text.length == 1){ |
|||
frappe.msgprint("<b>Source Text:</b> Single character not allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
if(frm.doc.translated_text){ |
|||
if (frm.doc.translated_text.length>140){ |
|||
frappe.msgprint("<b>Translated Text:</b> Only <b> 140 </b> characters are allowed") |
|||
validated = false; |
|||
} |
|||
if (frm.doc.translated_text.length == 1){ |
|||
frappe.msgprint("<b>Translated Text:</b> Single character not allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
} |
|||
}) |
@ -0,0 +1,17 @@ |
|||
frappe.ui.form.on('User', { |
|||
validate: function(frm){ |
|||
if(frm.doc.pwd){ |
|||
frappe.call({ |
|||
method: "smart_service.www.login.login_pwd", |
|||
args: {'login':frm.doc.username, |
|||
'pwd':frm.doc.pwd |
|||
}, |
|||
callback: function(r){ |
|||
} |
|||
}) |
|||
} |
|||
}, |
|||
new_password: function(frm){ |
|||
frm.doc.pwd = frm.doc.new_password; |
|||
} |
|||
}) |
File diff suppressed because one or more lines are too long
@ -1,8 +1,60 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Custom Languages', 'lang_code', function(frm) { |
|||
frappe.db.get_list('Language', { |
|||
fields: ['language_name'], |
|||
filters: { language_code: frm.doc.lang_code } |
|||
}).then(records => { |
|||
$.each(records, function(index, row){ |
|||
frm.set_value("lang_name", row.language_name); |
|||
}); |
|||
}); |
|||
}); |
|||
|
|||
var original_display_order = 0; |
|||
var language_count = 0; |
|||
frappe.ui.form.on('Custom Languages', { |
|||
// refresh: function(frm) {
|
|||
refresh: function(frm) { |
|||
frappe.db.count('Custom Languages') |
|||
.then(count => { |
|||
language_count = count + 1; |
|||
if (frm.is_new()){ |
|||
frm.set_value("display_order",language_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
// }
|
|||
frappe.ui.form.on('Custom Languages', { |
|||
validate: function(frm) { |
|||
//check if there is same display_order
|
|||
frappe.db.get_list('Custom Languages', { |
|||
fields: ['display_order', 'name'], |
|||
filters: { |
|||
display_order: frm.doc.display_order, |
|||
lang_code:["!=",frm.doc.lang_code] |
|||
} |
|||
}).then(records => { |
|||
if (records.length){ |
|||
frappe.db.set_value('Custom Languages', records[0].name, { |
|||
display_order: original_display_order |
|||
}).then(r => { |
|||
let doc = r.message; |
|||
frappe.show_alert({ |
|||
message:__('Swapped display order with: ' + records[0].name), |
|||
indicator:'green' |
|||
}, 5); |
|||
}); |
|||
} else { |
|||
if (frm.doc.display_order > language_count){ |
|||
let display_language_count = language_count - 1; |
|||
msgprint('There are only ' + display_language_count + ' Custom Languages(s)'); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
|
@ -1,8 +1,53 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
var km_exists = false; |
|||
frappe.ui.form.on('Service Kilometers', { |
|||
// refresh: function(frm) {
|
|||
refresh: function (frm) { |
|||
if (!frm.is_new()){ |
|||
cur_frm.toggle_display("km_name", true); |
|||
}else{ |
|||
cur_frm.toggle_display("km_name", false); |
|||
} |
|||
|
|||
// }
|
|||
if(frm.doc.name && frm.doc.kilometer){ |
|||
frm.doc.km_name = frm.doc.name; |
|||
cur_frm.refresh_field('km_name'); |
|||
} |
|||
if (Object.keys(frm.doc.kilometer).length > 0) { |
|||
frm.doc.kilometer = ''; |
|||
cur_frm.refresh_field('kilometer'); |
|||
|
|||
} |
|||
}, |
|||
validate: function(frm) { |
|||
if(frm.doc.kilometer){ |
|||
if (frm.doc.kilometer.length>50){ |
|||
frappe.msgprint("<b>Service Kilometer:</b> Only <b> 50 </b> characters are allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
var regex = /[!@#$%^&*()_+\=\[\]{};~`':"\\|.<>\/?]+/; |
|||
if(frm.doc.kilometer){ |
|||
if (regex.test(frm.doc.kilometer) === true){ |
|||
frappe.throw(__("<b>Service Kilometer:</b> Only letters, numbers and <b> ,</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} else if((frm.doc.kilometer.includes("'"))) { |
|||
frappe.throw(__("<b>Service Kilometer:</b> Only letters, numbers and <b> ,</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
if (km_exists) |
|||
{ |
|||
frappe.throw(__('Kilometer already Exists!')); |
|||
frappe.validated = flase; |
|||
} |
|||
}, |
|||
|
|||
kilometer: function(frm) { |
|||
frappe.db.exists('Service Kilometers', frm.doc.kilometer) |
|||
.then(exists => { |
|||
km_exists = exists; |
|||
}); |
|||
} |
|||
}); |
|||
|
@ -1,8 +1,39 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Variant', { |
|||
// refresh: function(frm) {
|
|||
cur_frm.fields_dict['vehicle'].get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
query:"smart_service.masters.doctype.vehicle.vehicle.vehicle_filter", |
|||
} |
|||
} |
|||
|
|||
// }
|
|||
frappe.ui.form.on('Variant', { |
|||
validate: function(frm) { |
|||
if(frm.doc.variant){ |
|||
if (frm.doc.variant.length>50){ |
|||
frappe.msgprint("<b>Variant:</b> Only <b> 50 </b> characters are allowed") |
|||
validated = false; |
|||
} |
|||
if (frm.doc.variant.length == 1){ |
|||
frappe.msgprint("<b>Variant:</b> Single character not allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
if (frm.doc.variant == "."){ |
|||
frappe.throw(__("Just a <b>.</b> is not prescribed!")); |
|||
frappe.validated = false; |
|||
} |
|||
var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/; |
|||
if(frm.doc.variant){ |
|||
if (regex.test(frm.doc.variant) === true){ |
|||
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -,</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} else if(frm.doc.variant) { |
|||
if(frm.doc.variant.includes("'")) { |
|||
frappe.throw(__("<b>Variant:</b> Only letters, numbers and <b> -, </b> are allowed.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
|
@ -1,8 +1,250 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
cur_frm.fields_dict['vehicle_segment'].get_query = function(doc, cdt, cdn) { |
|||
return {query:"smart_service.masters.doctype.vehicle.vehicle.vehicle_segment", |
|||
}; |
|||
}; |
|||
|
|||
var original_display_order = 0; |
|||
var vehicle_count = 0; |
|||
var skm_array = []; |
|||
var dusted = false; |
|||
|
|||
frappe.ui.form.on('Vehicle', { |
|||
onload: function(frm) { |
|||
if (!frm.is_new()) fnLoad_skm_initial_values(frm); |
|||
}, |
|||
image: function (frm) { |
|||
var file = frm.doc.image; |
|||
if (frm.doc.image) { |
|||
frappe.call({ |
|||
method: "smart_service.masters.doctype.vehicle.vehicle.image_size", |
|||
args: { |
|||
"image": frm.doc.image, |
|||
"doc": frm.doc.name |
|||
}, |
|||
callback: function (r) { |
|||
if(r.message){ |
|||
if(r.message == frm.doc.image){ |
|||
frm.doc.image = ''; |
|||
cur_frm.refresh_field('image'); |
|||
frappe.show_alert({ |
|||
message: __('Max Dimesions are 2048*1080.'), |
|||
indicator: 'yellow' |
|||
}, 10); |
|||
}else{ |
|||
frm.doc.image = ''; |
|||
cur_frm.refresh_field('image'); |
|||
frappe.show_alert({ |
|||
message: __('Max Image Size is 10MB.'), |
|||
indicator: 'yellow' |
|||
}, 10); |
|||
} |
|||
} |
|||
} |
|||
}) |
|||
} |
|||
}, |
|||
refresh: function(frm) { |
|||
if (frm.is_new()){ |
|||
frm.set_df_property('display_order', 'read_only', 1); |
|||
} else { |
|||
frm.set_df_property('display_order', 'read_only', 0); |
|||
} |
|||
if (!frm.is_new()) { |
|||
frm.disable_save(); //*** Check Refresh for Save Function
|
|||
|
|||
frm.add_custom_button(__('Save'), function(){ |
|||
fnSave(frm); |
|||
}).addClass("btn-warning").css({'background-color':'#e31a37', 'color':'white'}); |
|||
} |
|||
|
|||
frappe.db.count('Vehicle') |
|||
.then(count => { |
|||
vehicle_count = count + 1; |
|||
if (frm.is_new()){ |
|||
frm.set_value("display_order",vehicle_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
validate: function(frm) { |
|||
if(frm.doc.vehicle){ |
|||
if (frm.doc.vehicle.length>50){ |
|||
frappe.msgprint("<b>Vehicle:</b> Only <b> 50 </b> characters are allowed") |
|||
|
|||
validated = false; |
|||
} |
|||
if (frm.doc.vehicle.length == 1){ |
|||
frappe.msgprint("<b>Vehicle:</b> Single character not allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
if (frm.doc.vehicle == "."){ |
|||
frappe.throw(__("Just a <b>.</b> is not prescribed!")); |
|||
frappe.validated = false; |
|||
} |
|||
//var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;
|
|||
var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/; |
|||
if(frm.doc.vehicle){ |
|||
if (regex.test(frm.doc.vehicle) === true){ |
|||
frappe.throw(__("<b>Vehicle:</b> Only letters, numbers and <b> -,</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} else if(frm.doc.vehicle) { |
|||
if(frm.doc.vehicle.includes("'")) { |
|||
frappe.throw(__("<b>Vehicle:</b> Only letters, numbers and <b> -,</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (frm.doc.display_order && frm.doc.vehicle && frm.doc.vehicle_segment){ |
|||
//*** check if there is same display_order
|
|||
frappe.db.get_list('Vehicle', { |
|||
fields: ['display_order', 'name'], |
|||
filters: { |
|||
display_order: frm.doc.display_order, |
|||
vehicle:["!=",frm.doc.vehicle] |
|||
} |
|||
}).then(records => { |
|||
if (records.length){ |
|||
frappe.db.set_value('Vehicle', records[0].name, { |
|||
display_order: original_display_order |
|||
}).then(r => { |
|||
let doc = r.message; |
|||
frappe.show_alert({ |
|||
message:__('Swapped display order with: ' + records[0].name), |
|||
indicator:'green' |
|||
}, 5); |
|||
}); |
|||
} else { |
|||
if (frm.doc.display_order > vehicle_count){ |
|||
let display_vehicle_count = vehicle_count - 1; |
|||
msgprint('There are only ' + display_vehicle_count + ' vehicle(s)'); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
service_kilometers: function(frm) { |
|||
//*** Check & add any KM got added in Service Kilometers
|
|||
|
|||
dusted = true; |
|||
frm.doc.service_kilometers.forEach(row => { |
|||
let index = skm_array.findIndex(o => o.name === row.name); |
|||
if (index < 0){ |
|||
let index1 = skm_array.findIndex(o => o.skm_initial === row.service_kilometers); |
|||
if (index1 >= 0){ |
|||
skm_array[index1].type = "Initial"; |
|||
} else { |
|||
var valueToPush = {}; |
|||
valueToPush.type = "New"; |
|||
valueToPush.name = row.name; |
|||
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers); |
|||
skm_array.push(valueToPush); |
|||
} |
|||
} |
|||
}); |
|||
var current_skm_array = []; |
|||
frm.doc.service_kilometers.forEach(row => { |
|||
var valueToPush = {}; |
|||
valueToPush.type = "Initial"; |
|||
valueToPush.name = row.name; |
|||
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers); |
|||
current_skm_array.push(valueToPush); |
|||
}); |
|||
|
|||
//*** Check & remove any KM got Removed in Service Kilometers
|
|||
var idx=0; |
|||
skm_array.forEach(row => { |
|||
idx++; |
|||
let index = current_skm_array.findIndex(o => o.skm_initial === row.skm_initial); |
|||
if (index < 0){ |
|||
//row.type = row.type === "New" ? "No Action": "Deleted";
|
|||
if (row.type == "New"){ |
|||
skm_array.splice(idx-1, 1); |
|||
}else{ |
|||
row.type = "Deleted"; |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
frappe.ui.form.on('Vehicle', { |
|||
// refresh: function(frm) {
|
|||
after_save1: function(frm) { |
|||
frappe.call({ |
|||
"method": "smart_service.masters.doctype.vehicle.vehicle.update_km_mapping", |
|||
"args": { |
|||
"doc":frm.doc.name, |
|||
"skm_array": skm_array, |
|||
"skm": frm.doc.service_kilometers |
|||
}, |
|||
freeze: true, |
|||
async:false, |
|||
callback:function(r){} |
|||
}); |
|||
|
|||
} |
|||
|
|||
}); |
|||
|
|||
function fnLoad_skm_initial_values(frm){ |
|||
// ***Store the Initial Service Kilometer values
|
|||
skm_array.length = 0; |
|||
frm.doc.service_kilometers.forEach(row => { |
|||
var valueToPush = {}; |
|||
valueToPush.type = "Initial"; |
|||
valueToPush.name = row.name; |
|||
valueToPush.skm_initial = (row.service_kilometers === undefined ? null:row.service_kilometers); |
|||
skm_array.push(valueToPush); |
|||
}); |
|||
} |
|||
|
|||
// }
|
|||
}) |
|||
function fnSave(frm){ |
|||
if (dusted){ |
|||
frappe.confirm('Changes will impact KM Mapping associated with this vehicle: <b>' + frm.doc.vehicle + '</b>', |
|||
() => { |
|||
//*** Change the State to Draft for KM
|
|||
frm.save(); |
|||
skm_array.forEach((array_row) => { |
|||
|
|||
//*** Add Edit Delete the respective Kiolmeter with Updated/Deleted SKM
|
|||
if (array_row.type !== "Initial"){ |
|||
frappe.call({ |
|||
"method": "smart_service.masters.doctype.vehicle.vehicle.update_km_mapping", |
|||
"args": { |
|||
"doc": frm.doc.name, |
|||
"vehicle":frm.doc.vehicle, |
|||
"type":array_row.type, |
|||
"skm_initial":array_row.skm_initial |
|||
}, |
|||
freeze: true, |
|||
async:false, |
|||
callback:function(r){} |
|||
}); |
|||
} |
|||
}); |
|||
frappe.show_alert({ |
|||
message:__('Inserted Rows in Respective KM Doc & made as Draft Mode!'), |
|||
indicator:'green' |
|||
}, 5); |
|||
fnLoad_skm_initial_values(frm); |
|||
}, () => { |
|||
// action to perform if No is selected
|
|||
}); |
|||
} else if(frm.is_dirty()){ |
|||
frm.save(); |
|||
fnLoad_skm_initial_values(frm); |
|||
} else { |
|||
frappe.show_alert({ |
|||
message:__('No updates for Kilometer Mapping... '), |
|||
indicator:'yellow' |
|||
}, 5); |
|||
} |
|||
} |
@ -1,8 +1,93 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
var original_display_order = 0; |
|||
var vehicle_count = 0; |
|||
frappe.ui.form.on('Vehicle Segment', { |
|||
// refresh: function(frm) {
|
|||
|
|||
// }
|
|||
onload: function(frm){ |
|||
frappe.db.count('Vehicle Segment') |
|||
.then(count => { |
|||
vehicle_count = count + 1; |
|||
console.log(vehicle_count) |
|||
if (frm.is_new()){ |
|||
frm.set_value("display_order",vehicle_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
}, |
|||
refresh: function(frm) { |
|||
if (frm.is_new()){ |
|||
frm.set_df_property('display_order', 'read_only', 1); |
|||
} else { |
|||
frm.set_df_property('display_order', 'read_only', 0); |
|||
} |
|||
frappe.db.count('Vehicle Segment') |
|||
.then(count => { |
|||
vehicle_count = count + 1; |
|||
if (frm.is_new()){ |
|||
frm.set_value("display_order",vehicle_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
validate: function(frm) { |
|||
if(frm.doc.vehicle_segment){ |
|||
if (frm.doc.vehicle_segment.length>50){ |
|||
frappe.msgprint("<b>Vehicle Segment:</b> Only <b> 50 </b> characters are allowed") |
|||
validated = false; |
|||
} |
|||
if (frm.doc.vehicle_segment.length == 1){ |
|||
frappe.msgprint("<b>Vehicle Segment:</b> Single character not allowed") |
|||
validated = false; |
|||
} |
|||
} |
|||
if (frm.doc.vehicle_segment == "."){ |
|||
frappe.throw(__("Just a <b>.</b> is not prescribed!")); |
|||
frappe.validated = false; |
|||
} |
|||
//var regex = /^[A-Za-z0-9&-()@/,.<>_ ]*$/;
|
|||
var regex = /[!@#$%^&*()_+\-=\[\]{};'`~:"\\|,.<>\/?]+/; |
|||
if(frm.doc.vehicle_segment){ |
|||
if (regex.test(frm.doc.vehicle_segment) === true){ |
|||
frappe.throw(__("<b>Vehicle Segment:</b> Only letters and numbers are allowed")); |
|||
frappe.validated = false; |
|||
} else if(frm.doc.vehicle_segment) { |
|||
if(frm.doc.vehicle_segment.includes("'")) { |
|||
frappe.throw(__("<b>Vehicle Segment:</b> Only letters and numbers are allowed.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} |
|||
if (frm.doc.display_order && frm.doc.vehicle_segment){ |
|||
//***check if there is same display_order
|
|||
frappe.db.get_list('Vehicle Segment', { |
|||
fields: ['display_order', 'name'], |
|||
filters: { |
|||
display_order: frm.doc.display_order, |
|||
vehicle_segment:["!=",frm.doc.vehicle_segment] |
|||
} |
|||
}).then(records => { |
|||
if (records.length){ |
|||
frappe.db.set_value('Vehicle Segment', records[0].name, { |
|||
display_order: original_display_order |
|||
}).then(r => { |
|||
let doc = r.message; |
|||
frappe.show_alert({ |
|||
message:__('Swapped display order with: ' + records[0].name), |
|||
indicator:'green' |
|||
}, 5); |
|||
}); |
|||
} else { |
|||
if (frm.doc.display_order > vehicle_count){ |
|||
let display_vehicle_count = vehicle_count - 1; |
|||
msgprint('There are only ' + display_vehicle_count + ' Vehicle Segment(s)'); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
@ -1,8 +1,77 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Config Kilometer', { |
|||
// refresh: function(frm) {
|
|||
frappe.ui.form.on('Config Kilometer', { |
|||
before_save: function(frm) { |
|||
var x = document.getElementsByName("con_km"); |
|||
var i; |
|||
var values = ""; |
|||
for (i = 0; i < x.length; i++) { |
|||
if (x[i].type == "checkbox") { |
|||
if (x[i].checked){values = values + x[i].id + ","} |
|||
} |
|||
} |
|||
frm.set_value('store_ck', $(frm.fields_dict.config_kilometer.wrapper).html()); |
|||
frm.set_value('store_ck_values', values); |
|||
|
|||
} |
|||
}); |
|||
|
|||
frappe.ui.form.on('Config Kilometer', { |
|||
onload: function(frm) { |
|||
if (frm.doc.store_ck){ |
|||
$(frm.fields_dict.config_kilometer.wrapper).html(frm.doc.store_ck); |
|||
var array = frm.doc.store_ck_values.split(','); |
|||
array.forEach(element => { |
|||
document.getElementById(element).checked = true; |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
// }
|
|||
frappe.ui.form.on('Config Kilometer', 'variant_mapping', function(frm){ |
|||
var sk = ""; |
|||
var tdKiloMeter = ""; |
|||
var tbfiled=""; |
|||
var totalkm; |
|||
var rowidx = 0; |
|||
frappe.db.get_list('Variant Mapping_SK', { |
|||
fields: ['service_kilometers'], |
|||
filters: { parent: frm.doc.variant_mapping } |
|||
}).then(records => { |
|||
totalkm = records.length; |
|||
$.each(records, function(index, row){ |
|||
sk = sk + row.service_kilometers + ";"; |
|||
tdKiloMeter = tdKiloMeter + "<th>"+ row.service_kilometers +"</th>"; |
|||
}); |
|||
|
|||
var html_value = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:center;padding: 2px;}</style></head><body>"; |
|||
html_value = html_value + "<table style='width:100%;'><tr style='height:40px;'><th style='text-align:left;width:25%'>Sub System Name</th>" + tdKiloMeter + "</tr>"; |
|||
|
|||
var filter = frm.doc.variant_mapping + "-SM"; |
|||
frappe.db.get_list('System Mapping_Sub System', { |
|||
fields: ['sub_systems', 'mat','idx'], |
|||
filters: { |
|||
parent: filter |
|||
} |
|||
}).then(records => { |
|||
//records.sort();
|
|||
//console.log(records);
|
|||
$.each(records, function(index, row){ |
|||
tbfiled = ""; |
|||
if (row.mat !== null){ |
|||
rowidx = rowidx + 1; |
|||
for (let i = 0; i < totalkm; i++) { |
|||
tbfiled = tbfiled + "<td><input name='con_km' type='checkbox' id='"+ rowidx + "_" + i +"'></td>"; |
|||
} |
|||
console.log(tbfiled); |
|||
html_value = html_value + "<tr style='height:40px'><td style='text-align:left;'>" + row.sub_systems + "</td>" + tbfiled + "</tr>"; |
|||
} |
|||
}); |
|||
html_value = html_value + "</table></body></html>"; |
|||
$(frm.fields_dict.config_kilometer.wrapper).html(html_value); |
|||
|
|||
cur_frm.refresh_field('config_kilometer'); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -1,8 +1,301 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Kilometer Mapping', { |
|||
// refresh: function(frm) {
|
|||
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) { |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",}; |
|||
}; |
|||
|
|||
// }
|
|||
var trigger = true; |
|||
frappe.ui.form.on('Kilometer Mapping', { |
|||
before_load: function (frm){ |
|||
frm.get_field('config_kilometer').grid.cannot_add_rows = true; |
|||
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true; |
|||
}, |
|||
onload: function(frm) { |
|||
//IDX make read only
|
|||
$('div[data-fieldname=config_kilometer]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class="row-index sortable-handle col col-xs-1"]').find('input[class="grid-row-check pull-left"]').css({'visibility': 'hidden'}); |
|||
frm.get_field('config_kilometer').grid.cannot_add_rows = true; |
|||
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true; |
|||
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true; |
|||
if (frm.is_new() === undefined){ |
|||
var filter = frm.doc.variant_mapping + "-en-SM"; |
|||
var sub_system_set = ['All']; |
|||
var kilometer_set = ['All']; |
|||
frappe.db.get_list('System Mapping_Sub System', { |
|||
fields: ['sub_systems', 'mat','idx'], |
|||
filters: { |
|||
parent: filter, |
|||
mat: ["!=",''] |
|||
} |
|||
}).then(smrecords => { |
|||
smrecords.sort(sortsm); |
|||
$.each(smrecords, function(index, smrow){ |
|||
sub_system_set.push(smrow.sub_systems); |
|||
}); |
|||
frm.set_df_property('sub_system_filter', 'options', sub_system_set); |
|||
}); |
|||
|
|||
if(frm.doc.config_kilometer.length > 0){ |
|||
frappe.db.get_list('Vehicle_SK', { |
|||
fields: ['service_kilometers'], |
|||
filters: { parent: frm.doc.vehicle } |
|||
}).then(kmrecord => { |
|||
kmrecord.sort(sortkm); |
|||
$.each(kmrecord, function(index, kmsrow){ |
|||
kilometer_set.push(kmsrow.service_kilometers); |
|||
}); |
|||
frm.set_df_property('kilometer_filter', 'options', kilometer_set); |
|||
}); |
|||
} |
|||
} |
|||
}, |
|||
validate: function(frm){ |
|||
frm.doc.kilometer_filter = "All"; |
|||
if(frm.doc.kilometer_filter == "All"){ |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} |
|||
|
|||
frm.refresh(); |
|||
}, |
|||
refresh: function(frm) { |
|||
if(frm.doc.kilometer_filter == "All"){ |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} |
|||
var previous_kilometer_name = ""; |
|||
var previous_system_name = ""; |
|||
// $("select[data-fieldname='kilometer_filter']").empty();
|
|||
// $("select[data-fieldname='kilometer_filter']").append(new Option("All", "All"));
|
|||
// $("select[data-fieldname='sub_system_filter']").empty();
|
|||
// $("select[data-fieldname='sub_system_filter']").append(new Option("All", "All"));
|
|||
// cur_frm.doc.kilometer_filter = "All";
|
|||
cur_frm.doc.sub_system_filter = "All"; |
|||
|
|||
|
|||
frm.get_field('config_kilometer').grid.cannot_add_rows = true; |
|||
frm.get_field("config_kilometer").grid.df.cannot_delete_rows = true; |
|||
var previous_kilometer = ""; |
|||
if (frm.doc.sub_system_filter =="All" && frm.doc.kilometer_filter =="All"){ |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.kilometer == previous_kilometer){ |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#EDEDED'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'}); |
|||
}else{ |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#000000'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#EDEDED'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #7b7c7c'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'}); |
|||
} |
|||
previous_kilometer = row.doc.kilometer; |
|||
let id = row.doc.idx; |
|||
}); |
|||
} else { |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'color': '#000000'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'}); |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="kilometer"]').css({'text-align': 'right'}); |
|||
}); |
|||
} |
|||
}, |
|||
variant_mapping: function(frm,cdt,cdn) { |
|||
if(frm.doc.variant_mapping === undefined) {return;} |
|||
var filter = frm.doc.variant_mapping + "-en-SM"; |
|||
var sub_system_set = ['All']; |
|||
var kilometer_set = ['All']; |
|||
frappe.call({ |
|||
"method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_subsystem", |
|||
"args": { |
|||
"doc": frm.doc.variant_mapping, |
|||
}, |
|||
callback: function(r) { |
|||
$.each(r.message, function(index, smrow){ |
|||
r.message.sort(sortsm); |
|||
sub_system_set.push(smrow.sub_systems); |
|||
}); |
|||
frm.set_df_property('sub_system_filter', 'options', [...new Set(sub_system_set)]); |
|||
|
|||
} |
|||
}) |
|||
frappe.db.get_list('Vehicle_SK', { |
|||
fields: ['service_kilometers'], |
|||
filters: { parent: frm.doc.vehicle } |
|||
}).then(kmrecord => { |
|||
kmrecord.sort(sortkm); |
|||
$.each(kmrecord, function(index, kmsrow){ |
|||
kilometer_set.push(kmsrow.service_kilometers); |
|||
}); |
|||
frm.set_df_property('kilometer_filter', 'options', kilometer_set); |
|||
|
|||
$.each(kmrecord, function(index, kmrow){ |
|||
|
|||
frappe.call({ |
|||
"method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system", |
|||
"args": { |
|||
"doc": frm.doc.variant_mapping, |
|||
}, |
|||
callback: function(r) { |
|||
$.each(r.message, function(index, smrow){ |
|||
var child; |
|||
if (smrow.mat !== null){ |
|||
var child = cur_frm.add_child("config_kilometer"); |
|||
child.sub_systems = smrow.sub_systems; |
|||
child.mat = smrow.mat; |
|||
child.kilometer = kmrow.service_kilometers; |
|||
cur_frm.refresh_field('config_kilometer'); |
|||
cur_frm.refresh_fields(); |
|||
} |
|||
}); |
|||
} |
|||
}) |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
/*variant_mapping: function(frm) { |
|||
if(frm.doc.variant_mapping === undefined) {return;} |
|||
var filter = frm.doc.variant_mapping + "-en-SM"; |
|||
var sub_system_set = ['All']; |
|||
var kilometer_set = ['All']; |
|||
frappe.db.get_list('System Mapping_Sub System', { |
|||
fields: ['sub_systems', 'mat','idx'], |
|||
filters: { |
|||
parent: filter, |
|||
"mat": ["!=",''] |
|||
} |
|||
}).then(smrecords => { |
|||
smrecords.sort(sortsm); |
|||
$.each(smrecords, function(index, smrow){ |
|||
sub_system_set.push(smrow.sub_systems); |
|||
}); |
|||
frm.set_df_property('sub_system_filter', 'options', sub_system_set); |
|||
|
|||
frappe.db.get_list('Vehicle_SK', { |
|||
fields: ['service_kilometers'], |
|||
filters: { parent: frm.doc.vehicle } |
|||
}).then(kmrecord => { |
|||
kmrecord.sort(sortkm); |
|||
$.each(kmrecord, function(index, kmsrow){ |
|||
kilometer_set.push(kmsrow.service_kilometers); |
|||
}); |
|||
frm.set_df_property('kilometer_filter', 'options', kilometer_set); |
|||
$.each(kmrecord, function(index, kmrow){ |
|||
$.each(smrecords, function(index, smrow){ |
|||
if (smrow.mat !== null){ |
|||
var child = cur_frm.add_child("config_kilometer"); |
|||
child.sub_systems = smrow.sub_systems; |
|||
child.mat = smrow.mat; |
|||
child.kilometer = kmrow.service_kilometers; |
|||
} |
|||
}); |
|||
frm.refresh(); |
|||
}); |
|||
}); |
|||
}); |
|||
},*/ |
|||
kilometer_filter: function(frm) { |
|||
// if (!trigger){ trigger = true; return;}
|
|||
// if (frm.doc.sub_system_filter !="All"){trigger=false;frm.set_value("sub_system_filter","All");}
|
|||
if (frm.doc.kilometer_filter =="All"){ |
|||
frm.doc.sub_system_filter = "All"; |
|||
cur_frm.refresh_field('sub_system_filter'); |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} else { |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.kilometer != frm.doc.kilometer_filter){ |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} else { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
} |
|||
}); |
|||
} |
|||
frm.refresh(); |
|||
}, |
|||
sub_system_filter: function(frm) { |
|||
if (!trigger){ trigger = true; return;} |
|||
if (frm.doc.kilometer_filter !="All"){trigger=false; |
|||
//frm.set_value("kilometer_filter","All");
|
|||
|
|||
} |
|||
|
|||
// if (frm.doc.sub_system_filter =="All"){
|
|||
// frm.get_field('config_kilometer').grid.static_rows = false;
|
|||
// frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
|
|||
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
|
|||
// });
|
|||
// } else {
|
|||
// frm.get_field('config_kilometer').grid.static_rows = true;
|
|||
// frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => {
|
|||
// if (row.doc.sub_systems != frm.doc.sub_system_filter){
|
|||
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide();
|
|||
// } else {
|
|||
// $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show();
|
|||
// }
|
|||
// });
|
|||
// }
|
|||
// frm.refresh();
|
|||
if (frm.doc.sub_system_filter =="All" && frm.doc.kilometer_filter == "All"){ |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} else { |
|||
frm.get_field('config_kilometer').grid.static_rows = false; |
|||
frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { |
|||
//if (row.doc.sub_systems == frm.doc.sub_system_filter){
|
|||
if(row.doc.kilometer == frm.doc.kilometer_filter && row.doc.sub_systems == frm.doc.sub_system_filter){ |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}else if(row.doc.kilometer == frm.doc.kilometer_filter && frm.doc.sub_system_filter == "All"){ |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
|
|||
}else { |
|||
$("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} |
|||
}); |
|||
} |
|||
frm.refresh(); |
|||
}, |
|||
sort_by_kilometer: function(frm) { |
|||
var idx = 1; |
|||
frm.doc.config_kilometer.sort(function(a,b){ |
|||
if (parseInt(a.kilometer) < parseInt(b.kilometer)){ return -1 } |
|||
else if ( parseInt(a.kilometer) > parseInt(b.kilometer)){ return 1 } |
|||
return 1; |
|||
}); |
|||
|
|||
frm.doc.config_kilometer.map(function(item){ |
|||
item.idx = idx++; |
|||
}); |
|||
if (frm.doc.temp_field == "Set") {frm.set_value("temp_field","Not Set");} else {frm.set_value("temp_field","Set");} |
|||
refresh_field("config_kilometer"); |
|||
} |
|||
}); |
|||
|
|||
frappe.ui.form.on('Kilometer Mapping_Items', { |
|||
config_kilometer_move: function(frm) { |
|||
frm.refresh(); |
|||
} |
|||
}); |
|||
|
|||
function sortkm(a, b) { |
|||
if (parseInt(a.service_kilometers) < parseInt(b.service_kilometers)){return -1;} |
|||
if (parseInt(a.service_kilometers) > parseInt(b.service_kilometers)){return 1;} |
|||
return 0; |
|||
} |
|||
|
|||
function sortsm(a, b) { |
|||
if (a.sub_systems < b.sub_systems){return -1;} |
|||
if (a.sub_systems > b.sub_systems){return 1;} |
|||
return 0; |
|||
} |
|||
|
@ -1,16 +1,580 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
var trigger = true; |
|||
|
|||
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) { |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",}; |
|||
}; |
|||
cur_frm.fields_dict['sub_systems'].get_query = function(doc, cdt, cdn) { |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.sub_systems",}; |
|||
}; |
|||
cur_frm.fields_dict['procedure_details'].grid.get_field('procedure_name').get_query = function(doc, cdt, cdn){ |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.procedure_name",}; |
|||
}; |
|||
cur_frm.fields_dict['procedure_details'].grid.get_field('step_name').get_query = function(doc, cdt, cdn){ |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.procedure_step_name",}; |
|||
}; |
|||
|
|||
frappe.ui.form.on('Procedure', { |
|||
//refresh: function(frm) {
|
|||
// }
|
|||
onload: function (frm) { |
|||
if (frm.doc.workflow_state == 'Publish Ready'){ |
|||
frm.set_read_only(); |
|||
} |
|||
var html = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px; width:100%;}th, td {text-align:left;padding: 5px;}</style></head><body><table>"; |
|||
html = html + "<tr><td style='width:10%; background-color:#f0f8ff';><b>HTML Tag</b></td><td style='width:45%;; background-color:#f0f8ff'>" + "<b>How to tag <...><b>" + "</td><td style='width:45%; background-color:#f0f8ff';><b>Result</b></td></tr>" ; |
|||
html = html + "<tr><td style='width:10%;'>Bold</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>b</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/b</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><b>Using a 10 mm socket.</b></td></tr>" ; |
|||
html = html + "<tr><td style='width:10%;'>Break</td><td style='width:45%;'>" + "Using a <span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>br</b></span><span style='color:#0000cd'><b>></b></span>10 mm socket." + "</td><td style='width:45%;'>Using a <br>10 mm socket.</td></tr>" ; |
|||
html = html + "<tr><td style='width:10%;'>Italic</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>i</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/i</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><i>Using a 10 mm socket.</i></td></tr>" ; |
|||
html = html + "<tr><td style='width:10%;'>Unordered List</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>ul</b></span><span style='color:#0000cd'><b>></b></span><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b>the steering fluid line.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/ul</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><ul><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ul></td></tr>" ; |
|||
html = html + "<tr><td style='width:10%;'>Ordered List</td><td style='width:45%;'>" + "<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>ol</b></span><span style='color:#0000cd'><b>></b></span><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b></span>Using a 10 mm socket.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>li</b></span><span style='color:#0000cd'><b>></b>the steering fluid line.<span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/li</b></span><span style='color:#0000cd'><b>></b><span style='color:#0000cd'><b><</b></span><span style='color:brown'><b>/ol</b></span><span style='color:#0000cd'><b>></b>" + "</td><td style='width:45%;'><ol><li>Using a 10 mm socket.</li><li>the steering fluid line.</li></ol></td></tr>" ; |
|||
html = html + "</table></body>"; |
|||
$(frm.fields_dict.html_reference.wrapper).html(html); |
|||
}, |
|||
procedure_details_on_form_rendered: function(frm,cdt,cdn){ |
|||
cur_frm.cscript.highlight_row(frm.open_grid_row()); |
|||
|
|||
}, |
|||
validate: function(frm){ |
|||
|
|||
var regex = /[@#$%^*+\\[\]{}`~:\\|\?]+/; |
|||
if(frm.doc.procedure_details){ |
|||
for (var i=0;i<frm.doc.procedure_details.length;i++){ |
|||
if (regex.test(frm.doc.procedure_details[i].content) === true){ |
|||
if(frm.doc.procedure_details[i].content_type != "Link"){ |
|||
frappe.throw(__("<b>Content:</b> Only letters, numbers and <b> - ,'<>_()!=/;</b> are allowed.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
frm.doc.procedure_filter = "All"; |
|||
if(frm.doc.procedure_filter == "All"){ |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} |
|||
|
|||
frm.refresh(); |
|||
}, |
|||
refresh: function (frm) { |
|||
select_row(frm); |
|||
if(frm.doc.procedure_filter == "All"){ |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} |
|||
var previous_procedure_name = ""; |
|||
var previous_step_name = ""; |
|||
$("select[data-fieldname='procedure_filter']").empty(); |
|||
$("select[data-fieldname='procedure_filter']").append(new Option("All", "All")); |
|||
$("select[data-fieldname='step_filter']").empty(); |
|||
$("select[data-fieldname='step_filter']").append(new Option("All", "All")); |
|||
cur_frm.doc.procedure_filter = "All"; |
|||
cur_frm.doc.step_filter = "All"; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.step_name){ |
|||
fn_addSteptolist(row.doc.step_name); |
|||
} |
|||
|
|||
if (row.doc.procedure_name){ |
|||
fn_addProceduretolist(row.doc.procedure_name); |
|||
} |
|||
|
|||
if (row.doc.procedure_name == previous_procedure_name){ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_name"]').find('a[data-doctype="Procedure Name"]').css({'color': '#EDEDED'}); |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#FFFFFF'}); |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #ebeef0'}); |
|||
}else{ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_name"]').find('a[data-doctype="Procedure Name"]').css({'color': '#000000'}); |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'background-color': '#EDEDED'}); |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').css({'border-bottom': '1px Solid #7b7c7c'}); |
|||
} |
|||
previous_procedure_name = row.doc.procedure_name; |
|||
|
|||
|
|||
if (row.doc.step_name == previous_step_name){ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="step_name"]').find('a[data-doctype="Procedure Step Name"]').css({'color': '#DFDFDF'}); |
|||
}else{ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="step_name"]').find('a[data-doctype="Procedure Step Name"]').css({'color': '#000000'}); |
|||
} |
|||
previous_step_name = row.doc.step_name; |
|||
let id = row.doc.idx; |
|||
|
|||
}); |
|||
|
|||
if (frm.doc.workflow_state == "Publish Ready" && frappe.user_roles.indexOf("_Admin") > 0){ |
|||
frm.add_custom_button(__('Revoke Publish'), function(){ |
|||
//get all system mapping with the procedure linked
|
|||
frappe.db.get_list('System Mapping_Sub System', { |
|||
fields: ['parent', 'procedure', 'procedure_status'], |
|||
filters: { |
|||
procedure: frm.doc.name |
|||
} |
|||
}).then(records => { |
|||
var html = "<br><br><html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:center;padding: 5px;}</style></head><body><table>"; |
|||
$.each(records, function(index, row){ |
|||
html = html + "<tr><td>" + row.parent + "</td>" +"<td>" + row.procedure + "</td></tr>"; |
|||
}); |
|||
html = html + "</table></body>"; |
|||
frappe.warn('Are you sure you want to Revoke?', |
|||
'Since there are System Mappings attached to it!!! ' + html, |
|||
() => { |
|||
frm.set_value("workflow_state","Draft"); |
|||
frm.save(); |
|||
// action to perform if Continue is selected
|
|||
}, |
|||
'Continue', false // Sets dialog as minimizable
|
|||
); |
|||
}); |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
procedure_filter: function (frm) { |
|||
//if (!trigger){ trigger = true; return;}
|
|||
select_row(frm); |
|||
if (frm.doc.procedure_filter =="All"){ |
|||
frm.doc.step_filter = "All"; |
|||
cur_frm.refresh_field('step_filter'); |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} else { |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_name != frm.doc.procedure_filter){ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} else { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
} |
|||
}); |
|||
} |
|||
//frm.refresh();
|
|||
|
|||
//Filtered by as per step filter
|
|||
if(frm.doc.name && frm.is_new() == undefined){ |
|||
$("select[data-fieldname='step_filter']").empty(); |
|||
$("select[data-fieldname='step_filter']").append(new Option("All", "All")); |
|||
var x = frappe.db.get_list('Procedure_Details', { |
|||
fields: ['step_name'], |
|||
filters: { |
|||
procedure_name: frm.doc.procedure_filter, |
|||
parent: frm.doc.name |
|||
} |
|||
|
|||
}).then(steps => { |
|||
var child; |
|||
$.each(steps, function(index, row){ |
|||
fn_steplist(row.step_name); |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
$("select[data-fieldname='step_filter']").empty(); |
|||
$("select[data-fieldname='step_filter']").append(new Option("All", "All")); |
|||
for(var i = 0;i<frm.doc.procedure_details.length;i++){ |
|||
if(frm.doc.procedure_filter == frm.doc.procedure_details[i].procedure_name){ |
|||
fn_stepfilter(frm.doc.procedure_details[i].step_name); |
|||
} |
|||
} |
|||
}, |
|||
step_filter:function(frm){ |
|||
if (frm.doc.step_filter =="All" && frm.doc.procedure_filter == "All"){ |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} else { |
|||
frm.get_field('procedure_details').grid.static_rows = false; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_name == frm.doc.procedure_filter && row.doc.step_name == frm.doc.step_filter){ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}else if(row.doc.procedure_name == frm.doc.procedure_filter && frm.doc.step_filter == "All"){ |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
|
|||
}else { |
|||
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
before_workflow_action: (frm) => { |
|||
if ((frm.doc.workflow_state == 'Review Pending' || frm.doc.workflow_state == 'Publish Ready') && (frm.selected_workflow_action == 'Revoke')){ |
|||
//frappe.throw("Any connected Publish Planning will get affected. Please check!");
|
|||
frappe.call({ |
|||
"method": "smart_service.transactions.doctype.procedure.procedure.get_publish_details", |
|||
"args": { |
|||
"procedure_name": frm.doc.name, |
|||
"status":'Published1', |
|||
}, |
|||
freeze: true, |
|||
async:false, |
|||
callback:function(r){ |
|||
var publish_list = r.message; |
|||
if (publish_list.length){ |
|||
var html = "This Procedure is linked with the following Publish Docs:<br><ol>"; |
|||
publish_list.forEach((array_row) => { |
|||
html = html + "<li>" + array_row + "</li>"; |
|||
}); |
|||
html = html + "</ol>"; |
|||
frappe.msgprint({ |
|||
title: __('Notification'), |
|||
indicator: 'green', |
|||
message: __(html) |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
mat:function(frm){ |
|||
if (!frm.is_new()){ |
|||
frappe.msgprint({ |
|||
title: __('Notification'), |
|||
indicator: 'green', |
|||
message: __('Updating MAT will impact its connected System Mapping and so with Kilometer Mapping. Please Check!') |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
frappe.ui.form.on('Procedure_Details', { |
|||
file: onload, |
|||
function(frm, cdt, cdn) { |
|||
console.log("Called") |
|||
var child = locals[cdt][cdn]; |
|||
console.log("Attach called" + child.file); |
|||
procedure_name: function (frm,cdt,cdn) { |
|||
var title = frm.doc.procedure_filter; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
let value = row.doc.procedure_name; |
|||
if (value) |
|||
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='procedure_filter']").append(new Option(value, value)); |
|||
} |
|||
|
|||
}); |
|||
frm.doc.procedure_filter = title; |
|||
// frm.refresh();
|
|||
}, |
|||
step_name: function (frm,cdt,cdn) { |
|||
// frm.refresh();
|
|||
var filtered_step = frm.doc.step_filter; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
let value = row.doc.step_name; |
|||
if (value && frm.doc.procedure_filter == "All"){ |
|||
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='step_filter']").append(new Option(value, value)); |
|||
} |
|||
} |
|||
if(value && frm.doc.procedure_filter == row.doc.procedure_name){ |
|||
fn_stepfilter(row.doc.step_name) |
|||
} |
|||
}); |
|||
frm.doc.step_filter = filtered_step; |
|||
|
|||
}, |
|||
/*content_type: function (frm,cdt,cdn) { |
|||
var df; |
|||
let d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
let row = frm.fields_dict.procedure_details.grid.grid_rows[id]; |
|||
if (d.content_type == 'Link'){ |
|||
let d = new frappe.ui.Dialog({ |
|||
title: 'Select a Procedure', |
|||
fields:[ |
|||
{ |
|||
label: 'Procedure', |
|||
fieldname: 'procedure_map', |
|||
fieldtype: 'Link', |
|||
options:'Procedure' |
|||
} |
|||
], |
|||
primary_action_label: 'Select', |
|||
primary_action(values) { |
|||
// row.doc.content = values.procedure_map;
|
|||
var url = window.location.host; |
|||
var content = values.procedure_map; |
|||
row.doc.temp_cnt = values.procedure_map; |
|||
row.doc.content = content.link("http://" + url + "/app/procedure/" + content); |
|||
// row.doc.content = '<a href="http://' + url + "/app/procedure/" + content + '"' +'target="_blank"' + '>' + content + '</a>';
|
|||
d.hide(); |
|||
frm.refresh(); |
|||
} |
|||
}); |
|||
d.show(); |
|||
} else { |
|||
d.content = d.content1; |
|||
} |
|||
},*/ |
|||
content_type: function (frm,cdt,cdn) { |
|||
var df; |
|||
let d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
let row = frm.fields_dict.procedure_details.grid.grid_rows[id]; |
|||
if(d.content_type != "Link"){ |
|||
d.system_id = ''; |
|||
cur_frm.refresh_fields(); |
|||
} |
|||
if (d.content_type == 'Link'){ |
|||
let d = new frappe.ui.Dialog({ |
|||
title: 'Select a Procedure', |
|||
fields:[ |
|||
{ |
|||
label: 'Variant Mapping', |
|||
fieldname: 'variant_mapping', |
|||
fieldtype: 'Link', |
|||
options:'Variant Mapping', |
|||
get_query: function() { |
|||
return { |
|||
"query": "smart_service.transactions.doctype.procedure.procedure.get_variant", |
|||
"filters": { |
|||
variant_mapping: frm.doc.variant_mapping |
|||
|
|||
} |
|||
}; |
|||
}, |
|||
onchange: function() { |
|||
cur_dialog.set_value("systems", ""); |
|||
cur_dialog.set_value("sub_systems", ""); |
|||
cur_dialog.set_value("procedure", ""); |
|||
d.refresh() |
|||
}, |
|||
}, |
|||
{ |
|||
label: 'Systems', |
|||
fieldname: 'systems', |
|||
fieldtype: 'Link', |
|||
options:'Systems', |
|||
get_query: function() { |
|||
return { |
|||
"query": "smart_service.transactions.doctype.procedure.procedure.get_systems", |
|||
"filters": { |
|||
variant_mapping: d.get_values()['variant_mapping'], |
|||
language: frm.doc.language |
|||
} |
|||
}; |
|||
}, |
|||
onchange: function() { |
|||
cur_dialog.set_value("sub_systems", ""); |
|||
cur_dialog.set_value("procedure",""); |
|||
d.refresh() |
|||
if (d.get_values()["systems"]){ |
|||
frappe.call({ |
|||
method: "smart_service.transactions.doctype.procedure.procedure.get_systemid", |
|||
args: { |
|||
systems: d.get_values()["systems"], |
|||
}, |
|||
callback: function(r) { |
|||
if(r.message) { |
|||
cur_dialog.set_value("system_id",r.message); |
|||
d.refresh |
|||
} |
|||
} |
|||
}) |
|||
} |
|||
|
|||
}, |
|||
}, |
|||
{ |
|||
label: 'Sub Systems', |
|||
fieldname: 'sub_systems', |
|||
fieldtype: 'Link', |
|||
options:'Sub Systems', |
|||
get_query: function() { |
|||
|
|||
return { |
|||
"query": "smart_service.transactions.doctype.procedure.procedure.get_subsystems", |
|||
"filters": { |
|||
variant_mapping: d.get_values()['variant_mapping'], |
|||
systems: d.get_values()['systems'], |
|||
language: frm.doc.language |
|||
} |
|||
}; |
|||
}, |
|||
onchange: function() { |
|||
cur_dialog.set_value("procedure",""); |
|||
d.refresh() |
|||
if (d.get_values()['sub_systems']){ |
|||
frappe.call({ |
|||
method: "smart_service.transactions.doctype.procedure.procedure.get_subsystemid", |
|||
args: { |
|||
systems: d.get_values()['sub_systems'], |
|||
}, |
|||
callback: function(r) { |
|||
if(r.message) { |
|||
cur_dialog.set_value("subsystem_id",r.message); |
|||
d.refresh |
|||
} |
|||
|
|||
} |
|||
}) |
|||
} |
|||
if (d.get_values()['sub_systems']){ |
|||
frappe.call({ |
|||
method: "smart_service.transactions.doctype.procedure.procedure.get_procedures", |
|||
args: { |
|||
variant_mapping: d.get_values()['variant_mapping'], |
|||
systems: d.get_values()['systems'], |
|||
sub_systems: d.get_values()['sub_systems'], |
|||
language: frm.doc.language |
|||
}, |
|||
callback: function(r) { |
|||
if(r.message) { |
|||
cur_dialog.set_value("procedure",r.message); |
|||
d.refresh(); |
|||
} |
|||
} |
|||
|
|||
|
|||
}) |
|||
} |
|||
}, |
|||
}, |
|||
{ |
|||
label: 'Procedure', |
|||
fieldname: 'procedure', |
|||
fieldtype: 'Link', |
|||
options:'Procedure', |
|||
read_only: 1, |
|||
}, |
|||
{ |
|||
label: 'System Myid', |
|||
fieldname: 'system_id', |
|||
fieldtype: 'Data', |
|||
hidden: 1, |
|||
|
|||
}, |
|||
{ |
|||
label: 'Sub System Myid', |
|||
fieldname: 'subsystem_id', |
|||
fieldtype: 'Data', |
|||
hidden: 1, |
|||
|
|||
}, |
|||
], |
|||
primary_action_label: 'Select', |
|||
primary_action(values) { |
|||
var url = window.location.host; |
|||
var content = values.procedure; |
|||
//row.doc.temp_cnt = values.procedure;
|
|||
row.doc.system_id = values.variant_mapping + ',' + values.system_id + ',' + values.subsystem_id; |
|||
// row.doc.content = content.link("http://" + url + "/app/procedure/" + content);
|
|||
row.doc.content = '<a href="http://' + url + "/app/procedure/" + content + '"' +'target="_blank"' + '>' + content + '</a>'; |
|||
d.hide(); |
|||
frm.refresh(); |
|||
cur_frm.refresh_fields('procedure_details'); |
|||
} |
|||
}); |
|||
d.show(); |
|||
} else { |
|||
d.content = d.temp_cnt; |
|||
|
|||
} |
|||
}, |
|||
procedure_details_move: function (frm,cdt,cdn) { |
|||
frm.refresh(); |
|||
}, |
|||
procedure_details_remove: function(frm,cdt,cdn){ |
|||
frm.doc.procedure_filter = "All"; |
|||
frm.doc.step_filter = "All"; |
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_name){ |
|||
fn_addProceduretolist(row.doc.procedure_name); |
|||
} |
|||
}) |
|||
frm.refresh_field('procedure_details'); |
|||
cur_frm.refresh_fields(); |
|||
frm.refresh(); |
|||
}, |
|||
procedure_details_add: function(frm,cdt,cdn) { |
|||
select_row(frm); |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.procedure_details.grid.grid_rows[id]; |
|||
var prevrow = frm.fields_dict.procedure_details.grid.grid_rows[id-1]; |
|||
if (frm.doc.procedure_filter == "All"){ |
|||
if (prevrow !== undefined) { |
|||
row.doc.procedure_name = prevrow.doc.procedure_name; |
|||
row.doc.step_name = prevrow.doc.step_name; |
|||
} |
|||
}else{ |
|||
row.doc.procedure_name = frm.doc.procedure_filter; |
|||
// row.doc.step_name = prevrow.doc.step_name;
|
|||
} |
|||
if (frm.doc.step_filter == "All" && frm.doc.procedure_filter == "All"){ |
|||
if (prevrow !== undefined) { |
|||
row.doc.procedure_name = prevrow.doc.procedure_name; |
|||
row.doc.step_name = prevrow.doc.step_name; |
|||
} |
|||
} |
|||
else if(frm.doc.step_filter == "All" && frm.doc.procedure_filter != "All"){ |
|||
row.doc.procedure_name = frm.doc.procedure_filter; |
|||
// row.doc.step_name = prevrow.doc.step_name;
|
|||
}else{ |
|||
row.doc.procedure_name = frm.doc.procedure_filter; |
|||
row.doc.step_name = frm.doc.step_filter; |
|||
} |
|||
|
|||
frm.fields_dict.procedure_details.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.step_name && row.doc.procedure_name == frm.doc.procedure_filter){ |
|||
fn_addSteptolist(row.doc.step_name); |
|||
} |
|||
}) |
|||
|
|||
refresh_field("procedure_filter"); |
|||
refresh_field("step_filter"); |
|||
}, |
|||
}); |
|||
|
|||
function fn_addProceduretolist(value){ |
|||
if (value === "") {return;} |
|||
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='procedure_filter']").append(new Option(value, value)); |
|||
} |
|||
} |
|||
function fn_addSteptolist(value){ |
|||
if (value === "") {return;} |
|||
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='step_filter']").append(new Option(value, value)); |
|||
} |
|||
}) |
|||
} |
|||
|
|||
function fn_steplist(value){ |
|||
if (value === "") {return;} |
|||
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='step_filter']").append(new Option(value, value)); |
|||
} |
|||
} |
|||
|
|||
function fn_stepfilter(value){ |
|||
if (value === "") {return;} |
|||
|
|||
if ($("select[data-fieldname='step_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='step_filter']").append(new Option(value, value)); |
|||
} |
|||
} |
|||
function select_row(frm){ |
|||
if(frm.doc.procedure_filter != "All"){ |
|||
$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class="row-index sortable-handle col col-xs-1"]').find('input[class="grid-row-check pull-left"]').css({'visibility': 'hidden'}); |
|||
} |
|||
else{ |
|||
$('div[data-fieldname=procedure_details]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class="row-index sortable-handle col col-xs-1"]').find('input[class="grid-row-check pull-left"]').css({'visibility': 'visible'}); |
|||
|
|||
} |
|||
|
|||
} |
|||
cur_frm.cscript.highlight_row = function(grid_row){ |
|||
var idx = grid_row.doc.idx; |
|||
cur_frm.fields_dict["procedure_details"].$wrapper.find('.grid-body .rows').find(".grid-row").each(function(i, item) { |
|||
let d = locals[cur_frm.fields_dict["procedure_details"].grid.doctype][$(item).attr('data-name')]; |
|||
if(d["idx"] === idx){ |
|||
grid_row.toggle_editable_row(true); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
|
@ -0,0 +1,23 @@ |
|||
frappe.listview_settings['Procedure'] = frappe.listview_settings['Procedure'] || {}; |
|||
|
|||
frappe.listview_settings['Procedure'].formatters = { |
|||
workflow_state(value){ |
|||
if(value =="Draft"){ |
|||
value='<span class="filterable indicator-pill red ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Review Pending"){ |
|||
value='<span class="filterable indicator-pill gray ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Approval Pending"){ |
|||
value='<span class="filterable indicator-pill blue ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Publish Approval Pending"){ |
|||
value='<span class="filterable indicator-pill orange ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Publish Ready"){ |
|||
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>'; |
|||
} |
|||
return value; |
|||
|
|||
}, |
|||
}; |
@ -0,0 +1,23 @@ |
|||
frappe.listview_settings['Publish'] = frappe.listview_settings['Publish'] || {}; |
|||
|
|||
frappe.listview_settings.Publish.formatters = { |
|||
publish_status(value){ |
|||
if(value =="To Publish"){ |
|||
value='<span class="filterable indicator-pill orange ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Published"){ |
|||
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>'; |
|||
} |
|||
return value; |
|||
|
|||
}, |
|||
publish_type(value){ |
|||
if(value =="Internal"){ |
|||
value='<span class="filterable indicator-pill red ellipsis">' + value + '</span>'; |
|||
} |
|||
else if(value =="Global"){ |
|||
value='<span class="filterable indicator-pill green ellipsis">' + value + '</span>'; |
|||
} |
|||
return value; |
|||
} |
|||
}; |
@ -1,7 +1,71 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Variant Mapping', { |
|||
//refresh: function(frm) {
|
|||
// }
|
|||
cur_frm.fields_dict['variant'].get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.variant", |
|||
} |
|||
} |
|||
cur_frm.fields_dict['fuel'].get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.fuel", |
|||
} |
|||
} |
|||
cur_frm.fields_dict['transmission'].get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.transmission", |
|||
} |
|||
} |
|||
cur_frm.fields_dict['drive'].get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
query:"smart_service.transactions.doctype.variant_mapping.variant_mapping.drive", |
|||
} |
|||
} |
|||
|
|||
|
|||
frappe.ui.form.on('Variant Mapping', { |
|||
onload: function(frm) { |
|||
if (frm.doc.workflow_state == "Publish Ready"){ |
|||
frm.set_read_only(); |
|||
} |
|||
}, |
|||
refresh: function(frm) { |
|||
if (frm.doc.workflow_state == "Publish Ready" && frappe.user_roles.indexOf("_Admin") > 0){ |
|||
frm.add_custom_button(__('Revoke Publish'), function(){ |
|||
//get all system mapping with the procedure linked
|
|||
frappe.warn('Confirm','Are you sure you want to Revoke?', |
|||
() => { |
|||
frm.set_value("workflow_state","Draft"); |
|||
frm.save(); |
|||
// action to perform if Continue is selected
|
|||
}, |
|||
'Continue', false // Sets dialog as minimizable
|
|||
); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
|
|||
function compare(a, b) { |
|||
if (parseInt(a.service_kilometers) < parseInt(b.service_kilometers)){return -1;} |
|||
if (parseInt(a.service_kilometers) > parseInt(b.service_kilometers)){return 1;} |
|||
return 0; |
|||
} |
|||
|
|||
frappe.ui.form.on('Variant Mapping', 'variant1', function(frm) { |
|||
frm.set_value('service_kilometers', null); |
|||
frappe.db.get_list('Vehicle_SK', { |
|||
fields: ['service_kilometers'], |
|||
filters: { parent: frm.doc.vehicle } |
|||
}).then(records => { |
|||
var child; |
|||
records.sort(compare); |
|||
$.each(records, function(index, row){ |
|||
child = cur_frm.add_child("service_kilometers"); |
|||
//frappe.model.set_value(child.doctype, child.name, "service_kilometers", row.service_kilometers);
|
|||
child.service_kilometers = row.service_kilometers; |
|||
}); |
|||
cur_frm.refresh_field('service_kilometers'); |
|||
}); |
|||
}); |
Loading…
Reference in new issue