UNPKG

jive-sdk

Version:

Node.js SDK for Jive Software to assist with the development of add-ons

125 lines (112 loc) 4.19 kB
<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"> var project=undefined, username=undefined, closeFn=undefined; setDefaults = function(context) { if( context && context.jive && context.jive.content && context.jive.content.type && context.jive.content.type !== "") { osapi.jive.corev3.resolveContext(context, function (result) { if (result && result.content) { if(result.content.type === 'person') { username = result.content.jive && result.content.jive.username; } else if (result.content.type === 'project') { project = result.content.name; } } }); } }; // When coming to this view from the createTodoProject action, set the current project. gadgets.actions.updateAction({ id:"com.jivesoftware.example.todo.createTodoProject", callback:function(context){ setDefaults(context); } }); // When coming to this view from the top level create, set the current project. gadgets.actions.updateAction({ id:"com.jivesoftware.example.todo.createModalNav", callback:function(context){ setDefaults(context); } }); // When coming to this view from the !app action, change the close gadgets.actions.updateAction({ id:"com.jivesoftware.example.todo.createTodoInline", callback:function(context){ closeFn = function(content) { osapi.jive.core.container.closeApp({ data:{ display: { type:"text", label: content.name }, target: { type: "embed", view: "embedded.todoDetail", context: { id: content.id } } } }); }; } }); gadgets.util.registerOnLoadHandler(function() { if( !project ) { project = gadgets.views.getParams().project; } if( !username ) { osapi.jive.corev3.people.getViewer().execute(function(resp) { if( resp && resp.jive ) { username = resp.jive.username; } }); } var url = baseRESTUrl; var create = function() { var params = { 'href': url, 'authz': "signed", 'format': 'json', "noCache": DEV_MODE, "headers": {"content-type": ["application/json"]}, "body": { "name": $('#todoName').val(), "status": "Open" } }; if( project ) { params.body.project = project; } if( username ) { params.body.assignee = username; } osapi.http.post(params).execute(function (response) { if(response.error) { defaultErrorHandler(response); return; } if(closeFn) { closeFn(response.content); } else { gadgets.views.requestNavigateTo("todoDetail", {id: response.content.id}); } }); }; $("#createBtn").click(create); osapi.jive.core.container.getLaunchContext(function(context){ // This is necessary when going to this view from another view. setDefaults(context); }); }); </script> <body> <h1>Create Todo <span id="inProject"></span></h1> <div id="status"></div> <input id="todoName"> <input type="hidden" id="projectField" name="project" value="" /> <button id="createBtn">Create</button> </body>