Exemple #1
0
 protected internal override void VisitChainExpression(ChainExpression chainExpression)
 {
     VisitingChainExpression?.Invoke(this, chainExpression);
     base.VisitChainExpression(chainExpression);
     VisitedChainExpression?.Invoke(this, chainExpression);
 }
Exemple #2
0
        //Listing 20-25. Creating an HTML Client Screen Template Extension


        public void Generate(IScreenTemplateHost host)
        {
            //1 Add a tab
            var screenTab = host.AddContentItem(host.ScreenTabPagesContentItem,
                                                "Tab1", ContentItemKind.Group);

            // 2 Add a group and data items
            ContentItem screenGroup =
                host.AddContentItem(screenTab,
                                    "Group1", host.PrimaryDataSourceProperty);

            screenGroup.View = "Microsoft.LightSwitch.MobileWeb:RowsLayout";
            host.ExpandContentItem(screenGroup,
                                   disableNavigationPropertyGeneration: false,
                                   disableGeneratedPropertyGeneration: false);

            //3 Add a popup called ConfirmDelete
            var popupControl = host.AddContentItem(
                host.ScreenDialogPagesContentItem, "ConfirmDelete",
                ContentItemKind.Group);

            //4.1 Add a string property for the popup title
            ScreenProperty titleProperty =
                (ScreenProperty)host.AddScreenProperty(":String?", "PopupTitle");

            //4.2 Add a text control to the popup and bind it to the string property
            var titleControl = host.AddContentItem(popupControl,
                                                   "PopupTitle", titleProperty);

            titleControl.View = "Microsoft.LightSwitch.MobileWeb:Text";

            //5 Add OK and Cancel methods and add a command to the popup
            ScreenMethod    methodDoDelete   = host.AddScreenMethod("DoDelete");
            CallExpression  callExpDoDelete  = host.CreateCallExpression(methodDoDelete.Id);
            ChainExpression chainExpDoDelete =
                host.CreateChainExpression(callExpDoDelete);
            ScreenExpressionTree expTreeDoDelete =
                new ScreenExpressionTree()
            {
                Body = chainExpDoDelete
            };
            ContentItem commandDoDelete = host.AddContentItem(
                popupControl,
                "DoDelete",
                ContentItemKind.Command);

            host.SetDisplayName(commandDoDelete, "OK");

            //6.1 Create a method to show the popup window
            var commandShowPopup = new ContentItem();

            commandShowPopup.Kind = ContentItemKind.Command;
            ScreenMethod         methodShowPopup  = host.AddScreenMethod("ShowPopup");
            CallExpression       callExpression   = host.CreateCallExpression(methodShowPopup.Id);
            ChainExpression      chainExpression  = host.CreateChainExpression(callExpression);
            ScreenExpressionTree expTreeShowPopup =
                new ScreenExpressionTree()
            {
                Body = chainExpression
            };

            host.SetControlPropertyExpressionTree(
                commandShowPopup,
                "Microsoft.LightSwitch.MobileWeb:RootControl",
                "Tap",
                expTreeShowPopup);

            //6.2 Configure the button to show the trash icon
            ConstantExpression constExpTrashIcon = new ConstantExpression();

            constExpTrashIcon.ResultType = ":String";
            constExpTrashIcon.Value      = "msls-trash";
            ChainExpression chainExpTrashIcon =
                host.CreateChainExpression(constExpTrashIcon);
            ScreenExpressionTree expTreeTrashIcon =
                new ScreenExpressionTree()
            {
                Body = chainExpTrashIcon
            };

            host.SetControlPropertyExpressionTree(
                commandShowPopup,
                "Microsoft.LightSwitch.MobileWeb:RootCommand",
                "Icon",
                expTreeTrashIcon);

            host.SetDisplayName(commandShowPopup, "ShowPopup");
            screenTab.CommandItems.Add(commandShowPopup);

            //7 Add the JavaScript code for the methods

            StringBuilder sb = new StringBuilder();

            sb.Append("{0}myapp.{1}.created = function (screen) {{");
            sb.Append("{0}    screen.PopupTitle = 'Confirm Delete';");
            sb.Append("{0}}};");

            sb.Append("{0}myapp.{1}.DoDelete_execute = function (screen) {{");
            sb.Append("{0}    screen.{2}.deleteEntity();");
            sb.Append("{0}    return myapp.commitChanges();");
            sb.Append("{0}}};");

            sb.Append("{0}myapp.{1}.ShowPopup_execute = function (screen) {{");
            sb.Append("{0}    return screen.showPopup('ShowPopup');");
            sb.Append("{0}}};");

            host.AddScreenCodeBehind(String.Format(sb.ToString(),
                                                   Environment.NewLine,
                                                   host.ScreenName,
                                                   host.PrimaryDataSourceProperty.Name
                                                   ));
        }