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); }
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); }
public void Show() { var windowHtml = R.RenderViewToString(Controller, ViewName, ViewModel); var init = new JsObject(); init.AddProperty("show", true); init.AddProperty("backdrop", "static"); //init.AddProperty("modalOverflow", true); init.AddRawProperty("maxHeight", "function(){return $(window).height()-200;}"); var script = new StringBuilder(); // script.Append("var tag = $("+ windowHtml.AsJavaScript() + ").appendTo('#popups').modal("+init.AsJavaScript()+");"); script.Append("docReady = function(callback) { callback() };"); EmitBinders(script); script.Append("var modal = $(" + windowHtml.AsJavaScript() + ");"); script.Append("modal.attr('id','" + UniqueId + "');"); script.Append("$('body').append(modal);"); if (ViewModel is MessageDialogModel) { script.Append("modal.on('hidden.bs.modal', function (e) {"); script.Append(" bindingHub.server.sendEvent(localStorage.ChromeSessionId,'" + ViewModel.BindingId + "','" + nameof(MessageDialogModel.ClosedByEsc) + "', {} );"); script.Append("}); "); } script.Append("modal.modal(" + init.AsJavaScript() + ");"); script.Append("modal.off('keyup.dismiss.modal');"); script.Append("modal.on('keyup.esc.modal', function(e) {if (e.which == 27) { modal.find('.modal-cancel-button').trigger('click')}; });"); //if (OnClose_Bind != null) //{ // script.AppendLine("tag.on('close',function(event){"); // script.AppendLine(" var args={}; if (event) {args=event.args || {}};"); // script.AppendLine(" bindingHub.server.sendEvent('" + ParentModel.BindingId + "','" + OnClose_Bind + "', args );"); // script.AppendLine("});"); //} Thread.Sleep(1); // не удалять, иначе все глючит !!! Model.ExecuteJavaScript(script.ToString()); }