<!DOCTYPE html>
<html>

  <head>
    <base href="." />
    <script type="text/javascript" charset="utf-8">
      window.AngularVersionForThisPlunker = 'latest'
    </script>
    <title>angular playground</title>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="https://cdn.syncfusion.com/15.4.0.17/js/web/flat-azure/ej.web.all.min.css" />
    <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
    <script src="https://unpkg.com/zone.js/dist/zone.js"></script>
    <script src="https://unpkg.com/zone.js/dist/long-stack-trace-zone.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
    <script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
    <script src="config.js"></script>
    <script>
    System.import('app')
      .catch(console.error.bind(console));
  </script>
  </head>

  <body>
    <my-app>
    loading...
  </my-app>
  </body>

</html>
/* Styles go here */
.menu{
  padding-left:1px;
  padding-right:1px;
}
### Angular Starter Plunker - Typescript
var angularVersion;
if(window.AngularVersionForThisPlunker === 'latest'){
  angularVersion = ''; //picks up latest
}
else {
  angularVersion = '@' + window.AngularVersionForThisPlunker;
}

System.config({
  //use typescript for compilation
  transpiler: 'typescript',
  //typescript compiler options
  typescriptOptions: {
    emitDecoratorMetadata: true
  },
  paths: {
    'npm:': 'https://unpkg.com/'
  },
  //map tells the System loader where to look for things
  map: {
    
    'app': './src',
    '@angular/core': 'npm:@angular/core'+ angularVersion + '/bundles/core.umd.js',
    '@angular/common': 'npm:@angular/common' + angularVersion + '/bundles/common.umd.js',
    '@angular/common/http': 'npm:@angular/common' + angularVersion + '/bundles/common-http.umd.js',
    '@angular/compiler': 'npm:@angular/compiler' + angularVersion  + '/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic' + angularVersion + '/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:@angular/http' + angularVersion + '/bundles/http.umd.js',
    '@angular/router': 'npm:@angular/router' + angularVersion +'/bundles/router.umd.js',
    '@angular/forms': 'npm:@angular/forms' + angularVersion + '/bundles/forms.umd.js',
    '@angular/animations': 'npm:@angular/animations' + angularVersion + '/bundles/animations.umd.js',
    '@angular/platform-browser/animations': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser-animations.umd.js',
    '@angular/animations/browser': 'npm:@angular/animations' + angularVersion + '/bundles/animations-browser.umd.js',
    
    '@angular/core/testing': 'npm:@angular/core' + angularVersion + '/bundles/core-testing.umd.js',
    '@angular/common/testing': 'npm:@angular/common' + angularVersion + '/bundles/common-testing.umd.js',
    '@angular/common/http/testing': 'npm:@angular/common' + angularVersion + '/bundles/common-http-testing.umd.js',
    '@angular/compiler/testing': 'npm:@angular/compiler' + angularVersion + '/bundles/compiler-testing.umd.js',
    '@angular/platform-browser/testing': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser-testing.umd.js',
    '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic' + angularVersion + '/bundles/platform-browser-dynamic-testing.umd.js',
    '@angular/http/testing': 'npm:@angular/http' + angularVersion + '/bundles/http-testing.umd.js',
    '@angular/router/testing': 'npm:@angular/router' + angularVersion + '/bundles/router-testing.umd.js',
    'tslib': 'npm:tslib@1.6.1',
    'rxjs': 'npm:rxjs',
    'typescript': 'npm:typescript@2.2.1/lib/typescript.js',
     'jquery': 'npm:jquery/dist/jquery.min.js',
      'jsrender': 'npm:jsrender/jsrender.min.js',
      'jquery-validation': 'npm:jquery-validation/dist/jquery.validate.min.js',
      'syncfusion-javascript': 'npm:syncfusion-javascript',
      'ej-angular2': 'npm:ej-angular2'
  },
  //packages defines our app package
  packages: {
    app: {
      main: './main.ts',
      defaultExtension: 'ts'
    },
    rxjs: {
      defaultExtension: 'js'
    }
    ,
      'ej-angular2': {
        main: './src/index.js'
      },
      'syncfusion-javascript': {
        defaultExtension: 'js'
      }
  }
});
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app';

platformBrowserDynamic().bootstrapModule(AppModule)
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'; 
import {EJ_TREEVIEW_COMPONENTS } from 'ej-angular2/src/ej/treeview.component';
import {EJ_MENU_COMPONENTS } from 'ej-angular2/src/ej/menu.component';
@Component({
  selector: 'my-app',
  template: `
    <ej-treeview id="treeView">
       <div class="content-container-fluid">
        <div class="row">
            <div class="cols-sample-area">
                <div style="width: 250px">
                    <ul>
                        <li class="expanded">ASP.NET MVC Team
                                    <ul>
                                        <li>Smith</li>
                                        <li>Johnson</li>
                                        <li>Anderson</li>
                                    </ul>
                        </li>
                        <li>Windows Team
                                    <ul>
                                        <li>Clark</li>
                                        <li>Wright</li>
                                        <li>Lopez</li>
                                    </ul>
                        </li>
                        <li>Web Team
                                    <ul>
                                        <li>Joshua </li>
                                        <li>Matthew </li>
                                        <li>David </li>
                                    </ul>
                        </li>
                        <li>Build Team
                                    <ul>
                                        <li>Ryan </li>
                                        <li>Justin </li>
                                        <li>Robert </li>
                                    </ul>
                        </li>
                        <li>WPF Team
                                    <ul>
                                        <li>Brown </li>
                                        <li>Johnson </li>
                                        <li>Miller </li>
                                    </ul>
                        </li>
                    </ul>
                </div>
                
            </div>
        </div>
    </div>
    </ej-treeview>
    <ej-menu id="treeviewMenu" menuType="contextmenu" [openOnClick]="false" contextMenuTarget="#treeView" (close)="onClose($event)" (beforeOpen)="beforeOpen($event)" (click)="menuclick($event)">
    <div>
                    <ul id="treeviewMenu" class="menu">
                        <li><a href="#">Add New Item</a></li>
                        <li><a href="#">Remove Item</a></li>
                        <li><a href="#">Disable Item</a></li>
                        <li><a href="#">Enable Item</a></li>
                    </ul>
    </div>
    </ej-menu>
  `,
})
export class App {
  constructor() {
      
   
  }
  public selectedNode;
  public onClose(event) {
    event.events.preventDefault();
    }
    public beforeOpen(event) {
      let treeviewObj = $("#treeView").data("ejTreeView");
         if (!$(event.target).hasClass("e-text"))
                event.cancel = true;
            else {
                this.selectedNode = $(event.target).closest('.e-item');
                treeviewObj.selectNode(this.selectedNode);
            }
    }
    public menuclick(event) {
      let treeviewObj = $("#treeView").data("ejTreeView");
      let tabIndex = 1;
            if (event.target.innerText  == "Add New Item") {
              debugger
                treeviewObj.addNode("Item" + tabIndex, null,this.selectedNode);
                tabIndex++;
            }
            else if (event.target.innerText  == "Remove Item") {
                treeviewObj.removeNode(this.selectedNode);
            }
            else if (event.target.innerText  == "Disable Item") {
                treeviewObj.disableNode(this.selectedNode)
            }
            else if (event.target.innerText  == "Enable Item") {
                treeviewObj.enableNode(this.selectedNode)
            }
        }
  }

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App,EJ_TREEVIEW_COMPONENTS,EJ_MENU_COMPONENTS ],
  bootstrap: [ App ]
})
export class AppModule {}