MDL-59369 user: Render status as highlighted labels
authorJun Pataleta <jun@moodle.com>
Tue, 18 Jul 2017 07:00:00 +0000 (15:00 +0800)
committerJun Pataleta <jun@moodle.com>
Wed, 26 Jul 2017 01:44:33 +0000 (09:44 +0800)
user/amd/build/status_field.min.js
user/amd/src/status_field.js
user/classes/participants_table.php
user/classes/status_field.php
user/templates/status_details.mustache
user/templates/status_field.mustache

index bd35c47..ea0b365 100644 (file)
Binary files a/user/amd/build/status_field.min.js and b/user/amd/build/status_field.min.js differ
index 51a0687..e57b7e9 100644 (file)
@@ -196,6 +196,7 @@ define(['core/templates',
                     "coursename": parentContainer.data('coursename'),
                     "enrolinstancename": parentContainer.data('enrolinstancename'),
                     "status": parentContainer.data('status'),
+                    "statusclass": parentContainer.find('span').attr('class'),
                     "timestart": parentContainer.data('timestart'),
                     "timeend": parentContainer.data('timeend')
                 };
index a162001..94256f7 100644 (file)
@@ -340,23 +340,28 @@ class participants_table extends \table_sql {
                 $timestart = $ue->timestart;
                 $timeend = $ue->timeend;
                 $status = '';
+                $statusclass = '';
                 switch ($ue->status) {
                     case ENROL_USER_ACTIVE:
                         $currentdate = new DateTime();
                         $now = $currentdate->getTimestamp();
                         if ($timestart <= $now && ($timeend == 0 || $timeend >= $now)) {
                             $status = get_string('participationactive', 'enrol');
+                            $statusclass = 'success';
                         } else {
                             $status = get_string('participationnotcurrent', 'enrol');
+                            $statusclass = 'default';
                         }
                         break;
                     case ENROL_USER_SUSPENDED:
                         $status = get_string('participationsuspended', 'enrol');
+                        $statusclass = 'warning';
                         break;
                 }
                 $actions = $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue);
                 $instancename = $ue->enrolmentinstancename;
-                $statusfield = new status_field($instancename, $coursename, $fullname, $status, $timestart, $timeend, $actions);
+                $statusfield = new status_field($instancename, $coursename, $fullname, $status, $statusclass, $timestart, $timeend,
+                    $actions);
                 $statusfielddata = $statusfield->export_for_template($OUTPUT);
                 $enrolstatusoutput .= $OUTPUT->render_from_template('core_user/status_field', $statusfielddata);
             }
index 3bb7576..38bf432 100644 (file)
@@ -53,6 +53,9 @@ class status_field implements renderable, templatable {
     /** @var string $status The user enrolment status. */
     protected $status;
 
+    /** @var string $statusclass The CSS class to be used for rendering the status label.  */
+    protected $statusclass;
+
     /** @var int $timestart The timestamp when the user's enrolment starts. */
     protected $timestart;
 
@@ -69,16 +72,18 @@ class status_field implements renderable, templatable {
      * @param string $coursename The course's full name.
      * @param string $fullname The user's full name.
      * @param string $status The user enrolment status.
+     * @param string $statusclass The CSS class to be used for rendering the status label.
      * @param int|null $timestart The timestamp when the user's enrolment starts.
      * @param int|null $timeend The timestamp when the user's enrolment ends.
      * @param user_enrolment_action[] $enrolactions Array of enrol action objects for the given enrolment method.
      */
-    public function __construct($enrolinstancename, $coursename, $fullname, $status,
+    public function __construct($enrolinstancename, $coursename, $fullname, $status, $statusclass = '',
                                 $timestart = null, $timeend = null, $enrolactions = []) {
         $this->enrolinstancename = $enrolinstancename;
         $this->coursename = $coursename;
         $this->fullname = $fullname;
         $this->status = $status;
+        $this->statusclass = $statusclass;
         $this->timestart = $timestart;
         $this->timeend = $timeend;
         $this->enrolactions = $enrolactions;
@@ -99,6 +104,7 @@ class status_field implements renderable, templatable {
         $data->coursename = $this->coursename;
         $data->fullname = $this->fullname;
         $data->status = $this->status;
+        $data->statusclass = $this->statusclass;
         if ($this->timestart) {
             $data->timestart = userdate($this->timestart);
         }
index dd2c940..079f1cb 100644 (file)
@@ -24,6 +24,7 @@
     * coursename string - The course name.
     * enrolinstancename string - The enrolment instance name.
     * status string - The enrolment status.
+    * statusclass string - The CSS class for the enrolment status.
     * timestart string - Optional. The enrolment time start.
     * timeend string - Optional. The enrolment time end.
 
@@ -33,6 +34,7 @@
         "coursename": "TC 1",
         "enrolinstancename": "Manual enrolment",
         "status": "Active",
+        "statusclass": "label label-success",
         "timestart": "1 January 2017",
         "timeend": "31 January 2018"
     }
@@ -67,7 +69,9 @@
             {{#str}}participationstatus, enrol{{/str}}
         </th>
         <td class="user-enrol-status">
-            {{status}}
+            <span class="{{statusclass}}">
+                {{status}}
+            </span>
         </td>
     </tr>
     {{#timestart}}
index 2873889..002b06e 100644 (file)
@@ -55,7 +55,7 @@
 }}
 <div data-fullname="{{fullname}}" data-coursename="{{coursename}}" data-enrolinstancename="{{enrolinstancename}}"
      data-status="{{status}}" data-timestart="{{timestart}}" data-timeend="{{timeend}}">
-    <span>{{status}}</span>
+    <span class="label {{#statusclass}}label-{{statusclass}}{{/statusclass}}">{{status}}</span>
     <a data-action="showdetails" role="button" tabindex="0">
         {{#pix}}docs, core, {{#str}}enroldetails, enrol{{/str}}{{/pix}}
     </a>