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 runtime, gui, odf */
 26 
 27 
 28 /**
 29  * @constructor
 30  * @param {!ops.Session} session
 31  * @param {!string} inputMemberId
 32  */
 33 gui.SessionContext = function (session, inputMemberId) {
 34     "use strict";
 35 
 36     var odtDocument = session.getOdtDocument(),
 37         odfUtils = odf.OdfUtils;
 38 
 39     /**
 40      * @return {!boolean}
 41      */
 42     this.isLocalCursorWithinOwnAnnotation = function () {
 43         var cursor = odtDocument.getCursor(inputMemberId),
 44             cursorNode,
 45             currentUserName,
 46             parentAnnotation;
 47 
 48         if (!cursor) {
 49             return false;
 50         }
 51 
 52         cursorNode = cursor && cursor.getNode();
 53         currentUserName = odtDocument.getMember(inputMemberId).getProperties().fullName;
 54         parentAnnotation = odfUtils.getParentAnnotation(cursorNode, odtDocument.getRootNode());
 55 
 56         if (parentAnnotation && odfUtils.getAnnotationCreator(parentAnnotation) === currentUserName) {
 57             return true;
 58         }
 59 
 60         return false;
 61     };
 62 };
 63