MDL-59369 user: Render status as highlighted labels

This commit is contained in:
Jun Pataleta
2017-07-26 09:44:33 +08:00
parent 06aa592315
commit 4544451aff
6 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -1 +1 @@
define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){b(j.UNENROL).click(function(a){a.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename")}}];b.when(c.get_strings(j)).then(function(a){var b=a[0],c=a[1];return f.create({body:c,large:!0,title:b,type:f.types.CONFIRM})}).done(function(a){a.getRoot().on(g.yes,function(){var a={confirm:1,sesskey:d.sesskey,ue:b(h).attr("rel")};window.location.href=d.wwwroot+"/enrol/unenroluser.php?"+b.param(a)}),a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),timestart:i.data("timestart"),timeend:i.data("timeend")},k=c.get_string("enroldetails","enrol"),l=f.create({large:!0,type:f.types.CANCEL});b.when(k,l).done(function(b,c){var d=a.render("core_user/status_details",j);c.setTitle(b),c.setBody(d),c.show(),c.getRoot().on(g.hidden,function(){c.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}});
define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){b(j.UNENROL).click(function(a){a.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename")}}];b.when(c.get_strings(j)).then(function(a){var b=a[0],c=a[1];return f.create({body:c,large:!0,title:b,type:f.types.CONFIRM})}).done(function(a){a.getRoot().on(g.yes,function(){var a={confirm:1,sesskey:d.sesskey,ue:b(h).attr("rel")};window.location.href=d.wwwroot+"/enrol/unenroluser.php?"+b.param(a)}),a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend")},k=c.get_string("enroldetails","enrol"),l=f.create({large:!0,type:f.types.CANCEL});b.when(k,l).done(function(b,c){var d=a.render("core_user/status_details",j);c.setTitle(b),c.setBody(d),c.show(),c.getRoot().on(g.hidden,function(){c.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}});
+1
View 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')
};
+6 -1
View 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);
}
+7 -1
View 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);
}
+5 -1
View 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}}
+1 -1
View 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>