{"id":3924,"date":"2021-01-29T04:33:08","date_gmt":"2021-01-29T04:33:08","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=3924"},"modified":"2021-01-29T06:39:53","modified_gmt":"2021-01-29T06:39:53","slug":"custom-dialogs-in-totara","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/","title":{"rendered":"Custom dialogs in Totara"},"content":{"rendered":"<p>Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled by using them, we can create a custom dialog. In the custom dialog, we can define our own HTML, CSS, and Actions. By following the below steps, we can easily make a custom dialog.<\/p>\n<p>Let\u2019s take \u201c<em>\/totara\/report\/test\/index.php<\/em>\u201d as an example. Assume, We have one button \u201c<em>Custom Dialog<\/em>\u201d on this page. While clicking this button, our dialog will appear on the screen.<\/p>\n<ol>\n<li>When you make any new dialog, you have to need two javascript classes : \u201c<em>totaraDialog<\/em>\u201c and \u201c<em>totaraDialog_handler<\/em>\u201d. These classes are defined into the core javascript file \u201c<em>totara_dialog.js<\/em>\u201d. So firstly, we need to include these classes on the index page:<br \/>\n<code>$code = array();<br \/>\n $code[] = TOTARA_JS_DIALOG;<br \/>\n local_js($code);<\/code>\n<\/li>\n<li>After that, we will create a js file into our plugin \u201c<em>\/totara\/report\/test\/js\/test_dialog.js<\/em>\u201d. The dialog structure will be defined in this file.<br \/>\n<code>M.test_dialog = M.test_dialog || {<br \/>\n    Y: null,<br \/>\n    init: function(Y, args) {<br \/>\n        this.Y = Y;<br \/>\n        var test_dialog_handler = function() {};<br \/>\n        test_dialog_handler = new totaraDialog_handler();<br \/>\n        test_dialog_handler.prototype.every_load = function() {<br \/>\n       \t\/\/ Code written down in this block is executed on every load of the dialog<br \/>\n         });<br \/>\n        var handler = new test_dialog_handler();<br \/>\n        var name = <dialog_name>;<br \/>\n        var id= <dialog_id>;<br \/>\n        var buttons = {};<br \/>\n        buttons[M.util.get_string('close')] = function() { handler._cancel() };<br \/>\n        var url = M.cfg.wwwroot+dialogcontent.php\u2019;<br \/>\n         totaraDialogs[name] = new totaraDialog(<br \/>\n                name,<br \/>\n                id,<br \/>\n                {<br \/>\n                    buttons: buttons,<br \/>\n                    title: '&lt;h2>&lt;title>&lt;\/h2>'<br \/>\n                },<br \/>\n                url, \/\/default url<br \/>\n                handler \/\/assign the handler<br \/>\n           );<br \/>\n        }<br \/>\n    }<\/code><\/p>\n<p><em>totaraDialogs[&lt;name>]<\/em> is a global array that contains a list of all dialog objects of the website. \u2018Name\u2019 should be unique from all other dialog objects.<\/p>\n<p><em>totaraDialog_handler():<\/em> All the button clicks and logic are handled by this function. It provides various features to users. For example: on every load of the dialog, the user can perform one action. On the first load, he can perform another action. When the user closes the dialog, it handles the cancel request. Thus, we can customize the javascript side of the dialog by using this class.<\/p>\n<h2>totaraDialog: It has five parameters:<\/h2>\n<ol>\n<li>It specifies the id of the dialog.<\/li>\n<li>You will have to pass the id of the open button into this button. In our example, we will give the id of the \u201cCustom Dialog\u201d button in this parameter.<\/li>\n<li>You can set the custom configuration of the dialog into this parameter. For eg. If you want to set the width\/height of the dialog frame, you can send their values into the third parameter of this class. In our example, we set \u201ctitle\u201d and \u201cbuttons\u201d in this parameter.<\/li>\n<li>It will contain the URL to load the contents of the dialog.<\/li>\n<li>The last parameter is the object of the totaraDialog_handler class.<\/li>\n<\/ol>\n<\/li>\n<li>In the default_url parameter, we have passed the \u201c<em>\/totara\/report\/test\/dialogcontent.php<\/em>\u201d url. So, we have to create a <em>dialogcontent.php<\/em> file under the given folder. We will write the html code here:<br \/>\n<code>$html  =  html_writer::start_tag(\u2018div\u2019);<br \/>\n$html . = html_writer::start_span(). \u2018Dialog Content\u2019. html_writer::end_span();<br \/>\n$html  =  html_writer::end_tag(\u2018div\u2019);<\/code><br \/>\nYou can also display the web form created using forms API as the dialog content:<br \/>\n<code>$mform = new report_test_save_form();\/\/ This form definition will be defined in the \u201ctotara\/report\/test_save_form.php\u201d<br \/>\n if ($data = $mform->get_data()) {<br \/>\n    \/\/report_test_save_form submitted<br \/>\n }<br \/>\n $mform->display();<\/code>\n<\/li>\n<li>Now, we need to include \u201ctest_dialog.js\u201d  in \u201c\/totara\/report\/report\/test\/index.php\u201d file .We will call $PAGE->requires>js_init_call() function to initialize the dialog and $PAGE->requires->strings_for_js() to load the language strings.<br \/>\n<code>$jsmodule = array(<br \/>\n         \t\t'name' => test_dialog,<br \/>\n         \t\t 'fullpath' => '\/report\/test\/js\/test_dialog.js',<br \/>\n         \t\t 'requires' => array('json', 'totara_core'));<br \/>\n      \t$jsdetails->strings = array(<br \/>\n          \t\t'form' => array('close')<br \/>\n      \t);<br \/>\nif (!empty($jsdetails->strings)) {<br \/>\n          foreach ($jsdetails->strings as $scomponent => $sstrings) {<br \/>\n              $PAGE->requires->strings_for_js($sstrings, $scomponent);<br \/>\n          }<br \/>\n }<br \/>\n$PAGE->requires->js_init_call('M.test_dialog.init', array(), false, $jsmodule);<br \/>\n<\/code>\n<\/li>\n<\/ol>\n<p><small><em>People having good command over the French language can get a French certification from StudySection. StudySection offers both beginner level and expert level <a href=\"https:\/\/www.studysection.com\/french-language-and-concepts-advanced\">French Certification Exams<\/a> to test the ability to communicate in the French language.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is<\/p>\n","protected":false},"author":1,"featured_media":3925,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[621,493],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog - Custom dialogs in Totara LMS<\/title>\n<meta name=\"description\" content=\"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog - Custom dialogs in Totara LMS\" \/>\n<meta property=\"og:description\" content=\"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-29T04:33:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-29T06:39:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/01\/totara.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Custom dialogs in Totara\",\"datePublished\":\"2021-01-29T04:33:08+00:00\",\"dateModified\":\"2021-01-29T06:39:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\"},\"wordCount\":494,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"LMS\",\"Totara\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\",\"url\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\",\"name\":\"StudySection Blog - Custom dialogs in Totara LMS\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-01-29T04:33:08+00:00\",\"dateModified\":\"2021-01-29T06:39:53+00:00\",\"description\":\"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom dialogs in Totara\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog - Custom dialogs in Totara LMS","description":"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog - Custom dialogs in Totara LMS","og_description":"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.","og_url":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-01-29T04:33:08+00:00","article_modified_time":"2021-01-29T06:39:53+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/01\/totara.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Custom dialogs in Totara","datePublished":"2021-01-29T04:33:08+00:00","dateModified":"2021-01-29T06:39:53+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/"},"wordCount":494,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["LMS","Totara"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/","url":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/","name":"StudySection Blog - Custom dialogs in Totara LMS","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-01-29T04:33:08+00:00","dateModified":"2021-01-29T06:39:53+00:00","description":"Totara has two standard dialogs, one is Single select dialogs and the second is Multi-select dialogs. When our requirement is not fulfilled.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/custom-dialogs-in-totara\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom dialogs in Totara"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":221,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3924"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=3924"}],"version-history":[{"count":3,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3924\/revisions"}],"predecessor-version":[{"id":3928,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3924\/revisions\/3928"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/3925"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=3924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=3924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=3924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}