@ -9,39 +9,76 @@ frappe.ui.form.on('Feature Finder', {
refresh : function ( frm ) {
// filter_value = "SOP"
// set_default_tab(frm,filter_value)
setTimeout ( function mysam ( ) {
if ( ! frm . doc . feature_finder_images ) {
console . log ( "calling 1" )
$ ( cur_frm . fields_dict . image_html . wrapper ) . empty ( ) ;
}
if ( ! frm . is_new ( ) ) {
custom_tab_html ( frm )
}
} , 2000 )
set_display_order ( frm )
show_images ( frm )
// show_images(frm)
} ,
onload : function ( frm ) {
// filter_value = "SOP"
// set_default_tab(frm,filter_value)
setTimeout ( function mysam ( ) {
if ( ! frm . doc . feature_finder_images ) {
console . log ( "calling 1" )
$ ( cur_frm . fields_dict . image_html . wrapper ) . empty ( ) ;
}
if ( ! frm . is_new ( ) ) {
custom_tab_html ( frm )
}
} , 2000 )
set_display_order ( frm )
show_images ( frm )
// show_images(frm)
} ,
variant : function ( frm ) {
frm . doc . features_names = ""
frm . doc . feature_name = ""
cur_frm . refresh_fields ( "features_names" )
cur_frm . refresh_fields ( "feature_name" )
if ( frm . doc . variant ) {
frm . toggle_display ( 'feature_name' , true )
frm . toggle_display ( 'features_names' , true )
} else
{
frm . toggle_display ( 'features_names' , false )
frm . toggle_display ( 'feature_name' , false )
}
set_display_order ( frm )
} ,
features_names : function ( frm ) {
if ( frm . doc . features_names ) {
frappe . db . get_list ( 'Feature Finder Master' , {
fields : [ 'name' ] ,
filters : {
feature_name : frm . doc . feature_name ,
feature_name : frm . doc . features _names ,
vehicle : frm . doc . vehicle
}
} ) . then ( records => {
console . log ( records )
if ( records . length > 0 ) {
frm . doc . feature_name = records [ 0 ] . name
cur_frm . refresh_fields ( "feature_name" )
} else {
frm . doc . feature_name = ""
cur_frm . refresh_fields ( "feature_name" )
}
} )
}
} ,
create_feature_finder_images : function ( frm ) {
if ( click_count == 0 ) {
@ -54,12 +91,27 @@ frappe.ui.form.on('Feature Finder', {
}
} ,
language : function ( frm ) {
console . log ( 'Language trigger' ) ;
if ( frm . doc . language == "en" ) {
frm . toggle_display ( 'translated_feature_name' , false )
frm . doc . translated_feature_name = ""
cur_frm . refresh_fields ( "translated_feature_name" )
} else {
frm . toggle_display ( 'translated_feature_name' , true )
frappe . call ( {
method : "smart_service.phase_2.doctype.feature_finder.feature_finder.get_feature_list" ,
args : {
vehicle : frm . doc . vehicle ,
language : frm . doc . language
} ,
callback : function ( r ) {
console . log ( r . message )
frm . set_df_property ( 'features_names' , 'options' , r . message ) ;
frm . refresh_field ( 'features_names' )
}
} )
}
} ,
// feature_type: function (frm) {
@ -113,18 +165,20 @@ frappe.ui.form.on('Feature Finder', {
frm . reload_doc ( )
}
} ) ;
function show_images ( frm ) {
var res = $ ( cur_frm . fields_dict . image_html . wrapper ) . empty ( ) ;
if ( cur_frm . doc . feature_finder_images && cur_frm . doc . feature_finder_images . length > 0 ) {
var img_html = ""
img_html += "<div style='height: 300px;overflow-y: auto;overflow-x: hidden;border:1px solid var(--table-border-color);margin: 5px 0px 10px 0px;'><div style='padding: 5px;' class='row'>"
cur_frm . doc . feature_finder_images . forEach ( ( val ) =>
img_html += "<div class='col-3' style='padding-top:13px;'><img src=" + "'" + val . image + "'" + "></div>"
) ;
img_html += "</div></div>"
$ ( res ) . append ( img_html )
}
}
// function show_images(frm) {
// var res = $(cur_frm.fields_dict.image_html.wrapper).empty();
// if (cur_frm.doc.feature_finder_images && cur_frm.doc.feature_finder_images.length > 0) {
// var img_html = ""
// img_html += "<div style='height: 300px;overflow-y: auto;overflow-x: hidden;border:1px solid var(--table-border-color);margin: 5px 0px 10px 0px;'><div style='padding: 5px;' class='row'>"
// cur_frm.doc.feature_finder_images.forEach((val) =>
// img_html += "<div class='col-3' style='padding-top:13px;'><img src=" + "'" + val.image + "'" + "></div>"
// );
// img_html += "</div></div>"
// $(res).append(img_html)
// }
// }
function custom_tab_html ( frm ) {
// $('[data-fieldname="specification"]').show()
@ -155,10 +209,11 @@ function custom_tab_html(frm){
var res = $ ( cur_frm . fields_dict . test_html . wrapper ) . empty ( ) ;
var ret = '<div class="main"><div class="custom_tab style="border:1px solid var(--table-border-color);"><ul class="nav nav-tabs" role="tablist">'
if ( frm . doc . post_vin_cutoff_id_tab . length > 0 ) {
ret += '<li class="nav-item">'
ret += '<a class="nav-link active" id="SOP" data-toggle="tab" role="tab" value="SOP">SOP</a>'
ret += '</li>'
if ( frm . doc . post_vin_cutoff_id_tab && frm . doc . post_vin_cutoff_id_tab . length > 0 ) {
frm . doc . post_vin_cutoff_id_tab . map ( val => {
ret += '<li class="nav-item">'
ret += '<a class="nav-link" id="' + val . post_vin_cutoff_name + '" value=' + val . post_vin_cutoff_name + ' data-toggle="tab" role="tab">PV-' + val . post_vin_cutoff_name + '</a>'
@ -181,16 +236,25 @@ function custom_tab_html(frm){
var specification = ""
var feature_finder_images = ""
var feature_finder_content = ""
if ( frm . doc . specification && frm . doc . feature_finder_images && frm . doc . feature_finder_content ) {
specification = frm . doc . specification . filter ( o => o . feature_type == "SOP" )
feature_finder_images = frm . doc . feature_finder_images . filter ( o => o . feature_type == "SOP" )
feature_finder_content = frm . doc . feature_finder_content . filter ( o => o . feature_type == "SOP" )
specification . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_images . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_content . sort ( ( a , b ) => a . display_order - b . display_order ) ;
}
var spec_dialog_value = ""
var image_dialog_value = ""
var content_dialog_value = ""
var nav_spec = { }
nav_spec . feature_type = "SOP"
all_tabs ( )
show_images ( )
$ ( '.main' ) . find ( '.nav-link' ) . click ( function ( event ) {
console . log ( $ ( this ) [ 0 ] . id )
@ -200,6 +264,11 @@ function custom_tab_html(frm){
specification = frm . doc . specification . filter ( o => o . feature_type == $ ( this ) [ 0 ] . id )
feature_finder_images = frm . doc . feature_finder_images . filter ( o => o . feature_type == $ ( this ) [ 0 ] . id )
feature_finder_content = frm . doc . feature_finder_content . filter ( o => o . feature_type == $ ( this ) [ 0 ] . id )
specification . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_images . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_content . sort ( ( a , b ) => a . display_order - b . display_order ) ;
}
else {
nav_spec . feature_type = "Post Vin CutOff"
@ -208,13 +277,32 @@ function custom_tab_html(frm){
feature_finder_images = frm . doc . feature_finder_images . filter ( o => o . post_vin_cutoff_name == $ ( this ) [ 0 ] . id )
console . log ( feature_finder_images , "---feature_finder_images" )
feature_finder_content = frm . doc . feature_finder_content . filter ( o => o . post_vin_cutoff_name == $ ( this ) [ 0 ] . id )
specification . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_images . sort ( ( a , b ) => a . display_order - b . display_order ) ;
feature_finder_content . sort ( ( a , b ) => a . display_order - b . display_order ) ;
}
all_tabs ( )
show_images ( )
} )
function show_images ( frm ) {
var res = $ ( cur_frm . fields_dict . image_html . wrapper ) . empty ( ) ;
if ( feature_finder_images . length > 0 ) {
var img_html = ""
img_html += "<div style='height: 300px;overflow-y: auto;overflow-x: hidden;border:1px solid var(--table-border-color);margin: 5px 0px 10px 0px;'><div style='padding: 5px;' class='row'>"
feature_finder_images . forEach ( ( val ) =>
img_html += "<div class='col-3' style='padding-top:13px;'><img src=" + "'" + val . image + "'" + "></div>"
) ;
img_html += "</div></div>"
$ ( res ) . append ( img_html )
}
}
function all_tabs ( ) {
@ -278,9 +366,9 @@ function custom_tab_html(frm){
if ( specification . length > 0 ) {
specification . map ( val => {
specification_count += 1
// spec_custom_dt += '<tr draggable="true" ondragstart="dragstartFunction(event)" ondragover="dragovertFunction(event)">'
spec_custom_dt += '<tr>'
spec_custom_dt += '<td style="width: 7%;" id="count"><input id=' + val . name + ' type="checkbox" class="speccheck grid-row-check pull-left"><span class="spec_check">' + specification_count + '</span></td>'
spec_custom_dt += '<tr id=' + val . name + ' draggable="true" ondragstart="dragstartFunction(event)" ondragover="dragovertFunction(event)">'
// spec_custom_dt += '<tr>'
spec_custom_dt += '<td style="width: 7%;" id="spec_ count"><input id=' + val . name + ' type="checkbox" class="speccheck grid-row-check pull-left"><span class="spec_check">' + specification_count + '</span></td>'
spec_custom_dt += '<td>' + val . specification + '</td>'
spec_custom_dt += '<td>' + val . value + '</td>'
spec_custom_dt += '<td>' + val . active_status + '</td>'
@ -305,9 +393,9 @@ function custom_tab_html(frm){
if ( feature_finder_images . length ) {
feature_finder_images . map ( val => {
image_count += 1
// spec_custom_dt += '<tr draggable="true" ondragstart="dragstartFunction(event)" ondragover="dragovertFunction(event)">'
image_custom_dt += '<tr>'
image_custom_dt += '<td style="width: 7%;" id="count"><input id=' + val . name + ' type="checkbox" class="imagecheck grid-row-check pull-left"><span class="image_check">' + image_count + '</span></td>'
image_custom_dt += '<tr id=' + val . name + ' draggable="true" ondragstart="dragstartFunction_1 (event)" ondragover="dragovertFunction_1 (event)">'
// image_custom_dt += '<tr>'
image_custom_dt += '<td style="width: 7%;" id="image_ count"><input id=' + val . name + ' type="checkbox" class="imagecheck grid-row-check pull-left"><span class="image_check">' + image_count + '</span></td>'
image_custom_dt += '<td>' + val . image + '</td>'
image_custom_dt += '<td>' + val . active_status + '</td>'
image_custom_dt += '<td>' + val . feature_type + '</td>'
@ -331,9 +419,9 @@ function custom_tab_html(frm){
if ( feature_finder_content . length ) {
feature_finder_content . map ( val => {
content_count += 1
// spec_custom_dt += '<tr draggable="true" ondragstart="dragstartFunction(event)" ondragover="dragovertFunction(event)">'
content_custom_dt += '<tr>'
content_custom_dt += '<td style="width: 7%;" id="count"><input id=' + val . name + ' type="checkbox" class="contentcheck grid-row-check pull-left"><span class="content_check">' + content_count + '</span></td>'
content_custom_dt += '<tr id=' + val . name + ' draggable="true" ondragstart="dragstartFunction_2 (event)" ondragover="dragovertFunction_2 (event)">'
// content_custom_dt += '<tr>'
content_custom_dt += '<td style="width: 7%;" id="cont_co unt"><input id=' + val . name + ' type="checkbox" class="contentcheck grid-row-check pull-left"><span class="content_check">' + content_count + '</span></td>'
content_custom_dt += '<td>' + val . content + '</td>'
content_custom_dt += '<td>' + val . active_status + '</td>'
content_custom_dt += '<td>' + val . feature_type + '</td>'
@ -392,28 +480,29 @@ function custom_tab_html(frm){
$ ( res ) . find ( '.feature_contbl' ) . empty ( )
$ ( res ) . find ( '.feature_contbl' ) . append ( content_custom_dt )
$ ( res ) . append ( ` <style>.spec_check{padding:0px 5px 0px 5px !important}.spec_custom_save{display:none}.spec_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}</style> ` )
$ ( res ) . append ( ` <style>.spec_check{padding:0px 5px 0px 5px !important}.spec_custom_save{display:none;margin:10px 0px 0px 10px;background-color:red !important;color:#fff !important; }.spec_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}</style> ` )
$ ( res ) . append ( ` <style>.image_check{padding:0px 5px 0px 5px !important}.image_custom_save{display:none}.image_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}
$ ( res ) . append ( ` <style>.image_check{padding:0px 5px 0px 5px !important}.image_custom_save{display:none;margin:10px 0px 0px 10px;background-color:red !important;color:#fff !important; }.image_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}
. image_custom_add { margin : 10 px 0 px 0 px 0 px < / s t y l e > ` )
$ ( res ) . append ( ` <style>.content_check{padding:0px 5px 0px 5px !important}.content_custom_save{display:none}.content_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}
$ ( res ) . append ( ` <style>.content_check{padding:0px 5px 0px 5px !important}.content_custom_save{display:none;margin:10px 0px 0px 10px;background-color:red !important;color:#fff !important; }.content_custom_delete{margin:10px 10px 0px 0px;background-color:red !important;color:#fff !important;display:none}
. content_custom_add { margin : 10 px 0 px 0 px 0 px < / s t y l e > ` )
//append end
//add button
$ ( res ) . find ( '.feature_imgbl' ) . find ( '.image_custom_add' ) . click ( function ( event ) {
image_dialog_value = ""
image_dialog_value = nav_spec
image_dialog_view ( )
} )
$ ( res ) . find ( '.specification_bl' ) . find ( '.spec_custom_add' ) . click ( function ( event ) {
spec_dialog_value = ""
spec_dialog_value = nav_spec
spec_dialog_view ( )
} )
$ ( res ) . find ( '.feature_imgbl' ) . find ( '.image_custom_add' ) . click ( function ( event ) {
image_dialog_value = ""
image_dialog_value = nav_spec
image_dialog_view ( )
} )
$ ( res ) . find ( '.feature_contbl' ) . find ( '.content_custom_add' ) . click ( function ( event ) {
content_dialog_value = ""
content_dialog_value = nav_spec
@ -422,6 +511,58 @@ function custom_tab_html(frm){
//end add button
//save function
$ ( res ) . find ( '.specification_bl' ) . find ( '.spec_custom_save' ) . click ( function ( event ) {
var spec_id_dis = [ ]
$ ( document ) . ready ( function ( ) {
$ ( '.specification_bl' ) . find ( 'table > tbody > tr' ) . each ( function ( index , tr ) {
spec_id_dis . push ( this . id ) ;
} ) ;
set_display_order_child ( "Feature Finder Specification" , spec_id_dis )
} )
} )
$ ( res ) . find ( '.feature_imgbl' ) . find ( '.image_custom_save' ) . click ( function ( event ) {
var image_id_dis = [ ]
$ ( document ) . ready ( function ( ) {
$ ( '.feature_imgbl' ) . find ( 'table > tbody > tr' ) . each ( function ( index , tr ) {
image_id_dis . push ( this . id ) ;
} ) ;
set_display_order_child ( "Feature Finder Images" , image_id_dis )
} )
} )
$ ( res ) . find ( '.feature_contbl' ) . find ( '.content_custom_save' ) . click ( function ( event ) {
var cont_id_dis = [ ]
$ ( document ) . ready ( function ( ) {
$ ( '.feature_contbl' ) . find ( 'table > tbody > tr' ) . each ( function ( index , tr ) {
cont_id_dis . push ( this . id ) ;
} ) ;
set_display_order_child ( "Feature Finder Content" , cont_id_dis )
} )
} )
function set_display_order_child ( doctype_name , values ) {
frappe . call ( {
method : "smart_service.phase_2.doctype.feature_finder.feature_finder.set_display_order" ,
args : {
doctype_name : doctype_name ,
values : values
} ,
callback : function ( r ) {
console . log ( r . message . status , '-rmessage' )
if ( r . message . status == "success" ) {
cur_frm . reload_doc ( )
}
}
} )
}
//end save function
//edit button
$ ( res ) . find ( '.feature_imgbl' ) . find ( '.image_edit_row' ) . click ( function ( event ) {
image_dialog_value = frm . doc . feature_finder_images . filter ( o => o . name == $ ( this ) [ 0 ] . id ) [ 0 ]
@ -713,7 +854,7 @@ function custom_tab_html(frm){
primary_action_label : 'Submit' ,
primary_action ( values ) {
console . log ( values , "values" ) ;
if ( values ) {
if ( values && values . image ) {
console . log ( values , "---values" )
frappe . call ( {
method : "smart_service.phase_2.doctype.feature_finder.feature_finder.insert_image_data" ,
@ -724,7 +865,8 @@ function custom_tab_html(frm){
callback : function ( r ) {
console . log ( r . message . status , '-rmessage' )
if ( r . message . status == "success" ) {
cur_frm . reload_doc ( )
cur_frm . refresh ( )
// cur_frm.reload_doc()
}
}
} )
@ -873,13 +1015,7 @@ function custom_tab_html(frm){
// }
function set_display_order ( frm ) {
if ( frm . doc . variant ) {
frm . toggle_display ( 'feature_name' , true )
frm . toggle_display ( 'features_names' , true )
} else {
frm . toggle_display ( 'feature_name' , false )
frm . toggle_display ( 'features_names' , false )
}
// if (frm.doc.feature_type == "Post VIN Cutoff") {
// frm.toggle_display('post_vin_cutoff_id', true)
// }
@ -887,11 +1023,12 @@ function set_display_order(frm) {
// frm.toggle_display('post_vin_cutoff_id', false)
// }
if ( frm . doc . variant && frm . doc . vehicle ) {
if ( frm . doc . variant && frm . doc . vehicle && frm . doc . language ) {
frappe . call ( {
method : "smart_service.phase_2.doctype.feature_finder.feature_finder.get_feature_list" ,
args : {
vehicle : frm . doc . vehicle
vehicle : frm . doc . vehicle ,
language : frm . doc . language
} ,
callback : function ( r ) {
frm . set_df_property ( 'features_names' , 'options' , r . message ) ;