Exemplo n.º 1
0
        private static string RenderLookupScript(MenuItem item)
        {
            StringBuilder script = new StringBuilder();

            if (item.MCEEditorFields != null)
                foreach (string field in item.MCEEditorFields)
                    script.AppendFormat("\r\n$('#{0}').val(tinyMCE.get('{0}').getContent()); ", field);

            if (item.Paras != null && item.Paras.Count > 0
                && item.DefineMapPopupControlID != null && item.DefineMapPopupControlID.Count > 0)
            {
                foreach (var para in item.Paras)
                {
                    if (item.DefineMapPopupControlID.Keys.Contains(para.Key) && !string.IsNullOrWhiteSpace(item.DefineMapPopupControlID[para.Key]))
                        script.AppendFormat("\r\n$(\"#{0} #{1}\").val($(\"{2}#{3}\").val() == null ? '{4}' : $(\"{2}#{3}\").val()); ",
                            item.URLOrDiv, item.DefineMapPopupControlID[para.Key],
                            string.IsNullOrWhiteSpace(item.AreaContainerID) ? string.Empty : "#" + item.AreaContainerID + " ",
                            para.Key, string.IsNullOrWhiteSpace(para.Value) ? "" : para.Value);
                }
            }

            script//.AppendLine("\r\n$(\"#dialog:ui-dialog\").dialog( \"destroy\" ); ")
                .AppendFormat("$(\"#{0}\").dialog(", item.URLOrDiv)
                .Append("{")
                .AppendFormat("width: {0},", item.Width == 0 ? "'auto'" : item.Width.ToString())
                .AppendFormat("height: {0},", item.Height == 0 ? "'auto'" : item.Height.ToString())
                .Append("modal: true, ")
                .AppendLine("buttons: { \"Ok\": function () {");

            if (item.GetValueAfterAction != null && item.GetValueAfterAction.Count > 0
                && item.DefineMapPopupControlID != null && item.DefineMapPopupControlID.Count > 0)
            {
                foreach (var val in item.GetValueAfterAction)
                {
                    if (item.DefineMapPopupControlID.Keys.Contains(val.Key) && !string.IsNullOrWhiteSpace(item.DefineMapPopupControlID[val.Key]))
                        script.AppendFormat("$(\"{0}#{1}\").val($(\"#{2} #{3}\").val() == null ? '{4}' : $(\"#{2} #{3}\").val()); \r\n",
                            string.IsNullOrWhiteSpace(item.AreaContainerID) ? string.Empty : "#" + item.AreaContainerID + " ",
                            item.DefineMapPopupControlID[val.Key], item.URLOrDiv, 
                            val.Key, string.IsNullOrWhiteSpace(val.Value) ? "" : val.Value);
                }
            }

            script.AppendLine("$(this).dialog(\"close\");}, ")
                .AppendLine("Cancel: function () { $(this).dialog(\"close\"); } }, ")
                .AppendLine("close: function() { $(this).dialog('destroy');	} ")
                .AppendLine("}); ");

            return script.ToString();
        }
Exemplo n.º 2
0
        private static string RenderAction(HtmlHelper html, LevelType levelType, MenuItem item)
        {
            if (levelType != LevelType.Group && levelType != LevelType.ItemList && levelType != LevelType.ItemMenu)
            {
                return string.Empty;
            }
            string id = Guid.NewGuid().ToString();
            StringBuilder script = new StringBuilder();

            if (!IsEnableAction(html,item))
            {
                if (levelType == LevelType.Group || levelType == LevelType.ItemList)
                {
                    script = new StringBuilder(string.Format("<div id='btn{0}' class='disable'><a class='menu-item disable' href='javascript:void(0);'><img src='{1}' alt='{2}'/>{3}</a></div>", id, item.Icon, item.Name, AddShortcutToName(item.Shortcut, item.Name)));
                }
                else
                {
                    script = new StringBuilder(string.Format("<li class='ribbon-itemmenu disable' id='btn{0}' ><a class='menu-item' href='javascript:void(0);'>{1}</a></li>", id, AddShortcutToName(item.Shortcut, item.Name)));
                }
                return script.ToString();
            }

            if (levelType == LevelType.Group || levelType == LevelType.ItemList)
            {
                script = new StringBuilder(string.Format("<div id='btn{0}' ><a class='menu-item disable' href='javascript:void(0);'><img src='{1}' alt='{2}'/>{3}</a><script type=\"text/javascript\">", id, item.Icon, item.Name, AddShortcutToName(item.Shortcut, item.Name)));
            }
            else
            {
                script = new StringBuilder(string.Format("<li class='ribbon-itemmenu' id='btn{0}' ><a class='menu-item' href='javascript:void(0);'>{1}</a><script type=\"text/javascript\">", id, AddShortcutToName(item.Shortcut, item.Name)));
            }

            script.AppendFormat("$('#btn{0} .menu-item').click(function () ", id)
                .Append("{");
            switch(item.ActionType)
            {
                case ActionType.Ajax:
                    script.Append(RenderAjaxScript(item));
                    break;
                case ActionType.Dialog:
                    script.Append(RenderDialogScript(item));
                    break;
                case ActionType.Lookup:
                    script.Append(RenderLookupScript(item));
                    break;
            }
            script.AppendLine("});");


            if (!string.IsNullOrWhiteSpace(item.Shortcut))
            {
                script.Append("$.Shortcuts.add({ type: 'down', mask: '" + item.Shortcut + "', handler: function() { ");
                switch (item.ActionType)
                {
                    case ActionType.Ajax:
                        script.Append(RenderAjaxScript(item));
                        break;
                    case ActionType.Dialog:
                        script.Append(RenderDialogScript(item));
                        break;
                    case ActionType.Lookup:
                        script.Append(RenderLookupScript(item));
                        break;
                }
                script.AppendLine("} }); ")
                .AppendLine("$.Shortcuts.start(); ");
            }

            if (levelType == LevelType.Group || levelType == LevelType.ItemList)
            {
                script.Append("</script></div>");
            }
            else
            {
                script.Append("</script></li>");
            }
            return script.ToString();
        }
Exemplo n.º 3
0
        private static string RenderAjaxScript(MenuItem item)
        {
            StringBuilder script = new StringBuilder();

            //if (item.Paras != null&&item.Paras.Count>0)
            //{
            //    script.Append("\r\n $('#Description').val(tinyMCE.get('Description').getContent()); var dataVals = {};");
            //    foreach (var para in item.Paras)
            //    {
            //        script.Append(string.Format("\r\n dataVals['{0}'] = $(\"{2}#{0}\").val() == null ? {1} : $(\"{2}#{0}\").val(); ", para.Key, string.IsNullOrWhiteSpace(para.Value) ? "''" : para.Value, string.IsNullOrWhiteSpace(item.AreaContainerID) ? string.Empty : "#" + item.AreaContainerID + " "));
            //    }
            //}

            if(item.MCEEditorFields!=null)
                foreach(string field in item.MCEEditorFields)
                    script.AppendFormat("\r\n$('#{0}').val(tinyMCE.get('{0}').getContent()); \r\n ", field);

            script.AppendLine("$.ajax({ ")
                .AppendLine("type: \"POST\", ")
                .AppendFormat("url: \"{0}\", \r\n", item.URLOrDiv)
                .AppendFormat("data: $(\"{0}form\").serialize(),\r\n", string.IsNullOrWhiteSpace(item.AreaContainerID) ? string.Empty : "#" + item.AreaContainerID + " ") //$(\"form\").serializeArray(),") //serialize()    //dataVals,")
                .AppendLine("success: function(msg){")
                .AppendLine("alert( \"Data Saved: \" + msg );")
                .AppendLine("} }); ");

            return script.ToString();
        }
Exemplo n.º 4
0
        private static bool IsEnableAction(HtmlHelper html, MenuItem item)
        {
            bool b = false;
            if (item.EnableActionOnViews == null || item.EnableActionOnViews.Count == 0)
                return b;

            foreach(var enable in item.EnableActionOnViews)
            {
                b = enable.Trim().ToLower() == "/" + html.ViewContext.RouteData.Values["controller"].ToString().Trim().ToLower()
                    + "/" + html.ViewContext.RouteData.Values["action"].ToString().Trim().ToLower() + "/";
                if (b)
                    break;
            }
            return b;
        }