Esempio n. 1
0
 public void SaveSessionState()
 {
     if (SessionStateId != null)
     {
         var stateObject = new bsTreeSessionState();
         stateObject.Id = SessionStateId;
         stateObject.Tree = this;
         stateObject.Save();
     }
 }
Esempio n. 2
0
        public override void EmitScriptAndHtml(StringBuilder script, StringBuilder html)
        {
            if (SessionStateId != null)
                sessionStateObject = AppServer.GetStateObject<bsTreeSessionState>(SessionStateId);

            AddClass("table");

            JsObject init = new JsObject();

            JsArray extensions = new JsArray();
            extensions.AddObject("table");
            extensions.AddObject("filter");
            init.AddProperty("extensions", extensions);

            JsObject filter = new JsObject();
            filter.AddProperty("mode", "hide");
            filter.AddProperty("counter", "false");
            filter.AddProperty("hideExpandedCounter", "false");
            init.AddProperty("filter", filter);

            JsObject table = new JsObject();
            table.AddProperty("indentation", 20);
            table.AddProperty("nodeColumnIdx", 0);
            init.AddProperty("table", table);

            if (IsShowCheckboxes)
                init.AddProperty("checkbox", true);
            init.AddProperty("icon", IsShowIcons);

            init.AddProperty("activeVisible", true);
            init.AddProperty("debugLevel", 0);
            init.AddProperty("keyboard", true);

            //ObservableCollection<string> selectedRows = null;
            //if (SelectedRows_Bind != null)
            //{
            //    selectedRows = Model.GetPropertyValue<ObservableCollection<string>>(SelectedRows_Bind);
            //    init.AddProperty("checkbox", true);

            //    script.AppendLine("var " + SelectedRows_Bind + "=function(event, data) {");
            //    script.AppendLine("  bindingHub.server.sendSelectedRowsChanged('" + Model.BindingId + "', '" + SelectedRows_Bind + "', data.node.key, data.node.isSelected()); ");
            //    script.AppendLine("}");

            //    init.AddRawProperty("select", SelectedRows_Bind);

            //}

            script.AppendLine("var renderColumns=function(event, data) {");
            script.AppendLine("  var node = data.node;");
            script.AppendLine("  var row = node.data.row || {};");
            script.AppendLine("  row.node = node;");
            script.AppendLine("  var td = $(node.tr).find('>td');");
            int colIndex = -1;
            foreach (var col in Columns.Where(c => c.Hidden != true))
            {
                colIndex++;

                if (colIndex != 0)
                    script.AppendLine("  var td_tag=td.eq(" + colIndex + ");");
                else
                    script.AppendLine("  var td_tag=td.eq(" + colIndex + ").find('.fancytree-title');");

                if (col.CellTemplate != null)
                {
                    script.AppendLine(@"  var f" + colIndex + "=function(row){");
                    if (col.CellTemplateJS != null)
                        script.AppendLine(col.CellTemplateJS);
                    script.AppendLine(@"    return Mustache.render(""" + col.CellTemplate.Replace("\n", "").Replace(@"""", @"\""") + @""", row);");
                    script.AppendLine(@"  };");
                    if (colIndex != 0)
                        script.AppendLine("  td_tag.html(f" + colIndex + "(row));");
                    else
                        // node.saveHtml ипользуется в jquery.fancytree.filter.js
                        script.AppendLine("  td_tag.html(f" + colIndex + "(row)); node.saveHtml=f" + colIndex + "(row);");
                }
                else
                if (col.EditableType != bsEditableType.None)
                {
                    var edt = new bsTreeEditable(Model);
                    edt.Tree = this;
                    edt.TreeColumn = col;
                    edt.Bind_Value<string>(col.Field_Bind);
                    var edt_html = new StringBuilder();
                    var edt_script = new StringBuilder();
                    edt.EmitScriptAndHtml(edt_script, edt_html);

                    script.AppendLine("  td_tag.html(" + edt_html.AsJavaScript() + ".replace('4D57BEAC0040F92312A4',row['" + col.Field_Bind + "']).replace('"+ edt.UniqueId + "',node.key));");

                    script.AppendLine("  setTimeout(function(){ " + edt_script.ToString() + " }, 100);");

                }
                else
                {
                    script.AppendLine("  td_tag.text(row['" + col.Field_Bind + "']);");
                }

                //if (col.TextColorClass != null)
                //    script.AppendLine("  td_tag.addClass('" + col.TextColorClass + "');");
                //if (col.BackColorClass != null)
                //    script.AppendLine("  td_tag.addClass('" + col.BackColorClass + "');");

                foreach (string cls in col.Classes)
                    script.AppendLine("  td_tag.addClass('" + cls + "');");

                foreach (var style in col.Styles)
                    script.AppendLine("  td_tag.css('" + style.Key + "','" + style.Value + "');");

                if (col.Align == bsTreeColumnAlign.center)
                    script.AppendLine("  td_tag.css('text-align','center');");
                if (col.Align == bsTreeColumnAlign.right)
                    script.AppendLine("  td_tag.css('text-align','right');");

            }
            script.AppendLine("}");
            init.AddRawProperty("renderColumns", "renderColumns");

            script.AppendLine("$('#" + UniqueId + "').fancytree(" + init.ToJson() + ");");

            if (ClickAction != null)
            {
                script.AppendLine("$('#" + UniqueId + "').on('click',function(event){");
                ClickAction.EmitJsCode(script);
                script.AppendLine("});");

            }

            // toolbar
            if (IsShowTextFilter)
                EmitFilterScript(script);

            if (rightToolbar.Count > 0 || leftToolbar.Count > 0 || IsShowTextFilter)
            {
                html.Append("<div class='row'>");  // begin row

                html.Append(@"<form class='form-inline'>");

                if (leftToolbar.Count > 0 || IsShowTextFilter)
                {
                    html.Append(@"<div class='form-group col-xs-12 col-md-6' style='margin-bottom:10px; padding-left:0px'>");

                    if (IsShowTextFilter)
                        html.Append(@"<input id='" + UniqueId + @"-filter-input' type='text' class='form-control input-sm' placeholder='строка для поиска' style='max-width:150px; margin-left1:-15px; display:inline-block'>");

                    foreach (var control in leftToolbar)
                        html.Append(control.GetHtml());

                    html.Append(@"</div>");
                }

                if (rightToolbar.Count > 0)
                {
                    html.Append("<div class='form-group col-xs-12 col-md-6' style='margin-bottom:10px; padding-right:0px'>");
                    html.Append("<div class='pull-right'>");
                    foreach (var control in rightToolbar)
                        html.Append(control.GetHtml());
                    html.Append("</div>");
                    html.Append("</div>");
                }
                html.Append("</div>");  // end row
                html.Append("</form>");
            }

            html.Append("<div class='row'>");  // begin row
            html.Append("<table id='" + UniqueId + "' " + GetAttrs() + ">");
            //html.Append("<colgroup>");
            //foreach (var col in Columns)
            //    col.EmitColgroupCol(Html, Script);
            //html.Append("</colgroup>");

            html.Append("<thead>");
            html.Append("<tr>");
            foreach (var col in Columns.Where(c => c.Hidden != true))
                html.Append("<th>" + col.Caption + "</th>");
            html.Append("</tr>");
            html.Append("</thead>");

            html.Append("<tbody>");
            html.Append("<tr>");
            foreach (var col in Columns.Where(c => c.Hidden != true))
                html.Append("<td></td>");
            html.Append("</tr>");
            html.Append("</tbody>");

            html.Append("</table>");
            html.Append("</div>");  // end row

            base.EmitScriptAndHtml(script, html);
        }