@ -13,12 +13,13 @@ frappe.ui.form.on('Kilometer Mapping', {
} ,
} ,
onload : function ( frm ) {
onload : function ( frm ) {
$ ( document ) . on ( 'mouseover' , function ( events ) {
$ ( document ) . on ( 'mouseover' , function ( events ) {
$ ( "a:contains(Copy to Clipboard)" ) . css ( { 'pointer-events' : 'none' } ) ,
$ ( "a:contains(Copy to Clipboard)" ) . css ( { 'pointer-events' : 'none' } )
$ ( "a:contains(Duplicate)" ) . css ( { 'pointer-events' : 'none' } ) ;
$ ( "a:contains(Duplicate)" ) . css ( { 'pointer-events' : 'none' } ) ;
} ) ,
} ) ,
//IDX make read only
//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' } ) ;
$ ( '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 . 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 ;
frm . get_field ( "config_kilometer" ) . grid . df . cannot_delete_rows = true ;
frm . get_field ( "config_kilometer" ) . grid . df . cannot_delete_rows = true ;
@ -56,6 +57,7 @@ frappe.ui.form.on('Kilometer Mapping', {
} ,
} ,
validate : function ( frm ) {
validate : function ( frm ) {
frm . doc . kilometer_filter = "All" ;
frm . doc . kilometer_filter = "All" ;
if ( frm . doc . kilometer_filter == "All" ) {
if ( frm . doc . kilometer_filter == "All" ) {
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
@ -68,6 +70,65 @@ frappe.ui.form.on('Kilometer Mapping', {
} ,
} ,
refresh : function ( frm ) {
refresh : function ( frm ) {
//custom button
frm . add_custom_button ( __ ( "Duplicate Data" ) , function ( ) {
let d = new frappe . ui . Dialog ( {
title : 'Choose the variant' ,
fields : [
{
label : 'Kilometer Mapping' ,
fieldname : 'variant' ,
fieldtype : 'Link' ,
options : "Kilometer Mapping" ,
reqd : 1
}
] ,
size : 'small' ,
secondary_action_label : "No" ,
primary_action_label : 'Yes' ,
primary_action ( values ) {
console . log ( values . variant ) ;
if ( values . variant ) {
console . log ( "calling" )
cur_frm . refresh_fields ( "config_kilometer" ) ;
frappe . call ( {
"method" : "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer" ,
"args" : {
"doc" : values . variant ,
"docname" : frm . doc . name
} ,
callback : function ( r ) {
if ( r . message && r . message . length > 0 ) {
cur_frm . refresh_fields ( "config_kilometer" ) ;
frm . save ( )
frm . refresh ( )
}
}
} )
d . hide ( ) ;
}
else {
d . hide ( )
}
} ,
secondary_action ( values ) {
d . hide ( ) ;
}
} ) ;
d . show ( ) ;
setTimeout ( function mysam ( ) {
console . log ( "jiiii" , $ ( '.modal-dialog' ) . find ( '.custom-actions' ) . html ( '<p>Are you sure to update the kilometer mapping?</p>' ) )
$ ( '.modal-dialog' ) . find ( '.custom-actions' ) . html ( '<p>Are you sure to update the <b>kilometer mapping</b>?</p>' )
}
, 300 ) ;
// var res = $(d.fields_dict.content_html.wrapper).empty();
// var ret="<p>Are you sure to update the kilometer mapping ?</p>"
// res.append(ret)
} ) . css ( { "color" : "#fff" , "background-color" : "red" } ) ; ;
//end
if ( frm . doc . kilometer_filter == "All" ) {
if ( frm . doc . kilometer_filter == "All" ) {
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . fields_dict . config_kilometer . grid . grid_rows . forEach ( ( row ) => {
frm . fields_dict . config_kilometer . grid . grid_rows . forEach ( ( row ) => {
@ -133,7 +194,7 @@ frappe.ui.form.on('Kilometer Mapping', {
kilometer_set . push ( kmsrow . service_kilometers ) ;
kilometer_set . push ( kmsrow . service_kilometers ) ;
} ) ;
} ) ;
frm . set_df_property ( 'kilometer_filter' , 'options' , kilometer_set ) ;
frm . set_df_property ( 'kilometer_filter' , 'options' , kilometer_set ) ;
$ . each ( kmrecord , function ( index , kmrow ) {
$ . each ( kmrecord , function ( index , kmrow ) {
frappe . call ( {
frappe . call ( {
"method" : "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system" ,
"method" : "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_system" ,
@ -180,14 +241,14 @@ frappe.ui.form.on('Kilometer Mapping', {
} ,
} ,
kilometer_filter1 : function ( frm ) {
kilometer_filter1 : function ( frm ) {
frm . doc . duplicate_kilometer_mapping_items = '' ;
frm . doc . duplicate_kilometer_mapping_items = '' ;
frm . refresh_field ( 'duplicate_kilometer_mapping_items' ) ;
frm . refresh_field ( 'duplicate_kilometer_mapping_items' ) ;
console . log ( "call" )
console . log ( "call" )
frappe . call ( {
frappe . call ( {
"method" : "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.update_duplicate_km" ,
"method" : "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.update_duplicate_km" ,
"args" : {
"args" : {
"doc" : frm . doc . name ,
"doc" : frm . doc . name ,
"kilometer" : frm . doc . kilometer_filter
"kilometer" : frm . doc . kilometer_filter
} ,
} ,
callback : function ( r ) {
callback : function ( r ) {
cur_frm . reload_doc ( )
cur_frm . reload_doc ( )
@ -204,13 +265,13 @@ frappe.ui.form.on('Kilometer Mapping', {
}
}
if ( frm . doc . sub_system_filter == "All" && frm . doc . kilometer_filter == "All" ) {
if ( frm . doc . sub_system_filter == "All" && frm . doc . kilometer_filter == "All" ) {
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . fields_dict . config_kilometer . grid . grid_rows . forEach ( ( row ) => {
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 ( ) ;
$ ( "div[data-fieldname=config_kilometer]" ) . find ( 'div.grid-row[data-idx="' + row . doc . idx + '"]' ) . show ( ) ;
} ) ;
} ) ;
} else {
} else {
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . get_field ( 'config_kilometer' ) . grid . static_rows = false ;
frm . fields_dict . config_kilometer . grid . grid_rows . forEach ( ( row ) => {
frm . fields_dict . config_kilometer . grid . grid_rows . forEach ( ( row ) => {
if ( row . doc . kilometer == frm . doc . kilometer_filter && 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 ( ) ;
$ ( "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" ) {
} else if ( row . doc . kilometer == frm . doc . kilometer_filter && frm . doc . sub_system_filter == "All" ) {
@ -227,7 +288,7 @@ frappe.ui.form.on('Kilometer Mapping', {
sort_by_kilometer : function ( frm ) {
sort_by_kilometer : function ( frm ) {
var idx = 1 ;
var idx = 1 ;
frm . doc . config_kilometer . sort ( function ( a , b ) {
frm . doc . config_kilometer . sort ( function ( a , b ) {
if ( parseInt ( a . kilometer ) < parseInt ( b . kilometer ) ) { console . log ( a . kilometer + "inside if" + b . kilometer ) ; return - 1 }
if ( parseInt ( a . kilometer ) < parseInt ( b . kilometer ) ) { console . log ( a . kilometer + "inside if" + b . kilometer ) ; return - 1 }
else if ( parseInt ( a . kilometer ) > parseInt ( b . kilometer ) ) { console . log ( a . kilometer + "inside else if" + b . kilometer ) ; return 1 }
else if ( parseInt ( a . kilometer ) > parseInt ( b . kilometer ) ) { console . log ( a . kilometer + "inside else if" + b . kilometer ) ; return 1 }
return 1 ;
return 1 ;
} ) ;
} ) ;
@ -236,7 +297,7 @@ frappe.ui.form.on('Kilometer Mapping', {
item . idx = idx ++ ;
item . idx = idx ++ ;
} ) ;
} ) ;
if ( frm . doc . temp_field == "Set" ) { frm . set_value ( "temp_field" , "Not Set" ) ; } else { frm . set_value ( "temp_field" , "Set" ) ; }
if ( frm . doc . temp_field == "Set" ) { frm . set_value ( "temp_field" , "Not Set" ) ; } else { frm . set_value ( "temp_field" , "Set" ) ; }
refresh_field ( "config_kilometer" ) ;
refresh_field ( "config_kilometer" ) ;
}
}
} ) ;
} ) ;