1 /**
  2  * Copyright (C) 2012-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*/
 26 
 27 /**
 28  * @constructor
 29  * @implements ops.Operation
 30  */
 31 ops.OpRemoveStyle = function OpRemoveStyle() {
 32     "use strict";
 33 
 34     var memberid, timestamp, styleName, styleFamily;
 35 
 36     /**
 37      * @param {!ops.OpRemoveStyle.InitSpec} data
 38      */
 39     this.init = function (data) {
 40         memberid = data.memberid;
 41         timestamp = data.timestamp;
 42         styleName = data.styleName;
 43         styleFamily = data.styleFamily;
 44     };
 45 
 46     this.isEdit = true;
 47     this.group = undefined;
 48 
 49     /**
 50      * @param {!ops.Document} document
 51      */
 52     this.execute = function (document) {
 53         var odtDocument = /**@type{ops.OdtDocument}*/(document),
 54             styleNode = odtDocument.getFormatting().getStyleElement(styleName, styleFamily);
 55 
 56         if (!styleNode) {
 57             return false;
 58         }
 59 
 60         styleNode.parentNode.removeChild(styleNode);
 61 
 62         odtDocument.getOdfCanvas().refreshCSS();
 63         odtDocument.emit(ops.OdtDocument.signalCommonStyleDeleted, {name: styleName, family: styleFamily});
 64         return true;
 65     };
 66 
 67     /**
 68      * @return {!ops.OpRemoveStyle.Spec}
 69      */
 70     this.spec = function () {
 71         return {
 72             optype: "RemoveStyle",
 73             memberid: memberid,
 74             timestamp: timestamp,
 75             styleName: styleName,
 76             styleFamily: styleFamily
 77         };
 78     };
 79 };
 80 /**@typedef{{
 81     optype:string,
 82     memberid:string,
 83     timestamp:number,
 84     styleName:string,
 85     styleFamily:string
 86  }}*/
 87 ops.OpRemoveStyle.Spec;
 88 /**@typedef{{
 89     memberid:string,
 90     timestamp:(number|undefined),
 91     styleName:string,
 92     styleFamily:string
 93  }}*/
 94 ops.OpRemoveStyle.InitSpec;
 95