1 /**
  2  * Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global ops, runtime*/
 26 
 27 /**
 28  * @constructor
 29  */
 30 ops.MemberProperties = function () {
 31     "use strict";
 32     /**@type{string}*/
 33     this.fullName;
 34     /**@type{string}*/
 35     this.color;
 36     /**@type{string}*/
 37     this.imageUrl;
 38 };
 39 
 40 /**
 41  * Class to represent a member in WebODF.
 42  * A member is uniquely identified by it's memberId,
 43  * and this class encapsulates various things like
 44  * the full name and also custom properties that can represent
 45  * information like the avatar image, color, etc.
 46  * Custom properties that may contain some reserved keys such as fullName
 47  * (string), imageUrl (string representing a URL) and color (string
 48  * representing CSS color value) can be passed.
 49  * @constructor
 50  * @param {!string} memberId The unique identifier of this member.
 51  * @param {!ops.MemberProperties} properties
 52  */
 53 ops.Member = function Member(memberId, properties) {
 54     "use strict";
 55 
 56     var /**@type{!ops.MemberProperties}*/
 57         props = new ops.MemberProperties();
 58 
 59     /**
 60      * Returns the member ID of the member
 61      * @return {!string}
 62      */
 63     function getMemberId() {
 64         return memberId;
 65     }
 66     /**
 67      * Returns the properties of the member
 68      * (including fullName, color, and imageUrl)
 69      * @return {!ops.MemberProperties}
 70      */
 71     function getProperties() {
 72         return props;
 73     }
 74     /**
 75      * Sets some properties on the member
 76      * @param {!Object.<!string, !string>} newProperties
 77      * @return {undefined}
 78      */
 79     function setProperties(newProperties) {
 80         Object.keys(newProperties).forEach(function (key) {
 81             props[key] = newProperties[key];
 82         });
 83     }
 84 
 85     /**
 86      * Removes the properties specified in the object.
 87      * 'fullName', 'color', and 'imageUrl' are not
 88      * removable, they will be filtered out of 
 89      * removedProperties if found.
 90      * @param {!Object.<string,string>} removedProperties
 91      * @return {undefined}
 92      */
 93     function removeProperties(removedProperties) {
 94         Object.keys(removedProperties).forEach(function (key) {
 95             if (key !== "fullName" && key !== "color" && key !== "imageUrl"
 96                     && props.hasOwnProperty(key)) {
 97                 delete props[key];
 98             }
 99         });
100     }
101 
102     this.getMemberId = getMemberId;
103     this.getProperties = getProperties;
104     this.setProperties = setProperties;
105     this.removeProperties = removeProperties;
106 
107     function init() {
108         runtime.assert(Boolean(memberId), "No memberId was supplied!");
109 
110         if (!properties.fullName) {
111             properties.fullName = runtime.tr("Unknown Author");
112         }
113         if (!properties.color) {
114             properties.color = "black";
115         }
116         if (!properties.imageUrl) {
117             properties.imageUrl = "avatar-joe.png";
118         }
119 
120         props = properties;
121     }
122     init();
123 };
124