vgquotes/Src/VideoGameQuotes.Web/media/js/quoteform.compressed.js

1 line
9.7 KiB
JavaScript
Raw Normal View History

2011-03-04 08:20:37 +00:00
(function(g,e,i){var d=function(k){return function(){g("#create-"+k+"-form").find("input[type='text']").val("").end().find("input[type='checkbox']").removeAttr("checked").end().find("> .edit-mode").val(0).end().find("> fieldset > legend").text("Create new "+k).end().clearModelErrors().toggle();g("#"+k+"-select").toggle();return false}};var a=function(n,p,k,q,o){var m=n.find("tr:last");if(m.find("td").length===o){m=g("<tr/>");n.append(m)}var l=g("<td/>").append(g("<input/>").attr({type:"checkbox",name:p,value:k,id:p+"_"+k,checked:"checked"})).append(g("<label/>").attr("for",p+"_"+k).text(q));m.append(l);n.append(m)};var f=function(){g("#create-system-link, #create-system-cancel").click(d("system"));g("#create-system-submit").click(function(){var k=false;return function(){if(k){return false}k=true;var l=g("#create-system-form");var n=g(this).find(".submit-icon");var m={SystemName:g("#SystemName").val(),SystemAbbreviation:g("#SystemAbbreviation").val(),SystemReleaseDate:g("#SystemReleaseDate").val(),SystemIcon:g("#SystemIcon").val()};var p="/system/create";var o=l.find("> .edit-mode").val();if(o>0){p="/system/edit";m.SystemId=o}g.ajax(p,{type:"POST",data:m,beforeSend:function(){l.clearModelErrors();n.toggleClass("submit-icon loading-icon")},success:function(q,r,s){if(q.Error!==null){l.applyModelErrors(q.Error,q.Data);return}if(o<=0){a(g("#system-checkbox-table"),"SystemIds",q.Data.Id,q.Data.Abbreviation,6)}else{g("#system-checkbox-table").find("input[value='"+q.Data.Id+"'] + label").text(q.Data.Abbreviation)}d("system")()},complete:function(){k=false;n.toggleClass("submit-icon loading-icon")}});return false}}());g(".edit-system-link").click(function(){var l=g(this);l.toggleClass("edit-icon loading-icon");var k=l.siblings("input[name='SystemIds']").val();g.vgquotes.getResourceById("system",k,function(m){l.toggleClass("edit-icon loading-icon");if(m===null){alert("Unable to fetch system "+k);return}d("system")();g("#create-system-form > .edit-mode").val(k);g("#create-system-form > fieldset > legend").text("Edit System");g("#SystemName").val(m.Name);g("#SystemAbbreviation").val(m.Abbreviation);g("#SystemReleaseDate").val(g.vgquotes.parseAndFormatDate(m.ReleaseDate));g("#SystemIcon").val(m.Icon)});return false});g(".delete-system-link").click(function(){var l=g(this);l.toggleClass("delete-icon loading-icon");var k=l.siblings("input[name='SystemIds']").val();g.ajax("/system/delete",{type:"POST",data:{id:k},success:function(m,n,o){if(m.Error!==null){alert(m.Error);return}l.parent().empty()},complete:function(){l.toggleClass("delete-icon loading-icon")}});return false})};var h=function(){g("#create-game-link, #create-game-cancel").click(d("game"));g("#create-game-submit").click(function(){var k=false;return function(){if(k){return false}k=true;var l=[],q=[],m=[],p={GameName:g("#GameName").val(),GameWebsite:g("#GameWebsite").val(),GameIcon:g("#GameIcon").val()};g("input:checked[name='GameRegions']").each(function(u,t){if(typeof(p.GameRegions)==="undefined"){p.GameRegions=[]}p.GameRegions.push(t.value)});g("input:checked[name='SystemIds']").each(function(u,t){if(typeof(p.SystemIds)==="undefined"){p.SystemIds=[]}p.SystemIds.push(t.value)});g("input:checked[name='PublisherIds']").each(function(u,t){if(typeof(p.PublisherIds)==="undefined"){p.PublisherIds=[]}p.PublisherIds.push(t.value)});var s=g("#create-game-form");var r=g(this).find(".submit-icon");var o="/game/create";var n=g("#create-game-form > .edit-mode").val()==1;if(n){o="/game/edit";p.GameId=g("#GameId").val()}g.ajax(o,{type:"POST",data:p,traditional:true,beforeSend:function(){s.clearModelErrors();r.toggleClass("submit-icon loading-icon")},success:function(t,u,v){if(t.Error!==null){s.applyModelErrors(t.Error,t.Data);return}if(!n){g("#GameId").append(g("<option/>").attr({value:t.Data.Id}).text(t.Data.Name)).val(t.Data.Id)}else{g("#GameId option[value='"+t.Data.Id+"']").text(t.Data.Name)}d("game")()},complete:function(){k=false;r.toggleClass("submit-icon loading-icon")}});return false}}());g("#edit-game-link").click(function(){g("#edit-game-link").toggleClass("edit-icon loading-