Click here to Skip to main content
15,885,141 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 2 – Southwind Logic

Rate me:
Please Sign up or sign in to vote.
4.45/5 (6 votes)
15 Nov 2012LGPL325 min read 31.3K   1K   22  
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using System.Web.Mvc;

namespace Signum.Web
{
    public class JsFindOptions : JsRenderer
    {
        public JsValue<string> Prefix { get; set; }
        public FindOptions FindOptions { get; set; }
        public JsValue<int?> Top { get; set; }
        /// <summary>
        /// To be called to open a Find window
        /// </summary>
        public JsValue<string> NavigatorControllerUrl { get; set; }
        /// <summary>
        /// To be called when clicking the search button
        /// </summary>
        public JsValue<string> SearchControllerUrl { get; set; }
        /// <summary>
        /// To be called when closing the popup (if exists) with the Ok button
        /// </summary>
        public JsFunction OnOk { get; set; }
        public JsFunction OnCancelled { get; set; }
        public JsValue<bool?> Async { get; set; }

        public JsFindOptions()
        {
            Renderer = () =>
            {
                JsOptionsBuilder options = new JsOptionsBuilder(true)
                {
                    {"prefix", Prefix.TryCC(t=>t.ToJS())},
                    {"top", Top.TryCC(t=>t.ToJS()) },
                    {"navigatorControllerUrl", NavigatorControllerUrl.TryCC(t=>t.ToJS()) ?? RouteHelper.New().SignumAction("PartialFind").SingleQuote() },
                    {"searchControllerUrl",SearchControllerUrl.TryCC(t=>t.ToJS()) ?? RouteHelper.New().SignumAction("Search").SingleQuote() },
                    {"onOk",OnOk.TryCC(t=>t.ToJS())},
                    {"onCancelled", OnCancelled.TryCC(t=>t.ToJS())},
                    {"async", Async.TryCC(t=>t.ToJS())},
                };

                if (FindOptions != null)
                    FindOptions.Fill(options);

                return options.ToJS();
            };
        }
    }

    public class JsFindNavigator : JsInstruction
    {
        public JsFindNavigator(JsFindOptions options)
        {
            Renderer = () => "new SF.FindNavigator({0})".Formato(options.ToJS());
        }

        /// <summary>
        /// To be used when we only need to locate and retrieve values of an already open finder
        /// </summary>
        /// <param name="prefix"></param>
        public JsFindNavigator(JsValue<string> prefix)
            : this(new JsFindOptions { Prefix = prefix })
        {   
        }

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

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

        public JsInstruction hasSelectedItems(JsFunction onSuccess)
        {
            return new JsInstruction(() => "{0}.hasSelectedItems({1})".Formato(this.ToJS(), onSuccess.ToJS()));
        }

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

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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions