jive-sdk
Version:
Node.js SDK for Jive Software to assist with the development of add-ons
104 lines (95 loc) • 3.7 kB
HTML
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" media="screen" />
<script src="scripts/shared.js"></script>
<script type="text/javascript" charset="utf-8">
gadgets.util.registerOnLoadHandler(function() {
var url = undefined;
var loadTodo = function( id ) {
url = baseRESTUrl + "/" + id;
var params = {
'href': url,
'authz': "signed",
'format': 'json',
"noCache": DEV_MODE
};
osapi.http.get(params).execute(function (response) {
if(response.error) {
defaultErrorHandler(response);
return;
}
var todo = response.content;
if(todo) {
$(".todoDetails").show();
$("#todoId" ).text(todo.id);
$("#todoName" ).val(todo.name);
$("#assignee" ).val(todo.assignee);
if(todo.status) {
$("#todoStatus").val(todo.status);
}
if(todo.project) {
$("#project").val(todo.project);
}
} else {
$(".todoDetails").hide();
$("#status").text("ERROR - " + response.error);
}
});
}
var id=gadgets.views.getParams().id;
if(id) {
loadTodo(id);
} else {
opensocial.data.getDataContext().registerListener('org.opensocial.ee.context',
function(key) {
var context = opensocial.data.getDataContext().getDataSet(key);
if (context && context.target && context.target.context && context.target.context.id) {
id = context.target.context.id;
loadTodo(id);
}
});
}
var done = function() {
if (gadgets.views.getCurrentView().getName().indexOf("embedded") != -1) {
osapi.jive.core.container.closeApp();
} else {
gadgets.views.requestNavigateTo("todoList");
}
};
$("#done" ).click(done);
$("#save" ).click(function() {
var params = {
'href': url,
'authz': "signed",
'format': 'json',
"noCache": DEV_MODE,
"headers": {"content-type": ["application/json"]},
"body": {
id: $("#todoId").val(),
name: $("#todoName" ).val(),
status: $("#todoStatus" ).val(),
project: $("#project").val(),
assignee: $("#assignee").val()
}
};
osapi.http.put(params).execute(function (response) {
if(response.error) {
defaultErrorHandler(response);
return;
}
if (response.content) {
done();
}
});
});
});
</script>
<body>
<div id="status"></div>
<table class="todoDetails" style="display:hidden">
<tr><td>Id</td><td id="todoId"></td></tr>
<tr><td>Name</td><td><input id="todoName" /></td></tr>
<tr><td>Status</td><td><input id="todoStatus" value="Open"></td></tr>
<tr><td>Project</td><td><input id="project" value=""></td></tr>
<tr><td>Assignee</td><td><input id="assignee" value=""></td></tr>
</table>
<button id="done">Back</button><button id="save">Save</button>
</body>