1 /**
  2  * Copyright (C) 2012 KO GmbH <aditya.bhatt@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 core, gui*/
 26 
 27 /**
 28  * @constructor
 29  * @implements {core.Destroyable}
 30  * @param {!Element} parentElement
 31  */
 32 gui.EditInfoHandle = function EditInfoHandle(parentElement) {
 33     "use strict";
 34 
 35     var /**@type{!Array.<{memberid:!string,time:!Date}>}*/
 36         edits = [],
 37         /**@type{!HTMLDivElement}*/
 38         handle,
 39         document = /**@type{!Document}*/(parentElement.ownerDocument),
 40         htmlns = document.documentElement.namespaceURI,
 41         editinfons = 'urn:webodf:names:editinfo';
 42 
 43     function renderEdits() {
 44         var i, infoDiv, colorSpan, authorSpan, timeSpan;
 45         core.DomUtils.removeAllChildNodes(handle);
 46         for (i = 0; i < edits.length; i += 1) {
 47             infoDiv = document.createElementNS(htmlns, 'div');
 48             infoDiv.className = "editInfo";
 49 
 50             colorSpan = document.createElementNS(htmlns, 'span');
 51             colorSpan.className = "editInfoColor";
 52             colorSpan.setAttributeNS(editinfons, 'editinfo:memberid', edits[i].memberid);
 53 
 54             authorSpan = document.createElementNS(htmlns, 'span');
 55             authorSpan.className = "editInfoAuthor";
 56             authorSpan.setAttributeNS(editinfons, 'editinfo:memberid', edits[i].memberid);
 57 
 58             timeSpan = document.createElementNS(htmlns, 'span');
 59             timeSpan.className = "editInfoTime";
 60             timeSpan.setAttributeNS(editinfons, 'editinfo:memberid', edits[i].memberid);
 61             timeSpan.appendChild(document.createTextNode(edits[i].time.toString()));
 62 
 63             infoDiv.appendChild(colorSpan);
 64             infoDiv.appendChild(authorSpan);
 65             infoDiv.appendChild(timeSpan);
 66             handle.appendChild(infoDiv);
 67         }
 68     }
 69 
 70     /**
 71      * @param {!Array.<{memberid:!string,time:!Date}>} editArray
 72      */
 73     this.setEdits = function (editArray) {
 74         edits = editArray;
 75         renderEdits();
 76     };
 77 
 78     this.show = function () {
 79         handle.style.display = 'block';
 80     };
 81 
 82     this.hide = function () {
 83         handle.style.display = 'none';
 84     };
 85 
 86     /**
 87      * @param {!function(!Error=)} callback, passing an error object in case of error
 88      * @return {undefined}
 89      */
 90     this.destroy = function (callback) {
 91         parentElement.removeChild(handle);
 92         callback();
 93     };
 94 
 95     function init() {
 96         handle = /**@type{!HTMLDivElement}*/(document.createElementNS(htmlns, "div"));
 97         handle.setAttribute('class', 'editInfoHandle');
 98 
 99         handle.style.display = 'none';
100         parentElement.appendChild(handle);
101     }
102 
103     init();
104 };
105