private static void OnFormRendererEvent(
            IFormRenderer <HTMLElement> sender, ToolbarSettings toolbarSettings)
        {
            var maybeTopMostPopup = sender.TopMostPopup;

            Logger.Debug(typeof(FormRendererExtensions), "OnFormRendererEvent master={0} popup={1}", sender.Master, maybeTopMostPopup);

            if (maybeTopMostPopup is IAugmentsToolbar)
            {
                ((IAugmentsToolbar)sender.TopMostPopup).OnAugmentToolbar(toolbarSettings);
            }
            else if (sender.Master is IAugmentsToolbar)
            {
                ((IAugmentsToolbar)sender.Master).OnAugmentToolbar(toolbarSettings);
            }

            //TODO optimization opportunity: store "former settings" and compare it against new ones to execute necessary calls only
            IawAppApi.SetToolbarColors(toolbarSettings.AppBarBackgroundColor, toolbarSettings.AppBarForegroundColor);
            IawAppApi.SetToolbarSearchState(toolbarSettings.SearchCallback);
            IawAppApi.SetToolbarItems(activated => {
                Logger.Debug(typeof(FormRendererExtensions), "OnMenuItemActivated raw menuItem {0}", activated);
                var maybeMenuItem = toolbarSettings.MenuItems.FirstOrDefault(x => x.Item1.webMenuItemId == activated.webMenuItemId);
                Logger.Debug(typeof(FormRendererExtensions), "OnMenuItemActivated found?={0}", maybeMenuItem != null);
                maybeMenuItem?.Item2();
            },
                                      toolbarSettings.MenuItems.Select(x => x.Item1));
            IawAppApi.SetToolbarBackButtonState(toolbarSettings.BackActionVisible);
        }
        private async Task HandleScanning()
        {
            _hndl = IawAppApi.RequestScanQr(
                true,
                new MatchWidthWithFixedHeightLayoutStrategy(
                    _scannerPopupHeightMm, _scannerPopupMmFromTop));

            var ended = false;

            while (!ended)
            {
                var ev = await _hndl.GetNext();

                Logger.Debug(GetType(), "got ({0}; {1})", ev.Item1, ev.Item2);

                switch (ev.Item1)
                {
                case ScanResultType.Scanned:
                    try {
                        _errorOrNull = null;
                        ScannedCode  = await _getItemByCode(ev.Item2);
                    } catch (Exception ex) {
                        _errorOrNull = ex.Message;
                    }
                    await _errorLbl.DoChange(_errorOrNull, false, this, false);

                    break;

                case ScanResultType.Paused:
                    if (_errorOrNull == null)
                    {
                        _hndl.CancelScanning();
                    }
                    else
                    {
                        //TODO extract into stylesheet
                        _view.Unpause.Widget.Style.SetProperty("display", "");
                    }
                    break;

                case ScanResultType.Disposed:
                    _hndl = null;
                    ended = true;
                    Ended?.Invoke(this,
                                  ScannedCode == null ? CompletedOrCanceled.Canceled : CompletedOrCanceled.Completed);
                    break;
                }
            }
        }
Exemple #3
0
        public static void InitializeToolkit(
            ILoggerImplementation customLogger = null,
            Func <DatagridContent, Task <FileModel> > spreadsheetBuilder = null,
            bool?clickingOutsideOfDialogDismissesIt = null)
        {
            ExecOnUiThread.SetImplementation(
                async x => {
                x();
                await Task.Run(() => {});     //NOP
            },
                async x => {
                await x();
            });

            if (customLogger != null)
            {
                Logger.ConfigureImplementation(customLogger);
            }
            else if (DocumentUtil.HasQueryParameter("debug") && DocumentUtil.GetQueryParameter("debug") == "lite")
            {
                var toIgnoreByType = new [] {
                    typeof(Philadelphia.Web.GeneralAttrChangedObserver),
                    typeof(Philadelphia.Web.GeneralChildListChangedObserver),
                    typeof(Philadelphia.Web.SpecificChildListChangedObserver),
                    typeof(Philadelphia.Web.TooltipManager),
                    typeof(Philadelphia.Web.MouseObserver),
                    typeof(Philadelphia.Web.FormCanvasExtensions),
                    typeof(Philadelphia.Web.SpecificResizeObserver)
                };

                var toIgnoreByBaseName = new [] {
                    typeof(Philadelphia.Web.DataGridColumn <string, Unit>).FullNameWithoutGenerics()
                };

                Logger.ConfigureImplementation(new ForwardMatchingToConsoleLogLoggerImplementation(
                                                   x => !toIgnoreByType.Contains(x) && !toIgnoreByBaseName.Contains(x.FullNameWithoutGenerics())));
            }
            else if (DocumentUtil.HasQueryParameter("debug"))
            {
                Logger.ConfigureImplementation(new ForwardEverythingToConsoleLogLoggerImplementation());
            }
            else
            {
                Logger.ConfigureImplementation(new ForwardErrorsToConsoleLogLoggerImplementation());
            }

            DocumentUtil.Initialize(); //initialize tooltips, esc handler etc

            var env = EnvironmentTypeUtil.GetInstanceFromWindow(Window.Instance);

            Document.Body.SetAttribute(Magics.AttrDataEnvironment, env.AsDataEnvironmentAttributeValue());

            Func <DatagridContent, Task <FileModel> > noExportImpl =
                _ => {
                throw new Exception("spreadsheet builder not provided via DataGridSettings.Init()");
            };

            DataGridSettings.Init(spreadsheetBuilder ?? noExportImpl);

            Document.OnDragEnter += ev => {
                Document.Body.SetAttribute(Magics.AttrDataDraggingFile, "x");
                ev.PreventDefault();
            };
            //detect real end of dragging (leaving outside of browser)
            //https://stackoverflow.com/questions/3144881/how-do-i-detect-a-html5-drag-event-entering-and-leaving-the-window-like-gmail-d#14248483
            Document.OnDragLeave += ev => {
                var clientX = (int)ev.GetFieldValue("clientX");
                var clientY = (int)ev.GetFieldValue("clientY");

                if (clientX <= 0 || clientY <= 0)
                {
                    Document.Body.RemoveAttribute(Magics.AttrDataDraggingFile);
                }

                Logger.Debug(typeof(Toolkit), "Document dragleave {0}", ev.Target);
            };

            switch (env)
            {
            case EnvironmentType.Desktop:
                BaseFormCanvasTitleStrategy           = x => new RegularDomElementTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = DefaultExitButtonBuilder;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? false;
                break;

            case EnvironmentType.IndustrialAndroidWebApp:
                BaseFormCanvasTitleStrategy           = x => new BodyBasedPropagatesToAppBatTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = null;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? true;

                IawAppApi.SetOnBackPressed(() => {
                    Logger.Debug(typeof(Toolkit), "backbutton pressed");
                    var consumed = DocumentUtil.TryCloseTopMostForm();
                    Logger.Debug(typeof(Toolkit), "backbutton consumed?={0}", consumed);
                    return(consumed);
                });
                break;

            default: throw new Exception("unsupported environment");
            }
        }