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  * AddEmailInvite component.
 22  * 
 23  * @namespace Alfresco
 24  * @class Alfresco.AddEmailInvite
 25  */
 26 (function()
 27 {
 28    /**
 29     * YUI Library aliases
 30     */
 31    var Dom = YAHOO.util.Dom;
 32 
 33    /**
 34     * AddEmailInvite constructor.
 35     * 
 36     * @param {String} htmlId The HTML id of the parent element
 37     * @return {Alfresco.AddEmailInvite} The new AddEmailInvite instance
 38     * @constructor
 39     */
 40    Alfresco.AddEmailInvite = function(htmlId)
 41    {
 42       return Alfresco.AddEmailInvite.superclass.constructor.call(this, "Alfresco.AddEmailInvite", htmlId);
 43    };
 44    
 45    YAHOO.extend(Alfresco.AddEmailInvite, Alfresco.component.Base,
 46    {
 47       /**
 48        * Fired by YUI when parent element is available for scripting.
 49        * Component initialisation, including instantiation of YUI widgets and event listener binding.
 50        *
 51        * @method onReady
 52        */
 53       onReady: function AddEmailInvite_onReady()
 54       {  
 55          // listen on ok button click
 56          this.widgets.addEmailButton = Alfresco.util.createYUIButton(this, "add-email-button", this.addEmailButtonClick);         
 57       },
 58 
 59       /**
 60        * Add email button click
 61        *
 62        * @method addEmailButtonClick
 63        * @param e {object} DOM Event
 64        * @param p_obj {object} Optional object literal from event listener definition
 65        */
 66       addEmailButtonClick: function AddEmailInvite_addEmailButtonClick(e, p_obj)
 67       {
 68          // fetch the firstname, lastname nad email
 69          var firstNameElem = YAHOO.util.Dom.get(this.id + "-firstname"),
 70             firstName = firstNameElem.value,
 71             lastNameElem = YAHOO.util.Dom.get(this.id + "-lastname"),
 72             lastName = lastNameElem.value,
 73             emailElem = YAHOO.util.Dom.get(this.id + "-email"),
 74             email = emailElem.value;
 75          
 76          // check whether we got enough information to proceed
 77          if (firstName.length < 1 || lastName.length < 1 || email.length < 1)
 78          {
 79             Alfresco.util.PopupManager.displayMessage(
 80             {
 81                text: this.msg("addemail.mandatoryfieldsmissing")
 82             });
 83             return;
 84          }
 85          
 86          // Fire the personSelected bubble event
 87          YAHOO.Bubbling.fire("personSelected",
 88          {
 89             firstName: firstName,
 90             lastName: lastName,
 91             email: email
 92          });
 93             
 94          // clear the values
 95          firstNameElem.value = "";
 96          lastNameElem.value = "";
 97          emailElem.value = "";
 98       }
 99    });
100 })();
101