예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPServiceContext   _serviceContext = SPServiceContext.GetContext(WorkBox.Site);
                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
                UserProfile        profile         = _profileManager.GetUserProfile(true);

                UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

                string myFavouriteWorkBoxesString = "";

                if (myFavouriteWorkBoxesPropertyValue.Value != null)
                {
                    myFavouriteWorkBoxesString = myFavouriteWorkBoxesPropertyValue.Value.ToString();
                }

                if (myFavouriteWorkBoxesString.Contains(WorkBox.Web.ID.ToString()))
                {
                    // The user's favourites already contains this work box - so do nothing.
                    Message.Text = "The work box is already one of your favourites.";
                }
                else
                {
                    List <String> favourites = new List <String>();

                    if (!String.IsNullOrEmpty(myFavouriteWorkBoxesString.WBxTrim()))
                    {
                        favourites.AddRange(myFavouriteWorkBoxesString.Split(';'));
                    }

                    WBLink newFavourite = new WBLink(WorkBox, false);
                    favourites.Add(newFavourite.ToString());
                    //favourites.Add(WorkBox.Web.Title + "|" + WorkBox.Web.Url + "|" + WorkBox.UniqueID + "|" + WorkBox.Web.ID.ToString());

                    myFavouriteWorkBoxesString = WBUtils.JoinUpToLimit(";", favourites, 3100);

                    myFavouriteWorkBoxesPropertyValue.Value = myFavouriteWorkBoxesString;
                    WorkBox.Web.AllowUnsafeUpdates          = true;
                    profile.Commit();
                    WorkBox.Web.AllowUnsafeUpdates = false;

                    if (myFavouriteWorkBoxesString.Contains(WorkBox.Web.ID.ToString()))
                    {
                        Message.Text = "The work box has been added to your favourites.";
                    }
                    else
                    {
                        Message.Text = "The work box could not be added to your favourites as your list of favourites is too long.";
                    }
                }

                okButton.Focus();
            }
        }
예제 #2
0
        protected override void CreateChildControls()
        {
            Literal literal = new Literal();
            string  html    = "";


            try
            {
                html += "<style type=\"text/css\">\n tr.wbf-extra-favourites-items {display:none;}\n</style>\n\n" + getScriptCode();

                SPSite             _site           = SPContext.Current.Site;
                SPServiceContext   _serviceContext = SPServiceContext.GetContext(_site);
                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
                UserProfile        profile         = _profileManager.GetUserProfile(true);

                UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

                // If the NumberToShow value isn't set or is set zero or negative then fix the web part to show 5 items:
                if (NumberToShow <= 0)
                {
                    NumberToShow = 5;
                }

                if (myFavouriteWorkBoxesPropertyValue.Value != null)
                {
                    string[] myFavouriteWorkBoxes = myFavouriteWorkBoxesPropertyValue.Value.ToString().Split(';');

                    // We actually want to display the most recently added favourite first even though it'll be last in the list so:
                    Array.Reverse(myFavouriteWorkBoxes);

                    if (myFavouriteWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5' width='100%'>";
                        int    count         = 0;
                        bool   hasExtraItems = false;
                        String cssClass      = "";

                        foreach (string workBoxLinkDetails in myFavouriteWorkBoxes)
                        {
                            WBLink workBoxLink = new WBLink(workBoxLinkDetails);
                            if (!workBoxLink.IsOK)
                            {
                                continue;
                            }

                            count++;

                            if (count > NumberToShow)
                            {
                                cssClass      = " class='wbf-extra-favourites-items'";
                                hasExtraItems = true;
                            }

                            /*
                             * string[] details = recentWorkBoxDetails.Split('|');
                             *
                             * string guidString = details[2];
                             * if (details.Length == 4)
                             *  guidString = details[3];
                             *
                             * html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                             * html += details[1];
                             * html += "'>" + details[0] + "</a></td>";
                             *
                             * String command = "RemoveWorkBoxFromFavourites.aspx?workBoxTitle=" + HttpUtility.UrlEncode(details[0]) + "&workBoxGuid=" + guidString;
                             *
                             * html += "<td><a href='#' onclick='javascript: WorkBoxFramework_relativeCommandAction(\"" + command + "\", 0, 0);'>remove</a></td>";
                             * html += "</tr>";
                             */

                            html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                            html += workBoxLink.URL;
                            html += "'>" + workBoxLink.Title + "</a></td>";

                            String command = "RemoveWorkBoxFromFavourites.aspx?workBoxTitle=" + HttpUtility.UrlEncode(workBoxLink.Title) + "&workBoxGuid=" + workBoxLink.SPWebGUID;

                            html += "<td><a href='#' onclick='javascript: WorkBoxFramework_relativeCommandAction(\"" + command + "\", 0, 0);'>remove</a></td>";
                            html += "</tr>";
                        }

                        if (hasExtraItems)
                        {
                            html += "<tr class=\"wbf-show-more-favourites-link\"><td colspan='3' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-favourites-items\").show(); $(\".wbf-show-more-favourites-link\").hide(); '>More favourite work boxes ...</a></td></tr>";
                            html += "<tr class=\"wbf-extra-favourites-items\"><td colspan='3' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-favourites-items\").hide(); $(\".wbf-show-more-favourites-link\").show(); '>Fewer favourite work boxes</a></td></tr>";
                        }

                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No favourite work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No favourite work boxes)</i>";
                }
            }
            catch (Exception e)
            {
                html += "<i>(An error occurred)</i> \n\n <!-- \n Exception was: " + e.WBxFlatten() + " \n\n -->";
            }

            literal.Text = html;

            this.Controls.Add(literal);
        }
예제 #3
0
        protected override void CreateChildControls()
        {
            Literal literal = new Literal();
            string  html    = "<style type=\"text/css\">\n tr.wbf-extra-recent-items {display:none;}\n</style>\n\n";

            try
            {
                // Now let's check or set the last visited Guid:
                SPSite             _site           = SPContext.Current.Site;
                SPServiceContext   _serviceContext = SPServiceContext.GetContext(_site);
                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
                UserProfile        profile         = _profileManager.GetUserProfile(true);

                UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];

                // If the NumberToShow value isn't set or is set zero or negative then fix the web part to show 5 items:
                if (NumberToShow <= 0)
                {
                    NumberToShow = 5;
                }

                if (workBoxesRecentlyVisited.Value != null)
                {
                    string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';');

                    if (recentWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5' width='100%'>";
                        int    count         = 0;
                        bool   hasExtraItems = false;
                        String cssClass      = "";

                        foreach (string workBoxLinkDetails in recentWorkBoxes)
                        {
                            WBLink workBoxLink = new WBLink(workBoxLinkDetails);
                            if (!workBoxLink.IsOK)
                            {
                                continue;
                            }

                            //string[] details = workBoxLinkDetails.Split('|');

                            //String workBoxTitle = details[0];
                            //String workBoxUrl = details[1];
                            //String workBoxUniqueID = details[2];

                            // We're going to skip any work box whose title matches the unique prefix being filtered:
                            if (!String.IsNullOrEmpty(UniquePrefixToFilter))
                            {
                                if (workBoxLink.UniqueID.StartsWith(UniquePrefixToFilter))
                                {
                                    continue;
                                }
                            }

                            count++;
                            if (count > NumberToShow)
                            {
                                cssClass      = " class='wbf-extra-recent-items'";
                                hasExtraItems = true;
                            }

                            html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                            html += workBoxLink.URL;
                            html += "'>" + workBoxLink.Title + "</a></td></tr>";
                        }

                        if (hasExtraItems)
                        {
                            html += "<tr class=\"wbf-show-more-recent-link\"><td colspan='2' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-recent-items\").show(); $(\".wbf-show-more-recent-link\").hide(); '>More recent work boxes ...</a></td></tr>";
                            html += "<tr class=\"wbf-extra-recent-items\"><td colspan='2' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-recent-items\").hide(); $(\".wbf-show-more-recent-link\").show(); '>Fewer recent work boxes</a></td></tr>";
                        }

                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No recently visited work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No recently visited work boxes)</i>";
                }
            }
            catch (Exception e)
            {
                html += "<i>(An error occurred)</i> \n\n <!-- \n Exception was: " + e.WBxFlatten() + " \n\n -->";
            }

            literal.Text = html;

            this.Controls.Add(literal);
        }
        protected override void OnPreRender(EventArgs e)
        {
            try
            {
                if (this.Page == null)
                {
                    return;
                }
                if (SPContext.Current == null)
                {
                    return;
                }

                SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page);

                WorkBox workBox = null;

                // If we're looking at a modal dialog box then we want to
                // leave workBox == null so that no further action is taken:
                if (Request.QueryString["IsDlg"] == null || Request.QueryString["IsDlg"] != "1")
                {
                    workBox = WorkBox.GetIfWorkBox(SPContext.Current);
                }

                if (workBox != null)
                {
                    //OK so we are looking at a work box.
                    isWorkBox = true;
                    SPWeb workBoxWeb = workBox.Web;

                    if (!currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox"))
                    {
                        currentRibbon.MakeTabAvailable("WorkBoxFramework.Ribbon.WorkBox");
                    }

                    // Now let's register the commands for the tasks flyout button:
                    // Inspired by blogs:
                    // http://www.sharepointnutsandbolts.com/2010/02/ribbon-customizations-dropdown-controls.html
                    // http://patrickboom.wordpress.com/2010/05/25/adding-a-custom-company-menu-tab-with-dynamic-menu-on-the-ribbon/
                    // http://www.wictorwilen.se/Post/Creating-a-SharePoint-2010-Ribbon-extension-part-2.aspx

                    WBLogging.DEBUG.Monitorable("About to do various for Tasks flyout menu:");

                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Core.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "CUI.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "core.js", true, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Ribbon.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Runtime.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false, false);
                    //ScriptLink.RegisterScriptAfterUI(this.Page, "WorkBoxFramework/PageComponent.js", false, true);

                    var commands = new List <IRibbonCommand>();

                    // register the command at the ribbon. Include the callback to the server to generate the xml
                    commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTasks", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menuXml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menuXml != '') properties.PopulationXML = wbf_menuXml;"));
                    commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTemplates", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menu2Xml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menu2Xml != '') properties.PopulationXML = wbf_menu2Xml;"));

                    //                commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "properties.PopulationXML = errorMenuXml();"));
                    //commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Callaa to Popdyn'); if (menuXml == '') { CreateServerMenu('',''); } else { properties.PopulationXML = menuXml; }"));
                    //                commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Call to Popdyn: ' + menuXml); properties.PopulationXML = menuXml;"));

                    //Register various:
                    var manager = new SPRibbonScriptManager();

                    // Register ribbon scripts
                    manager.RegisterGetCommandsFunction(Page, "getGlobalCommands", commands);
                    manager.RegisterCommandEnabledFunction(Page, "commandEnabled", commands);
                    manager.RegisterHandleCommandFunction(Page, "handleCommand", commands);

                    WBLogging.DEBUG.Monitorable("Registered ribbon scripts");


                    //Register initialize function
                    var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic);
                    methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/WorkBoxFramework/PageComponent.js", false, "WorkBoxFramework.PageComponent.initialize()" });


                    // register the client callbacks so that the JavaScript can call the server.
                    ClientScriptManager cm = this.Page.ClientScript;

                    String cbReference    = cm.GetCallbackEventReference(this, "arg", "WorkBoxFramework_receiveTasksMenu", "", "WorkBoxFramework_processCallBackError", false);
                    String callbackScript = "function WorkBoxFramework_getDynamicTasksMenu(arg, context) {" + cbReference + "; }";
                    WBLogging.DEBUG.Monitorable("Creating the call back function WorkBoxFramework_getDynamicTasksMenu to call: \n" + callbackScript);
                    cm.RegisterClientScriptBlock(this.GetType(), "WorkBoxFramework_getDynamicTasksMenu", callbackScript, true);


                    // Now let's check or set the last visited Guid:
                    WBUser      user    = new WBUser(workBox);
                    UserProfile profile = user.Profile;

//                    SPSite _site = SPContext.Current.Site;
//                  SPServiceContext _serviceContext = SPServiceContext.GetContext(_site);
//                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
//                    UserProfile profile = _profileManager.GetUserProfile(true);

                    scriptForSettingGlobalVariables = makeScriptForSettingWorkBoxVariables(workBox, user, profile);

                    UserProfileValueCollection lastVisitedGuidUserProfileValueCollection = profile[WorkBox.USER_PROFILE_PROPERTY__WORK_BOX_LAST_VISITED_GUID];
                    bool needsUpdating = false;
                    if (lastVisitedGuidUserProfileValueCollection == null || lastVisitedGuidUserProfileValueCollection.Count == 0)
                    {
                        needsUpdating = true;
                    }
                    else
                    {
                        Guid lastGuid = new Guid(lastVisitedGuidUserProfileValueCollection.Value.ToString());

                        if (!lastGuid.Equals(workBoxWeb.ID))
                        {
                            needsUpdating = true;
                        }
                    }

                    if (needsUpdating)
                    {
                        workBoxWeb.AllowUnsafeUpdates = true;

                        string currentGuidString = workBoxWeb.ID.ToString();
                        lastVisitedGuidUserProfileValueCollection.Clear();
                        lastVisitedGuidUserProfileValueCollection.Add(currentGuidString);

                        // OK now we're going to make sure that this work box is the latest on the list of recently visited work boxes:
                        WBLogging.WorkBoxes.Verbose("Updating the list of recently visited work boxes - as we've just come to this work box");
                        UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];


                        //string mostRecentWorkBoxDetails = workBoxWeb.Title + "|" + workBoxWeb.Url + "|" + workBox.UniqueID + "|" + workBoxWeb.ID.ToString() + "|" + DateTime.Now.Ticks;
                        WBLink mostRecentWorkBoxDetails = new WBLink(workBox, true);
                        WBLogging.WorkBoxes.Verbose("The most recent work box details are: " + mostRecentWorkBoxDetails);

                        List <String> newList = new List <String>();
                        newList.Add(mostRecentWorkBoxDetails.ToString());

                        if (workBoxesRecentlyVisited.Value != null)
                        {
                            string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';');
                            int      totalLength     = 0;
                            foreach (string recentWorkBox in recentWorkBoxes)
                            {
                                if (totalLength >= 3000)
                                {
                                    break;
                                }
                                if (!recentWorkBox.Contains(currentGuidString))
                                {
                                    newList.Add(recentWorkBox);
                                    totalLength += recentWorkBox.Length + 1;
                                }
                            }
                        }

                        profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES].Value = WBUtils.JoinUpToLimit(";", newList, 3100);

                        profile.Commit();
                        workBoxWeb.AllowUnsafeUpdates = false;
                    }
                }
                else
                {
                    scriptForSettingGlobalVariables = makeScriptForSettingNonWorkBoxVariables(SPContext.Current.Web);
                    if (currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox"))
                    {
                        currentRibbon.TrimById("WorkBoxFramework.Ribbon.WorkBox");
                    }
                }

                //          currentRibbon.MakeContextualGroupInitiallyVisible("WorkBoxFramework.Ribbon.ContextualGroup", string.Empty);
            }
            catch (Exception exception)
            {
                // If this isn't working - let's just do nothing so that at least the SharePoint site is visible.
                scriptForSettingGlobalVariables = "<!-- Exception thrown in MaybeShowWorkBoxRibbonTools \n\n" + exception.Message + "\n\n" + exception.StackTrace + "\n\n-->";
            }
        }