var mainObj = { selectedId: 1, backPath: [], sklad: { }, relParent: { }, description: { }, init: function(theme){ var url; switch (theme) { case 1 : { var url = "/site/taxMap"; break; } case 2 : { var url = "/site/esvMap"; break; } case 3 : { var url = "/site/pdfoMap"; break; } } $.ajax({ url: url, type: "POST", data: "abc", async: false, dataType : "JSON", success: function (data) { mainObj.sklad = data.sklad; mainObj.relParent = data.relParent; mainObj.description = data.description; } }); if(this.selectedId == 0) this.selectedId = 1; mainObj.stepNext(); $("div#back-panel").click(mainObj.stepBack); }, stepNext: function(id){ if(isNaN(id)) id = this.selectedId; else { this.backPath.push(this.selectedId); this.selectedId = id; } $("div#current-title").html(this.sklad[id]["name"]); this.selectListUpdate(id); this.selectDescription(id); }, stepBack: function(){ for(var k in mainObj.relParent){ if(mainObj.relParent[k]["id"] == mainObj.selectedId) parId = mainObj.relParent[k]["par"]; } //parId = mainObj.relParent[selectedId]; if(parId > 0){ mainObj.selectedId = parId; $("div#current-title").html(mainObj.sklad[parId]["name"]); mainObj.selectListUpdate(parId); mainObj.selectDescription(parId); } }, selectListUpdate: function(id) { var strList = ""; for(var k in this.relParent){ if(mainObj.relParent[k]["par"] == id){ var childId = mainObj.relParent[k]["id"]; strList = strList + '
' + mainObj.sklad[childId]['name'] + '
'; } } $("div#next-panel").html(strList) .find("div").click(function(){ mainObj.stepNext($(this).attr("selId")); }); }, selectDescription: function(id){ var strDesc = ""; for(var k in this.description){ if(this.description[k]["id"] == id) strDesc = strDesc + '
  • ' + this.description[k]['desc'] + '
  • '; } $("ul#current-catList").html(strDesc); } }; //jQuery $(function(){ $("#taxmaplink, #esvmaplink, #pdfomaplink").click(function(){ var theme; var who = $(this).attr("id") switch (who) { case "taxmaplink" : { theme = 1; break; } case "esvmaplink" : { theme = 2; break; } case "pdfomaplink" : { theme = 3; break; } } mainObj.init(theme); var h = $(window).height(); var w = $(window).width(); //alert(h + "x" + w); if(h >= 500) h = 500; else h = "auto"; if(w >= 1000) w = 1000; else w = "auto"; $("div#tax_map_win").dialog({ title: "Тематична мапа", modal: true, width: w, height: h, draggable: false, resizable: false, position: {my: "center top", at: "center top", of: document } }); if(w == "auto"){ $("div.ui-dialog").css({ "position": "fixed", "right": 0, "left": 0 }); } if(h == "auto"){ $("div.ui-dialog").css({ "bottom": 0 }); var hb = $(window).height(); $("div#back-panel").css("height", hb-50); } }); });