<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using System.Web.Mvc;

namespace Signum.Web
{
    public class JsViewOptions : JsRenderer
    {
        public JsValue<string> Prefix { get; set; }
        public JsValue<string> ContainerDiv { get; set; }
        public JsValue<string> ControllerUrl { get; set; }
        public JsValidatorOptions ValidationOptions { get; set; }
        public JsFunction OnOk { get; set; }
        public JsFunction OnOkClosed { get; set; }
        public JsFunction OnCancelled { get; set; }
        public JsValue<string> Type { get; set; }
        public JsValue<int?> Id { get; set; }
        public JsValue<string> PartialViewName { get; set; }
        public JsInstruction RequestExtraJsonData { get; set; }

        public JsViewOptions()
        {
            Renderer = () =>
            {
                return new JsOptionsBuilder(false)
                {
                    {"prefix", Prefix.TryCC(a=>a.ToJS())},
                    {"containerDiv", ContainerDiv.TryCC(a=>a.ToJS())},
                    {"controllerUrl", ControllerUrl.TryCC(a=>a.ToJS()) ?? RouteHelper.New().SignumAction("PopupView").SingleQuote()},
                    {"validationOptions", ValidationOptions.TryCC(a => a.ToJS()) },
                    {"onOk", OnOk.TryCC(a=>a.ToJS())},
                    {"onOkClosed", OnOkClosed.TryCC(a=>a.ToJS())},
                    {"onCancelled", OnCancelled.TryCC(a=>a.ToJS())},
                    {"type", Type.TryCC(a=>a.ToJS())},
                    {"partialViewName", PartialViewName.TryCC(a=>a.ToJS())},
                    {"requestExtraJsonData", RequestExtraJsonData.TryCC(a=>a.ToJS())},
                }.ToJS();
            };
        }
    }

    public class JsViewNavigator : JsInstruction
    {
        JsViewOptions Options { get; set; }

        public JsViewNavigator(JsViewOptions options)
            : base(() => "new SF.ViewNavigator(" + options.ToJS() + ")")
        {
            this.Options = options;
        }

        public JsInstruction ShowCreateSave(JsValue<string> html)
        {
            return new JsInstruction(() => "{0}.{1}({2})".Formato(this.ToJS(), "showCreateSave", html.ToJS()));
        }

        public static JsInstruction ClosePopup(string prefix)
        {
            return new JsInstruction(() => "SF.closePopup('{0}')".Formato(prefix));
        }
    }
}<commit_msg>Reform JsViewNavigator to be as JsFindNavigator<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using System.Web.Mvc;

namespace Signum.Web
{
    public class JsViewOptions : JsRenderer
    {
        public JsValue<string> Prefix { get; set; }
        public JsValue<string> ContainerDiv { get; set; }
        public JsValue<string> ControllerUrl { get; set; }
        public JsValidatorOptions ValidationOptions { get; set; }
        public JsFunction OnOk { get; set; }
        public JsFunction OnOkClosed { get; set; }
        public JsFunction OnCancelled { get; set; }
        public JsValue<string> Type { get; set; }
        public JsValue<int?> Id { get; set; }
        public JsValue<string> PartialViewName { get; set; }
        public JsInstruction RequestExtraJsonData { get; set; }

        public JsViewOptions()
        {
            Renderer = () =>
            {
                return new JsOptionsBuilder(false)
                {
                    {"prefix", Prefix.TryCC(a=>a.ToJS())},
                    {"containerDiv", ContainerDiv.TryCC(a=>a.ToJS())},
                    {"controllerUrl", ControllerUrl.TryCC(a=>a.ToJS()) ?? RouteHelper.New().SignumAction("PopupView").SingleQuote()},
                    {"validationOptions", ValidationOptions.TryCC(a => a.ToJS()) },
                    {"onOk", OnOk.TryCC(a=>a.ToJS())},
                    {"onOkClosed", OnOkClosed.TryCC(a=>a.ToJS())},
                    {"onCancelled", OnCancelled.TryCC(a=>a.ToJS())},
                    {"type", Type.TryCC(a=>a.ToJS())},
                    {"partialViewName", PartialViewName.TryCC(a=>a.ToJS())},
                    {"requestExtraJsonData", RequestExtraJsonData.TryCC(a=>a.ToJS())},
                }.ToJS();
            };
        }
    }

    public class JsViewNavigator : JsInstruction
    {
        JsViewOptions Options { get; set; }

        public JsViewNavigator(JsViewOptions options)
            : base(() => "new SF.ViewNavigator(" + options.ToJS() + ")")
        {
            this.Options = options;
        }

        public JsInstruction viewOk()
        {
            return new JsInstruction(() => "{0}.viewOk()".Formato(this.ToJS()));
        }

        public JsInstruction createOk()
        {
            return new JsInstruction(() => "{0}.createOk()".Formato(this.ToJS()));
        }

        public JsInstruction viewSave(JsValue<string> html)
        {
            return new JsInstruction(() => "{0}.viewSave({1})".Formato(this.ToJS(), html.ToJS()));
        }

        public JsInstruction createSave(string saveUrl)
        {
            return new JsInstruction(() => "{0}.createSave('{1}')".Formato(this.ToJS(), saveUrl));
        }

        public static JsInstruction closePopup(string prefix)
        {
            return new JsInstruction(() => "SF.closePopup('{0}')".Formato(prefix));
        }
    }
}
{'fraction_non_alphanumeric': 0.1414029243013141, 'fraction_numerical': 0.0020359059781602813, 'mean_word_length': 2.1146974063400577, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704050', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1583, 'n_words': 303}