RSS Git Download  Clone
Raw Blame History 2kB 54 lines
p3xr.ng.factory('p3xrDialogJsonView', function (p3xrCommon, $mdDialog) {


    return new function () {

        this.show = async (options) => {

            try {
                const result = await $mdDialog.show({
                    controller: function ($scope, $mdDialog) {

                        try {
                            $scope.obj = JSON.parse(options.value)
                            $scope.isJson = true
                        } catch (e) {
                            $scope.obj = undefined
                            $scope.isJson = false
                        }


                        // Promise reject
                        $scope.ok = function () {
                            $mdDialog.cancel();
                        };

                        /*
                        // Promise resolve
                        $scope.hide = function () {
                            $mdDialog.hide();
                        };

                        // Promise resolve - with result
                        $scope.answer = function (answer) {
                            $mdDialog.hide(answer);
                        };
                        */

                    },
                    template: require('./p3xr-dialog-json-view.html'),
                    parent: angular.element(document.body),
                    targetEvent: options.$event,
                    clickOutsideToClose: true,
                    fullscreen: true // Only for -xs, -sm breakpoints.
                })
                // console.warn(result)
            } catch (error) {
                p3xrCommon.generalHandleError(error)
            }
        }

    }

});