[CLOSED] Print a Window

  1. #1

    [CLOSED] Print a Window

    I have a <Ext:Window>..

    I'd like to be able to issue a print command to print just the contents of that window.

    How can I do this?
  2. #2

    RE: [CLOSED] Print a Window

    Hi,

    Does the window contains AutoLoad content?
    Just browser can print only whole page but you can print particular iframe only (for example, you can build required print content and load it to the iframe)
  3. #3

    RE: [CLOSED] Print a Window

    No AutoLoad...its not a frame.
    How can I grab the content and add to frame?
  4. #4

    RE: [CLOSED] Print a Window

    Hi,

    It depends from window's content. Please post window code
  5. #5

    RE: [CLOSED] Print a Window







    Window Code...dynamically generated content.

    <ext:Window runat="server" ID="winTask" Icon="CogStart" Modal="true" InitCenter="true" 
        Hidden="true" AutoHeight="true"  Width="500" Layout="fit" AutoScroll="true">
        <LoadMask Msg="Fetching task information.." ShowMask="true" />
        <Items>
        
        </Items>
        <BottomBar>
            <ext:StatusBar ID="StatusTaskBar" runat="server">
                <Items>
                    <ext:Button ID="btnComplete" runat="server" Icon="Accept" Text="Complete Task">
                        <Listeners>
                            <Click Handler=" if (#{StatusTaskBar}.text.indexOf('invalid')==-1) 
                                        {  
                                            mask = new Ext.LoadMask(#{winTask}.getEl(), {msg:'Completing Task...'}); 
                                            mask.show();
                                            SaveData();
                                        }
                                        else
                                        {
                                             Ext.Msg.show({icon: Ext.MessageBox.ERROR, title:'Missing Form Data', msg: 'Form isn\'t properly completed.', buttons:Ext.Msg.OK}); 
                                             return false;
                                        }" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button10" runat="server" Text="Cancel" Icon="decline">
                        <Listeners>
                            <Click Handler="#{winTask}.hide();" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button2" runat="server" Text="Workflow Details" Icon="Cog">
                        <Listeners>
                            <Click Handler="window.open(#{hidSoeId}.getValue());" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button3" runat="server" Text="Error" Icon="Error">
                        <Listeners>
                            <Click Handler="EmailTaskError();" />
                        </Listeners>
                    </ext:Button>
                                   <ext:Button ID="Button4" runat="server" Text="Print" Icon="Printer">
                        <Listeners>
                            <Click Handler="#{winTask}.items.first().getFrame().print();" />
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:StatusBar>
        </BottomBar>
        <Listeners>
            <BeforeShow Handler="mask.hide();" />
        </Listeners>
    </ext:Window>

    Here is how the content is generated:

       public void ShowTaskWindow(string title, string assignid, string taskid, string workflowid, string soeid, string userid)
            {
    
                //init window and panel
                this.winTask.Show();
                this.winTask.Title = string.Format("Task: {0}", title);
                this.hidSoeId.Value = Aksia.Intranet.Library.Utilities.SiteRoot() + string.Format("/Workflow.aspx?soeid={0}", soeid);
                this.hidSoeIdRaw.Value = soeid;
                this.hidInstanceId.Value = BPMGetWorkflowInstanceId(soeid);
                var form = new FormPanel
                {
                    ID = "FormTaskPanel1",
                    RenderFormElement = false,
                    Border = false,
                    AutoHeight = false,
                    AutoScroll = true,
                    Height = 350,
                    LabelWidth = 150,
                    LabelAlign = LabelAlign.Right,
                    Padding = 0
                };
    
                form.Listeners.ClientValidation.Handler = "ctl00_ContentPlaceHolder1_MyTasks1_StatusTaskBar.setStatus({text: valid ? 'Form is valid' : 'Form is invalid', iconCls: valid ? 'icon-accept' : 'icon-exclamation'});";
                form.MonitorPoll = 500;
                form.MonitorValid = true;
                form.Defaults.Add(new Parameter("AllowBlank", "true", ParameterMode.Raw));
                form.Defaults.Add(new Parameter("MsgTarget", "qtip"));
    
                ValidationStatus.Config cnfg = new ValidationStatus.Config();
                cnfg.FormPanelID = "FormTaskPanel1";
                cnfg.ErrorIcon = Icon.Exclamation;
                cnfg.ValidIcon = Icon.Accept;
                this.winTask.Plugins.Add(new ValidationStatus(cnfg));
    
    
                form.Items.Add(new Hidden { Value = title, ID = "HIDtitle" });
                form.Items.Add(new Hidden { Value = taskid, ID = "HIDtaskid" });
                form.Items.Add(new Hidden { Value = workflowid, ID = "HIDworkflowid" });
                form.Items.Add(new Hidden { Value = userid, ID = "HIDuserid" });
    
                try
                {
    
                    #region GET BPM DATA
                    Bluespring.Workflow.WorkflowService Tasks = new Bluespring.Workflow.WorkflowService();
                    string credentials = string.Format("<" + ConfigurationManager.AppSettings["BPMCredentials"].ToString() + "/>", this.Page.User.Identity.Name.Replace("AKSIA\\", string.Empty));
                    XmlDocument xdRequest = new XmlDocument();
                    xdRequest.LoadXml(credentials);
                    Tasks.OpenSession(xdRequest.OuterXml);
                    XmlNodeList xNodeList = null;
    
                    //THIS GETS THE TASK ID...YET ANOTHER HACK TO GET AROUND BS BPM
                    //For some reason there is no TaskId when an email gets sent.
                    //So, in order for a user to act via email and be brought to this task, we need to
                    //query the BPM service for all of the taks for this user, then match the assigned task id,
                    string taskId = string.Empty;
                    if ( taskid == "none" )
                    {
                        XmlElement xeTask = (XmlElement)Tasks.GetTasks(string.Format("<gettasks assignedto='{0}' userclassid='Users' />", userid));
                        xNodeList = xeTask.GetElementsByTagName("task");
                        foreach ( XmlElement xElem in xNodeList )
                            if ( xElem.Attributes["assignedtaskid"].Value.Equals(assignid, StringComparison.InvariantCultureIgnoreCase) )
                            {
                                taskId = xElem.Attributes["taskid"].Value;
                                break;
                            }
                        xeTask = null;
                        xNodeList = null;
                    }
                    else
                        taskId = taskid;
    
    
    
    
                    //THIS GETS THE XML FOR THE CONTROLS TO SHOW 
                    XmlElement xeTaskWrkflow = (XmlElement)Tasks.GetWorkflowData(
                        string.Format(GETWORKFLOWCONTROLDATA, assignid, workflowid));
    
                    StringReader sr = new StringReader(xeTaskWrkflow.OuterXml);
                    DataSet ds = new DataSet();
                    ds.ReadXml(sr, XmlReadMode.Auto);
                    sr.Close();
                    sr.Dispose();
    
    
                    //HERE WE GET THE VALUES FOR THE CONTROLS 
                    xeTaskWrkflow = (XmlElement)Tasks.GetWorkflowData(
                        string.Format(GETWORKFLOWDATA,
                        workflowid));
                    xNodeList = xeTaskWrkflow.GetElementsByTagName("dataitem");
    
    
                    //write out the data xml that we'll need to submit back to the BPM service to move the tasks along.
                    //since this a dynamic form, we'll ned
                    //   this.Page.ClientScript.RegisterStartupScript(typeof(string), "dataxml", string.Format("<script> var dataxml='{0}'; </script>", xeTaskWrkflow.OuterXml.ToString().Replace("\'", "\\'")));
                    form.Items.Add(new Hidden { Value = xeTaskWrkflow.OuterXml.ToString().Replace("\'", "\\'"), ID = "dataxml" });
    
                    #endregion
    
    
                    //create form table.  
                    foreach ( DataRow r in ds.Tables[0].Rows )
                    {
                        //Handle any lookup tables, else, create textbox if editable, ,label otherwise.
                        if ( r["LU_TBL"].ToString().Length > 0 )
                        {
                            SelectBox sb = new SelectBox();
                            sb.FieldLabel = r["AttribName"].ToString();
                            sb.AllowBlank = ( r["Required"].ToString().Equals("0") ) ? true : false;
                            sb.LabelStyle = ( r["Required"].ToString().Equals("0") ) ? string.Empty : "color:red";
                            sb.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Drop", r["Required"].ToString());
                            sb.Items.Add(new ListItem("<--select-->", "-1"));
                            XmlNode luValues = Tasks.GetLookup(string.Format(GETLOOKUP, r["LU_TBL"].ToString()));
                            //for some reason, BPM system drop downs yeild different XML. Yay.
                            if ( r["LU_TBL"].ToString().StartsWith("Sys_") )
                            {
                                foreach ( XmlNode n in luValues.ChildNodes )
                                    sb.Items.Add(new ListItem(n.Attributes["Value"].Value, n.Attributes["Value"].Value));
                            }
                            else
                            {
                                foreach ( XmlNode n in luValues.ChildNodes )
                                    sb.Items.Add(new ListItem(n.Attributes[1].Value, n.Attributes[0].Value));
                            }
    
                            sb.SelectedItem.Value = SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString()));
                            form.Items.Add(sb);
                        }
                        else
                        {
                            if ( r["Enabled"].ToString().Equals("1") )  //if enabled, then this should be a textbox as it will require user input.
                            {
                                if ( r["DataType"].ToString().Equals("1") ) //boolean
                                {
                                    Checkbox c = new Checkbox();
                                    c.FieldLabel = r["AttribName"].ToString();
                                    c.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Check", r["Required"].ToString());
                                    c.Checked = SetControlValueBool(r["XmlTag"].ToString(), xNodeList);
                                    form.Items.Add(c);
                                }
                                else if ( r["DataType"].ToString().Equals("8") )
                                {
    
                                    DateField df = new DateField();
                                    df.FieldLabel = r["AttribName"].ToString();
                                    df.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Text", r["Required"].ToString());
                                    df.LabelStyle = ( r["Required"].ToString().Equals("0") ) ? string.Empty : "color:red";
                                    if ( SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString())).Length > 0 )
                                        df.Value = Convert.ToDateTime(SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString()))).ToShortDateString();
                                    form.Items.Add(df);
                                }
                                else
                                {
                                    //check to see if we have a text box that should be a memo size
                                    if ( r["DataType"].ToString().Equals("12") )
                                    {
                                       // create a text area for memo fields.
                                        TextArea tt = new TextArea();
                                        tt.FieldLabel = r["AttribName"].ToString();
                                        tt.AllowBlank = ( r["Required"].ToString().Equals("0") ) ? true : false;
                                        tt.Text = SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString()));
                                        tt.Width = 300;
                                        tt.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Text", r["Required"].ToString());
                                        tt.LabelStyle = ( r["Required"].ToString().Equals("0") ) ? string.Empty : "color:red";
                                        form.Items.Add(tt);
    
                                        //HtmlEditor tt = new HtmlEditor();
                                        //tt.FieldLabel = r["AttribName"].ToString();
                                        //tt.EnableAlignments = false;
                                        //tt.EnableColors = false;
                                        //tt.EnableFont = false;
                                        //tt.EnableFontSize = false;
                                        //tt.EnableLinks = false;
                                        //tt.EnableLists = false;
    
                                        ////   tt.AllowBlank = ( r["Required"].ToString().Equals("0") ) ? true : false;
                                        //tt.Text = SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString()));
                                        //tt.Width = 300;
                                        //tt.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Text", r["Required"].ToString());
                                        //tt.LabelStyle = ( r["Required"].ToString().Equals("0") ) ? string.Empty : "color:red";
                                        //form.Items.Add(tt);
    
                                    }
                                    else
                                    {
                                        //create a text field.
                                        TextField t = new TextField();
                                        t.FieldLabel = r["AttribName"].ToString();
                                        t.AllowBlank = ( r["Required"].ToString().Equals("0") ) ? true : false;
                                        t.LabelStyle = ( r["Required"].ToString().Equals("0") ) ? string.Empty : "color:red";
                                        t.ID = string.Format("{0}_{1}_{2}", r["XmlTag"].ToString(), "Text", r["Required"].ToString());
                                        t.Text = SetControlValue(r["XmlTag"].ToString(), xNodeList, false, Convert.ToInt32(r["DataType"].ToString()));
                                        form.Items.Add(t);
                                    }
                                }
                            }
                            else    //if not enabled, then we just show the label value.
                            {
                                Label l2 = new Label();
                                l2.FieldLabel = r["AttribName"].ToString();
                                l2.Html = ReplaceText(SetControlValue(r["XmlTag"].ToString(), xNodeList, true, Convert.ToInt32(r["DataType"].ToString())));
                                form.Items.Add(l2);
                            }
                        }
                    }
                    //render form to task window.
                    form.Render(this.winTask, RenderMode.AddTo);
                    //   form.Render();
                }
                catch ( Exception er )
                {
                    TextArea l2 = new TextArea();
                    l2.FieldLabel = "Error";
                    l2.Text = er.ToString();
                    l2.Width = 300;
                    form.Items.Add(l2);
                    form.Render(this.winTask, RenderMode.AddTo);
                    er.Data.Add("title", title);
                    er.Data.Add("soeid", soeid);
                    ExceptionPolicy.HandleException(er, "Aksia");
                }
            }

  6. #6

    RE: [CLOSED] Print a Window

    Hi,

    Well, it is complex code for manual moving to the iframe. All I can suggest to create separate page (for example, Print.aspx), in that page repeat required UI (in the code behind). You can load that page to any Ext.NET panel or window and print content.
    Window1.iframe.print();
  7. #7

    RE: [CLOSED] Print a Window

    beat.
    so there is no clever way to pass the innerHtml of the window to some javscript call for a print?
  8. #8

    RE: [CLOSED] Print a Window

    Hi,

    You can play with the following extension
    http://edspencer.net/2009/07/extuxpr...r-any-ext.html

Similar Threads

  1. [CLOSED] How I print ext:Window content?
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 29, 2012, 4:00 PM
  2. [CLOSED] Load html in window to print an image.
    By stoque in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 03, 2011, 10:37 AM
  3. Replies: 6
    Last Post: Feb 18, 2011, 2:12 PM
  4. [CLOSED] [1.0] Print Window Contents
    By MP in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Sep 22, 2010, 8:18 PM
  5. Replies: 1
    Last Post: Mar 25, 2010, 5:59 PM

Posting Permissions