mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-04-15 20:31:02 +00:00
124 lines
No EOL
3.5 KiB
HTML
124 lines
No EOL
3.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Forge A Module</title>
|
|
{{{head_requires}}}
|
|
|
|
<script type = "text/template" id="templ_action">
|
|
exports.myOwnActionFunction = function( args ) {
|
|
var data = {
|
|
companyId: '961',
|
|
context: '17936',
|
|
text: 'Binder entry based on event: ' + args.info
|
|
};
|
|
needle.post('https://probinder.com/service/27/save', data);
|
|
};
|
|
</script>
|
|
|
|
<script type = "text/template" id="templ_event">
|
|
exports.myOwnEventFunction = function( callback ) {
|
|
var myEvent = {
|
|
event: 'mail',
|
|
eventid: 'mail_0',
|
|
payload: {
|
|
subject: 'My mail event subject',
|
|
body: 'Complex text body'
|
|
}
|
|
};
|
|
callback( myEvent );
|
|
};
|
|
</script>
|
|
|
|
<script type = "text/template" id="templ_params">
|
|
{
|
|
"username": {
|
|
"description": "The username for the Web API"
|
|
},
|
|
"password": {
|
|
"description": "The password for the Web API"
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
{{{div_menubar}}}
|
|
<div id="mainbody">
|
|
<div id="pagetitle">Hi {{user.username}}, forge your own modules!</div>
|
|
<p>
|
|
<select id="select_type">
|
|
<option value="0">Action Module</option>
|
|
<option value="1">Event Module</option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
Module name: <input type="text" id="input_id" />
|
|
</p>
|
|
<p>
|
|
<textarea id="textarea_module" rows="20" cols="100"> </textarea>
|
|
</p>
|
|
<!-- <p>
|
|
Description of module:<br />
|
|
<textarea id="textarea_description" rows="2" cols="100">This module does...</textarea>
|
|
</p> -->
|
|
<p>
|
|
<!-- <input id="checkbox_public" type="checkbox"> Module is public, reusable for everybody<br />-->
|
|
<input id="checkbox_params" type="checkbox"> Module requires user-specific parameters
|
|
</p>
|
|
<p>
|
|
<textarea id="textarea_params" rows="10" cols="40">
|
|
</textarea>
|
|
</p>
|
|
<p>
|
|
<button id="but_submit">save</button>
|
|
</p>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
$('#select_type').change(function(e) {
|
|
if($(this).val() === '0') {
|
|
$('#textarea_module').val($('#templ_action').html());
|
|
} else {
|
|
$('#textarea_module').val($('#templ_event').html());
|
|
}
|
|
});
|
|
$('#but_submit').click(function() {
|
|
if($('#input_id').val() === '') alert('Please enter a module name!');
|
|
else {
|
|
var obj = {
|
|
id: $('#input_id').val(),
|
|
data: $('#textarea_module').val()
|
|
// description: $('#textarea_description').val(),
|
|
// ispublic: $('#checkbox_public').is(':checked')
|
|
};
|
|
try {
|
|
if($('#checkbox_params').is(':checked')) {
|
|
//TODO if syntax error we should make better info's
|
|
JSON.parse($('#textarea_params').val());
|
|
obj.params = $('#textarea_params').val();
|
|
}
|
|
if($('#select_type').val() === '0') obj.command = 'store_action';
|
|
else obj.command = 'store_event';
|
|
$.post('/usercommand', obj)
|
|
.done(function(data) {
|
|
alert(data);
|
|
})
|
|
.fail(function(err) {
|
|
console.error(err);
|
|
alert('Posting of module failed: ' + err.responseText);
|
|
});
|
|
} catch(err) {
|
|
alert(err);
|
|
}
|
|
}
|
|
});
|
|
$('#checkbox_params').click(function() {
|
|
$('#textarea_params').toggle();
|
|
});
|
|
$('#textarea_module').val($('#templ_action').html());
|
|
$('#textarea_params').val($('#templ_params').html());
|
|
$('#textarea_params').hide();
|
|
</script>
|
|
|
|
</body>
|
|
</html> |