Ask a Question

Still coding with AngularJS and Nuxeo, today I will show you another AngularJS sample I made using the REST API. The goal here was to let Nuxeo users ask and answer questions, a bit like we do on

It’s a simple application which makes it a good use case for CRUD operations. It was really quick and easy to do even though I am far from an expert in AngularJS and JavaScript (but I could really feel it becoming easier). Most of the new stuff I learned came from - you should start there if you don’t know AngularJS.

Here are a number of screenshots. Lise helped me a lot on this to make it look good, using Semantic UI/.

Question List

Let’s focus on the question asking. Here’s the template used for the form:

<div class="active side ui segment">
<form name="myForm" class="ui form control-group">

<div class="field" ng-class="{error:$invalid}">
<h2>Ask a question</h2>
<input type="text" name="title" placeholder="A question as clear and concise as possible" ng-model="['dc:title']" required>
<span ng-show="$error.required" class="help-inline">
<div class="field" ng-class="{error:$invalid}">
<textarea name="description" ng-model="['dc:description']" placeholder=" A factual description so that everyone understands the question and issue and can respond correctly" required></textarea>
<span ng-show="$error.required" class="help-inline">
<div class="field">
<select multiple id="communities" class="ui input medium" ng-model="['qs:community']">
<option ng-repeat="community in communities">{{community.title}}</option>
<div class="field">
<button ng-click="save()" ng-disabled="isClean() || myForm.$invalid"
class="ui blue submit button">Ask</button>
<a href="#/questions" class="btn">Cancel</a>

As you can see it’s simple, and using semantic UI makes it even easier to understand. The communities are actually the social workspaces available on my Nuxeo instance. You can see how they are fetched by looking at the controller:

.controller("AskCtrl", ['$scope', 'nxSession', '$location', 'nxSearch'
($scope, nxSession, $location, nxSearch) ->
$scope.doc = { type:"question", properties: {}}
communitiesSearch = new nxSearch()
.setQuery("SELECT * FROM SocialWorkspace WHERE ecm:currentLifeCycleState <> 'deleted'")
$scope.communities = communitiesSearch.items

$ = () ->
nxSession.createDocument("/collaboration/questions", $scope.doc).then (question) ->
$location.path("/question/" + question.uid + '/view')


The first part of the controller creates an empty doc document of type question, without any properties. Then the nxSearch service is used to fetch the list of communities. That’s all we need to display the ‘Ask a Question’ form. If the user clicks on the Ask button, we execute the $ method. It uses the nxSession service’s createDocument method. The first argument is the path of the parent document, the second argument is our doc object updated with the fields of our form.

Session.createDocument = (parentPath, doc)->
doc['entity-type'] = "document"
$ + "/path" + parentPath , doc).then (response)->
new nxDocument(,

As you can see, the createDocument is dead simple too. It’s an HTTP post of a JSON object. If you want to see all the other endpoints available for the REST API, I invite you to visit and try the API directly!

Single Question