|
|
@@ -2,11 +2,13 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro |
|
|
|
make_input() { |
|
|
|
super.make_input(); |
|
|
|
let stars = ''; |
|
|
|
[1, 2, 3, 4, 5].forEach(i => { |
|
|
|
let number_of_stars = this.df.options || 5; |
|
|
|
Array.from({length: cint(number_of_stars)}, (_, i) => i + 1).forEach(i => { |
|
|
|
stars += `<svg class="icon icon-md" data-rating=${i}> |
|
|
|
<use href="#icon-star"></use> |
|
|
|
</svg>`; |
|
|
|
}); |
|
|
|
|
|
|
|
const star_template = ` |
|
|
|
<div class="rating"> |
|
|
|
${stars} |
|
|
@@ -42,6 +44,9 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro |
|
|
|
$(this).removeClass('star-click'); |
|
|
|
} |
|
|
|
}); |
|
|
|
let out_of_ratings = this.df.options || 5; |
|
|
|
|
|
|
|
star_value = star_value/out_of_ratings; |
|
|
|
this.validate_and_set_in_model(star_value, ev); |
|
|
|
if (this.doctype && this.docname) { |
|
|
|
this.set_input(star_value); |
|
|
@@ -49,9 +54,12 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro |
|
|
|
}); |
|
|
|
} |
|
|
|
get_value() { |
|
|
|
return cint(this.value, null); |
|
|
|
let out_of_ratings = this.df.options || 5; |
|
|
|
return cint(this.value*out_of_ratings, null); |
|
|
|
} |
|
|
|
set_formatted_input(value) { |
|
|
|
let out_of_ratings = this.df.options || 5; |
|
|
|
value = value * out_of_ratings; |
|
|
|
let el = $(this.input_area).find('svg'); |
|
|
|
el.children('svg').prevObject.each( function(e) { |
|
|
|
if (e < value) { |
|
|
@@ -61,4 +69,7 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
validate(fraction) { |
|
|
|
return parseFloat(fraction); |
|
|
|
} |
|
|
|
}; |