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 odtDocument.emit(ops.OdtDocument.signalMetadataUpdated, { 72 setProperties: setProperties !== null ? setProperties : {}, 73 removedProperties: removedPropertiesArray !== null ? removedPropertiesArray : [] 74 }); 75 76 return true; 77 }; 78 79 /** 80 * @return {!ops.OpUpdateMetadata.Spec} 81 */ 82 this.spec = function () { 83 return { 84 optype: "UpdateMetadata", 85 memberid: memberid, 86 timestamp: timestamp, 87 setProperties: setProperties, 88 removedProperties: removedProperties 89 }; 90 }; 91 }; 92 /**@typedef{{ 93 optype:string, 94 memberid:string, 95 timestamp:number, 96 setProperties:Object, 97 removedProperties:?{attributes:string} 98 }}*/ 99 ops.OpUpdateMetadata.Spec; 100 /**@typedef{{ 101 memberid:string, 102 timestamp:(number|undefined), 103 setProperties:Object, 104 removedProperties:?{attributes:string} 105 }}*/ 106 ops.OpUpdateMetadata.InitSpec; 107