2
2
3
3
import { MediaDialog } from "@web_editor/components/media_dialog/media_dialog" ;
4
4
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" ;
6
11
7
- options . registry . Rating = options . Class . extend ( {
12
+ export class RatingOption extends SnippetOption {
8
13
/**
9
14
* @override
10
15
*/
11
- start : function ( ) {
16
+ willStart ( ) {
12
17
this . iconType = this . $target [ 0 ] . dataset . icon ;
13
18
this . faClassActiveCustomIcons = this . $target [ 0 ] . dataset . activeCustomIcon || '' ;
14
19
this . faClassInactiveCustomIcons = this . $target [ 0 ] . dataset . inactiveCustomIcon || '' ;
15
- return this . _super . apply ( this , arguments ) ;
16
- } ,
20
+ return super . willStart ( ... arguments ) ;
21
+ }
17
22
18
23
//--------------------------------------------------------------------------
19
24
// Options
@@ -24,22 +29,22 @@ options.registry.Rating = options.Class.extend({
24
29
*
25
30
* @see this.selectClass for parameters
26
31
*/
27
- setIcons : function ( previewMode , widgetValue , params ) {
32
+ setIcons ( previewMode , widgetValue , params ) {
28
33
this . iconType = widgetValue ;
29
34
this . _renderIcons ( ) ;
30
35
this . $target [ 0 ] . dataset . icon = widgetValue ;
31
36
delete this . $target [ 0 ] . dataset . activeCustomIcon ;
32
37
delete this . $target [ 0 ] . dataset . inactiveCustomIcon ;
33
- } ,
38
+ }
34
39
/**
35
40
* Allows to select a font awesome icon with media dialog.
36
41
*
37
42
* @see this.selectClass for parameters
38
43
*/
39
- customIcon : async function ( previewMode , widgetValue , params ) {
44
+ async customIcon ( previewMode , widgetValue , params ) {
40
45
const media = document . createElement ( 'i' ) ;
41
46
media . className = params . customActiveIcon === 'true' ? this . faClassActiveCustomIcons : this . faClassInactiveCustomIcons ;
42
- this . call ( " dialog" , " add" , MediaDialog , {
47
+ this . env . services . dialog . add ( MediaDialog , {
43
48
noImages : true ,
44
49
noDocuments : true ,
45
50
noVideos : true ,
@@ -58,25 +63,25 @@ options.registry.Rating = options.Class.extend({
58
63
this . iconType = 'custom' ;
59
64
}
60
65
} ) ;
61
- } ,
66
+ }
62
67
/**
63
68
* Sets the number of active icons.
64
69
*
65
70
* @see this.selectClass for parameters
66
71
*/
67
- activeIconsNumber : function ( previewMode , widgetValue , params ) {
72
+ activeIconsNumber ( previewMode , widgetValue , params ) {
68
73
this . nbActiveIcons = parseInt ( widgetValue ) ;
69
74
this . _createIcons ( ) ;
70
- } ,
75
+ }
71
76
/**
72
77
* Sets the total number of icons.
73
78
*
74
79
* @see this.selectClass for parameters
75
80
*/
76
- totalIconsNumber : function ( previewMode , widgetValue , params ) {
81
+ totalIconsNumber ( previewMode , widgetValue , params ) {
77
82
this . nbTotalIcons = Math . max ( parseInt ( widgetValue ) , 1 ) ;
78
83
this . _createIcons ( ) ;
79
- } ,
84
+ }
80
85
81
86
//--------------------------------------------------------------------------
82
87
// Private
@@ -85,7 +90,7 @@ options.registry.Rating = options.Class.extend({
85
90
/**
86
91
* @override
87
92
*/
88
- _computeWidgetState : function ( methodName , params ) {
93
+ _computeWidgetState ( methodName , params ) {
89
94
switch ( methodName ) {
90
95
case 'setIcons' : {
91
96
return this . $target [ 0 ] . dataset . icon ;
@@ -99,14 +104,14 @@ options.registry.Rating = options.Class.extend({
99
104
return this . nbTotalIcons ;
100
105
}
101
106
}
102
- return this . _super ( ...arguments ) ;
103
- } ,
107
+ return super . _computeWidgetState ( ...arguments ) ;
108
+ }
104
109
/**
105
110
* Creates the icons.
106
111
*
107
112
* @private
108
113
*/
109
- _createIcons : function ( ) {
114
+ _createIcons ( ) {
110
115
const $activeIcons = this . $target . find ( '.s_rating_active_icons' ) ;
111
116
const $inactiveIcons = this . $target . find ( '.s_rating_inactive_icons' ) ;
112
117
this . $target . find ( '.s_rating_icons i' ) . remove ( ) ;
@@ -118,13 +123,13 @@ options.registry.Rating = options.Class.extend({
118
123
}
119
124
}
120
125
this . _renderIcons ( ) ;
121
- } ,
126
+ }
122
127
/**
123
128
* Renders icons with selected fonts.
124
129
*
125
130
* @private
126
131
*/
127
- _renderIcons : function ( ) {
132
+ _renderIcons ( ) {
128
133
const icons = {
129
134
'fa-star' : 'fa-star-o' ,
130
135
'fa-thumbs-up' : 'fa-thumbs-o-up' ,
@@ -138,5 +143,11 @@ options.registry.Rating = options.Class.extend({
138
143
const $inactiveIcons = this . $target . find ( '.s_rating_inactive_icons > i' ) ;
139
144
$activeIcons . removeClass ( ) . addClass ( faClassActiveIcons ) ;
140
145
$inactiveIcons . removeClass ( ) . addClass ( faClassInactiveIcons ) ;
141
- } ,
146
+ }
147
+ }
148
+
149
+ registerWebsiteOption ( "Rating" , {
150
+ Class : RatingOption ,
151
+ template : "website.s_rating_option" ,
152
+ selector : ".s_rating" ,
142
153
} ) ;
0 commit comments