private String makeScriptForSettingWorkBoxVariables(WorkBox workBox, WBUser user, UserProfile profile)
        {
            string htmlForScript = "<script type=\"text/javascript\">\n";

            Dictionary <String, WBAction> allActions = workBox.GetAllActions();

            Dictionary <String, bool> allEnableFlags = new Dictionary <String, Boolean>();

            foreach (WBAction action in allActions.Values)
            {
                allEnableFlags.Add(action.ActionKey, action.IsEnabled);
            }

            htmlForScript += makeVarDeclaration("wbf_json__all_actions_details", JsonConvert.SerializeObject(allActions));
            htmlForScript += makeVarDeclaration("wbf_json__all_actions_enable_flags", JsonConvert.SerializeObject(allEnableFlags));

            htmlForScript += makeVarDeclaration("wbf__clipboard_action", user.GetClipboardAction(profile));

            htmlForScript += makeVarDeclaration("wbf__enable_tasks_button", false);
            htmlForScript += makeVarDeclaration("wbf__enable_document_templates_button", (workBox.DocumentTemplates != null));
            htmlForScript += makeVarDeclaration("wbf__document_library_root_folder_url", workBox.Web.Url + "/" + workBox.DocumentLibrary.RootFolder.Url);

            htmlForScript += makeVarDeclaration("wbf__spweb_url", workBox.Web.Url);

            htmlForScript += "</script>\n";
            return(htmlForScript);
        }
示例#2
0
        private void RenderClipboard()
        {
            WBUser user = new WBUser(WorkBox);

            CutOrCopiedText.Text = user.RenderClipboardAction(SPContext.Current.Site);

            ItemsOnClipboard.Text = user.RenderClipboardItems(SPContext.Current.Site);
        }
示例#3
0
        protected void clearAllButton_OnClick(object sender, EventArgs e)
        {
            WBUser user = new WBUser(WorkBox);

            WorkBox.Web.AllowUnsafeUpdates = true;
            user.ClearClipboard(SPContext.Current.Site);
            WorkBox.Web.AllowUnsafeUpdates = false;

            JustPastedText.Text = "";
//            RenderClipboard();

            CloseDialogAndRefresh();
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (SPLongOperation longOperation = new SPLongOperation(this.Page))
                {
                    longOperation.LeadingHTML  = "Pasting items from your work box clipboard";
                    longOperation.TrailingHTML = "If you are pasting a lot of items this might take some time.";

                    longOperation.Begin();


                    String folderPath = Request.QueryString["RootFolder"];
                    if (String.IsNullOrEmpty(folderPath))
                    {
                        folderPath = "";
                    }

                    String docLibraryFolderPath = WorkBox.Web.ServerRelativeUrl + "/" + WorkBox.DocumentLibrary.RootFolder.Url;

                    WBLogging.Generic.Unexpected("Root folder was: " + folderPath + "     in : " + WorkBox.DocumentLibrary.RootFolder.Url);
                    WBLogging.Generic.Unexpected("docLibraryFolderPath =  " + docLibraryFolderPath);

                    folderPath = folderPath.Replace(docLibraryFolderPath, "");

                    WBLogging.Generic.Unexpected("Now using folder path: " + folderPath);


                    WBUser user = new WBUser(WorkBox);

                    String clipboardAction = user.PasteClipboard(WorkBox, folderPath);

                    /*
                     * String justReturnOK = "Pasted items are still on clipboard to be copied again.";
                     * if (clipboardAction == WBUser.CLIPBOARD_ACTION__CUT)
                     * {
                     *  justReturnOK = "Pasted items removed from original location and clipboard.";
                     * }
                     */

                    string okPageUrl   = "WorkBoxFramework/GenericOKPage.aspx";
                    string queryString = "justRefreshOK=True";

                    longOperation.End(okPageUrl, SPRedirectFlags.RelativeToLayoutsPage, Context, queryString);
                }
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["NoRedirect"]))
            {
                redirecting = false;
                return;
            }

            WBUser currentUser = new WBUser(SPContext.Current);

            String myWBUrl = currentUser.GetUrlToMyUnprotectedWorkBox(SPContext.Current.Site);

            if (!String.IsNullOrEmpty(myWBUrl))
            {
                redirecting   = true;
                redirectToUrl = myWBUrl;
            }
        }
示例#6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["selectedItemsIDsString"] != null && Request.QueryString["selectedListGUID"] != null)
                {
                    String clipboardAction = Request.QueryString["clipboardAction"];
                    if (String.IsNullOrEmpty(clipboardAction))
                    {
                        clipboardAction = WBUser.CLIPBOARD_ACTION__COPY;
                    }

                    using (SPLongOperation longOperation = new SPLongOperation(this.Page))
                    {
                        string justReturnOK = "Copied to clipboard";
                        longOperation.LeadingHTML = "Copying details to the clipboard";

                        if (clipboardAction == WBUser.CLIPBOARD_ACTION__CUT)
                        {
                            justReturnOK = "Cut to clipboard";
                            longOperation.LeadingHTML = "Cutting details to the clipboard";
                        }

                        longOperation.TrailingHTML = "";

                        longOperation.Begin();

                        string   selectedListGUID = Request.QueryString["selectedListGUID"];
                        string[] selectedItemsIDs = Request.QueryString["selectedItemsIDsString"].ToString().Split('|');

                        WBUtils.logMessage("The list GUID was: " + selectedListGUID);
                        selectedListGUID = selectedListGUID.Substring(1, selectedListGUID.Length - 2).ToLower();

                        // Guid sourceListGuid = new Guid(selectedListGUID);
                        //ListGUID.Value = sourceListGuid.ToString();
                        //ItemID.Value = selectedItemsIDs[1].ToString();

                        //WBUtils.logMessage("The ListGUID was: " + ListGUID.Value);
                        //WBUtils.logMessage("The ItemID was: " + ItemID.Value);
                        // SPDocumentLibrary sourceDocLib = (SPDocumentLibrary)WorkBox.Web.Lists[sourceListGuid];

                        WBUser user = new WBUser(WorkBox);

                        WorkBox.Web.AllowUnsafeUpdates = true;
                        String error = user.AddToClipboard(clipboardAction, WorkBox, selectedItemsIDs, false);
                        WorkBox.Web.AllowUnsafeUpdates = false;

                        string okPageUrl   = "WorkBoxFramework/GenericOKPage.aspx";
                        string queryString = "justReturnOK=" + justReturnOK;

                        if (!String.IsNullOrEmpty(error))
                        {
                            queryString = "justReturnError=" + error;
                        }

                        longOperation.End(okPageUrl, SPRedirectFlags.RelativeToLayoutsPage, Context, queryString);
                    }

                    RenderClipboard();
                }
                else
                {
                    ItemsOnClipboard.Text = "There was an error with the passed through values";
                }

                closeButton.Focus();
            }
        }
        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-->";
            }
        }
        protected void saveButton_OnClick(object sender, EventArgs e)
        {
            try
            {
                bool digestOK = WorkBox.Web.ValidateFormDigest();

                if (digestOK)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite elevatedSite = new SPSite(WorkBox.Site.ID))
                            using (SPWeb elevatedWorkBoxWeb = elevatedSite.OpenWeb(WorkBox.Web.ID))
                            {
                                elevatedSite.AllowUnsafeUpdates       = true;
                                elevatedWorkBoxWeb.AllowUnsafeUpdates = true;

                                WorkBox elevatedWorkBox    = new WorkBox(elevatedSite, elevatedWorkBoxWeb);
                                elevatedWorkBox.ShortTitle = WorkBoxShortTitle.Text;
                                elevatedWorkBox.Web.Title  = WorkBoxPrettyTitle.Text;
                                elevatedWorkBox.GenerateTitle();

                                if (showReferenceID)
                                {
                                    elevatedWorkBox.ReferenceID = ReferenceID.Text;
                                }

                                if (showReferenceDate)
                                {
                                    if (!ReferenceDate.IsDateEmpty)
                                    {
                                        elevatedWorkBox.ReferenceDate = ReferenceDate.SelectedDate;
                                    }
                                }

                                elevatedWorkBox.Update();
                            }
                    });
                }
            }
            catch (Exception exception)
            {
                WBUtils.SendErrorReport(SPContext.Current.Web, "Exception in EditWorkBoxPropertise.saveButton_OnClick()", "Something went wrong when saving: " + exception.Message + " ... " + exception.StackTrace);
                throw new NotImplementedException("Something went wrong when saving the properties changes");
            }

            WBFarm farm = WBFarm.Local;
            String cachedDetailsListUrl = farm.OpenWorkBoxesCachedDetailsListUrl;

            if (!String.IsNullOrEmpty(cachedDetailsListUrl))
            {
                using (SPSite cacheSite = new SPSite(cachedDetailsListUrl))
                    using (SPWeb cacheWeb = cacheSite.OpenWeb())
                    {
                        SPList cacheList = cacheWeb.GetList(cachedDetailsListUrl);

                        SPServiceContext   serviceContext = SPServiceContext.GetContext(cacheSite);
                        UserProfileManager profileManager = new UserProfileManager(serviceContext);

                        // Get the current user's user profile:
                        UserProfile profile = profileManager.GetUserProfile(true);

                        // We're using the 'now' plus one hour ticks as we're not really looking to update the last modified dates of other work boxes.
                        WBUser.CheckLastModifiedDatesAndTitlesOfRecentWorkBoxes(cacheSite, cacheList, profile, DateTime.Now.AddHours(1).Ticks);

                        WBUser.CheckTitlesOfFavouriteWorkBoxes(cacheSite, cacheList, profile);
                    }
            }

            returnFromDialogOK("");
        }