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 odf, runtime, ops*/ 26 27 /** 28 * This allows you to update metadata. 29 * setProperties is a flat string -> string mapping Object 30 * that maps a metadata field name (including namespace prefix) 31 * to it's value. 32 * removedProperties is a comma-separated (no spaces) 33 * string of such field names to be removed. 34 * @constructor 35 * @implements ops.Operation 36 */ 37 ops.OpUpdateMetadata = function OpUpdateMetadata() { 38 "use strict"; 39 40 var memberid, timestamp, 41 setProperties, 42 removedProperties; 43 44 /** 45 * @param {!ops.OpUpdateMetadata.InitSpec} data 46 */ 47 this.init = function (data) { 48 memberid = data.memberid; 49 timestamp = parseInt(data.timestamp, 10); 50 setProperties = data.setProperties; 51 removedProperties = data.removedProperties; 52 }; 53 54 this.isEdit = true; 55 this.group = undefined; 56 57 /** 58 * @param {!ops.Document} document 59 */ 60 this.execute = function (document) { 61 var odtDocument = /**@type{ops.OdtDocument}*/(document), 62 odfContainer = odtDocument.getOdfCanvas().odfContainer(), 63 removedPropertiesArray = null; 64 65 if (removedProperties) { 66 removedPropertiesArray = removedProperties.attributes.split(','); 67 } 68 69 odfContainer.setMetadata(setProperties, removedPropertiesArray); 70 71 return true; 72 }; 73 74 /** 75 * @return {!ops.OpUpdateMetadata.Spec} 76 */ 77 this.spec = function () { 78 return { 79 optype: "UpdateMetadata", 80 memberid: memberid, 81 timestamp: timestamp, 82 setProperties: setProperties, 83 removedProperties: removedProperties 84 }; 85 }; 86 }; 87 /**@typedef{{ 88 optype:string, 89 memberid:string, 90 timestamp:number, 91 setProperties:Object, 92 removedProperties:?{attributes:string} 93 }}*/ 94 ops.OpUpdateMetadata.Spec; 95 /**@typedef{{ 96 memberid:string, 97 timestamp:(number|undefined), 98 setProperties:Object, 99 removedProperties:?{attributes:string} 100 }}*/ 101 ops.OpUpdateMetadata.InitSpec; 102