Implemented launch options & fixed issues with frame sizing
authorChris Scribner <scriby@gmail.com>
Tue, 30 Aug 2011 20:35:50 +0000 (16:35 -0400)
committerChris Scribner <scriby@gmail.com>
Mon, 7 Nov 2011 01:41:45 +0000 (20:41 -0500)
mod/blti/basiclti.js
mod/blti/edit_form.php
mod/blti/lang/en/blti.php
mod/blti/lib.php
mod/blti/locallib.php
mod/blti/mod_form.php
mod/blti/view.php

index 2d9dfe3..5b0673c 100644 (file)
 
 function basicltiDebugToggle() {
     var ele = document.getElementById('basicltiDebug');
-    if(ele.style.display == ''block') {
+    if(ele.style.display == 'block') {
         ele.style.display = 'none';
     }
     else {
         ele.style.display = 'block';
     }
 }
+
+alert('a');
\ No newline at end of file
index 55e0787..995824d 100644 (file)
@@ -83,6 +83,15 @@ class mod_blti_edit_types_form extends moodleform{
         \r
         $mform->addElement('checkbox', 'lti_coursevisible', '&nbsp;', ' ' . get_string('show_in_course', 'blti'));\r
         \r
+        $launchoptions=array();\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti');\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti');\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti');\r
+\r
+        $mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'blti'), $launchoptions);\r
+        $mform->setDefault('lti_launchcontainer', BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);\r
+//        $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti');\r
+        \r
         // Add privacy preferences fieldset where users choose whether to send their data\r
         $mform->addElement('header', 'privacy', get_string('privacy', 'blti'));\r
 \r
@@ -113,27 +122,6 @@ class mod_blti_edit_types_form extends moodleform{
         $mform->setDefault('lti_allowroster', '2');\r
 //        $mform->addHelpButton('lti_allowroster', 'allowroster', 'blti');\r
 \r
-        /*\r
-        // Add grading preferences fieldset where the tool is allowed to update settings\r
-        $mform->addElement('select', 'lti_allowsetting', get_string('allowsetting', 'blti'), $options);\r
-        $mform->setDefault('lti_allowsetting', '0');\r
-//        $mform->addHelpButton('lti_allowsetting', 'allowsetting', 'blti');\r
-         */\r
-\r
-//-------------------------------------------------------------------------------\r
-        // Add launch parameters fieldset\r
-        $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti'));\r
-\r
-        $launchoptions=array();\r
-        $launchoptions[0] = get_string('embed', 'blti');\r
-        $launchoptions[1] = get_string('embed_no_blocks', 'blti');\r
-        $launchoptions[2] = get_string('popup_window', 'blti');\r
-        $launchoptions[3] = get_string('new_window', 'blti');\r
-\r
-        $mform->addElement('select', 'lti_launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions);\r
-        $mform->setDefault('lti_launchinpopup', '0');\r
-//        $mform->addHelpButton('lti_launchinpopup', 'launchinpopup', 'blti');\r
-\r
                 \r
 //-------------------------------------------------------------------------------\r
         // Add setup parameters fieldset\r
index b13eeb7..afc41ef 100644 (file)
@@ -170,8 +170,8 @@ $string['tool_settings'] = 'Tool Settings';
 $string['miscellaneous'] = 'Miscellaneous';\r
 $string['embed'] = 'Embed';\r
 $string['embed_no_blocks'] = 'Embed, without blocks';\r
-$string['popup_window'] = 'Popup window';\r
-$string['new_window'] = 'New browser window / tab';\r
+$string['new_window'] = 'New window';\r
+$string['default_launch_container'] = 'Default Launch Container';\r
 \r
 //New instructor strings\r
 $string['display_name'] = 'Display activity name when launched';\r
@@ -182,4 +182,5 @@ $string['share_name'] = 'Share launcher\'s name with the tool';
 $string['share_email'] = 'Share launcher\'s email with the tool';\r
 $string['accept_grades'] = 'Accept grades from the tool';\r
 $string['share_roster'] = 'Allow the tool to access this course\'s roster';\r
-$string['automatic'] = 'Automatic, based on Launch URL';
\ No newline at end of file
+$string['automatic'] = 'Automatic, based on Launch URL';\r
+$string['default'] = 'Default';\r
index 2c13f93..214de3c 100644 (file)
@@ -112,6 +112,14 @@ function blti_update_instance($formdata) {
     $formdata->timemodified = time();\r
     $formdata->id = $formdata->instance;\r
 \r
+    if(!isset($formdata->showtitle)){\r
+        $formdata->showtitle = 0;\r
+    }\r
+    \r
+    if(!isset($formdata->showdescription)){\r
+        $formdata->showdescription = 0;\r
+    }\r
+    \r
     if ($formdata->instructorchoiceacceptgrades == 1) {\r
         $basicltirec = $DB->get_record("blti", array("id" => $formdata->id));\r
         $basicltirec->cmidnumber = $formdata->cmidnumber;\r
index 8e616f1..6d32d43 100644 (file)
@@ -51,6 +51,11 @@ require_once($CFG->dirroot.'/mod/blti/OAuth.php');
 \r
 define('BLTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i');\r
 \r
+define('BLTI_LAUNCH_CONTAINER_DEFAULT', 1);\r
+define('BLTI_LAUNCH_CONTAINER_EMBED', 2);\r
+define('BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3);\r
+define('BLTI_LAUNCH_CONTAINER_WINDOW', 4);\r
+\r
 /**\r
  * Prints a Basic LTI activity\r
  *\r
@@ -459,9 +464,6 @@ function blti_get_type_config_from_instance($id) {
     if (isset($config['toolurl'])) {\r
         $type->lti_toolurl = $config['toolurl'];\r
     }\r
-    if (isset($config['preferheight'])) {\r
-        $type->lti_preferheight = $config['preferheight'];\r
-    }\r
     if (isset($config['instructorchoicesendname'])) {\r
         $type->lti_sendname = $config['instructorchoicesendname'];\r
     }\r
@@ -474,9 +476,7 @@ function blti_get_type_config_from_instance($id) {
     if (isset($config['instructorchoiceallowroster'])) {\r
         $type->lti_allowroster = $config['instructorchoiceallowroster'];\r
     }\r
-    if (isset($config['instructorchoiceallowsetting'])) {\r
-        $type->lti_allowsetting = $config['instructorchoiceallowsetting'];\r
-    }\r
+\r
     if (isset($config['instructorcustomparameters'])) {\r
         $type->lti_allowsetting = $config['instructorcustomparameters'];\r
     }\r
@@ -506,9 +506,7 @@ function blti_get_type_type_config($id) {
     if (isset($config['password'])) {\r
         $type->lti_password = $config['password'];\r
     }\r
-    if (isset($config['preferheight'])) {\r
-        $type->lti_preferheight = $config['preferheight'];\r
-    }\r
+\r
     if (isset($config['sendname'])) {\r
         $type->lti_sendname = $config['sendname'];\r
     }\r
@@ -533,18 +531,11 @@ function blti_get_type_type_config($id) {
     if (isset($config['instructorchoiceallowroster'])){\r
         $type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster'];\r
     }\r
-    if (isset($config['allowsetting'])){\r
-        $type->lti_allowsetting = $config['allowsetting'];\r
-    }\r
-    if (isset($config['instructorchoiceallowsetting'])){\r
-        $type->lti_instructorchoiceallowsetting = $config['instructorchoiceallowsetting'];\r
-    }\r
+\r
     if (isset($config['customparameters'])) {\r
         $type->lti_customparameters = $config['customparameters'];\r
     }\r
-    if (isset($config['allowinstructorcustom'])) {\r
-        $type->lti_allowinstructorcustom = $config['allowinstructorcustom'];\r
-    }\r
+\r
     if (isset($config['organizationid'])) {\r
         $type->lti_organizationid = $config['organizationid'];\r
     }\r
@@ -554,8 +545,8 @@ function blti_get_type_type_config($id) {
     if (isset($config['organizationdescr'])) {\r
         $type->lti_organizationdescr = $config['organizationdescr'];\r
     }\r
-    if (isset($config['launchinpopup'])) {\r
-        $type->lti_launchinpopup = $config['launchinpopup'];\r
+    if (isset($config['launchcontainer'])) {\r
+        $type->lti_launchcontainer = $config['launchcontainer'];\r
     }\r
     if (isset($config['debuglaunch'])) {\r
         $type->lti_debuglaunch = $config['debuglaunch'];\r
@@ -655,11 +646,9 @@ function sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oaut
  */\r
 function post_launch_html($newparms, $endpoint, $debug=false, $height=false) {\r
     global $lastbasestring;\r
-    if ($height) {\r
-        $r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";\r
-    } else {\r
-        $r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";\r
-    }\r
+    \r
+    $r = "<form action=\"".$endpoint."\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";\r
+    \r
     $submittext = $newparms['ext_submit'];\r
 \r
     // Contruct html for the launch parameters\r
index 670f421..7ec6413 100644 (file)
@@ -115,6 +115,16 @@ class mod_blti_mod_form extends moodleform_mod {
         $mform->setType('instructorcustomparameters', PARAM_TEXT);\r
         $mform->setAdvanced('instructorcustomparameters');\r
         \r
+        $launchoptions=array();\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'blti');\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'blti');\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'blti');\r
+        $launchoptions[BLTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'blti');\r
+\r
+        $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'blti'), $launchoptions);\r
+\r
+        $mform->setDefault('launchcontainer', BLTI_LAUNCH_CONTAINER_DEFAULT);\r
+        \r
 //-------------------------------------------------------------------------------\r
         //$mform->addElement('hidden', 'typeid', $this->typeid);\r
         //$mform->addElement('hidden', 'toolurl', $this->typeconfig['toolurl']);\r
@@ -138,25 +148,6 @@ class mod_blti_mod_form extends moodleform_mod {
 \r
 //-------------------------------------------------------------------------------\r
 \r
-        // Add launch parameters fieldset\r
-        $mform->addElement('header', 'launchoptions', get_string('launchoptions', 'blti'));\r
-\r
-        $launchoptions=array();\r
-        $launchoptions[0] = get_string('embed', 'blti');\r
-        $launchoptions[1] = get_string('embed_no_blocks', 'blti');\r
-        $launchoptions[2] = get_string('popup_window', 'blti');\r
-        $launchoptions[3] = get_string('new_window', 'blti');\r
-\r
-        $mform->addElement('select', 'launchinpopup', get_string('launchinpopup', 'blti'), $launchoptions);\r
-\r
-        if (isset($this->typeconfig['launchinpopup'])) {\r
-            if ($this->typeconfig['launchinpopup'] == 0) {\r
-                $mform->setDefault('launchinpopup', '0');\r
-            } else if ($this->typeconfig['launchinpopup'] == 1) {\r
-                $mform->setDefault('launchinpopup', '1');\r
-            }\r
-        }\r
-\r
 /*        $debugoptions=array();\r
         $debugoptions[0] = get_string('debuglaunchoff', 'blti');\r
         $debugoptions[1] = get_string('debuglaunchon', 'blti');\r
index 47364bf..3624e68 100644 (file)
@@ -77,13 +77,27 @@ if ($id) {
     }\r
 }\r
 \r
+$tool = blti_get_tool_by_url_match($basiclti->toolurl);\r
+$toolconfig = blti_get_type_config($tool->id);\r
+\r
 $PAGE->set_cm($cm, $course); // set's up global $COURSE\r
 $context = get_context_instance(CONTEXT_MODULE, $cm->id);\r
 $PAGE->set_context($context);\r
 \r
 $url = new moodle_url('/mod/blti/view.php', array('id'=>$cm->id));\r
 $PAGE->set_url($url);\r
-$PAGE->set_pagelayout('incourse');\r
+\r
+$launchcontainer = $basiclti->launchcontainer == BLTI_LAUNCH_CONTAINER_DEFAULT ? \r
+                        $toolconfig['launchcontainer'] :\r
+                        $basiclti->launchcontainer;\r
+\r
+if($launchcontainer == BLTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){\r
+    $PAGE->set_pagelayout('frametop'); //Use the frametop layout to get the navbar, but no footer\r
+    $PAGE->blocks->show_only_fake_blocks(); //Disable blocks\r
+} else {\r
+    $PAGE->set_pagelayout('incourse');\r
+}\r
+\r
 require_login($course);\r
 \r
 add_to_log($course->id, "blti", "view", "view.php?id=$cm->id", "$basiclti->id");\r
@@ -95,35 +109,63 @@ $PAGE->set_heading($course->fullname);
 /// Print the page header\r
 echo $OUTPUT->header();\r
 \r
-/// Print the main part of the page\r
-echo $OUTPUT->heading(format_string($basiclti->name));\r
-echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');\r
+if($basiclti->showtitle) {\r
+    /// Print the main part of the page\r
+    echo $OUTPUT->heading(format_string($basiclti->name));\r
+}\r
+\r
+if($basiclti->showdescription && $basiclti->intro){\r
+    echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');\r
+}\r
 \r
 if ($basiclti->instructorchoiceacceptgrades == 1) {\r
     echo '<div class="reportlink">'.submittedlink($cm).'</div>';\r
 }\r
 \r
-echo $OUTPUT->box_start('generalbox activity');\r
-\r
-\r
-if ( false /*$basiclti->launchinpopup > 0*/ ) {\r
-    print "<script language=\"javascript\">//<![CDATA[\n";\r
-    print "window.open('launch.php?id=".$cm->id."','window name');";\r
-    print "//]]\n";\r
-    print "</script>\n";\r
-    print "<p>".get_string("basiclti_in_new_window", "blti")."</p>\n";\r
+if ( $launchcontainer == BLTI_LAUNCH_CONTAINER_WINDOW ) {\r
+    echo "<script language=\"javascript\">//<![CDATA[\n";\r
+    echo "window.open('launch.php?id=".$cm->id."','blti');";\r
+    echo "//]]\n";\r
+    echo "</script>\n";\r
+    echo "<p>".get_string("basiclti_in_new_window", "blti")."</p>\n";\r
 } else {\r
     // Request the launch content with an object tag\r
-    /*$height = $basiclti->preferheight;\r
-    if ((!$height) || ($height == 0)) {\r
-        $height = 400;\r
-    }*/\r
-    $height=600;\r
-    print '<object height="'.$height.'" width="100%" data="launch.php?id='.$cm->id.'&amp;withobject=true"></object>';\r
-\r
+    echo '<object id="contentframe" height="600px" width="100%" type="text/html" data="launch.php?id='.$cm->id.'&amp;withobject=true"></object>';\r
+    \r
+    //Output script to make the object tag be as large as possible\r
+    $resize = <<<'SCRIPT'\r
+        <script type='text/javascript'>\r
+        //<![CDATA[\r
+            (function(){\r
+                //Take scrollbars off the outer document to prevent double scroll bar effect\r
+                document.body.style.overflow = 'hidden';\r
+\r
+                var dom = YAHOO.util.Dom;\r
+                var frame = document.getElementById('contentframe');\r
+\r
+                var lastHeight;\r
+\r
+                var resize = function(){\r
+                    var viewportHeight = dom.getViewportHeight();\r
+\r
+                    if(lastHeight !== Math.min(dom.getDocumentHeight(), viewportHeight)){\r
+                        frame.style.height = viewportHeight - dom.getY(frame) + 'px';\r
+\r
+                        lastHeight = Math.min(dom.getDocumentHeight(), dom.getViewportHeight());\r
+                    }\r
+                };\r
+\r
+                resize();\r
+\r
+                setInterval(resize, 250);\r
+            })();\r
+        //]]    \r
+        </script>\r
+SCRIPT;\r
+    \r
+    echo $resize;\r
 }\r
 \r
-echo $OUTPUT->box_end();\r
 \r
 /// Finish the page\r
 echo $OUTPUT->footer();\r