mavensmate
Version:
Core APIs that drive MavensMate IDEs for Salesforce1/Force.com
139 lines (121 loc) • 3.83 kB
HTML
{% extends "views/layouts/base.html" %}
{% block yield %}
<script src="{{ mavensmate.ui.getStaticResourcePath() }}/editor/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="{{ mavensmate.ui.getStaticResourcePath() }}/editor/mode-java.js" type="text/javascript" charset="utf-8"></script>
<style>
#editor {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.gutter-mark {
background:red;
}
div#div-editor-wrapper {
width:100%;
height:100%;
}
.ace_gutter-tooltip {
background-image: linear-gradient(45deg,rgba(0,0,0,.025) 25%,transparent 25%,transparent 50%,rgba(0,0,0,.025) 50%,rgba(0,0,0,.025) 75%,transparent 75%,transparent);
background-size: 64px 64px;
background-color: #f4f6f9;
}
</style>
<div class="slds-grid">
<div class="slds-col">
<div class="slds-box slds-theme--info slds-m-bottom--medium" role="alert">
<div class="slds-notify__content slds-grid">
<svg aria-hidden="true" class="slds-icon slds-icon--small slds-m-right--small slds-col slds-no-flex">
<use xlink:href="/app/static/lds/assets/icons/utility-sprite/svg/symbols.svg#info"></use>
</svg>
<div class="slds-col slds-align-middle">
<h2 class="slds-text-heading--small ">Logs are streamed to your project's debug/logs directory. You can run the "Flush Debug Logs" command to clear logs from your file system.</h2>
</div>
</div>
</div>
<div id="div-editor-wrapper" style="position:relative;">
<div id="editor"></div>
</div>
</div>
</div>
{% endblock %}
{% block buttons %}
<button class="slds-button slds-button--brand" onclick="executeApex()" id="btnExecuteApex">Execute</button>
{% include 'views/partials/cancel_button.html' %}
{% endblock %}
{% block body_js %}
<script>
var editor;
$(function(){
editor = ace.edit('editor');
editor.setTheme('ace/theme/dawn');
var JavaMode = ace.require('ace/mode/java').Mode;
editor.getSession().setMode(new JavaMode());
editor.getSession().setUseWrapMode(true);
editor.setFontSize(16);
editor.getSession().setTabSize(4);
editor.resize();
editor.focus();
});
function executeApex() {
editor.getSession().clearAnnotations();
editor.setReadOnly(true);
var opts = {
showPageHeaderLoading: true,
ajax: {
type: 'POST',
url: "/app/apex",
data: JSON.stringify({
body: editor.getValue()
})
}
};
mavensmate.request(opts)
.then(function(response) {
console.log('deploy done', response);
var response = response.result;
if (response.success) {
showToast('Apex successfully executed. Check your project\'s debug directory for logs.', 'success');
} else {
var returnMessage = '';
var errorMessage = response.compileProblem;
var exceptionMessage = response.exceptionMessage;
if (errorMessage) {
returnMessage += errorMessage;
}
if (exceptionMessage) {
if (returnMessage === '') {
returnMessage = exceptionMessage;
} else {
returnMessage += '<br/><br/>' + exceptionMessage;
}
}
var line = (parseInt(response.line) === -1) ? 0 : (parseInt(response.line) - 1)
if (line === -1) {
line = 0;
}
var column = (parseInt(response.column) === -1) ? 0 : (parseInt(response.column) - 1)
console.log(line);
console.log(column);
console.log(returnMessage);
editor.getSession().setAnnotations([{
row: line,
column: column,
text: returnMessage,
type: 'error' // also warning and information
}]);
showToast(returnMessage, 'error');
}
})
.catch(function(err) {
console.error('could not execute apex', err);
})
.finally(function() {
hidePageHeaderLoading();
editor.setReadOnly(false);
});
}
</script>
{% endblock %}