Skip to content

Commit

Permalink
moved View js to seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaker26 committed May 9, 2020
1 parent cb1b556 commit 1998022
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 73 deletions.
71 changes: 5 additions & 66 deletions SAP1EMU.WebApp/Views/Home/Assembler.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<link href="/js/CodeMirror/theme/default.css" rel="stylesheet" type="text/css" />

<script src="/lib/jquery/dist/jquery.js" type="text/javascript"></script>
<script src="/js/Views/AssemblerView.js" type="text/javascript"></script>

<script>
</script>

@* Need to get jQuery lib into the project staticly, no web ref *@
@{
ViewData["Title"] = "Assembler";
}
Expand All @@ -17,8 +21,6 @@
<h3>Assembly</h3>
<br />

@* An AJAX Form is prob the answer here *@
@*https://stackoverflow.com/questions/1720020/mvc-jquery-submit-form-without-page-refresh-from-javascript-function*@
<form id="asm_form" method="post" action="AssembleCode">
@Html.TextArea("CodeList", null, new { rows = "20", cols = "80", @class = "codebox", id = "asm_code" })
@*<input type="submit" name="CodeList" value="Assemble" />*@
Expand Down Expand Up @@ -48,67 +50,4 @@
<div></div> @*This blank div is req to trick the row::after or else the margins get screwed up*@
</div>

<script>
var asm_editor = CodeMirror.fromTextArea(document.getElementById("asm_code"), {
lineNumbers: true,
matchBrackets: true,
mode: {name: "gas_sap1", architecture: "x86"},
});
var bin_editor = CodeMirror.fromTextArea(document.getElementById("bin_code"), {
lineNumbers: true,
matchBrackets: true,
mode: {name: "gas_sap1", architecture: "x86"},
readOnly: true,
});
</script>

@*<script type="text/javascript">
$("#asm_form").submit(function () {
var jqxhr = $.post('AssembleCode', $('#asm_form').serialize())
.success(function () {
var loc = jqxhr.getResponseHeader('Location');
var a = $('<a/>', { href: loc, text: loc });
$('#message').html(a);
})
.error(function () {
$('#message').html("Error posting the update.");
});
return false;
});
</script>*@
<script>
function AssembleCode(btnClicked)
{
var asm_code = asm_editor.getValue().split('\n');
var asm_json = JSON.stringify(asm_code);
console.log(asm_code);
console.log(asm_json);

$.ajax({
url: "../api/Assembler",
type: "POST",
contentType: 'application/json; charset=UTF-8',
data: asm_json,
success: function(data) {
console.log(data.toString());
console.log(data.toString().replace(/,/g ,'\n'));
$('#assembler-out').html('<br />');
bin_editor.setValue(data.toString().replace(/,/g ,'\n'));
return data;
},
error: function (request, status, error) {
bin_editor.setValue("");
$('#assembler-out').html(request.responseText);
}
});
return false;// if it's a link to prevent post
}
</script>
50 changes: 50 additions & 0 deletions SAP1EMU.WebApp/wwwroot/js/Views/AssemblerView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var asm_editor;
var bin_editor;

window.onload = function () {
asm_editor = CodeMirror.fromTextArea(document.getElementById("asm_code"), {
lineNumbers: true,
matchBrackets: true,
mode: { name: "gas_sap1", architecture: "x86" },
});

bin_editor = CodeMirror.fromTextArea(document.getElementById("bin_code"), {
lineNumbers: true,
matchBrackets: true,
mode: { name: "gas_sap1", architecture: "x86" },
readOnly: true,
});
}


function AssembleCode(btnClicked) {
var asm_code = asm_editor.getValue().split('\n');
var asm_json = JSON.stringify(asm_code);
console.log(asm_code);
console.log(asm_json);

$.ajax({
url: "../api/Assembler",
type: "POST",
contentType: 'application/json; charset=UTF-8',
data: asm_json,
success: function (data) {

console.log(data.toString());
console.log(data.toString().replace(/,/g, '\n'));
$('#assembler-out').html('<br />');



bin_editor.setValue(data.toString().replace(/,/g, '\n'));
return data;
},
error: function (request, status, error) {
bin_editor.setValue("");
$('#assembler-out').html(request.responseText);
}
});

return false;// if it's a link to prevent post

}
8 changes: 1 addition & 7 deletions SAP1EMU.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.Lib.Test", "SAP1EMU
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.Engine", "SAP1EMU.Engine\SAP1EMU.Engine.csproj", "{B1680C97-D8B2-480C-852D-FB82686D5CF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.GUI-Windows", "SAP1EMU.GUI-Windows\SAP1EMU.GUI-Windows.csproj", "{0C6629AF-D88C-41A7-BEE2-7B091B18CA77}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.Assembler-CLI", "SAP1EMU.Assembler-CLI\SAP1EMU.Assembler-CLI.csproj", "{99A4A7B4-B3B7-47D7-AF77-7DEACFEBDA5D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.Engine-CLI", "SAP1EMU.Engine-CLI\SAP1EMU.Engine-CLI.csproj", "{3DB615A3-ADC4-4EF8-96D2-BF64668C2BB9}"
Expand All @@ -21,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.Assembler", "SAP1EM
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F62A82B5-7BC1-430B-8E3B-A76E27724A49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SAP1EMU.WebApp", "SAP1EMU.WebApp\SAP1EMU.WebApp.csproj", "{28B1CC5D-C440-43E3-A812-17B0C29FB41C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SAP1EMU.WebApp", "SAP1EMU.WebApp\SAP1EMU.WebApp.csproj", "{28B1CC5D-C440-43E3-A812-17B0C29FB41C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -41,10 +39,6 @@ Global
{B1680C97-D8B2-480C-852D-FB82686D5CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1680C97-D8B2-480C-852D-FB82686D5CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1680C97-D8B2-480C-852D-FB82686D5CF5}.Release|Any CPU.Build.0 = Release|Any CPU
{0C6629AF-D88C-41A7-BEE2-7B091B18CA77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C6629AF-D88C-41A7-BEE2-7B091B18CA77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C6629AF-D88C-41A7-BEE2-7B091B18CA77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C6629AF-D88C-41A7-BEE2-7B091B18CA77}.Release|Any CPU.Build.0 = Release|Any CPU
{99A4A7B4-B3B7-47D7-AF77-7DEACFEBDA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99A4A7B4-B3B7-47D7-AF77-7DEACFEBDA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99A4A7B4-B3B7-47D7-AF77-7DEACFEBDA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 1998022

Please sign in to comment.