function ViewModel() { var self = this; self.CategoryAjaxView = false; self.JsTreeFirstLoad = ko.observable(true); self.selectedCatId = ko.observable(1); self.selectedCatTitle = ko.observable('اصول عقاید'); self.AjaxWait = ko.observable(false); self.PageSize = 10; self.Items = ko.observableArray([]); self.FoundItems =ko.computed({ read: function () { if(self.AjaxWait()) {return '

';} if(self.Items().length>0) { return (self.Items().length.toString()).toFaDigit() + " مورد یافت شد." } else { return "موردی یافت نشد" } }, write: function (value) { return value; }, owner: self }); } var ViewModel = new ViewModel() ko.applyBindings(ViewModel); $(function () { jQuery("#Ctree") .bind("loaded.jstree", function (event, data) { //alert("TREE IS LOADED"); var id = 'li.mcat-' + ViewModel.selectedCatId(); $.jstree._reference("#Ctree").select_node(id); }) .bind("select_node.jstree", function (event, data) { // `data.rslt.obj` is the jquery extended node that was clicked var node = data.rslt.obj; ViewModel.selectedCatId(node.attr("relid")); ViewModel.selectedCatTitle(node.find('a:first').text()); var categoryId = node.attr("relid"); if (jQuery.jstree._reference("#Ctree")._get_children(node).length == 0) { // if clicked node has no children node //// alert(data.rslt.obj.attr("id")); if(ViewModel.CategoryAjaxView) { ViewModel.AjaxWait(true); $.post("/fa/Category/getPagsOfCategory", { categoryId: ViewModel.selectedCatId(), languageId: '1' }, function (data) { ViewModel.Items(data); ViewModel.AjaxWait(false); $('#ArtList').pajinate({ nav_label_prev: ' قبلی ', nav_label_next: 'بعدی', nav_label_first:'اولین', nav_label_last:'آخرین', show_first_last:false, wrap_around:true, items_per_page:20 }); if(isLessOrEqual(data.length ,ViewModel.PageSize)) { $('.page_navigation').hide(); } else { $('.page_navigation').show(); $(".page_link").each(function(){ $(this).html($(this).html().toFaDigit()) }); } }, "json"); } else { if(!ViewModel.JsTreeFirstLoad()) { window.location = "/fa/Category/View/[ID]".replace("[ID]",ViewModel.selectedCatId()); } ViewModel.JsTreeFirstLoad(false); } //var id = node.attr("id"); // or data.rslt.obj.find("a").attr("rel"); ////if (id == selectedID) return; //var text = node.attr("title"); //window.location = ViewCatPageUrl + '/' + id + '/' + text.replace(/ /g, '_'); } else { jQuery.jstree._reference("#Ctree").toggle_node(node); }; //alert(categoryId); //PageDTable.fnReloadAjax(Urls.PageList.PagesOfCategory_RP.replace('CATEGORYID', categoryId)); }) .jstree({ core: { rtl:true }, plugins: ["themes", "json_data", "ui"], "themes": { "theme": "default2", // load theme name from resources "dots": true, "icons": true, "url" : "/Content/Component/jstree/themes/default2/style.css" }, "json_data": { //default-rtl "ajax": { // Load From Json "url": "/fa/Category/CategoriesToJsTree?LanguageId=1" } } }); });