Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic solution to manage windows with ASP.NET MVC

I have three different cases in my project for opening new window. When I click a link in a window, I expected to do one of the following solutions:

I will use following types for window open:

_blank
_self
_parent

I have the following columns for opening a new window:

Code          Width   Height   Behaviour
AccountPage    400      600      Self
ProspectPage   700      700      Blank
PasswordPage   200      200      Single

I need to pass specific parameters to javascript like width, height and code. Code is used for which screen is open and take its parameters. I have invoicepage, prospectpage,searchpage etc. If invoicepage is opened its width will be 200 or if prospectpage is opened the width will be 400px.

What is the proper way to manage and pass to javascript window open types and parameters in generic technique? How Can I prepare my classes and types?

I tried to use meta tag in my LayoutGeneral.cshtml for pass the dataset to javascript but I couldn't get it.

<meta name="IrisTabHeaderName" content="@Model.WindowInfo" />

Should I hold my data in my BaseViewModel and pass the parameters to javascript from there or should I hold my all cases in javascript and call from cshtml page with class?

like image 478
tdog Avatar asked Jan 22 '26 20:01

tdog


1 Answers

The way of your passing the dataset to javascript would be wrong. You can do hold your page parameters with enumeration or in a json object and then deserialize it as follows:

  var data =
'[{
    "Code": {
        "AccountPage": { "width": "400", "height": "600", "name": "_self" },   
        "ProspectPage": { "width": "700", "height": 700, "name": "_blank" },
        "PasswordPage": { "width": "200", "height": "200", "name": "PasswordPage" }
    }
}]';

add this data.json file in the script source:

<script type="text/javascript" src="data.json"></script>

and get your object from json file in javascript:

var pageRules = JSON.parse(data);

and finally you can check it with attach to 'a' tag's click event:

$(function () {
    $("a").click(MyLinkClickFunc);
});

function MyLinkClickFunc()
{
    var $this = $(this);
    var attrName = $this.attr("name");
    var params = null;

    if (typeof attrName !== typeof undefined && attrName !== false) {
        params = pageRules.Code[attrName];
        if(params == null)
        {
            var authCode = attrName.substr(0, attrName.indexOf('_'));
            params = pageRules.Code[authCode];
        }
    }

    if (params != null)
    {
        MyPopupOpener($this.attr("href"), params.name, params.width, params.height);
    }
}
like image 125
utaco Avatar answered Jan 25 '26 10:01

utaco