From 25451759fe81db75cc9e7f5068658c7ac82750a2 Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Mon, 15 Jan 2018 13:42:03 +0100 Subject: [PATCH] `add_dropdown_item` should only add unique labels (#4818) * do not allow add_menu_button duplicate items * JSDOC documentation --- frappe/public/js/frappe/ui/page.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frappe/public/js/frappe/ui/page.js b/frappe/public/js/frappe/ui/page.js index bf969f1566..728e9a6034 100644 --- a/frappe/public/js/frappe/ui/page.js +++ b/frappe/public/js/frappe/ui/page.js @@ -247,12 +247,27 @@ frappe.ui.Page = Class.extend({ //-- Generic --// + /* + * Add label to given drop down menu. If label, is already contained in the drop + * down menu, it will be ignored. + * @param {string} label - Text for the drop down menu + * @param {function} click - function to be called when `label` is clicked + * @param {Boolean} standard + * @param {object} parent - DOM object representing the parent of the drop down item lists + */ add_dropdown_item: function(label, click, standard, parent) { + const is_already_added = () => { + let found_lists = $(parent).find('li > a.grey-link:contains(' + label + ')'); + return found_lists.length > 0; + } + parent.parent().removeClass("hide"); var $li = $('
  • '+ label +'
  • '), $link = $li.find("a").on("click", click); + if (is_already_added()) return; + if(standard===true) { $li.appendTo(parent); } else {