Browse Source

contenty type condition added

master
Ubuntu 2 years ago
parent
commit
eb75789a88
  1. 720
      smart_service/transactions/doctype/procedure/procedure.js

720
smart_service/transactions/doctype/procedure/procedure.js

@ -2,69 +2,66 @@
// 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['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['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('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",};
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', {
onload: function (frm) {
if(frm.doc.procedure_details){
var url = window.location.host;
frappe.db.get_value('Fish', {name: "Fish"}, 'path' , (r) =>{
for (var i=0;i<frm.doc.procedure_details.length;i++){
if(frm.doc.procedure_details[i].content && r.path){
var x = "<a href=" + '"' + r.path + "://" + url + "/app/procedure/" + frm.doc.procedure_details[i].content
frm.doc.procedure_details[i].content = x + '"' + 'target="_blank"' + '>' + frm.doc.procedure_details[i].content + '</a>';
if (frm.doc.procedure_details) {
var url = window.location.host;
frappe.db.get_value('Fish', { name: "Fish" }, 'path', (r) => {
for (var i = 0; i < frm.doc.procedure_details.length; i++) {
if (frm.doc.procedure_details[i].content && r.path && frm.doc.procedure_details[i].content_type == "Link") {
var x = "<a href=" + '"' + r.path + "://" + url + "/app/procedure/" + frm.doc.procedure_details[i].content
frm.doc.procedure_details[i].content = x + '"' + 'target="_blank"' + '>' + frm.doc.procedure_details[i].content + '</a>';
}
}
}
})
})
}
if (frm.doc.workflow_state == 'Publish Ready'){
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 + "<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){
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;
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"){
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();
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show();
});
}
@ -72,10 +69,10 @@ frappe.ui.form.on('Procedure', {
},
refresh: function (frm) {
select_row(frm);
if(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();
$("div[data-fieldname=procedure_details]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show();
});
}
var previous_procedure_name = "";
@ -87,165 +84,162 @@ frappe.ui.form.on('Procedure', {
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){
if (row.doc.step_name) {
fn_addSteptolist(row.doc.step_name);
}
if (row.doc.procedure_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'});
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'});
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(){
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
);
}).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"){
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();
$("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();
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();
$("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);
})
})
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){
$("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"){
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();
$("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();
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!");
if ((frm.doc.workflow_state == 'Review Pending' || frm.doc.workflow_state == 'Publish Ready') && (frm.selected_workflow_action == 'Revoke')) {
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>";
"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()){
mat: function (frm) {
if (!frm.is_new()) {
frappe.msgprint({
title: __('Notification'),
indicator: 'green',
@ -256,283 +250,243 @@ frappe.ui.form.on('Procedure', {
});
frappe.ui.form.on('Procedure_Details', {
procedure_name: function (frm,cdt,cdn) {
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;
let value = row.doc.procedure_name;
if (value)
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){
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();
step_name: function (frm, cdt, cdn) {
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){
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){
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) {
content_type: function (frm, cdt, cdn) {
var df;
let d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
id = id - 1;
let row = frm.fields_dict.procedure_details.grid.grid_rows[id];
if (d.content_type == 'Link'){
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: 'Procedure',
fieldname: 'procedure_map',
fieldtype: 'Link',
options:'Procedure'
}
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) {
// 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>';
var content = values.procedure;
row.doc.system_id = values.variant_mapping + ',' + values.system_id + ',' + values.subsystem_id;
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.content1;
d.content = d.temp_cnt;
}
},*/
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) {
},
procedure_details_move: function (frm, cdt, cdn) {
frm.refresh();
},
procedure_details_remove: function(frm,cdt,cdn){
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){
if (row.doc.procedure_name) {
fn_addProceduretolist(row.doc.procedure_name);
}
})
frm.refresh_field('procedure_details');
cur_frm.refresh_fields();
frm.refresh();
frm.refresh_field('procedure_details');
cur_frm.refresh_fields();
frm.refresh();
},
procedure_details_add: function(frm,cdt,cdn) {
procedure_details_add: function (frm, cdt, cdn) {
select_row(frm);
var d = locals[cdt][cdn];
var id = d.idx;
id = id-1;
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"){
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{
} 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 (frm.doc.step_filter == "All" && frm.doc.procedure_filter == "All") {
if (prevrow !== undefined) {
row.doc.procedure_name = prevrow.doc.procedure_name;
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"){
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{
} 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){
if (row.doc.step_name && row.doc.procedure_name == frm.doc.procedure_filter) {
fn_addSteptolist(row.doc.step_name);
}
})
@ -542,50 +496,50 @@ frappe.ui.form.on('Procedure_Details', {
},
});
function fn_addProceduretolist(value){
if (value === "") {return;}
if ($("select[data-fieldname='procedure_filter'] option[value='" + value + "']").length === 0){
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){
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_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 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'});
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);
}
});
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);
}
});
}

Loading…
Cancel
Save