summaryrefslogtreecommitdiff
path: root/addons/survey/static
diff options
context:
space:
mode:
authorJérémy Hennecart <jeh@odoo.com>2020-01-30 10:41:59 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-17 09:37:37 +0000
commit5b74f54396f6cf8986494e4632d0ea1b9940619b (patch)
tree0b0feb93af1f5f2a6a01015affd649bfefff0ecc /addons/survey/static
parent4d9e3171140da0672a4cfd95dbdaf64c7ef45507 (diff)
[IMP] survey: allow to add a description on page
The purpose of this task is to allow the user to create pages which describe the next survey questions. He can now edit the description in a form when he clicks on the info icon when he creates or edits a page/section. Page will be displayed on the frontend in all cases. This allows notably to have pages with some text / comment for presenters when doing live action surveys. Task 2182886 Pr #44271 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/survey/static')
-rw-r--r--addons/survey/static/src/js/fields_form_page_description.js53
-rw-r--r--addons/survey/static/src/js/fields_section_one2many.js48
2 files changed, 77 insertions, 24 deletions
diff --git a/addons/survey/static/src/js/fields_form_page_description.js b/addons/survey/static/src/js/fields_form_page_description.js
new file mode 100644
index 00000000000..05de3cac32f
--- /dev/null
+++ b/addons/survey/static/src/js/fields_form_page_description.js
@@ -0,0 +1,53 @@
+odoo.define('survey.fields_form', function (require) {
+"use strict";
+
+var FieldRegistry = require('web.field_registry');
+var FieldChar = require('web.basic_fields').FieldChar;
+
+var FormDescriptionPage = FieldChar.extend({
+
+ //--------------------------------------------------------------------------
+ // Widget API
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @override
+ */
+ _renderEdit: function () {
+ var def = this._super.apply(this, arguments);
+ this.$el.addClass('col');
+ var $inputGroup = $('<div class="input-group">');
+ this.$el = $inputGroup.append(this.$el);
+ var $button = $(
+ '<div class="input-group-append">\
+ <button type="button" title="Open section" class="btn oe_edit_only o_icon_button">\
+ <i class="fa fa-fw o_button_icon fa-info-circle"/>\
+ </button>\
+ </div>'
+ );
+ this.$el = this.$el.append($button);
+ $button.on('click', this._onClickEdit.bind(this));
+
+ return def;
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _onClickEdit: function (ev) {
+ ev.stopPropagation();
+ var id = this.record.id;
+ if (id) {
+ this.trigger_up('open_record', {id: id, target: ev.target});
+ }
+ },
+});
+
+FieldRegistry.add('survey_description_page', FormDescriptionPage);
+
+});
diff --git a/addons/survey/static/src/js/fields_section_one2many.js b/addons/survey/static/src/js/fields_section_one2many.js
index 7f82200fb90..80a637bc390 100644
--- a/addons/survey/static/src/js/fields_section_one2many.js
+++ b/addons/survey/static/src/js/fields_section_one2many.js
@@ -1,4 +1,4 @@
-odoo.define('survey.question_page_one2many', function (require){
+odoo.define('survey.question_page_one2many', function (require) {
"use strict";
var Context = require('web.Context');
@@ -12,12 +12,12 @@ var SectionListRenderer = ListRenderer.extend({
this.sectionFieldName = "is_page";
this._super.apply(this, arguments);
},
- _checkIfRecordIsSection: function (id){
+ _checkIfRecordIsSection: function (id) {
var record = this._findRecordById(id);
return record && record.data[this.sectionFieldName];
},
- _findRecordById: function (id){
- return _.find(this.state.data, function (record){
+ _findRecordById: function (id) {
+ return _.find(this.state.data, function (record) {
return record.id === id;
});
},
@@ -32,23 +32,23 @@ var SectionListRenderer = ListRenderer.extend({
* @param {*} index
* @param {*} options
*/
- _renderBodyCell: function (record, node, index, options){
+ _renderBodyCell: function (record, node, index, options) {
var $cell = this._super.apply(this, arguments);
var isSection = record.data[this.sectionFieldName];
- if (isSection){
- if (node.attrs.widget === "handle" || node.attrs.name === "random_questions_count"){
+ if (isSection) {
+ if (node.attrs.widget === "handle" || node.attrs.name === "random_questions_count") {
return $cell;
- } else if (node.attrs.name === "title"){
+ } else if (node.attrs.name === "title") {
var nbrColumns = this._getNumberOfCols();
- if (this.handleField){
+ if (this.handleField) {
nbrColumns--;
}
- if (this.addTrashIcon){
+ if (this.addTrashIcon) {
nbrColumns--;
}
- if (record.data.questions_selection === "random"){
+ if (record.data.questions_selection === "random") {
nbrColumns--;
}
$cell.attr('colspan', nbrColumns);
@@ -67,7 +67,7 @@ var SectionListRenderer = ListRenderer.extend({
* @param {*} record
* @param {*} index
*/
- _renderRow: function (record, index){
+ _renderRow: function (record, index) {
var $row = this._super.apply(this, arguments);
if (record.data[this.sectionFieldName]) {
$row.addClass("o_is_section");
@@ -81,7 +81,7 @@ var SectionListRenderer = ListRenderer.extend({
* @private
* @override
*/
- _renderView: function (){
+ _renderView: function () {
var def = this._super.apply(this, arguments);
var self = this;
return def.then(function () {
@@ -98,11 +98,11 @@ var SectionListRenderer = ListRenderer.extend({
* @override
* @param {*} ev
*/
- _onRowClicked: function (ev){
+ _onRowClicked: function (ev) {
var parent = this.getParent();
var recordId = $(ev.currentTarget).data('id');
var is_section = this._checkIfRecordIsSection(recordId);
- if (is_section && parent.mode === "edit"){
+ if (is_section && parent.mode === "edit") {
this.editable = "bottom";
} else {
this.editable = null;
@@ -118,11 +118,11 @@ var SectionListRenderer = ListRenderer.extend({
* @override
* @param {*} ev
*/
- _onCellClick: function (ev){
+ _onCellClick: function (ev) {
var parent = this.getParent();
var recordId = $(ev.currentTarget.parentElement).data('id');
var is_section = this._checkIfRecordIsSection(recordId);
- if (is_section && parent.mode === "edit"){
+ if (is_section && parent.mode === "edit") {
this.editable = "bottom";
} else {
this.editable = null;
@@ -138,13 +138,13 @@ var SectionListRenderer = ListRenderer.extend({
* @override
* @param {*} ev
*/
- _onNavigationMove: function (ev){
+ _onNavigationMove: function (ev) {
this.unselectRow();
},
});
var SectionFieldOne2Many = FieldOne2Many.extend({
- init: function (parent, name, record, options){
+ init: function (parent, name, record, options) {
this._super.apply(this, arguments);
this.sectionFieldName = "is_page";
this.rendered = false;
@@ -154,8 +154,8 @@ var SectionFieldOne2Many = FieldOne2Many.extend({
* @private
* @override
*/
- _getRenderer: function (){
- if (this.view.arch.tag === 'tree'){
+ _getRenderer: function () {
+ if (this.view.arch.tag === 'tree') {
return SectionListRenderer;
}
return this._super.apply(this, arguments);
@@ -170,10 +170,10 @@ var SectionFieldOne2Many = FieldOne2Many.extend({
*/
_onAddRecord: function (ev) {
this.editable = null;
- if (!config.device.isMobile){
+ if (!config.device.isMobile) {
var context_str = ev.data.context && ev.data.context[0];
var context = new Context(context_str).eval();
- if (context['default_' + this.sectionFieldName]){
+ if (context['default_' + this.sectionFieldName]) {
this.editable = "bottom";
}
}
@@ -182,4 +182,4 @@ var SectionFieldOne2Many = FieldOne2Many.extend({
});
FieldRegistry.add('question_page_one2many', SectionFieldOne2Many);
-}); \ No newline at end of file
+});