Loading ...
Sorry, an error occurred while loading the content.

Re: Contextmenu for treeview

Expand Messages
  • jeremymefford
    Found a typo, sorry. Instead of doing: if (oTextNode.tier == 1) { do if (oTextNode.data.tier == 1) {
    Message 1 of 3 , Jun 3, 2008
    • 0 Attachment
      Found a typo, sorry. Instead of doing:

      if (oTextNode.tier == 1) {

      do

      if (oTextNode.data.tier == 1) {

      --- In ydn-javascript@yahoogroups.com, "jeremymefford"
      <jeremymefford@...> wrote:
      >
      > If you're using the context menu example then here is a modified
      > function that should be helpful to you.
      >
      >
      > function onTriggerContextMenu(p_oEvent, event, menu) {
      > function getTextNodeFromEventTarget(p_oTarget) {
      > var ret;
      > if (p_oTarget.tagName.toUpperCase() == "A" &&
      > p_oTarget.className == "ygtvlabel") {
      > ret = textNodeMap[p_oTarget.id];
      > }
      > else {
      > if (p_oTarget.parentNode &&
      > p_oTarget.parentNode.nodeType == 1) {
      > ret =
      > getTextNodeFromEventTarget(p_oTarget.parentNode);
      > }
      > }
      > return ret;
      > }
      > var oTextNode =
      > getTextNodeFromEventTarget(this.contextEventTarget);
      > if (oTextNode) {
      > oCurrentTextNode = oTextNode;
      > menu.clearContent();
      > if (oTextNode.data.label == 'Main Menu') {
      > menu.addItems(
      > [
      > { text: "Reorder Items", onclick:
      > { fn: reorderLinks } }
      > ]);
      > } else {
      > if (oTextNode.isLeaf) {
      > menu.addItems(
      > [
      > { text: "Edit", onclick: { fn:
      > editNode } },
      > { text: "Delete", onclick: {
      > fn: deleteNode } }
      > ]);
      > } else {
      > menu.addItems(
      > [
      > {
      > text: "Add",
      > submenu: {
      > id: 'addItems',
      > itemdata: [
      > { text: "New Node", onclick: {fn: addNode }}
      > ]
      > }
      > },
      > { text: "Edit", onclick: { fn:
      > editNode } },
      > { text: "Reorder Items",
      > onclick: { fn: reorderLinks } },
      > { text: "Delete", onclick: {
      > fn: deleteNode } }
      > ]);
      > }
      > }
      > menu.render(document.body);
      > menu.show();
      > } else {
      > this.cancel();
      > }
      > }
      >
      > This only goes by whether the node is a leaf or whether it has another
      > layer below it, however it can easily be scaled to be whatever. If
      > you want to specify menu just by tier then when you're creating the
      > treeview add to the data a tier label.
      >
      > var tempNode = new YAHOO.widget.TextNode({
      > label:'myNode',
      > tier:1,
      > foo:'bar'
      > });
      >
      > then in the onTriggerContextMenu function do this.
      >
      > if (oTextNode.tier == 1) {
      > menu.clearContent();
      > menu.addItems(
      > //generate menu here
      > );
      > }
      >
      > Best-
      > Jeremy
      >
      >
      > --- In ydn-javascript@yahoogroups.com, "nhajek" <nhajek@> wrote:
      > >
      > > Is it possible to have a different context menu for different levels
      > > of a treeview and if it is, how would I implement this? thanks.
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.