Example #1
0
                // For Editing:
                // RDdetail     =   need to know what is selected (if anything yet)
                public string Edit()
                {
                    string prompt="",html="", js="", phraseselect="";
                    string[] phrases;
                    DataType datatype = new DataType();
                    UIFS.Form_Output FormOut = new Form_Output();

                    FormControl.Checkbox Ctrl_Checkbox;
                    FormControl.DateTime Ctrl_DateTime;
                    FormControl.Number Ctrl_Number;
                    FormControl.Percentage Ctrl_Percentage;
                    FormControl.List Ctrl_List;
                    FormControl.Range Ctrl_Range;
                    FormControl.Textbox Ctrl_Textbox;

                    // Load Phrases for this datatype, if phrase selection data does not exist ... set to default
                    phrases = datatype.Phrases(detail.type).Split(new char[] { ',' });
                    if (RDdetail == null)
                    {
                        RDdetail = new ReportDefinition.Detail();
                        RDdetail.lang = phrases[0]; // first language phrase
                    }
                    prompt = "<span class=\"name\">" + detail.name + "</span> ";
                    // Language selection
                    //: currently based on datatype
                    prompt = prompt + "<select id=\""+this.id.ToString()+"_phrase\" onchange=\"Option_Redraw('"+this.id.ToString()+"'); \">";
                    foreach (string phrase in phrases)
                    {
                        if (RDdetail.lang == phrase) { phraseselect = " selected=\"1\" "; } else { phraseselect = ""; }
                        prompt = prompt + "<option value=\"" + phrase + "\" " + phraseselect + ">" + phrase + "</option>";
                    }
                    prompt = prompt + "</select>";

                    // --[  Builds a dynamic UIFS.FormControl we use to get input needed to build form  ]
                    // entry type...based on language, then datatype
                    string CtrlEntryType = datatype.FormEntryType(detail.type, RDdetail.lang);
                    switch (CtrlEntryType)
                    {
                        // possibly have two different methods
                        // 1: for getting data specific to UIFS.Form (this way we can mirror our control properties)
                        // 2: for generic Subject-Detail

                        case "id":
                        case "list_id":
                            // GLOBAL identifiers are user defined formlinks to id lists of this Subject type...
                            //. Use a list control
                            if (detail.name.StartsWith("[global]")) {
                                Ctrl_List = new FormControl.List();
                                Ctrl_List.id = this.id;
                                Ctrl_List.prompt = prompt;
                                Ctrl_List.tip = "Please choose your Subject";
                                Ctrl_List.type = FormControl.List.listtype.dropdown;
                                Ctrl_List.Items = PossibleValues;
                                FormOut.HTML_FormControl(ControlType.List, Ctrl_List, ref html, ref js);
                                Control = Ctrl_List; Control_type = ControlType.List;
                            }
                            break;
                        case "checkbox":
                            if (UIFSFormControl) {
                                Ctrl_Checkbox = (FormControl.Checkbox)UIFSControl;
                                Ctrl_Checkbox.hasinput = false; // we do not want this
                            }
                            else {
                                Ctrl_Checkbox = new FormControl.Checkbox(); }
                            Ctrl_Checkbox.id = this.id;
                            Ctrl_Checkbox.prompt = prompt; //TEST: we want to use this as part of our Control div if possible
                            Ctrl_Checkbox.tip = "Choose one or the other";
                            FormOut.HTML_FormControl(ControlType.Checkbox, Ctrl_Checkbox, ref html, ref js); // builds html for control
                            Control = Ctrl_Checkbox; Control_type = ControlType.Checkbox;
                            break;
                        case "number":
                            if (UIFSFormControl){Ctrl_Number = (FormControl.Number)UIFSControl; }
                            else { Ctrl_Number = new FormControl.Number(); }
                            Ctrl_Number.id = this.id; Ctrl_Number.prompt = prompt;
                            Ctrl_Number.tip = "Please choose a number between: " + Ctrl_Number.min.ToString() + " AND " + Ctrl_Number.max.ToString();
                            FormOut.HTML_FormControl(ControlType.Number, Ctrl_Number, ref html, ref js);
                            Control = Ctrl_Number; Control_type = ControlType.Number;
                            break;
                        case "datetime":
                        case "date":
                        case "time":
                            if (UIFSFormControl) {Ctrl_DateTime = (FormControl.DateTime)UIFSControl; }
                            else { Ctrl_DateTime = new FormControl.DateTime();}
                            Ctrl_DateTime.id = this.id;
                            Ctrl_DateTime.prompt = prompt;
                            Ctrl_DateTime.tip = "Please select a date/time";
                            switch (CtrlEntryType)
                            {
                                case "datetime":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.datetime;
                                    break;
                                case "date":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.date;
                                    break;
                                case "time":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.time;
                                    break;
                            }
                            FormOut.HTML_FormControl(ControlType.DateTime, Ctrl_DateTime, ref html, ref js);
                            Control = Ctrl_DateTime; Control_type = ControlType.DateTime;
                            break;
                        case "text":
                            if (UIFSFormControl)
                            { // if
                                switch (UIFSFormControl_type)
                                {
                                    case ControlType.List: // List Controls are basically text field values; which is what the input value is
                                        Ctrl_List = (FormControl.List)UIFSControl;
                                        Ctrl_List.id = this.id;
                                        Ctrl_List.prompt = prompt;
                                        FormOut.HTML_FormControl(ControlType.List, Ctrl_List, ref html, ref js);
                                        Control = Ctrl_List; Control_type = ControlType.List;
                                        break;
                                    case ControlType.Textbox:
                                        Ctrl_Textbox = (FormControl.Textbox)UIFSControl;
                                        Ctrl_Textbox.id = this.id;
                                        Ctrl_Textbox.prompt = prompt;
                                        FormOut.HTML_FormControl(ControlType.Textbox, Ctrl_Textbox, ref html, ref js);
                                        Control = Ctrl_Textbox; Control_type = ControlType.Textbox;
                                        break;
                                }
                            }
                            else
                            { // default
                                Ctrl_Textbox = new FormControl.Textbox();
                                Ctrl_Textbox.id = this.id;
                                Ctrl_Textbox.prompt = prompt;
                                Ctrl_Textbox.tip = "value to look for...";
                                FormOut.HTML_FormControl(ControlType.Textbox, Ctrl_Textbox, ref html, ref js);
                                Control = Ctrl_Textbox; Control_type = ControlType.Textbox;
                            }
                            break;
                        //NOTE: should this be allowed to be a generic?
                        case "percentage":
                            if (UIFSFormControl) { Ctrl_Percentage = (FormControl.Percentage)UIFSControl; }
                            else { Ctrl_Percentage = new FormControl.Percentage(); }
                            Ctrl_Percentage.id = this.id;
                            Ctrl_Percentage.prompt = prompt;
                            Ctrl_Percentage.interval = 1; // allow to select all values
                            Ctrl_Percentage.tip = "select a percentage value";
                            FormOut.HTML_FormControl(ControlType.Percentage, Ctrl_Percentage, ref html, ref js);
                            Control = Ctrl_Percentage; Control_type = ControlType.Percentage;
                            break;
                        case "range_number":
                        case "range_percentage":
                            Ctrl_Range = new FormControl.Range();
                            if (CtrlEntryType == "range_percentage")
                            {
                                Ctrl_Range.min = 0; Ctrl_Range.max = 100;
                                Ctrl_Range.tip = "Please choose your percentage range";
                            }
                            else
                            {
                                if (UIFSFormControl)
                                {
                                    if (this.UIFSFormControl_type == ControlType.Number)
                                    {
                                        Ctrl_Number = (FormControl.Number)UIFSControl;
                                        Ctrl_Range.min = Ctrl_Number.min; Ctrl_Range.max = Ctrl_Number.max; // get values from UIFS control properties
                                        Ctrl_Range.tip = Ctrl_Number.tip;
                                    }
                                }
                                else
                                {
                                    Ctrl_Range.min = 0; Ctrl_Range.max = 1000; // default
                                    Ctrl_Range.tip = "Please choose your range";
                                }
                            }
                            Ctrl_Range.id = this.id; Ctrl_Range.prompt = prompt;
                            Ctrl_Range.type = FormControl.Range.Rangetype.MinMax;
                            FormOut.HTML_FormControl(ControlType.Range, Ctrl_Range, ref html, ref js);
                            Control = Ctrl_Range; Control_type = ControlType.Range;
                            break;
                        case "range_time":
                        case "range_date":
                        case "range_datetime":
                            Ctrl_Range = new FormControl.Range();
                            if (UIFSFormControl) {
                                if (this.UIFSFormControl_type == ControlType.DateTime)
                                {
                                    Ctrl_DateTime = (FormControl.DateTime)UIFSControl;
                                    Ctrl_Range.tip = Ctrl_DateTime.tip;
                                    switch (Ctrl_DateTime.type)
                                    {
                                        case FormControl.DateTime.datetimetype.time:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.TimeRange;
                                            break;
                                        case FormControl.DateTime.datetimetype.date:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.DateRange;
                                            break;
                                        case FormControl.DateTime.datetimetype.datetime:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.DateTimeRange;
                                            break;
                                    }
                                }
                            }
                            else{ // non-UIFS control
                                Ctrl_Range.tip = "Please choose your range";
                                switch (CtrlEntryType)
                                {
                                    case "range_time":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.TimeRange;
                                        break;
                                    case "range_date":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.DateRange;
                                        break;
                                    case "range_datetime":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.DateTimeRange;
                                        break;
                                }
                            }
                            Ctrl_Range.id = this.id; Ctrl_Range.prompt = prompt;
                            FormOut.HTML_FormControl(ControlType.Range, Ctrl_Range, ref html, ref js);
                            Control = Ctrl_Range; Control_type = ControlType.Range;
                            break;
                        case "list_number":
                            break;
                        default:
                            return "";
                    }
                    Control.id = this.id; // mirror for simplification in ajax routines

                    //TODO: temp to show what exists if it does not find its way through
                    if (html == "") { html = "<div id='"+detail.name+"'>"+prompt+"</div>"; }
                    // USE button
                    html = "<table class='selection' onMouseover=\"ToggleButton(this,1);\" onMouseout=\"ToggleButton(this,0);\" ><tr><td class='input'>" + html + "</td>" +
                        "<td class='buttons'><div class='button' onMousedown=\"ToggleButton(this.parentNode,2);\" onMouseup=\"ToggleButton(this.parentNode,3);\" onclick=\"Option_Use(" + this.id + ",'" + Control_type.ToString() + "');\">USE</div></td>" +
                        "</tr></table>";

                    // return combined (if js exists)
                    if (js == "") { return html; }
                    else { return html + "<script type='text/javascript'>" + js + "</script>"; }
                }