UNPKG

unserver-unify

Version:

44 lines (38 loc) 1.31 kB
'use strict'; angular.module('bamboo.course') .controller('RatingDlgCtrl', function( $uibModalInstance, title, types, CommonService, $filter) { this.title = title; var self = this; this.types=types; this.averageRating=0; this.ratings={}; this.comments="", angular.forEach(types, function(value, key){ self.ratings[value] = 3; }); this.value; this.values=[]; this.updaterating=function(){ var _value = 0; var _length = 0; angular.forEach(self.ratings, function(value, key){ console.log(value); _value += value; _length +=1; }); var average= _length != 0 ? _value/_length : 0; this.averageRating=parseFloat(average.toString().substring(0,4)); } this.submit=function(){ self.updaterating(); //update averageRating var result={ comments : self.comments, ratings : self.ratings, averageRating : self.averageRating, date : new Date() }; CommonService.showConfirm( $filter('trans')( {eng: 'Are you sure to submit the rating, be noticed that you can only submit rating once!', chn : '确定提交课程打分吗,请注意:评分提交后无法修改!'} ) , function () { $uibModalInstance.close(result); }) } });