@ -1,6 +1,6 @@
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
// For license information, please see license.txt
var selected_module = 0
cur_frm . fields_dict [ 'variant_mapping' ] . get_query = function ( doc , cdt , cdn ) {
return {
@ -10,25 +10,29 @@ cur_frm.fields_dict['variant_mapping'].get_query = function (doc, cdt, cdn) {
}
} ;
} ;
var selected_module = ''
cur_frm . fields_dict [ 'vehicle' ] . get_query = function ( doc , cdt , cdn ) {
return { query : "smart_service.masters.doctype.vehicle.vehicle.vehicle_filter" , } ;
} ;
let lang_set_first_time = true ;
frappe . ui . form . on ( 'Publish' , {
publish_module : function ( frm ) {
if ( cur_frm . doc . publish_module == 'Automotive' ) {
selected_module = 1
onload : function ( frm ) {
// $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish")
if ( frm . doc . docstatus == 0 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module != 'Automotive System' ) {
$ ( '[data-route="Form/Publish/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Internal Publish" )
}
else {
selected_module = 0
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" && frm . doc . publish_module != 'Automotive System' ) {
$ ( '[data-route="Form/Publish/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
}
} ,
onload : function ( frm ) {
// if (frm.doc.status = "Published" && frm.doc.publish_module != 'Automotive System') {
// frm.set_df_property('repair_checksheet_publish', 'hidden', 0)
// frm.refresh_field('repair_checksheet_publish')
// }
$ ( document ) . on ( 'mouseover' , function ( events ) {
$ ( "a:contains(Copy to Clipboard)" ) . css ( { 'pointer-events' : 'none' } ) ,
$ ( "a:contains(Duplicate)" ) . css ( { 'pointer-events' : 'none' } ) ;
@ -49,266 +53,330 @@ frappe.ui.form.on('Publish', {
} ,
refresh : function ( frm ) {
cur_frm . set_df_property ( 'system_mapping' , "read_only" , 1 ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . system_mapping . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
if ( frm . doc . docstatus == 0 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" ) {
$ ( '[data-route="Form/Publish/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Internal Publish" )
}
if ( frm . doc . docstatus == 0 && frm . doc . publish_type == "Global" ) {
$ ( '[data-route="Form/Publish/' + frm . doc . name + '"]' ) . find ( '.primary-action' ) . html ( "Global Publish" )
}
if ( frm . doc . publish_module == 'Automotive System' ) {
cur_frm . set_df_property ( 'system_mapping' , "read_only" , 1 ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'system_mapping' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . system_mapping . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . variant_mapping_assets . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-all-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete_all_rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-move-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . publish_documents . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
document . querySelectorAll ( "[data-fieldname='km_report']" ) [ 1 ] . style . backgroundColor = "#e31a37" ;
document . querySelectorAll ( "[data-fieldname='km_report']" ) [ 1 ] . style . color = "#FFFFFF" ;
document . querySelectorAll ( "[data-fieldname='add_variant_mapping_to_publish']" ) [ 1 ] . style . backgroundColor = "#e31a37" ;
document . querySelectorAll ( "[data-fieldname='add_variant_mapping_to_publish']" ) [ 1 ] . style . color = "#FFFFFF" ;
if ( frm . doc . docstatus === 1 && frm . doc . publish_type == "Internal" && frm . doc . publish_status == 'Published' && ! frm . doc . global_publish && frappe . user . has_role ( '_Publisher' ) ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.max_publish" ,
args : {
"doc" : frm . doc . name ,
} ,
callback : function ( r ) {
if ( r . message ) {
if ( r . message == frm . doc . version ) {
frm . add_custom_button ( __ ( 'Global Publish' ) , function ( ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.global_publish" ,
args : {
"doc" : frm . doc . name ,
} ,
callback : function ( r ) {
cur_frm . reload_doc ( ) ;
}
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
}
}
}
} )
}
if ( frm . doc . docstatus === 1 && frm . doc . publish_status == 'To Publish' && frappe . user . has_role ( '_Publisher' ) && frm . doc . publish_module == 'Automotive System' ) {
frm . add_custom_button ( __ ( 'Publish' ) , function ( ) {
frappe . confirm ( 'Are you sure you want to Publish?' ,
( ) => {
// action to perform if Yes is selected
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type && frm . doc . publish_module == 'Automotive System' ) {
debugger
frappe . call ( {
method : 'smart_service.transactions.doctype.publish.publish.cal_ver' ,
args : {
vehicle : frm . doc . vehicle ,
lang : frm . doc . language ,
publish_type : frm . doc . publish_type ,
doc : frm . doc . name
} ,
callback : ( r ) => {
debugger
frm . set_value ( 'version' , r . message ) ;
cur_frm . refresh_field ( 'version' )
if ( frm . doc . docstatus === 1 && frm . doc . publish_status == 'To Publish' ) {
frappe . call ( {
// method: "smart_service.apis.publish_api.api_procedure",
method : "smart_service.apis.publish_api.new_publish" ,
args : {
"args" : frm . doc . name ,
"publish_type" : frm . doc . publish_type ,
"vehicle" : frm . doc . vehicle ,
"language" : frm . doc . language ,
"version" : frm . doc . version
} ,
callback : function ( r ) {
// if (r.message[0]) {
frm . set_value ( 'publish_status' , 'Published' ) ;
frm . page . clear_primary_action ( "Publish" ) ;
frm . set_value ( 'actual_published_date' , frappe . datetime . nowdate ( ) ) ;
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.update_procedure_value" ,
args : {
"name" : frm . doc . name ,
"file_path" : r . message [ 1 ] ,
} ,
callback : ( r ) => {
// frm.save('Update');
}
} )
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
message : __ ( '<b>Successfully Published:</b> ' + r . message [ 1 ] ) ,
primary_action : {
action ( values ) {
frm . save ( 'Update' ) ;
}
}
} ) ;
// }
// else {
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Not Successfully Published:</b> ' + r.message[1]),
// // primary_action: {
// // action(values) {
// // frm.save('Update');
// // }
// // }
// });
// }
// if (r.message != "Failed to save file") {
// frm.set_value('publish_status', 'Published');
// frm.set_value('actual_published_date', frappe.datetime.nowdate());
// frappe.call({
// method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
// args: {
// "name": frm.doc.name,
// "file_path": r.message,
// },
// callback: (r) => {
// // frm.save('Update');
// }
// })
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Successfully Published:</b> ' + r.message),
// primary_action: {
// action(values) {
// frm.save('Update');
// }
// }
// });
// } else {
// frappe.msgprint('Publish Failed')
// }
}
} ) ;
}
} ,
} )
}
} , ( ) => {
// action to perform if No is selected
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
} else if ( frm . doc . publish_status == 'Published' ) {
frm . set_read_only ( ) ;
frm . set_df_property ( 'add_variant_mapping_to_publish' , 'hidden' , 1 ) ;
}
if ( frm . doc . docstatus === 0 && frm . doc . publish_status == 'To Publish' ) {
frm . get_field ( 'system_mapping' ) . grid . add_custom_button ( __ ( 'Add to Publish' ) , function ( ) {
let added = 0 ;
let topublish = [ ] ;
if ( frm . doc . publish_type == 'Global' ) { topublish = [ 'Publish Ready' ] ; } else { topublish = [ 'Review Pending' , 'Publish Ready' , 'Approval Pending' ] ; }
frm . doc . system_mapping . forEach ( row => {
if ( topublish . indexOf ( row . procedure_status ) > - 1 ) {
let dulicate = false ;
if ( frm . doc . publish_documents ) {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping &&
row . systems == publishrow . system &&
row . sub_systems == publishrow . sub_system && row . procedure == publishrow . procedure_link ) {
dulicate = true ;
}
} ) ;
}
if ( dulicate === false ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . system = row . systems ;
child . sub_system = row . sub_systems ;
child . procedure_link = row . procedure ;
child . procedure_status = row . procedure_status ;
child . update_procedure_status = row . procedure_status ;
child . item_category = "System Mapping" ;
child . variant = frm . doc . variant ;
refresh_field ( "publish_documents" ) ;
added += 1 ;
}
}
} ) ;
if ( added ) { frappe . msgprint ( __ ( added + " Doc(s) Added" ) ) ; }
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
} ) ;
frm . fields_dict . system_mapping . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'variant_mapping_assets' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . variant_mapping_assets . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-add-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-upload' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-all-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-remove-rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-delete_all_rows' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-move-row' ) . hide ( ) ;
cur_frm . fields_dict [ 'publish_documents' ] . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
frm . fields_dict . publish_documents . grid . wrapper . find ( '.grid-append-row' ) . hide ( ) ;
document . querySelectorAll ( "[data-fieldname='km_report']" ) [ 1 ] . style . backgroundColor = "#e31a37" ;
document . querySelectorAll ( "[data-fieldname='km_report']" ) [ 1 ] . style . color = "#FFFFFF" ;
document . querySelectorAll ( "[data-fieldname='add_variant_mapping_to_publish']" ) [ 1 ] . style . backgroundColor = "#e31a37" ;
document . querySelectorAll ( "[data-fieldname='add_variant_mapping_to_publish']" ) [ 1 ] . style . color = "#FFFFFF" ;
if ( frm . doc . docstatus === 1 && frm . doc . publish_type == "Internal" && frm . doc . publish_status == 'Published' && ! frm . doc . global_publish && frappe . user . has_role ( '_Publisher' ) ) {
}
if ( frm . doc . docstatus === 0 && frm . doc . publish_status == 'To Publish' ) {
frm . get_field ( 'variant_mapping_assets' ) . grid . add_custom_button ( __ ( 'Add to Publish' ) , function ( ) {
let added = 0 ;
frm . doc . variant_mapping_assets . forEach ( row => {
if ( row . active_status == "Active" || row . active_status == "Inactive" ) {
let dulicate = false ;
if ( frm . doc . publish_documents ) {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping &&
row . category == publishrow . asset_category && row . attach_file == publishrow . attach_file ) {
dulicate = true ;
}
} ) ;
}
if ( dulicate === false ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . asset_category = row . category ;
child . item_category = "Variant Mapping Assets" ;
child . variant = frm . doc . variant ;
child . attach_file = row . attach_file ;
refresh_field ( "publish_documents" ) ;
added += 1 ;
}
}
} ) ;
if ( added ) { frappe . msgprint ( __ ( added + " Doc(s) Added" ) ) ; }
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
} ) ;
frm . fields_dict . variant_mapping_assets . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
}
if ( frm . doc . docstatus == 1 ) {
$ ( ".grid-buttons" ) . hide ( ) ;
}
}
if ( frm . doc . docstatus == 1 && ! frm . is_new ( ) && frm . doc . publish_type != "Global" && frm . doc . publish_module != 'Automotive System' ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.max_publish" ,
method : "smart_service.transactions.doctype.publish.publish.max_publish_new_module " ,
args : {
"doc" : frm . doc . name ,
} ,
callback : function ( r ) {
debugger
if ( r . message ) {
if ( r . message == frm . doc . version ) {
debugger
if ( r . message ) {
frm . add_custom_button ( __ ( 'Global Publish' ) , function ( ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.global_publish" ,
method : "smart_service.transactions.doctype.publish.publish.generate_g lobal_publish" ,
args : {
"doc" : frm . doc . name ,
name : frm . doc . name
} ,
callback : function ( r ) {
cur_frm . reload_doc ( ) ;
if ( r . message . status == "success" ) {
window . location . href = r . message . url + "/app/publish" + "/" + r . message . message
}
}
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
} )
} ) . addClass ( "btn-primary" ) ;
}
}
}
} )
}
if ( frm . doc . docstatus === 1 && frm . doc . publish_status == 'To Publish' && frappe . user . has_role ( '_Publisher' ) ) {
frm . add_custom_button ( __ ( 'Publish' ) , function ( ) {
frappe . confirm ( 'Are you sure you want to Publish?' ,
( ) => {
// action to perform if Yes is selected
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type ) {
frappe . call ( {
method : 'smart_service.transactions.doctype.publish.publish.cal_ver' ,
args : {
vehicle : frm . doc . vehicle ,
lang : frm . doc . language ,
publish_type : frm . doc . publish_type ,
doc : frm . doc . name
} ,
callback : ( r ) => {
frm . set_value ( 'version' , r . message ) ;
cur_frm . refresh_field ( 'version' )
if ( frm . doc . docstatus === 1 && frm . doc . publish_status == 'To Publish' ) {
frappe . call ( {
// method: "smart_service.apis.publish_api.api_procedure",
method : "smart_service.apis.publish_api.new_publish" ,
args : {
"args" : frm . doc . name ,
"publish_type" : frm . doc . publish_type ,
"vehicle" : frm . doc . vehicle ,
"language" : frm . doc . language ,
"version" : frm . doc . version
} ,
callback : function ( r ) {
// if (r.message[0]) {
frm . set_value ( 'publish_status' , 'Published' ) ;
frm . page . clear_primary_action ( "Publish" ) ;
frm . set_value ( 'actual_published_date' , frappe . datetime . nowdate ( ) ) ;
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.update_procedure_value" ,
args : {
"name" : frm . doc . name ,
"file_path" : r . message [ 1 ] ,
} ,
callback : ( r ) => {
// frm.save('Update');
}
} )
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
message : __ ( '<b>Successfully Published:</b> ' + r . message [ 1 ] ) ,
primary_action : {
action ( values ) {
frm . save ( 'Update' ) ;
}
}
} ) ;
// }
// else {
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Not Successfully Published:</b> ' + r.message[1]),
// // primary_action: {
// // action(values) {
// // frm.save('Update');
// // }
// // }
// });
// }
// if (r.message != "Failed to save file") {
// frm.set_value('publish_status', 'Published');
// frm.set_value('actual_published_date', frappe.datetime.nowdate());
// frappe.call({
// method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
// args: {
// "name": frm.doc.name,
// "file_path": r.message,
// },
// callback: (r) => {
// // frm.save('Update');
// }
// })
// frappe.msgprint({
// title: __('Notification'),
// message: __('<b>Successfully Published:</b> ' + r.message),
// primary_action: {
// action(values) {
// frm.save('Update');
// }
// }
// });
// } else {
// frappe.msgprint('Publish Failed')
// }
}
} ) ;
}
} ,
} )
}
} , ( ) => {
// action to perform if No is selected
} ) ;
} ) . addClass ( "btn-warning" ) . css ( { 'background-color' : '#f5b0cd' , 'color' : 'black' } ) ;
} else if ( frm . doc . publish_status == 'Published' ) {
frm . set_read_only ( ) ;
frm . set_df_property ( 'add_variant_mapping_to_publish' , 'hidden' , 1 ) ;
}
if ( frm . doc . docstatus === 0 && frm . doc . publish_status == 'To Publish' ) {
frm . get_field ( 'system_mapping' ) . grid . add_custom_button ( __ ( 'Add to Publish' ) , function ( ) {
let added = 0 ;
let topublish = [ ] ;
if ( frm . doc . publish_type == 'Global' ) { topublish = [ 'Publish Ready' ] ; } else { topublish = [ 'Review Pending' , 'Publish Ready' , 'Approval Pending' ] ; }
frm . doc . system_mapping . forEach ( row => {
if ( topublish . indexOf ( row . procedure_status ) > - 1 ) {
let dulicate = false ;
if ( frm . doc . publish_documents ) {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping &&
row . systems == publishrow . system &&
row . sub_systems == publishrow . sub_system && row . procedure == publishrow . procedure_link ) {
dulicate = true ;
}
} ) ;
}
if ( dulicate === false ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . system = row . systems ;
child . sub_system = row . sub_systems ;
child . procedure_link = row . procedure ;
child . procedure_status = row . procedure_status ;
child . update_procedure_status = row . procedure_status ;
child . item_category = "System Mapping" ;
child . variant = frm . doc . variant ;
refresh_field ( "publish_documents" ) ;
added += 1 ;
}
}
} ) ;
if ( added ) { frappe . msgprint ( __ ( added + " Doc(s) Added" ) ) ; }
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
} ) ;
frm . fields_dict . system_mapping . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
} ,
validate : function ( frm ) {
if ( frm . doc . publish_module == 'Automotive System' ) {
let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/ ;
if ( regex . test ( frm . doc . release_description ) === true ) {
frm . doc . release_description = '' ;
frm . refresh_fields ( ) ;
frappe . msgprint ( __ ( "<b>Publish Description:</b> Only letters, numbers and <b> / - () & , ' : </b> are allowed." ) ) ;
}
}
if ( frm . doc . docstatus === 0 && frm . doc . publish_status == 'To Publish' ) {
frm . get_field ( 'variant_mapping_assets' ) . grid . add_custom_button ( __ ( 'Add to Publish' ) , function ( ) {
let added = 0 ;
frm . doc . variant_mapping_assets . forEach ( row => {
if ( row . active_status == "Active" || row . active_status == "Inactive" ) {
let dulicate = false ;
if ( frm . doc . publish_documents ) {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping &&
row . category == publishrow . asset_category && row . attach_file == publishrow . attach_file ) {
dulicate = true ;
}
} ) ;
}
if ( dulicate === false ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . asset_category = row . category ;
child . item_category = "Variant Mapping Assets" ;
child . variant = frm . doc . variant ;
child . attach_file = row . attach_file ;
refresh_field ( "publish_documents" ) ;
added += 1 ;
}
}
} ) ;
if ( added ) { frappe . msgprint ( __ ( added + " Doc(s) Added" ) ) ; }
else { frappe . msgprint ( __ ( "No Doc Added" ) ) ; }
} ) ;
if ( frm . doc . vehicle && frm . doc . release_description && frm . fields_dict . publish_documents . grid . grid_rows . length === 0 ) {
frappe . msgprint ( __ ( "No item selected to Publish" ) ) ;
frappe . validated = false ;
}
if ( frm . doc . planned_publish_date < frappe . datetime . get_today ( ) ) {
frappe . msgprint ( __ ( "<b>Planned Publish Date:</b> You can not select past date" ) ) ;
frappe . validated = false ;
}
frm . fields_dict . variant_mapping_assets . grid . grid_buttons . find ( '.btn-custom' ) . removeClass ( 'btn-default' ) . addClass ( 'btn-primary' ) ;
}
if ( frm . doc . docstatus == 1 ) {
$ ( ".grid-buttons" ) . hide ( ) ;
//check for atleast one data to publish
if ( frm . doc . publish_module != 'Automotive System' && ! frm . doc . hasOwnProperty ( 'repair_checksheet_publish' ) && ! frm . doc . hasOwnProperty ( 'feature_finder_publish' ) ) {
frappe . throw ( 'No Data Found To Publish' )
}
} ,
validate : function ( frm ) {
let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/ ;
if ( regex . test ( frm . doc . release_description ) === true ) {
frm . doc . release_description = '' ;
frm . refresh_fields ( ) ;
frappe . msgprint ( __ ( "<b>Publish Description:</b> Only letters, numbers and <b> / - () & , ' : </b> are allowed." ) ) ;
}
if ( frm . doc . vehicle && frm . doc . release_description && frm . fields_dict . publish_documents . grid . grid_rows . length === 0 ) {
frappe . msgprint ( __ ( "No item selected to Publish" ) ) ;
frappe . validated = false ;
}
if ( frm . doc . planned_publish_date < frappe . datetime . get_today ( ) ) {
frappe . msgprint ( __ ( "<b>Planned Publish Date:</b> You can not select past date" ) ) ;
frappe . validated = false ;
}
} ,
variant_mapping : function ( frm ) {
frappe . db . get_value ( 'Variant Mapping' , { name : frm . doc . variant_mapping } , [ 'fuel' , 'transmission' , 'drive' ] , ( r ) => {
frm . doc . variant = r . fuel + ',' + r . transmission + ',' + r . drive ;
cur_frm . refresh_field ( 'variant' ) ;
} )
if ( frm . doc . publish_module == 'Feature Finder' ) {
add_feature_finder ( frm )
}
let km_name = frm . doc . variant_mapping + "-" + frm . doc . language + "-KM" ;
frappe . db . get_value ( 'Kilometer Mapping' , { name : km_name } , 'workflow_state' , ( r ) => {
@ -342,7 +410,7 @@ frappe.ui.form.on('Publish', {
} ,
km_active_status : function ( frm ) {
if ( frm . doc . variant_mapping ) {
if ( frm . doc . variant_mapping && frm . doc . publish_module == 'Automotive System' ) {
frappe . show_alert ( {
message : __ ( 'Please wait until variant mapping details are loaded.' ) ,
indicator : 'yellow'
@ -350,7 +418,7 @@ frappe.ui.form.on('Publish', {
}
if ( frm . doc . km_active_status === "" || frm . doc . km_active_status === null ) { return ; }
let filter = frm . doc . variant_mapping + "-" + frm . doc . language + "-SM" ;
if ( frm . doc . variant_mapping_status == "Active" && frm . doc . km_active_status == "Active" ) {
if ( frm . doc . variant_mapping_status == "Active" && frm . doc . km_active_status == "Active" && frm . doc . publish_module == 'Automotive System' ) {
frappe . call ( {
"method" : "smart_service.transactions.doctype.publish.publish.get_system" ,
"args" : {
@ -423,7 +491,7 @@ frappe.ui.form.on('Publish', {
} )
} else {
if ( frm . doc . variant_mapping_status ) {
if ( frm . doc . variant_mapping_status && frm . doc . publish_module == 'Automotive System' ) {
frappe . msgprint ( {
title : __ ( 'Notification' ) ,
indicator : 'red' ,
@ -434,7 +502,7 @@ frappe.ui.form.on('Publish', {
} ,
add_variant_mapping_to_publish : function ( frm ) {
let dulicate = false ;
if ( frm . doc . publish_documents ) {
if ( frm . doc . publish_documents && frm . doc . publish_module == 'Automotive System' ) {
frm . doc . publish_documents . forEach ( publishrow => {
if ( frm . doc . variant_mapping == publishrow . variant_mapping && publishrow . systems === undefined && publishrow . sub_systems === undefined && publishrow . procedure === undefined ) {
dulicate = true ;
@ -442,7 +510,7 @@ frappe.ui.form.on('Publish', {
} ) ;
frappe . msgprint ( "Variant Mapping already added" ) ;
}
if ( dulicate === false ) {
if ( dulicate === false && frm . doc . publish_module == 'Automotive System' ) {
let child = cur_frm . add_child ( "publish_documents" ) ;
child . variant_mapping = frm . doc . variant_mapping ;
child . item_category = "Variant Mapping" ;
@ -453,8 +521,15 @@ frappe.ui.form.on('Publish', {
km_report : function ( frm , cdt , cdn ) {
frappe . set_route ( "query-report" , 'Kilometer Mapping' , { 'kilometer_mapping' : frm . doc . kilometer_mapping } ) ;
} ,
after_save : function ( frm ) {
frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
frm . refresh_field ( 'repair_checksheet_publish' )
} ,
vehicle : function ( frm ) {
if ( frm . doc . publish_module == 'Automotive System' ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.old_publish" ,
async : false ,
@ -473,15 +548,56 @@ frappe.ui.form.on('Publish', {
}
}
} ) ;
}
if ( frm . doc . publish_module == 'Repair service' ) {
if ( frm . doc . vehicle === undefined || frm . doc . vehicle === null ) { return ; }
add_to_publish ( frm )
}
if ( frm . doc . vehicle === undefined || frm . doc . vehicle === null && frm . doc . publish_module == 'Automotive System' ) { return ; }
$ ( "[data-fieldname=variant_mapping]" ) . focus ( ) ;
if ( frm . doc . vehicle ) {
frm . set_df_property ( 'vehicle' , 'read_only' , 1 ) ;
}
//other modules-Repair Checksheet
if ( frm . doc . publish_module == 'Repair service' ) {
if ( frm . doc . repair_checksheet_publish && frm . doc . repair_checksheet_publish . length > 0 ) {
content_flag = 1
cur_frm . clear_table ( "repair_checksheet_publish" ) ;
cur_frm . refresh_fields ( 'repair_checksheet_publish' ) ;
}
}
} ,
language : function ( frm ) {
if ( ! lang_set_first_time ) {
if ( frm . doc . publish_module == 'Repair service' ) {
if ( frm . doc . repair_checksheet_publish && frm . doc . repair_checksheet_publish . length > 0 ) {
cur_frm . clear_table ( "repair_checksheet_publish" ) ;
cur_frm . refresh_fields ( 'repair_checksheet_publish' ) ;
}
add_to_publish ( frm )
}
if ( frm . doc . publish_module == 'Feature Finder' ) {
if ( frm . doc . feature_finder_publish && frm . doc . feature_finder_publish . length > 0 ) {
cur_frm . clear_table ( "feature_finder_publish" ) ;
cur_frm . refresh_fields ( 'feature_finder_publish' ) ;
}
add_feature_finder ( frm )
}
if ( ! lang_set_first_time && frm . doc . publish_module == 'Automotive System' ) {
frappe . confirm ( 'This will clear all the data, are you sure you want to proceed?' ,
( ) => {
// action to perform if Yes is selected
@ -494,10 +610,36 @@ frappe.ui.form.on('Publish', {
} , ( ) => {
// action to perform if No is selected
} ) ;
} else { lang_set_first_time = false ; }
}
if ( ! lang_set_first_time && frm . doc . publish_module == 'Repair service' ) {
frappe . confirm ( 'This will clear all the data, are you sure you want to proceed?' ,
( ) => {
// action to perform if Yes is selected
frm . set_value ( 'feature_finder_publish' , null ) ;
lang_set_first_time = false ;
} , ( ) => {
// action to perform if No is selected
} ) ;
}
if ( ! lang_set_first_time && frm . doc . publish_module == 'Feature Finder' ) {
frappe . confirm ( 'This will clear all the data, are you sure you want to proceed?' ,
( ) => {
// action to perform if Yes is selected
frm . set_value ( 'feature_finder_publish' , null ) ;
frm . set_value ( 'variant_mapping' , '' )
lang_set_first_time = false ;
} , ( ) => {
// action to perform if No is selected
} ) ;
}
else { lang_set_first_time = false ; }
} ,
auto_version_update : function ( frm ) {
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type ) {
if ( frm . doc . vehicle && frm . doc . language && frm . doc . publish_type && frm . doc . publish_module == 'Automotive System' ) {
frappe . call ( {
method : 'smart_service.transactions.doctype.publish.publish.cal_ver' ,
args : {
@ -515,7 +657,11 @@ frappe.ui.form.on('Publish', {
}
} ) ;
}
} ,
else {
}
}
} ) ;
frappe . ui . form . on ( 'Publish_Temp Doc' , {
@ -528,3 +674,66 @@ frappe.ui.form.on('Publish_Temp Doc', {
frm . fields_dict . system_mapping . grid . wrapper . find ( '.grid-insert-row' ) . hide ( ) ;
} ,
} )
function add_to_publish ( frm ) {
if ( frm . doc . vehicle ) {
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.get_service_repair" ,
args : { vehicle : frm . doc . vehicle , language_label : frm . doc . language , publish_type : frm . doc . publish_type } ,
callback : function ( r ) {
debugger
if ( r . message . length > 0 ) {
var records = r . message
records . map ( v => {
var childTable = cur_frm . add_child ( "repair_checksheet_publish" ) ;
childTable . parent_name = v [ 'name' ] ;
childTable . vehicle = v [ 'vehicle' ] ;
childTable . language = v [ 'language' ] ;
childTable . lang_myid = v [ 'lang_myid' ] ;
childTable . display_order = v [ 'display_order' ] ;
childTable . check_list_name = v [ 'check_list_name' ] ;
childTable . active_status = v [ 'active_status' ] ;
childTable . my_id = v [ 'my_id' ] ;
childTable . lang_myid = v [ 'lang_myid' ] ;
} )
cur_frm . set_df_property ( 'repair_checksheet_publish' , 'hidden' , 0 )
cur_frm . refresh_field ( "repair_checksheet_publish" ) ;
}
}
} )
}
}
function add_feature_finder ( frm ) {
debugger
frappe . call ( {
method : "smart_service.transactions.doctype.publish.publish.get_feature_finder" ,
args : { vehicle : frm . doc . vehicle , variant : frm . doc . variant_mapping , language_label : frm . doc . language , publish_type : frm . doc . publish_type } ,
callback : function ( r ) {
debugger
if ( r . message . length > 0 ) {
cur_frm . set_df_property ( 'feature_finder_publish' , 'hidden' , 0 )
var records = r . message
records . map ( v => {
var childTable = cur_frm . add_child ( "feature_finder_publish" ) ;
childTable . parent1 = v [ 'name' ] ;
childTable . vehicle = v [ 'vehicle' ] ;
childTable . language = v [ 'language' ] ;
childTable . variant = v [ 'variant' ] ;
childTable . active_status = v [ 'active_status' ] ;
} )
cur_frm . refresh_field ( "feature_finder_publish" ) ;
}
}
} )
}