|
|
@@ -1,22 +1,24 @@ |
|
|
|
frappe.ui.form.ControlRating = frappe.ui.form.ControlInt.extend({ |
|
|
|
make_input() { |
|
|
|
this._super(); |
|
|
|
let stars = ''; |
|
|
|
[1, 2, 3, 4, 5].forEach(i => { |
|
|
|
stars += `<svg class="icon icon-md" data-rating=${i}> |
|
|
|
<use href="#icon-star"></use> |
|
|
|
</svg>`; |
|
|
|
}); |
|
|
|
const star_template = ` |
|
|
|
<div class="rating"> |
|
|
|
<i class="fa fa-fw fa-star" data-rating=1></i> |
|
|
|
<i class="fa fa-fw fa-star" data-rating=2></i> |
|
|
|
<i class="fa fa-fw fa-star" data-rating=3></i> |
|
|
|
<i class="fa fa-fw fa-star" data-rating=4></i> |
|
|
|
<i class="fa fa-fw fa-star" data-rating=5></i> |
|
|
|
${stars} |
|
|
|
</div> |
|
|
|
`; |
|
|
|
|
|
|
|
$(this.input_area).html(star_template); |
|
|
|
|
|
|
|
$(this.input_area).find('i').hover((ev) => { |
|
|
|
$(this.input_area).find('svg').hover((ev) => { |
|
|
|
const el = $(ev.currentTarget); |
|
|
|
let star_value = el.data('rating'); |
|
|
|
el.parent().children('i.fa').each( function(e) { |
|
|
|
el.parent().children('svg').each( function(e) { |
|
|
|
if (e < star_value) { |
|
|
|
$(this).addClass('star-hover'); |
|
|
|
} else { |
|
|
@@ -25,16 +27,16 @@ frappe.ui.form.ControlRating = frappe.ui.form.ControlInt.extend({ |
|
|
|
}); |
|
|
|
}, (ev) => { |
|
|
|
const el = $(ev.currentTarget); |
|
|
|
el.parent().children('i.fa').each( function() { |
|
|
|
el.parent().children('svg').each( function() { |
|
|
|
$(this).removeClass('star-hover'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
$(this.input_area).find('i').click((ev) => { |
|
|
|
$(this.input_area).find('svg').click((ev) => { |
|
|
|
const el = $(ev.currentTarget); |
|
|
|
let star_value = el.data('rating'); |
|
|
|
el.parent().children('i.fa').each( function(e) { |
|
|
|
if (e < star_value){ |
|
|
|
el.parent().children('svg').each( function(e) { |
|
|
|
if (e < star_value) { |
|
|
|
$(this).addClass('star-click'); |
|
|
|
} else { |
|
|
|
$(this).removeClass('star-click'); |
|
|
@@ -51,7 +53,7 @@ frappe.ui.form.ControlRating = frappe.ui.form.ControlInt.extend({ |
|
|
|
}, |
|
|
|
set_formatted_input(value) { |
|
|
|
let el = $(this.input_area).find('i'); |
|
|
|
el.children('i.fa').prevObject.each( function(e) { |
|
|
|
el.children('svg').prevObject.each( function(e) { |
|
|
|
if (e < value) { |
|
|
|
$(this).addClass('star-click'); |
|
|
|
} else { |
|
|
@@ -59,4 +61,4 @@ frappe.ui.form.ControlRating = frappe.ui.form.ControlInt.extend({ |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |