MDL-14790 ajax delete confirmation box now uses the same wording as the non-ajax...
authorDavid Mudrak <david.mudrak@gmail.com>
Tue, 9 Nov 2010 11:55:26 +0000 (11:55 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Tue, 9 Nov 2010 11:55:26 +0000 (11:55 +0000)
course/lib.php
lib/ajax/ajaxcourse.js
lib/ajax/ajaxlib.php
lib/ajax/section_classes.js

index a32bde4..101f73f 100644 (file)
@@ -1348,7 +1348,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                 }
             }
 
-            echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">';  // Unique ID
+            echo '<li class="activity '.$mod->modname.' modtype_'.$mod->modname.'" id="module-'.$modnumber.'">';  // Unique ID
             if ($ismoving) {
                 echo '<a title="'.$strmovefull.'"'.
                      ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
@@ -1432,7 +1432,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                     echo '<a '.$linkcss.' '.$extra.
                          ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
                          '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename',$mod->modname).'" /> '.
-                         $accesstext.'<span>'.$instancename.$altname.'</span></a>';
+                         $accesstext.'<span class="instancename">'.$instancename.$altname.'</span></a>';
 
                     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                         if (!isset($groupings)) {
index 0e5dd34..3d6e208 100644 (file)
@@ -274,6 +274,13 @@ main_class.prototype.getString = function(identifier, variable) {
     }
 };
 
+main_class.prototype.hasString = function(identifier) {
+    if (this.portal.strings[identifier]) {
+        return true;
+    }
+    return false;
+};
+
 main_class.prototype.is_ie = function() {
     var agent = navigator.userAgent.toLowerCase();
     if ((agent.indexOf('msie') != -1)) {
index fdfb492..815385b 100644 (file)
@@ -152,10 +152,13 @@ class jsportal {
         $output .= "    main.portal.strings['groupsseparate']='".get_string('groupsseparate')."';\n";
         $output .= "    main.portal.strings['groupsvisible']='".get_string('groupsvisible')."';\n";
         $output .= "    main.portal.strings['clicktochange']='".get_string('clicktochange')."';\n";
-        $output .= "    main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
+        $output .= "    main.portal.strings['deletecheck']='".get_string('deletecheckfull','','_var_')."';\n";
         $output .= "    main.portal.strings['resource']='".get_string('resource')."';\n";
         $output .= "    main.portal.strings['activity']='".get_string('activity')."';\n";
         $output .= "    main.portal.strings['sesskey']='".sesskey()."';\n";
+        foreach (array_keys(get_plugin_list('mod')) as $modtype) {
+            $output .= "    main.portal.strings['modtype_".$modtype."']='".get_string('pluginname', 'mod_'.$modtype)."';\n";
+        }
         $output .= "    main.portal.icons['spacerimg']='".$OUTPUT->pix_url('spacer')."';\n";
         $output .= "    main.portal.icons['marker']='".$OUTPUT->pix_url('i/marker')."';\n";
         $output .= "    main.portal.icons['ihide']='".$OUTPUT->pix_url('i/hide')."';\n";
index a03c15c..11adee3 100755 (executable)
@@ -856,7 +856,49 @@ resource_class.prototype.delete_button = function() {
     if (this.debug) {
     YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
     }
-    if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) {
+
+    // default fallback to something like 'Resource 42'
+    var modtype = main.getString(this.is);
+    var modname = this.id;
+
+    // try to get less cryptic instance name from DOM
+    if (YAHOO.util.Dom.hasClass(this.getEl(), 'activity')) {
+        if (YAHOO.util.Dom.hasClass(this.getEl(), 'label')) {
+            // mod_label instance
+            modtype = main.getString('modtype_label');
+            modname = '';
+        } else {
+            // other mod instance, get the type first
+            matches = new RegExp(/modtype_(\w+)/).exec(this.getEl().className);
+            if (matches[1] && main.hasString('modtype_' + matches[1])) {
+                modtype = main.getString('modtype_' + matches[1]);
+            }
+            // look for span.instancename content to get the module instance name from it
+            instancename = YAHOO.util.Selector.query('.instancename', this.getEl(), true);
+            if (instancename) {
+                // remove the span.accesshide
+                accesshides = YAHOO.util.Selector.query('.accesshide', instancename);
+                for (x in accesshides) {
+                    instancename.removeChild(accesshides[x]);
+                }
+                // strip HTML tags
+                instancenametext = instancename.innerHTML.replace(/<[^>]+>/g, '');
+                // and if anything survived, consider it the instance name
+                if (instancenametext) {
+                    modname = instancenametext;
+                }
+                // put span.accesshides back
+                for (x in accesshides) {
+                    instancename.appendChild(accesshides[x]);
+                }
+            }
+        }
+    }
+
+    if (modname) {
+        modname = "'" + modname + "'";
+    }
+    if (!confirm(main.getString('deletecheck', modtype + ' ' + modname))) {
         return false;
     }
     this.parentObj.remove_resource(this);