22
33import { MediaDialog } from "@web_editor/components/media_dialog/media_dialog" ;
44
5- import options from "@web_editor/js/editor/snippets.options.legacy" ;
5+ import {
6+ SnippetOption ,
7+ } from "@web_editor/js/editor/snippets.options" ;
8+ import {
9+ registerWebsiteOption ,
10+ } from "@website/js/editor/snippets.registry" ;
611
7- options . registry . Rating = options . Class . extend ( {
12+ export class RatingOption extends SnippetOption {
813 /**
914 * @override
1015 */
11- start : function ( ) {
16+ willStart ( ) {
1217 this . iconType = this . $target [ 0 ] . dataset . icon ;
1318 this . faClassActiveCustomIcons = this . $target [ 0 ] . dataset . activeCustomIcon || '' ;
1419 this . faClassInactiveCustomIcons = this . $target [ 0 ] . dataset . inactiveCustomIcon || '' ;
15- return this . _super . apply ( this , arguments ) ;
16- } ,
20+ return super . willStart ( ... arguments ) ;
21+ }
1722
1823 //--------------------------------------------------------------------------
1924 // Options
@@ -24,22 +29,22 @@ options.registry.Rating = options.Class.extend({
2429 *
2530 * @see this.selectClass for parameters
2631 */
27- setIcons : function ( previewMode , widgetValue , params ) {
32+ setIcons ( previewMode , widgetValue , params ) {
2833 this . iconType = widgetValue ;
2934 this . _renderIcons ( ) ;
3035 this . $target [ 0 ] . dataset . icon = widgetValue ;
3136 delete this . $target [ 0 ] . dataset . activeCustomIcon ;
3237 delete this . $target [ 0 ] . dataset . inactiveCustomIcon ;
33- } ,
38+ }
3439 /**
3540 * Allows to select a font awesome icon with media dialog.
3641 *
3742 * @see this.selectClass for parameters
3843 */
39- customIcon : async function ( previewMode , widgetValue , params ) {
44+ async customIcon ( previewMode , widgetValue , params ) {
4045 const media = document . createElement ( 'i' ) ;
4146 media . className = params . customActiveIcon === 'true' ? this . faClassActiveCustomIcons : this . faClassInactiveCustomIcons ;
42- this . call ( " dialog" , " add" , MediaDialog , {
47+ this . env . services . dialog . add ( MediaDialog , {
4348 noImages : true ,
4449 noDocuments : true ,
4550 noVideos : true ,
@@ -58,25 +63,25 @@ options.registry.Rating = options.Class.extend({
5863 this . iconType = 'custom' ;
5964 }
6065 } ) ;
61- } ,
66+ }
6267 /**
6368 * Sets the number of active icons.
6469 *
6570 * @see this.selectClass for parameters
6671 */
67- activeIconsNumber : function ( previewMode , widgetValue , params ) {
72+ activeIconsNumber ( previewMode , widgetValue , params ) {
6873 this . nbActiveIcons = parseInt ( widgetValue ) ;
6974 this . _createIcons ( ) ;
70- } ,
75+ }
7176 /**
7277 * Sets the total number of icons.
7378 *
7479 * @see this.selectClass for parameters
7580 */
76- totalIconsNumber : function ( previewMode , widgetValue , params ) {
81+ totalIconsNumber ( previewMode , widgetValue , params ) {
7782 this . nbTotalIcons = Math . max ( parseInt ( widgetValue ) , 1 ) ;
7883 this . _createIcons ( ) ;
79- } ,
84+ }
8085
8186 //--------------------------------------------------------------------------
8287 // Private
@@ -85,7 +90,7 @@ options.registry.Rating = options.Class.extend({
8590 /**
8691 * @override
8792 */
88- _computeWidgetState : function ( methodName , params ) {
93+ _computeWidgetState ( methodName , params ) {
8994 switch ( methodName ) {
9095 case 'setIcons' : {
9196 return this . $target [ 0 ] . dataset . icon ;
@@ -99,14 +104,14 @@ options.registry.Rating = options.Class.extend({
99104 return this . nbTotalIcons ;
100105 }
101106 }
102- return this . _super ( ...arguments ) ;
103- } ,
107+ return super . _computeWidgetState ( ...arguments ) ;
108+ }
104109 /**
105110 * Creates the icons.
106111 *
107112 * @private
108113 */
109- _createIcons : function ( ) {
114+ _createIcons ( ) {
110115 const $activeIcons = this . $target . find ( '.s_rating_active_icons' ) ;
111116 const $inactiveIcons = this . $target . find ( '.s_rating_inactive_icons' ) ;
112117 this . $target . find ( '.s_rating_icons i' ) . remove ( ) ;
@@ -118,13 +123,13 @@ options.registry.Rating = options.Class.extend({
118123 }
119124 }
120125 this . _renderIcons ( ) ;
121- } ,
126+ }
122127 /**
123128 * Renders icons with selected fonts.
124129 *
125130 * @private
126131 */
127- _renderIcons : function ( ) {
132+ _renderIcons ( ) {
128133 const icons = {
129134 'fa-star' : 'fa-star-o' ,
130135 'fa-thumbs-up' : 'fa-thumbs-o-up' ,
@@ -138,5 +143,11 @@ options.registry.Rating = options.Class.extend({
138143 const $inactiveIcons = this . $target . find ( '.s_rating_inactive_icons > i' ) ;
139144 $activeIcons . removeClass ( ) . addClass ( faClassActiveIcons ) ;
140145 $inactiveIcons . removeClass ( ) . addClass ( faClassInactiveIcons ) ;
141- } ,
146+ }
147+ }
148+
149+ registerWebsiteOption ( "Rating" , {
150+ Class : RatingOption ,
151+ template : "website.s_rating_option" ,
152+ selector : ".s_rating" ,
142153} ) ;
0 commit comments