1 /**
  2  * Copyright (C) 2005-2010 Alfresco Software Limited.
  3  *
  4  * This file is part of Alfresco
  5  *
  6  * Alfresco is free software: you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as published by
  8  * the Free Software Foundation, either version 3 of the License, or
  9  * (at your option) any later version.
 10  *
 11  * Alfresco is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  * GNU Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public License
 17  * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
 18  */
 19  
 20 /**
 21  * Alfresco.dashlet.WikiDashlet
 22  * Aggregates events from all the sites the user belongs to.
 23  * For use on the user's dashboard.
 24  *
 25  * @namespace Alfresco
 26  * @class Alfresco.dashlet.WikiDashlet
 27  */
 28 (function()
 29 {
 30    /**
 31     * YUI Library aliases
 32     */
 33    var Dom = YAHOO.util.Dom,
 34       Event = YAHOO.util.Event;
 35 
 36    /**
 37     * WikiDashlet constructor.
 38     * 
 39     * @param {String} htmlId The HTML id of the parent element
 40     * @return {Alfresco.dashlet.WikiDashlet} The new WikiDashlet instance
 41     * @constructor
 42     */
 43    Alfresco.dashlet.WikiDashlet = function WikiDashlet_constructor(htmlId)
 44    {
 45       Alfresco.dashlet.WikiDashlet.superclass.constructor.call(this, "Alfresco.dashlet.WikiDashlet", htmlId);
 46       
 47       this.parser = new Alfresco.WikiParser();
 48       
 49       return this;
 50    };
 51 
 52    YAHOO.extend(Alfresco.dashlet.WikiDashlet, Alfresco.component.Base,
 53    {
 54       /**
 55        * Object container for initialization options
 56        *
 57        * @property options
 58        * @type object
 59        */
 60       options:
 61       {
 62          /**
 63           * The gui id.
 64           *
 65           * @property guid
 66           * @type string
 67           */
 68          guid: "",
 69 
 70          /**
 71           * Current siteId.
 72           *
 73           * @property siteId
 74           * @type string
 75           */
 76          siteId: "",
 77 
 78          /**
 79           * The pages on this site's wiki.
 80           *
 81           * @property pages
 82           * @type Array
 83           */
 84          pages: []
 85       },
 86 
 87       /**
 88        * Wiki mark-up parser instance.
 89        *
 90        * @property parser
 91        * @type Alfresco.WikiParser
 92        */
 93       parser: null,
 94 
 95       /**
 96        * Allows the user to configure the feed for the dashlet.
 97        *
 98        * @property configDialog
 99        * @type DOM node
100        */
101       configDialog: null,
102       
103       /**
104        * Fired by YUI when parent element is available for scripting.
105        * Initialises components, including YUI widgets.
106        *
107        * @method onReady
108        */ 
109       onReady: function WikiDashlet_onReady()
110       {
111          Event.addListener(this.id + "-wiki-link", "click", this.onConfigFeedClick, this, true);
112          
113          this.parser.URL = Alfresco.util.uriTemplate("sitepage",
114          {
115             site: this.options.siteId,
116             pageid: "wiki-page?title="
117          });
118 
119          var wikiDiv = Dom.get(this.id + "-scrollableList");
120          wikiDiv.innerHTML = this.parser.parse(wikiDiv.innerHTML, this.options.pages);
121       },
122       
123       /**
124        * Configuration click handler
125        *
126        * @method onConfigFeedClick
127        * @param e {object} HTML event
128        */
129       onConfigFeedClick: function WikiDashlet_onConfigFeedClick(e)
130       {
131          Event.stopEvent(e);
132 
133          var actionUrl = Alfresco.constants.URL_SERVICECONTEXT + "modules/wiki/config/" + encodeURIComponent(this.options.guid);
134          
135          if (!this.configDialog)
136          {
137             this.configDialog = new Alfresco.module.SimpleDialog(this.id + "-configDialog").setOptions(
138             {
139                width: "50em",
140                templateUrl: Alfresco.constants.URL_SERVICECONTEXT + "modules/wiki/config/" + this.options.siteId,
141                onSuccess:
142                {
143                   fn: function WikiDashlet_onConfigFeed_callback(e)
144                   {
145                      var obj = YAHOO.lang.JSON.parse(e.serverResponse.responseText);
146                      if (obj)
147                      {
148                         // Update the content via the parser
149                         Dom.get(this.id + "-scrollableList").innerHTML = this.parser.parse(obj["content"], this.options.pages);
150                         
151                         // Update the title
152                         Dom.get(this.id + "-title").innerHTML = Alfresco.util.message("label.header-prefix", this.name) + (obj.title !== "" ? " - <a href=\"wiki-page?title=" + encodeURIComponent(e.config.dataObj.wikipage) + "\">" + obj.title + "</a>" : "");
153                      }
154                   },
155                   scope: this
156                }
157             });
158          }
159 
160          this.configDialog.setOptions(
161          {
162             actionUrl: actionUrl
163          }).show();
164       }
165    });
166 })();