Example #1
0
        // при загрузке сохраняются и восстанавливаются состояния раскрытых и выбранных нод
        public string GetLoadDataScript(JsArray data, bool isFlatData)
        {
            string flatToTreeConvertFunctionName = "buhta.FancyTree.convertFlatDataToTree";
            if (!isFlatData)
                flatToTreeConvertFunctionName = "";

            return @"
            (function(){

            var expanded_state={};
            var selected_state={};
            var active_state={};

            var rootNode=$('#" + UniqueId + @"').fancytree('getRootNode');

            if (rootNode)
              rootNode.visit(function(node){
             expanded_state[node.key]=node.isExpanded();
             selected_state[node.key]=node.isSelected();
             active_state[node.key]=node.isActive();
              });

            $('#" + UniqueId + @"').fancytree('getTree').clearFilter();

            $('#" + UniqueId + @"').fancytree('option','source'," + flatToTreeConvertFunctionName + "(" + data.ToJson() + @"));

            rootNode=$('#" + UniqueId + @"').fancytree('getRootNode');

            rootNode.visit(function(node){
             if (expanded_state[node.key]!=undefined)
            node.setExpanded(expanded_state[node.key]);
             if (selected_state[node.key]!=undefined)
            node.setSelected(selected_state[node.key]);
             if (active_state[node.key]!=undefined)
            node.setActive(active_state[node.key]);
            });

            var match=$('#" + UniqueId + @"').fancytree('getTree').filter_match;
            if (match) {
              var opts = {
               autoExpand: true,
               leavesOnly: true
              };
              $('#" + UniqueId + @"').fancytree('getTree').filterNodes(match, opts);
            }

            })();
            ";
        }
Example #2
0
        public override void EmitScriptAndHtml(StringBuilder script, StringBuilder html)
        {
            AddClass("table");
            AddClass("table-bordered");

            JsObject init = new JsObject();
            init.AddProperty("paging", false);
            init.AddProperty("select", true);
            init.AddRawProperty("createdRow", GetCreatedRowEventScript());

            //jsArray extensions = new jsArray();
            //extensions.AddObject("table");
            //init.AddProperty("extensions", extensions);

            JsArray columns = new JsArray();
            foreach (var col in Columns)
            {
                var jscol = new JsObject();
                jscol.AddProperty("title", col.Caption);
                jscol.AddProperty("name", col.Field_Bind);
                columns.AddObject(jscol);
            }
            init.AddProperty("columns", columns);

            // сортировка

            List<SortRec> sortArray = new List<SortRec>();
            int colIndex = 0;
            foreach (var col in Columns)
            {
                if (col.Sort != bsGridColumnSort.none)
                {
                    var sortRec = new SortRec() { ColIndex = colIndex };
                    sortRec.SortIndex = Math.Abs((int)col.Sort);
                    if ((int)col.Sort > 0)
                        sortRec.AscDesc = "asc";
                    else
                        sortRec.AscDesc = "desc";
                    sortArray.Add(sortRec);
                }
                colIndex++;
            }
            JsArray order = new JsArray();
            foreach (SortRec rec in sortArray.OrderBy((r) => r.SortIndex))
            {
                var jsorder = new JsArray();
                jsorder.AddObject(rec.ColIndex);
                jsorder.AddObject(rec.AscDesc);
                order.AddObject(jsorder);
            }
            if (order.Length > 0)
                init.AddProperty("order", order);

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

            //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 i = -1;
            //foreach (var col in Columns.Where(c => c.Hidden != true))
            //{
            //    i++;
            //    if (col.CellTemplate != null)
            //    {
            //        script.AppendLine(@"  var f" + i + "=function(row){");
            //        if (col.CellTemplateJS != null)
            //            script.AppendLine(col.CellTemplateJS);
            //        script.AppendLine(@"    return Mustache.render(""" + col.CellTemplate + @""", row);");
            //        script.AppendLine(@"  };");
            //        if (i != 0)
            //            script.AppendLine("  td.eq(" + i + ").html(f" + i + "(row));");
            //        else
            //            script.AppendLine("  td.eq(" + i + ").find('.fancytree-title').html(f" + i + "(row));");
            //    }
            //    else
            //    {
            //        if (i != 0)
            //            script.AppendLine("  td.eq(" + i + ").text(row['" + col.Field_Bind + "']);");
            //        else
            //            script.AppendLine("  td.eq(" + i + ").find('.fancytree-title').text(row['" + col.Field_Bind + "']);");
            //    }

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

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

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

            //}

            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>");

            base.EmitScriptAndHtml(script, html);
        }
Example #3
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);
        }