-
Notifications
You must be signed in to change notification settings - Fork 776
/
question_ranking.ts
734 lines (652 loc) · 24.8 KB
/
question_ranking.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
import { ISurveyImpl } from "./base-interfaces";
import { DragDropRankingChoices } from "./dragdrop/ranking-choices";
import { DragDropRankingSelectToRank } from "./dragdrop/ranking-select-to-rank";
import { ItemValue } from "./itemvalue";
import { property, Serializer } from "./jsonobject";
import { QuestionFactory } from "./questionfactory";
import { QuestionCheckboxModel } from "./question_checkbox";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { IsMobile } from "./utils/devices";
import { Helpers } from "./helpers";
import { settings } from "../src/settings";
import { AnimationGroup, IAnimationConsumer } from "./utils/animation";
import { DragOrClickHelper } from "./utils/dragOrClickHelper";
/**
* A class that describes the Ranking question type.
*
* [View Demo](https://surveyjs.io/form-library/examples/questiontype-ranking/ (linkStyle))
*/
export class QuestionRankingModel extends QuestionCheckboxModel {
private domNode: HTMLElement = null;
private dragOrClickHelper: DragOrClickHelper;
constructor(name: string) {
super(name);
this.createNewArray("rankingChoices");
this.createNewArray("unRankingChoices");
this.registerFunctionOnPropertyValueChanged("selectToRankEnabled", () => {
this.clearValue();
this.setDragDropRankingChoices();
this.updateRankingChoicesSync();
});
this.dragOrClickHelper = new DragOrClickHelper(this.startDrag);
}
protected getDefaultItemComponent(): string {
return "";
}
public getType(): string {
return "ranking";
}
public getItemTabIndex(item: ItemValue) {
if (this.isDesignMode || item.disabled) return undefined;
return 0;
}
protected supportContainerQueries() {
return this.selectToRankEnabled;
}
public get rootClass(): string {
return new CssClassBuilder()
.append(this.cssClasses.root)
.append(this.cssClasses.rootMobileMod, this.isMobileMode())
.append(this.cssClasses.rootDisabled, this.isDisabledStyle)
.append(this.cssClasses.rootReadOnly, this.isReadOnlyStyle)
.append(this.cssClasses.rootPreview, this.isPreviewStyle)
.append(this.cssClasses.rootDesignMode, !!this.isDesignMode)
.append(this.cssClasses.itemOnError, this.hasCssError())
.append(this.cssClasses.rootDragHandleAreaIcon, settings.rankingDragHandleArea === "icon")
.append(this.cssClasses.rootSelectToRankMod, this.selectToRankEnabled)
.append(this.cssClasses.rootSelectToRankEmptyValueMod, this.isEmpty())
.append(this.cssClasses.rootSelectToRankAlignHorizontal, this.selectToRankEnabled && this.renderedSelectToRankAreasLayout === "horizontal")
.append(this.cssClasses.rootSelectToRankAlignVertical, this.selectToRankEnabled && this.renderedSelectToRankAreasLayout === "vertical")
.toString();
}
protected isItemSelectedCore(item: ItemValue): boolean {
return false;
}
protected getItemClassCore(item: ItemValue, options: any): string {
const itemIndex = this.rankingChoices.indexOf(item);
const unrankedItemIndex = this.unRankingChoices.indexOf(item);
const dropTargetIndex = this.rankingChoices.indexOf(this.currentDropTarget);
let isDrop = (this.selectToRankEnabled && itemIndex > -1 && unrankedItemIndex > -1) || this.currentDropTarget === item;
return new CssClassBuilder()
.append(super.getItemClassCore(item, options))
.append(this.cssClasses.itemGhostMod, isDrop)
.append(
"sv-dragdrop-movedown",
itemIndex === dropTargetIndex + 1 && this.dropTargetNodeMove === "down"
)
.append(
"sv-dragdrop-moveup",
itemIndex === dropTargetIndex - 1 && this.dropTargetNodeMove === "up"
)
.toString();
}
public getContainerClasses(containerType?: string) {
let isEmpty = false;
const isToContainer = containerType === "to";
const isFromContainer = containerType === "from";
if (isToContainer) {
isEmpty = this.rankingChoices.length === 0;
} else if (isFromContainer) {
isEmpty = this.unRankingChoices.length === 0;
}
return new CssClassBuilder()
.append(this.cssClasses.container)
.append(this.cssClasses.containerToMode, isToContainer)
.append(this.cssClasses.containerFromMode, isFromContainer)
.append(this.cssClasses.containerEmptyMode, isEmpty)
.toString();
}
protected isItemCurrentDropTarget(item: ItemValue): boolean {
return this.dragDropRankingChoices.dropTarget === item;
}
public get ghostPositionCssClass(): string {
if (this.ghostPosition === "top")
return this.cssClasses.dragDropGhostPositionTop;
if (this.ghostPosition === "bottom")
return this.cssClasses.dragDropGhostPositionBottom;
return "";
}
public getItemIndexClasses(item: ItemValue) {
let noNumber;
if (this.selectToRankEnabled) {
noNumber = this.unRankingChoices.indexOf(item) !== -1;
} else {
noNumber = this.isEmpty();
}
return new CssClassBuilder()
.append(this.cssClasses.itemIndex)
.append(this.cssClasses.itemIndexEmptyMode, noNumber)
.toString();
}
public getNumberByIndex(index: number): string {
return this.isEmpty() ? "" : index + 1 + "";
}
private updateRankingChoicesSync() {
this.animationAllowed = false;
this.updateRankingChoices();
this.animationAllowed = true;
}
public setSurveyImpl(value: ISurveyImpl, isLight?: boolean) {
super.setSurveyImpl(value, isLight);
this.setDragDropRankingChoices();
this.updateRankingChoicesSync();
}
public isAnswerCorrect(): boolean {
return Helpers.isArraysEqual(this.value, this.correctAnswer, false);
}
get requireStrictCompare(): boolean { return true; }
onSurveyValueChanged(newValue: any) {
super.onSurveyValueChanged(newValue);
if (this.isLoadingFromJson) return;
this.updateRankingChoicesSync();
}
protected onVisibleChoicesChanged = (): void => {
super.onVisibleChoicesChanged();
if (this.carryForwardStartUnranked && !this.isValueSetByUser && !this.selectToRankEnabled) {
this.value = [];
}
// ranking question with only one choice doesn't make sense
if (this.visibleChoices.length === 1 && !this.selectToRankEnabled) {
this.value = [];
this.value.push(this.visibleChoices[0].value);
this.updateRankingChoicesSync();
return;
}
if (this.isEmpty()) {
this.updateRankingChoicesSync();
return;
}
if (this.selectToRankEnabled) {
this.updateRankingChoicesSync();
return;
}
if (this.visibleChoices.length > this.value.length)
this.addToValueByVisibleChoices();
if (this.visibleChoices.length < this.value.length)
this.removeFromValueByVisibleChoices();
this.updateRankingChoicesSync();
};
public localeChanged = (): void => {
super.localeChanged();
this.updateRankingChoicesSync();
};
private addToValueByVisibleChoices() {
const newValue = this.value.slice();
this.visibleChoices.forEach((choice) => {
if (newValue.indexOf(choice.value) === -1) {
newValue.push(choice.value);
}
});
this.value = newValue;
}
private removeFromValueByVisibleChoices() {
const newValue = this.value.slice();
const choices = this.visibleChoices;
for(let i = this.value.length - 1; i >= 0; i --) {
if(!ItemValue.getItemByValue(choices, this.value[i])) {
newValue.splice(i, 1);
}
}
this.value = newValue;
}
private getChoicesAnimation(isRankingChoices: boolean): IAnimationConsumer<[ItemValue]> {
return {
isAnimationEnabled: () => this.animationAllowed,
getLeaveOptions: (item: ItemValue) => {
const choices = isRankingChoices ? this.rankingChoices : this.unRankingChoices;
if(this.renderedSelectToRankAreasLayout == "vertical" && choices.length == 1 && choices.indexOf(item) >= 0) {
return { cssClass: "sv-ranking-item--animate-item-removing-empty" };
}
return { cssClass: "sv-ranking-item--animate-item-removing" };
},
getEnterOptions: (item: ItemValue) => {
const choices = isRankingChoices ? this.rankingChoices : this.unRankingChoices;
if(this.renderedSelectToRankAreasLayout == "vertical" && choices.length == 1 && choices.indexOf(item) >= 0) {
return { cssClass: "sv-ranking-item--animate-item-adding-empty" };
}
return { cssClass: "sv-ranking-item--animate-item-adding" };
},
getAnimatedElement: (item: ItemValue) => {
const containerSelector = isRankingChoices ? ".sv-ranking__container--to" : ".sv-ranking__container--from";
return this.getWrapperElement()?.querySelector(`${containerSelector} .sv-ranking-item--ghost`);
}
};
}
private _rankingChoicesAnimation = new AnimationGroup(this.getChoicesAnimation(true), (val) => {
this.setPropertyValue("rankingChoices", val);
}, () => this.rankingChoices)
public get rankingChoicesAnimation(): AnimationGroup<ItemValue> {
return this._rankingChoicesAnimation;
}
private _unRankingChoicesAnimation = new AnimationGroup(this.getChoicesAnimation(false), (val) => {
this.setPropertyValue("unRankingChoices", val);
}, () => this.unRankingChoices)
public get unRankingChoicesAnimation(): AnimationGroup<ItemValue> {
return this._unRankingChoicesAnimation;
}
public get rankingChoices(): Array<ItemValue> {
return this.getPropertyValue("rankingChoices", []);
}
public set rankingChoices(val) {
this._rankingChoicesAnimation.sync(val);
}
public get unRankingChoices(): Array<ItemValue> {
return this.getPropertyValue("unRankingChoices", []);
}
public set unRankingChoices(val) {
this._unRankingChoicesAnimation.sync(val);
}
private updateRankingChoices(forceUpdate = false): ItemValue[] {
if (this.selectToRankEnabled) {
this.updateRankingChoicesSelectToRankMode(forceUpdate);
return;
}
const newRankingChoices: ItemValue[] = [];
// ranking question with only one choice doesn't make sense
// if (this.visibleChoices.length === 1) {
// this.setPropertyValue("rankingChoices", newRankingChoices);
// return;
// }
if (forceUpdate) this.setPropertyValue("rankingChoices", []);
if (this.isEmpty()) {
this.setPropertyValue("rankingChoices", this.visibleChoices);
return;
}
this.value.forEach((valueItem: string) => {
this.visibleChoices.forEach((choice) => {
if (choice.value === valueItem) newRankingChoices.push(choice);
});
});
this.setPropertyValue("rankingChoices", newRankingChoices);
}
public updateUnRankingChoices(newRankingChoices: Array<ItemValue>) {
const unRankingChoices: ItemValue[] = [];
this.visibleChoices.forEach((choice) => {
unRankingChoices.push(choice);
});
newRankingChoices.forEach((rankingChoice: ItemValue) => {
unRankingChoices.forEach((choice, index) => {
if (choice.value === rankingChoice.value) unRankingChoices.splice(index, 1);
});
});
this.unRankingChoices = unRankingChoices;
}
private updateRankingChoicesSelectToRankMode(forceUpdate:boolean) {
const newRankingChoices: ItemValue[] = [];
if(!this.isEmpty()) {
this.value.forEach((valueItem: string) => {
this.visibleChoices.forEach((choice) => {
if (choice.value === valueItem) newRankingChoices.push(choice);
});
});
}
this.updateUnRankingChoices(newRankingChoices);
this.rankingChoices = newRankingChoices;
}
public dragDropRankingChoices: DragDropRankingChoices;
@property({ defaultValue: null }) currentDropTarget: ItemValue;
@property({ defaultValue: null }) dropTargetNodeMove: string;
endLoadingFromJson(): void {
super.endLoadingFromJson();
this.setDragDropRankingChoices();
}
private setDragDropRankingChoices() {
this.dragDropRankingChoices = this.createDragDropRankingChoices();
}
protected createDragDropRankingChoices() {
if (this.selectToRankEnabled)
return new DragDropRankingSelectToRank(this.survey, null, this.longTap);
return new DragDropRankingChoices(this.survey, null, this.longTap);
}
private draggedChoise: ItemValue;
private draggedTargetNode: HTMLElement;
public handlePointerDown = (
event: PointerEvent,
choice: ItemValue,
node: HTMLElement
): void => {
const target: HTMLElement = <HTMLElement>event.target;
if (!this.isDragStartNodeValid(target)) return;
if (
this.allowStartDrag &&
this.canStartDragDueMaxSelectedChoices(target) &&
this.canStartDragDueItemEnabled(choice)
)
{
this.draggedChoise = choice;
this.draggedTargetNode = node;
this.dragOrClickHelper.onPointerDown(event);
}
};
public startDrag = (event: PointerEvent): void => {
this.dragDropRankingChoices.startDrag(event, this.draggedChoise, this, this.draggedTargetNode);
}
public handlePointerUp = (
event: PointerEvent,
choice: ItemValue,
node: HTMLElement
): void => {
if (!this.selectToRankEnabled) return;
if (
this.allowStartDrag
) {
this.handleKeydownSelectToRank(<any>event, choice, " ", false);
}
};
private isDragStartNodeValid(target: HTMLElement): boolean {
if (settings.rankingDragHandleArea === "icon") {
return target.classList.contains(this.cssClasses.itemIconHoverMod);
}
return true;
}
private get allowStartDrag() {
return !this.isReadOnly && !this.isDesignMode;
}
private canStartDragDueMaxSelectedChoices(target: HTMLElement):boolean {
if (!this.selectToRankEnabled) return true;
let fromContainer: HTMLElement = target.closest("[data-ranking='from-container']");
if (fromContainer) {
return this.checkMaxSelectedChoicesUnreached();
}
return true;
}
private canStartDragDueItemEnabled(item: ItemValue): boolean {
return item.enabled;
}
public checkMaxSelectedChoicesUnreached() {
if (this.maxSelectedChoices < 1) return true;
var val = this.value;
var len = !Array.isArray(val) ? 0 : val.length;
return len < this.maxSelectedChoices;
}
//cross framework initialization
public afterRenderQuestionElement(el: HTMLElement): void {
this.domNode = el;
super.afterRenderQuestionElement(el);
}
//cross framework destroy
public beforeDestroyQuestionElement(el: HTMLElement): void {
super.beforeDestroyQuestionElement(el);
}
public handleKeydown = (event: KeyboardEvent, choice: ItemValue): void => {
if (!this.isDesignMode) {
const key: any = event.key;
let index = this.rankingChoices.indexOf(choice);
if (this.selectToRankEnabled) {
this.handleKeydownSelectToRank(event, choice);
return;
}
if (key === "ArrowUp" && index) {
this.handleArrowKeys(index, choice, false);
event.preventDefault();
}
if (key === "ArrowDown" && index !== this.rankingChoices.length - 1) {
this.handleArrowKeys(index, choice, true);
event.preventDefault();
}
}
};
protected supportSelectAll(): boolean { return false; }
public supportOther(): boolean { return false; }
public supportNone(): boolean { return false; }
public supportRefuse(): boolean { return false; }
public supportDontKnow(): boolean { return false; }
private handleArrowKeys = (index: number, choice: ItemValue, isDown: boolean) => {
const delta = isDown ? 1 : -1;
const choices = this.rankingChoices;
choices.splice(index, 1);
choices.splice(index + delta, 0, choice);
this.setValue();
setTimeout(() => {
this.focusItem(index + delta);
}, 1);
}
public handleKeydownSelectToRank(event: KeyboardEvent, movedElement: ItemValue, hardKey?:string, isNeedFocus: boolean = true): void {
if (this.isDesignMode) return;
let key: any = event.key;
if (hardKey) key = hardKey;
if(key !== " " && key !== "ArrowUp" && key !== "ArrowDown") return;
const dnd:any = this.dragDropRankingChoices; //????
const rankingChoices = this.rankingChoices;
const isMovedElementRanked = rankingChoices.indexOf(movedElement) !== -1;
const choices = isMovedElementRanked ? rankingChoices : this.unRankingChoices;
const fromIndex = choices.indexOf(movedElement);
if(fromIndex < 0) return;
let toIndex;
if (key === " " && !isMovedElementRanked) {
if (!this.checkMaxSelectedChoicesUnreached() || !this.canStartDragDueItemEnabled(movedElement)) return;
toIndex = this.value.length;
this.animationAllowed = false;
dnd.selectToRank(this, fromIndex, toIndex);
this.animationAllowed = true;
this.setValueAfterKeydown(toIndex, "to-container", isNeedFocus);
return;
}
if(!isMovedElementRanked) return;
if (key === " ") {
this.animationAllowed = false;
dnd.unselectFromRank(this, fromIndex);
this.animationAllowed = true;
toIndex = this.unRankingChoices.indexOf(movedElement); //'this.' leads to actual array after the 'unselectFromRank' method
this.setValueAfterKeydown(toIndex, "from-container", isNeedFocus);
return;
}
const delta = key === "ArrowUp" ? -1 : (key === "ArrowDown" ? 1 : 0);
if(delta === 0) return;
toIndex = fromIndex + delta;
if(toIndex < 0 || toIndex >= rankingChoices.length) return;
dnd.reorderRankedItem(this, fromIndex, toIndex);
this.setValueAfterKeydown(toIndex, "to-container", isNeedFocus);
}
private setValueAfterKeydown(index: number, container: string, isNeedFocus: boolean = true) {
this.setValue();
if (isNeedFocus) {
setTimeout(() => {
this.focusItem(index, container);
}, 1);
}
event && event.preventDefault();
}
private focusItem = (index: number, container?: string) => {
if (this.selectToRankEnabled && container) {
const containerSelector = "[data-ranking='" + container + "']";
const itemsNodes: any = this.domNode.querySelectorAll(
containerSelector + " " + "." + this.cssClasses.item
);
itemsNodes[index].focus();
} else {
const itemsNodes: any = this.domNode.querySelectorAll(
"." + this.cssClasses.item
);
itemsNodes[index].focus();
}
};
public isValueSetByUser = false;
public setValue = (): void => {
const value: string[] = [];
this.rankingChoicesAnimation.cancel();
this.unRankingChoicesAnimation.cancel();
this.rankingChoices.forEach((choice: ItemValue) => {
value.push(choice.value);
});
this.value = value;
this.isValueSetByUser = true;
};
public getIconHoverCss(): string {
return new CssClassBuilder()
.append(this.cssClasses.itemIcon)
.append(this.cssClasses.itemIconHoverMod)
.toString();
}
public getIconFocusCss(): string {
return new CssClassBuilder()
.append(this.cssClasses.itemIcon)
.append(this.cssClasses.itemIconFocusMod)
.toString();
}
/**
* Specifies whether to use a long tap (press and hold) gesture to start dragging.
*
* Default value: `true`
*
* Disable this property if you want to start dragging when users perform a scroll gesture.
*/
public get longTap(): boolean {
return this.getPropertyValue("longTap");
}
public set longTap(val: boolean) {
this.setPropertyValue("longTap", val);
}
/**
* Specifies whether users can select choices they want to rank.
*
* When you enable this property, the Ranking question displays two areas for ranked and unranked choices. To order choices, users should first drag them from the unranked to the ranked area. Use this mode if you want to let users order only the choices they select.
*
* Default value: `false`
* @see selectToRankAreasLayout
*/
public get selectToRankEnabled(): boolean {
return this.getPropertyValue("selectToRankEnabled", false);
}
public set selectToRankEnabled(val: boolean) {
this.setPropertyValue("selectToRankEnabled", val);
}
@property({ defaultValue: true }) carryForwardStartUnranked: boolean;
/**
* Specifies the layout of the ranked and unranked areas. Applies when [`selectToRankEnabled`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#selectToRankEnabled) is `true`.
*
* Possible values:
*
* - `"horizontal"` (default) - The ranked and unranked areas are positioned next to each other. Users drag and drop choices between them in the horizontal direction.
* - `"vertical"`- The ranked area is positioned above the unranked area. Users drag and drop choices between them in the vertical direction.
* @see selectToRankAreasLayout
*/
public get selectToRankAreasLayout(): string {
return this.getPropertyValue("selectToRankAreasLayout");
}
public set selectToRankAreasLayout(val: string) {
this.setPropertyValue("selectToRankAreasLayout", val);
}
public get renderedSelectToRankAreasLayout(): string {
if (this.isMobileMode()) return "vertical";
return this.selectToRankAreasLayout;
}
public isMobileMode(): boolean {
return IsMobile;
}
/**
* A placeholder displayed in the area for ranked choices. Applies when [`selectToRankEnabled`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#selectToRankEnabled) is `true`.
*/
@property({ localizable: { defaultStr: "selectToRankEmptyRankedAreaText" } }) selectToRankEmptyRankedAreaText: string;
/**
* A placeholder displayed in the area for unranked choices. Applies when [`selectToRankEnabled`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#selectToRankEnabled) is `true`.
*/
@property({ localizable: { defaultStr: "selectToRankEmptyUnrankedAreaText" } }) selectToRankEmptyUnrankedAreaText: string;
public get useFullItemSizeForShortcut(): boolean {
return this.getPropertyValue("useFullItemSizeForShortcut");
}
public set useFullItemSizeForShortcut(val: boolean) {
this.setPropertyValue("useFullItemSizeForShortcut", val);
}
public get dragDropSvgIcon(): string {
return this.cssClasses.dragDropSvgIconId || "#icon-drag-n-drop";
}
public get arrowsSvgIcon(): string {
return this.cssClasses.arrowsSvgIconId || "#icon-ranking-arrows";
}
public get dashSvgIcon(): string {
return this.cssClasses.dashSvgIconId || "#icon-ranking-dash";
}
//a11y
public get isNewA11yStructure(): boolean {
return false;
}
// EO a11y
}
Serializer.addClass(
"ranking",
[
{ name: "showOtherItem", visible: false, isSerializable: false },
{ name: "otherText", visible: false, isSerializable: false },
{ name: "otherErrorText", visible: false, isSerializable: false },
{ name: "storeOthersAsComment", visible: false, isSerializable: false },
{ name: "showNoneItem", visible: false, isSerializable: false },
{ name: "showRefuseItem", visible: false, isSerializable: false },
{ name: "showDontKnowItem", visible: false, isSerializable: false },
{ name: "noneText", visible: false, isSerializable: false },
{ name: "showSelectAllItem", visible: false, isSerializable: false },
{ name: "selectAllText", visible: false, isSerializable: false },
{ name: "colCount:number", visible: false, isSerializable: false },
{ name: "separateSpecialChoices", visible: false, isSerializable: false },
{
name: "longTap",
default: true,
visible: false,
isSerializable: false,
},
{
name: "selectToRankEnabled:switch",
default: false,
visible: true,
isSerializable: true,
},
{
name: "selectToRankAreasLayout",
default: "horizontal",
choices: ["horizontal", "vertical"],
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
visible: true,
isSerializable: true,
},
{
name: "selectToRankEmptyRankedAreaText:text",
serializationProperty: "locSelectToRankEmptyRankedAreaText",
category: "general",
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
},
{
name: "selectToRankEmptyUnrankedAreaText:text",
serializationProperty: "locSelectToRankEmptyUnrankedAreaText",
category: "general",
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
},
{
name: "maxSelectedChoices:number",
visible: true,
default: 0,
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
isSerializable: true
},
{ name: "minSelectedChoices:number",
visible: true,
default: 0,
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
isSerializable: true
},
{ name: "itemComponent", visible: false, default: "" }
],
function () {
return new QuestionRankingModel("");
},
"checkbox"
);
QuestionFactory.Instance.registerQuestion("ranking", (name) => {
const q: QuestionRankingModel = new QuestionRankingModel(name);
q.choices = QuestionFactory.DefaultChoices;
return q;
});