From bcd15d26915760f5a394bccaacfef0cbd4376137 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Thu, 8 Sep 2016 11:25:03 +0200 Subject: [PATCH] moved MotionComment factory to base.js --- openslides/motions/static/js/motions/base.js | 112 +++++++++++++++++++ openslides/motions/static/js/motions/site.js | 112 ------------------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index fd04d5384..5d7f120d8 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -312,6 +312,118 @@ angular.module('OpenSlidesApp.motions', [ } ]) +// Service for generic comment fields +.factory('MotionComment', [ + 'Config', + function (Config) { + return { + getFields: function () { + // Take input from config field and parse it. It can be some + // JSON or just a comma separated list of strings. + // + // The result is an array of objects. Each object contains + // at least the name of the comment field See configSchema. + // + // Attention: This code does also exist on server side. + var configSchema = { + $schema: "http://json-schema.org/draft-04/schema#", + title: "Motion Comments", + type: "array", + items: { + type: "object", + properties: { + name: { + type: "string", + minLength: 1 + }, + public: { + type: "boolean" + }, + forRecommendation: { + type: "boolean" + }, + forState: { + type: "boolean" + } + }, + required: ["name"] + }, + minItems: 1, + uniqueItems: true + }; + var configValue = Config.get('motions_comments').value; + var fields; + var isJSON = true; + try { + fields = JSON.parse(configValue); + } catch (err) { + isJSON = false; + } + if (isJSON) { + // Config is JSON. Validate it. + if (!jsen(configSchema)(fields)) { + fields = []; + } + } else { + // Config is a comma separated list of strings. Strip out + // empty parts. All valid strings lead to public comment + // fields. + fields = _.map( + _.filter( + configValue.split(','), + function (name) { + return name; + }), + function (name) { + return { + 'name': name, + 'public': true + }; + } + ); + } + return fields; + }, + getFormFields: function () { + var fields = this.getFields(); + return _.map( + fields, + function (field) { + // TODO: Hide non-public fields for unauthorized users. + return { + key: 'comment ' + field.name, + type: 'input', + templateOptions: { + label: field.name, + }, + hideExpression: '!model.more' + }; + } + ); + }, + populateFields: function (motion) { + // Populate content of motion.comments to the single comment + // fields like motion['comment MyComment'], motion['comment MyOtherComment'], ... + var fields = this.getFields(); + if (!motion.comments) { + motion.comments = []; + } + for (var i = 0; i < fields.length; i++) { + motion['comment ' + fields[i].name] = motion.comments[i]; + } + }, + populateFieldsReverse: function (motion) { + // Reverse equivalent to populateFields. + var fields = this.getFields(); + motion.comments = []; + for (var i = 0; i < fields.length; i++) { + motion.comments.push(motion['comment ' + fields[i].name] || ''); + } + } + }; + } +]) + .factory('Category', [ 'DS', function(DS) { diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 9670933ae..bc81867f7 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -525,118 +525,6 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid } ]) -// Service for generic comment fields -.factory('MotionComment', [ - 'Config', - function (Config) { - return { - getFields: function () { - // Take input from config field and parse it. It can be some - // JSON or just a comma separated list of strings. - // - // The result is an array of objects. Each object contains - // at least the name of the comment field See configSchema. - // - // Attention: This code does also exist on server side. - var configSchema = { - $schema: "http://json-schema.org/draft-04/schema#", - title: "Motion Comments", - type: "array", - items: { - type: "object", - properties: { - name: { - type: "string", - minLength: 1 - }, - public: { - type: "boolean" - }, - forRecommendation: { - type: "boolean" - }, - forState: { - type: "boolean" - } - }, - required: ["name"] - }, - minItems: 1, - uniqueItems: true - }; - var configValue = Config.get('motions_comments').value; - var fields; - var isJSON = true; - try { - fields = JSON.parse(configValue); - } catch (err) { - isJSON = false; - } - if (isJSON) { - // Config is JSON. Validate it. - if (!jsen(configSchema)(fields)) { - fields = []; - } - } else { - // Config is a comma separated list of strings. Strip out - // empty parts. All valid strings lead to public comment - // fields. - fields = _.map( - _.filter( - configValue.split(','), - function (name) { - return name; - }), - function (name) { - return { - 'name': name, - 'public': true - }; - } - ); - } - return fields; - }, - getFormFields: function () { - var fields = this.getFields(); - return _.map( - fields, - function (field) { - // TODO: Hide non-public fields for unauthorized users. - return { - key: 'comment ' + field.name, - type: 'input', - templateOptions: { - label: field.name, - }, - hideExpression: '!model.more' - }; - } - ); - }, - populateFields: function (motion) { - // Populate content of motion.comments to the single comment - // fields like motion['comment MyComment'], motion['comment MyOtherComment'], ... - var fields = this.getFields(); - if (!motion.comments) { - motion.comments = []; - } - for (var i = 0; i < fields.length; i++) { - motion['comment ' + fields[i].name] = motion.comments[i]; - } - }, - populateFieldsReverse: function (motion) { - // Reverse equivalent to populateFields. - var fields = this.getFields(); - motion.comments = []; - for (var i = 0; i < fields.length; i++) { - motion.comments.push(motion['comment ' + fields[i].name] || ''); - } - } - }; - } -]) - // Service for generic motion form (create and update) .factory('MotionForm', [ 'gettextCatalog',