예제 #1
0
        private void RegisterPluginJavaScript(ILinkItemCollectionPlugin plugin)
        {
            StringBuilder script = new StringBuilder(@"$(document).ready(function ()
            {
                $('#divAddEdit{0}').dialog(
                {
                    autoOpen: false,
                    modal: true,
                    resizable: false,
                    width: {2},
                    buttons:
                    [
                        {
                            text: 'Save',
                            click: function() { Save{0}(); }, 
                        },
                        {
                            text: 'Cancel',
                            click: function() { $(this).dialog('close'); }
                        }
                    ],
                    close: function ()
                    {
                        ResetAddEdit{0}Dialog();

                        ToggleAllValidatorsEnabledState($(this), false);
                    }
                });
            });

            function Add{0}_Click(event)
            {
                event.preventDefault();

                ToggleAllValidatorsEnabledState($('#divAddEdit{0}'), true);

                ResetAddEdit{0}Dialog();

                OpenAddEdit{0}Dialog('Add {1}');
            }

            function OpenAddEdit{0}Dialog(title)
            {
                $('#divAddEdit{0}').dialog('option', 'title', title);
                $('#divAddEdit{0}').dialog('open');  
            }");

            script.Replace("{0}", plugin.Name);
            script.Replace("{1}", plugin.FriendlyName);
            script.Replace("{2}", plugin.DialogWidth.ToString());

            //This ensures that the script for the plugin will not be registered twice
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "jsN2LinkEditorPlugin-" + plugin.Name, script.ToString(), true);
        }
예제 #2
0
        private static LinkItemCollection Parse(string json)
        {
            LinkItemCollection coll = new LinkItemCollection();

            Dictionary <string, object>[] jsonItems = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(json);

            LinkItemBase[] arrLinkItemBase = new LinkItemBase[jsonItems.Length];

            //Execute this in parallel if possible to save time with json serialization/deserization for child items
            Parallel.ForEach(jsonItems, (x, state, index) =>
            {
                Dictionary <string, object> dic = (Dictionary <string, object>)x;

                string linkType = dic["LinkTypeString"].ToString();

                //HACK: Find a better way of doing this - we dont want to have to serialize/deserialize this again!
                //Need a good way of initially getting the array elements
                string json2 = JsonConvert.SerializeObject(dic);

                LinkItemBase itemBase = null;

                if (linkType == "Image")
                {
                    itemBase = JsonConvert.DeserializeObject <ImageItem>(json2);
                }
                else if (linkType == "Internal")
                {
                    itemBase = JsonConvert.DeserializeObject <InternalLinkItem>(json2);
                }
                else if (linkType == "External")
                {
                    itemBase = JsonConvert.DeserializeObject <ExternalLinkItem>(json2);
                }
                else if (linkType == "Document")
                {
                    itemBase = JsonConvert.DeserializeObject <DocumentItem>(json2);
                }
                else
                {
                    if (PluginList != null)
                    {
                        ILinkItemCollectionPlugin plugin = PluginList.Find(y => y.Name == linkType);
                        if (plugin != null)
                        {
                            itemBase = JsonConvert.DeserializeObject(json2, plugin.PluginType) as LinkItemBase;
                            if (itemBase == null)
                            {
                                throw new Exception("The following json string for linkType " + linkType + " could not be parsed: " + json2);
                            }
                        }
                    }
                }

                itemBase.SortOrder = (int)index;

                arrLinkItemBase[index] = itemBase;
            });

            //Add the array items to the LinkItemCollection
            coll.AddRange(arrLinkItemBase);

            return(coll);
        }