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
|
odoo.define('website_slides_survey.upload_modal', function (require) {
"use strict";
var core = require('web.core');
var _t = core._t;
var sessionStorage = window.sessionStorage;
var SlidesUpload = require('website_slides.upload_modal');
/**
* Management of the new 'certification' slide_type
*/
SlidesUpload.SlideUploadDialog.include({
events: _.extend({}, SlidesUpload.SlideUploadDialog.prototype.events || {}, {
'change input#certification_id': '_onChangeCertification'
}),
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* Will automatically set the title of the slide to the title of the chosen certification
*/
_onChangeCertification: function (ev) {
if (ev.added && ev.added.text) {
this.$("input#name").val(ev.added.text);
}
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Overridden to add the "certification" slide type
*
* @override
* @private
*/
_setup: function () {
this._super.apply(this, arguments);
this.slide_type_data['certification'] = {
icon: 'fa-trophy',
label: _t('Certification'),
template: 'website.slide.upload.modal.certification',
};
},
/**
* Overridden to add certifications management in select2
*
* @override
* @private
*/
_bindSelect2Dropdown: function () {
this._super.apply(this, arguments);
var self = this;
this.$('#certification_id').select2(this._select2Wrapper(_t('Certification'), false,
function () {
return self._rpc({
route: '/slides_survey/certification/search_read',
params: {
fields: ['title'],
}
});
}, 'title')
);
},
/**
* The select2 field makes the "required" input hidden on the interface.
* We need to make the "certification" field required so we override this method
* to handle validation in a fully custom way.
*
* @override
* @private
*/
_formValidate: function () {
var result = this._super.apply(this, arguments);
var $certificationInput = this.$('#certification_id');
if ($certificationInput.length !== 0) {
var $select2Container = $certificationInput
.closest('.form-group')
.find('.select2-container');
$select2Container.removeClass('is-invalid is-valid');
if ($certificationInput.is(':invalid')) {
$select2Container.addClass('is-invalid');
} else if ($certificationInput.is(':valid')) {
$select2Container.addClass('is-valid');
}
}
return result;
},
/**
* Overridden to add the 'certification' field into the submitted values
*
* @override
* @private
*/
_getSelect2DropdownValues: function () {
var result = this._super.apply(this, arguments);
var certificateValue = this.$('#certification_id').select2('data');
var survey = {};
if (certificateValue) {
if (certificateValue.create) {
survey.id = false;
survey.title = certificateValue.text;
} else {
survey.id = certificateValue.id;
}
}
result['survey'] = survey;
return result;
},
/**
* Overridde to handle certification created on-the-fly: toaster will hold
* survey edit url, need to put it in session to use it in CertificationUploadToast
*
* @override
* @private
*/
_onFormSubmitDone: function (data) {
if (!data.error && data.redirect_to_certification) {
sessionStorage.setItem("survey_certification_url", data.redirect_url);
window.location.reload();
} else {
this._super.apply(this, arguments);
}
},
});
SlidesUpload.websiteSlidesUpload.include({
xmlDependencies: (SlidesUpload.websiteSlidesUpload.prototype.xmlDependencies || []).concat(
["/website_slides_survey/static/src/xml/website_slide_upload.xml"]
),
});
});
|