I added 2 custom buttons to load dump from file. I want to make individual confirmation…
- User
I added 2 custom buttons to load dump from file. I want to make individual confirmation message for two of them for k10 "k10", for k7 "k7". How to do that?? it is inav-configurator here is snippets.
cli.js ('.tab-cli .load-k10').on('click', function (event) { event.preventDefault(); let previewArea = ("#snippetpreviewcontent textarea#preview"); const filePath = path.join(__dirname, '..', '.dump', 'k10.txt'); function executeSnippet() { const commands = previewArea.val(); executeCommands(commands); self.GUI.snippetPreviewWindow.close(); ('.backdrop .window .wrapper').css({ 'opacity': '0', 'user-select': 'none', '-webkit-user-select': 'none', '-moz-user-select': 'none', '-ms-user-select': 'none', 'pointer-events': 'none' }); ('.tab-cli .copy').prop('disabled', true); $('.tab-cli .copy').hide(); }
function previewCommandsK(result) { $(previewArea).css({'display': 'none'}); previewArea.val(result); self.GUI.snippetPreviewWindow = new jBox("Modal", { id: "snippetPreviewWindow", theme: "NoticeFancy", addClass: "RoiDark", width: 'auto', height: 'auto', closeButton: 'title', animation: false, isolateScroll: false, title: i18n.getMessage("cliConfirmSnippetDialogTitle"), content: $('#snippetpreviewcontent'), onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippet), }); self.GUI.snippetPreviewWindow.open(); }...... } }); } }); } });
cli.html
<div class="btn save_btn pull-right"> <a class="cliDocsBtn" href="#" i18n="cliDocsBtn" target="_blank"></a> <a class="load" href="#" i18n="cliLoadFromFileBtn"></a> <a style="display:none !important;" class="save" href="#" i18n="cliSaveToFileBtn"></a> <a class="copy" href="#" i18n="cliCopyToClipboardBtn"></a> <a class="clear" href="#" i18n="cliClearOutputHistoryBtn"></a> <a class="diffall" href="#" i18n="cliDiffAllBtn"></a> <a class="load-k7" href="#">K7</a> <a class="load-k10" href="#">K10</a> </div> </div> <!-- Snippet preview dialog --> <div id="snippetpreviewcontent" style="display: none"> <div class="note"> <div class="note_spacer"> <p i18n="cliConfirmSnippetNote"></p> </div> </div> <textarea id="preview" cols="120" rows="20"></textarea> <div class="default_btn"> <a class="confirm" href="#" i18n="cliConfirmSnippetBtn"></a> </div> </div> Assistant
OK. The core of the problem is that you're using the same
previewCommandsKandexecuteSnippetfunctions for both the k7 and k10 buttons. You need to create separate, slightly modified versions of these functions for each button's confirmation message.Here's how you can modify your
cli.jsfile:$('.tab-cli .load-k10').on('click', function (event) { event.preventDefault(); let previewArea = $("#snippetpreviewcontent textarea#preview"); const filePath = path.join(__dirname, '..', '.dump', 'k10.txt'); function executeSnippetK10() { // Modified function for K10 const commands = previewArea.val(); executeCommands(commands); self.GUI.snippetPreviewWindow.close(); $('.cli-preloader').toggleClass('active'); $('.backdrop .window .wrapper').css({ 'opacity': '0', 'user-select': 'none', '-webkit-user-select': 'none', '-moz-user-select': 'none', '-ms-user-select': 'none', 'pointer-events': 'none' }); $('.tab-cli .copy').attr('disabled', true); $('.tab-cli .copy').prop('disabled', true); $('.tab-cli .copy').hide(); } function previewCommandsK10(result) { // Modified function for K10 $(previewArea).css({'display': 'none'}); previewArea.val(result); self.GUI.snippetPreviewWindow = new jBox("Modal", { id: "snippetPreviewWindow", theme: "NoticeFancy", addClass: "RoiDark", width: 'auto', height: 'auto', closeButton: 'title', animation: false, isolateScroll: false, title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K10", // Add specific title content: $('#snippetpreviewcontent'), onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK10), // Call K10 execute function }); self.GUI.snippetPreviewWindow.open(); } fs.readFile(filePath, 'utf8', (err, result) => { if (err) { console.error(err); GUI.log(i18n.getMessage("cliLoadFromFileError") + ": " + err.message); } else { previewCommandsK10(result); } }); }); $('.tab-cli .load-k7').on('click', function (event) { event.preventDefault(); let previewArea = $("#snippetpreviewcontent textarea#preview"); const filePath = path.join(__dirname, '..', '.dump', 'k7.txt'); function executeSnippetK7() { // Modified function for K7 const commands = previewArea.val(); executeCommands(commands); self.GUI.snippetPreviewWindow.close(); $('.cli-preloader').toggleClass('active'); $('.backdrop .window .wrapper').css({ 'opacity': '0', 'user-select': 'none', '-webkit-user-select': 'none', '-moz-user-select': '-none', 'pointer-events': 'none' }); $('.tab-cli .copy').attr('disabled', true); $('.tab-cli .copy').prop('disabled', true); $('.tab-cli .copy').hide(); } function previewCommandsK7(result) { // Modified function for K7 $(previewArea).css({'display': 'none'}); previewArea.val(result); self.GUI.snippetPreviewWindow = new jBox("Modal", { id: "snippetPreviewWindow", theme: "NoticeFancy", addClass: "RoiDark", width: 'auto', height: 'auto', closeButton: 'title', animation: false, isolateScroll: false, title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K7", // Add specific title content: $('#snippetpreviewcontent'), onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK7), // Call K7 execute function }); self.GUI.snippetPreviewWindow.open(); } fs.readFile(filePath, 'utf8', (err, result) => { if (err) { console.error(err); GUI.log(i18n.getMessage("cliLoadFromFileError") + ": " + err.message); } else { previewCommandsK7(result); } }); });Key changes and explanation:
-
Separate Functions: We've created
executeSnippetK10,previewCommandsK10,executeSnippetK7, andpreviewCommandsK7. This is crucial because now each button click uses its own functions. You need this separation to customize the title and the execution path. -
Specific Titles: The
titleproperty of thejBoxmodal is now customized:title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K10"title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K7"This appends " - K10" or " - K7" to your existing title, providing clear differentiation. Make sure thecliConfirmSnippetDialogTitlemessage is defined in youri18nsystem.
-
Correct Execution: The
onCreatedhandler in eachpreviewCommandsK*function now calls the correspondingexecuteSnippetK*function:onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK10)onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK7)This is critical. It ensures that when the user clicks the "confirm" button in the preview, the correct snippet execution function is triggered.
-
File paths: Adjusted filepath to k7.txt for 'k7' load button.
Important Considerations:
- i18n: Ensure
cliConfirmSnippetDialogTitleis defined in youri18ntranslation files. If it's not, the titles might look odd. You probably already have this defined, but double-check. - Error Handling: The
fs.readFilecalls include basic error handling. You might want to make this more robust, perhaps displaying a more user-friendly error message in the UI. - Code Duplication: The
executeSnippetK*functions are very similar. You could potentially refactor to reduce duplication if you wanted to make the common parts a single function and pass a parameter to differentiate (e.g., a "K10" or "K7" identifier). However, for clarity and maintainability, keeping them separate as above is often preferred.
With these changes, when you click the "K10" button, you should see a confirmation dialog with "K10" in the title and the correct dump will be loaded. Similarly, for the "K7" button. Remember to test thoroughly!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.