B2G/gecko/browser/components/places/content/editBookmarkOverlay.js
/**
   * Initialize the panel
   * @param aFor
   *        Either a places-itemId (of a bookmark, folder or a live bookmark),
   *        an array of itemIds (used for bulk tagging), or a URI object (in 
   *        which case, the panel would be initialized in read-only mode).
   * @param [optional] aInfo
   *        JS object which stores additional info for the panel
   *        initialization. The following properties may bet set:
   *        * hiddenRows (Strings array): list of rows to be hidden regardless
   *          of the item edited. Possible values: "title", "location",
   *          "description", "keyword", "loadInSidebar", "feedLocation",
   *          "siteLocation", folderPicker"
   *        * forceReadOnly - set this flag to initialize the panel to its
   *          read-only (view) mode even if the given item is editable.
   */
Initialize the panel
@param aFor
Either a places-itemId (of a bookmark, folder or a live bookmark),
an array of itemIds (used for bulk tagging), or a URI object (in
which case, the panel would be initialized in read-only mode).
@param [optional] aInfo
JS object which stores additional info for the panel
initialization. The following properties may bet set:
hiddenRows (Strings array): list of rows to be hidden regardless
of the item edited.
Initialize the panel @param aFor Either a places - itemId ( of a bookmark folder or a live bookmark ) an array of itemIds ( used for bulk tagging ) or a URI object ( in which case the panel would be initialized in read - only mode ) . @param [ optional ] aInfo JS object which stores additional info for the panel initialization . The following properties may bet set : hiddenRows ( Strings array ) : list of rows to be hidden regardless of the item edited .
function EIO_initPanel(aFor, aInfo) {
    if (this._initialized)
      this.uninitPanel(false);
    var aItemIdList;
    if (Array.isArray(aFor)) {
      aItemIdList = aFor;
      aFor = aItemIdList[0];
    }
    else if (this._multiEdit) {
      this._multiEdit = false;
      this._tags = [];
      this._uris = [];
      this._allTags = [];
      this._itemIds = [];
      this._element("selectionCount").hidden = true;
    }
    this._folderMenuList = this._element("folderMenuList");
    this._folderTree = this._element("folderTree");
    this._determineInfo(aInfo);
    if (aFor instanceof Ci.nsIURI) {
      this._itemId = -1;
      this._uri = aFor;
      this._readOnly = true;
    }
    else {
      this._itemId = aFor;
      this._readOnly = this._readOnly || this._itemId == -1;
      var containerId = PlacesUtils.bookmarks.getFolderIdForItem(this._itemId);
      this._itemType = PlacesUtils.bookmarks.getItemType(this._itemId);
      if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK) {
        this._uri = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
        this._initTextField("keywordField",
                            PlacesUtils.bookmarks
                                       .getKeywordForBookmark(this._itemId));
        this._element("loadInSidebarCheckbox").checked =
          PlacesUtils.annotations.itemHasAnnotation(this._itemId,
                                                    PlacesUIUtils.LOAD_IN_SIDEBAR_ANNO);
      }
      else {
        this._uri = null;
        this._isLivemark = false;
        PlacesUtils.livemarks.getLivemark(
          {id: this._itemId },
          (function (aStatus, aLivemark) {
            if (Components.isSuccessCode(aStatus)) {
              this._isLivemark = true;
              this._initTextField("feedLocationField", aLivemark.feedURI.spec, true);
              this._initTextField("siteLocationField", aLivemark.siteURI ? aLivemark.siteURI.spec : "", true);
              this._showHideRows();
            }
          }).bind(this)
        );
      }
      this._initFolderMenuList(containerId);
      this._initTextField("descriptionField", 
                          PlacesUIUtils.getItemDescription(this._itemId));
    }
    if (this._itemId == -1 ||
        this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK) {
      this._isLivemark = false;
      this._initTextField("locationField", this._uri.spec);
      if (!aItemIdList) {
        var tags = PlacesUtils.tagging.getTagsForURI(this._uri).join(", ");
        this._initTextField("tagsField", tags, false);
      }
      else {
        this._multiEdit = true;
        this._allTags = [];
        this._itemIds = aItemIdList;
        for (var i = 0; i < aItemIdList.length; i++) {
          if (aItemIdList[i] instanceof Ci.nsIURI) {
            this._uris[i] = aItemIdList[i];
            this._itemIds[i] = -1;
          }
          else
            this._uris[i] = PlacesUtils.bookmarks.getBookmarkURI(this._itemIds[i]);
          this._tags[i] = PlacesUtils.tagging.getTagsForURI(this._uris[i]);
        }
        this._allTags = this._getCommonTags();
        this._initTextField("tagsField", this._allTags.join(", "), false);
        this._element("itemsCountText").value =
          PlacesUIUtils.getPluralString("detailsPane.itemsCountLabel",
                                        this._itemIds.length,
                                        [this._itemIds.length]);
      }
      this._rebuildTagsSelectorList();
    }
    this._initNamePicker();
    this._showHideRows();
    if (!this._observersAdded) {
      if (this._itemId != -1 || this._uri || this._multiEdit)
        PlacesUtils.bookmarks.addObserver(this, false);
      window.addEventListener("unload", this, false);
      this._observersAdded = true;
    }
    this._initialized = true;
  }
function EIO_initPanel ( aFor , aInfo ) { if ( this . _initialized ) this . uninitPanel ( false ) ; var aItemIdList ; if ( Array . isArray ( aFor ) ) { aItemIdList = aFor ; aFor = aItemIdList [ 0 ] ; } else if ( this . _multiEdit ) { this . _multiEdit = false ; this . _tags = [ ] ; this . _uris = [ ] ; this . _allTags = [ ] ; this . _itemIds = [ ] ; this . _element ( "selectionCount" ) . hidden = true ; } this . _folderMenuList = this . _element ( "folderMenuList" ) ; this . _folderTree = this . _element ( "folderTree" ) ; this . _determineInfo ( aInfo ) ; if ( aFor instanceof Ci . nsIURI ) { this . _itemId = - 1 ; this . _uri = aFor ; this . _readOnly = true ; } else { this . _itemId = aFor ; this . _readOnly = this . _readOnly || this . _itemId == - 1 ; var containerId = PlacesUtils . bookmarks . getFolderIdForItem ( this . _itemId ) ; this . _itemType = PlacesUtils . bookmarks . getItemType ( this . _itemId ) ; if ( this . _itemType == Ci . nsINavBookmarksService . TYPE_BOOKMARK ) { this . _uri = PlacesUtils . bookmarks . getBookmarkURI ( this . _itemId ) ; this . _initTextField ( "keywordField" , PlacesUtils . bookmarks . getKeywordForBookmark ( this . _itemId ) ) ; this . _element ( "loadInSidebarCheckbox" ) . checked = PlacesUtils . annotations . itemHasAnnotation ( this . _itemId , PlacesUIUtils . LOAD_IN_SIDEBAR_ANNO ) ; } else { this . _uri = null ; this . _isLivemark = false ; PlacesUtils . livemarks . getLivemark ( { id : this . _itemId } , ( function ( aStatus , aLivemark ) { if ( Components . isSuccessCode ( aStatus ) ) { this . _isLivemark = true ; this . _initTextField ( "feedLocationField" , aLivemark . feedURI . spec , true ) ; this . _initTextField ( "siteLocationField" , aLivemark . siteURI ? aLivemark . siteURI . spec : "" , true ) ; this . _showHideRows ( ) ; } } ) . bind ( this ) ) ; } this . _initFolderMenuList ( containerId ) ; this . _initTextField ( "descriptionField" , PlacesUIUtils . getItemDescription ( this . _itemId ) ) ; } if ( this . _itemId == - 1 || this . _itemType == Ci . nsINavBookmarksService . TYPE_BOOKMARK ) { this . _isLivemark = false ; this . _initTextField ( "locationField" , this . _uri . spec ) ; if ( ! aItemIdList ) { var tags = PlacesUtils . tagging . getTagsForURI ( this . _uri ) . join ( ", " ) ; this . _initTextField ( "tagsField" , tags , false ) ; } else { this . _multiEdit = true ; this . _allTags = [ ] ; this . _itemIds = aItemIdList ; for ( var i = 0 ; i < aItemIdList . length ; i ++ ) { if ( aItemIdList [ i ] instanceof Ci . nsIURI ) { this . _uris [ i ] = aItemIdList [ i ] ; this . _itemIds [ i ] = - 1 ; } else this . _uris [ i ] = PlacesUtils . bookmarks . getBookmarkURI ( this . _itemIds [ i ] ) ; this . _tags [ i ] = PlacesUtils . tagging . getTagsForURI ( this . _uris [ i ] ) ; } this . _allTags = this . _getCommonTags ( ) ; this . _initTextField ( "tagsField" , this . _allTags . join ( ", " ) , false ) ; this . _element ( "itemsCountText" ) . value = PlacesUIUtils . getPluralString ( "detailsPane.itemsCountLabel" , this . _itemIds . length , [ this . _itemIds . length ] ) ; } this . _rebuildTagsSelectorList ( ) ; } this . _initNamePicker ( ) ; this . _showHideRows ( ) ; if ( ! this . _observersAdded ) { if ( this . _itemId != - 1 || this . _uri || this . _multiEdit ) PlacesUtils . bookmarks . addObserver ( this , false ) ; window . addEventListener ( "unload" , this , false ) ; this . _observersAdded = true ; } this . _initialized = true ; }
Initialize the panel
 @param aFor
        Either a places-itemId (of a bookmark, folder or a live bookmark),
        an array of itemIds (used for bulk tagging), or a URI object (in
        which case, the panel would be initialized in read-only mode).
Initialize the panel @param aFor Either a places - itemId ( of a bookmark folder or a live bookmark ) an array of itemIds ( used for bulk tagging ) or a URI object ( in which case the panel would be initialized in read - only mode ) .
// For sanity ensure that the implementer has uninited the panel before // trying to init it again, or we could end up leaking due to observers. // We can't store information on invalid itemIds. // folder picker // description field // tags selector // name picker // observe changes // Single bookmarks observe any change.  History entries and multiEdit // observe only tags changes, through bookmarks.