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  * OpAddMember has 3 required properties:
 29  * fullName, color, and imageUrl. Because the
 30  * spec does not expose those explicitly right now,
 31  * internally these properties are set as
 32  * runtime.tr("Unknown Author"), 'black', and "avatar-joe.png"
 33  * respectively, if unspecified.
 34  * @constructor
 35  * @implements ops.Operation
 36  */
 37 ops.OpAddMember = function OpAddMember() {
 38     "use strict";
 39 
 40     var memberid, timestamp, setProperties;
 41     /**
 42      * @param {!ops.OpAddMember.InitSpec} data
 43      */
 44     this.init = function (data) {
 45         memberid = data.memberid;
 46         timestamp = parseInt(data.timestamp, 10);
 47         setProperties = data.setProperties;
 48     };
 49 
 50     this.isEdit = false;
 51     this.group = undefined;
 52 
 53     /**
 54      * @param {!ops.Document} document
 55      */
 56     this.execute = function (document) {
 57         var odtDocument = /**@type{ops.OdtDocument}*/(document),
 58             member;
 59         if (odtDocument.getMember(memberid)) {
 60             return false;
 61         }
 62 
 63         member = new ops.Member(memberid, setProperties);
 64         odtDocument.addMember(member);
 65         odtDocument.emit(ops.Document.signalMemberAdded, member);
 66 
 67         return true;
 68     };
 69 
 70     /**
 71      * @return {!ops.OpAddMember.Spec}
 72      */
 73     this.spec = function () {
 74         return {
 75             optype: "AddMember",
 76             memberid: memberid,
 77             timestamp: timestamp,
 78             setProperties: setProperties
 79         };
 80     };
 81 };
 82 /**@typedef{{
 83     optype:string,
 84     memberid:string,
 85     timestamp:number,
 86     setProperties:!ops.MemberProperties
 87 }}*/
 88 ops.OpAddMember.Spec;
 89 /**@typedef{{
 90     memberid:string,
 91     timestamp:(number|undefined),
 92     setProperties:!ops.MemberProperties
 93 }}*/
 94 ops.OpAddMember.InitSpec;
 95