Quantcast
Channel: Bonitasoft Community - Bonita 7
Viewing all 34 articles
Browse latest View live

campo fecha Widget Fecha

$
0
0

como manejar la Zona Horaria en los campos de fecha, como puedo hacer para forzar que la zona horaria se me adapte en los campos de fecha de mis procesos de bonita, ya que al tener Zona horaria Bogota-Colombia al seleccionar una fecha me resta 1 día de la fecha.

ejemplo selecciono fecha 4 de agosto de 2014 y el me toma 3 de agosto de 2014.

how to handle the time zone in the date fields, as I can do to force the time zone suits me in the date fields of my Bonita process, because having Bogota-Colombia Time Zone to select a date I subtract 1 day date.

example selected date August 4, 2014 and takes me August 3, 2014.


How can I replace documents using the new UI Designer ?

$
0
0

Hi everybody,

After burning my brains out over this new UI Designer + Contrac t interface, I decided to cry for the help of my community fellows. I need to have the same options offered in Bonita 6.x forms for a document, but now on a Bonita 7 (AngularJS/Bootstrap): KEEP, REMOVE, MODIFY. I show a document in a form, using the HTTP widget. I also place an Upload widget on the form, so the user may replace the original file. So far so good, but the possibility of changing the file demands that I use a CONTRACT and because of that I must offer some JSON to it when the form is submitted. The problem is that the CONTRACT does not accept the context.document_ref as the old file JSON. When I try it, the following error occurs:

"exception":"class org.bonitasoft.engine.bpm.contract.ContractViolationException","message":"Error while validating expected inputs","explanations":["{id=8, processInstanceId=9, name=docsAnexados, author=3, creationDate=1438739037778, fileName=camiseta.JPG, contentMimeType=image/jpeg, contentStorageId=8, url=documentDownload?fileName=camiseta.JPG&contentStorageId=8, description=, version=1, index=-1, contentFileName=camiseta.JPG} cannot be assigned to FILE"]

The question is: how can I submit a valid JSON about the old file to the CONTRACT, since all I have is the context.document_ref one. The logic itself is ok because when I submit the JSON of the new file (obtained from the Upload widget) everything goes smoothy.

Regards,

Ricardo

How can I have masks for the input fields in Bonita 7 ?

$
0
0

Hi everyone,

I need to put masks in my input fields, on Bonita 7 forms. How do I do it using the new UI Designer? (Details, please, I am not that good programmer).

Regards,

Ricardo

How to redirect a page using AngularJS (or JS)

$
0
0

Hi,

I'm trying to redirect the browser to the login page using AngularJS from an app page but I can't do it. I'm using this code from a custom widget:

  1. $window.location.href =$scope.properties.URL;//URL is the login page
  2. $window.location.reload();

That code loads the login page but in the custom page frame, not the window, then I got the login page embedded on my app page. ( Click here for viewing an example )

How can I redirect all the window?

Thanks in advance.

Get current date on a new Bonita 7 form

$
0
0

Hi,

Maybe this is a dumb question but I've had issues trying to get the current date in a form.

First I create a variable and I call it "currentDate" as this JS expression:

return new Date();

Then I put a widget (text, input, title, etc) with this value.

Today is {{ currentDate | Date }}

Then I try the form.

When the form runs, it enters on an infinite loop, It always refresh the variable.

I've tried solve this using a condition (if variable is null -or undefined- get date else get the current value...) but this does not work.

Well I hope you can help me, thanks in advance.

Custom REST API Exception

$
0
0

Hi,

I'm trying to run this example of custom REST API, but I always get this response:

{"code":500,"contactEmail":null,"description":"The server encountered an unexpected condition which prevented it from fulfilling the request","homeRef":"/","reasonPhrase":"Internal Server Error","uri":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1"}

The catalina.log gets this exception:

2015-08-20 01:14:33.295 +0200 org.restlet.Component.BonitaSPRestletApplication org.restlet.resource.ServerResource doCatch 
Advertencia: Exception or error caught in server resource
java.lang.ClassCastException: Index cannot be cast to org.bonitasoft.console.common.server.page.RestApiController
    at org.bonitasoft.console.common.server.page.CustomPageService.loadRestApiPage(CustomPageService.java:156)
    at org.bonitasoft.console.common.server.page.RestApiRenderer.renderResponse(RestApiRenderer.java:73)
    at org.bonitasoft.console.common.server.page.RestApiRenderer.handleRestApiCall(RestApiRenderer.java:53)
    at org.bonitasoft.web.rest.server.api.extension.ApiExtensionResource.handleRequest(ApiExtensionResource.java:86)
    at org.bonitasoft.web.rest.server.api.extension.ApiExtensionResource.doHandle(ApiExtensionResource.java:42)
    at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:683)
    at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:357)
    at org.restlet.resource.ServerResource.handle(ServerResource.java:1044)
    at org.restlet.resource.Finder.handle(Finder.java:236)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Router.doHandle(Router.java:422)
    at org.restlet.routing.Router.handle(Router.java:639)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
    at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)
    at org.restlet.Application.handle(Application.java:385)
    at org.bonitasoft.web.rest.server.BonitaRestletApplication.handle(BonitaRestletApplication.java:175)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Router.doHandle(Router.java:422)
    at org.restlet.routing.Router.handle(Router.java:639)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.routing.Router.doHandle(Router.java:422)
    at org.restlet.routing.Router.handle(Router.java:639)
    at org.restlet.routing.Filter.doHandle(Filter.java:150)
    at org.restlet.routing.Filter.handle(Filter.java:197)
    at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
    at org.restlet.Component.handle(Component.java:408)
    at org.restlet.Server.handle(Server.java:507)
    at org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)
    at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1117)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:722)

What's wrong?

Pasar datos de una base de datos externas a un form

$
0
0

Recién estoy empezando a utilizar Bonita 7, y me gustaría ver un ejemplo de cómo usar un conector para conectarme a una base de datos (sql server, mysql... etc) y poder pasar información de dicha base de datos a un form.

Issue making a "Loading..." text for a widget.

$
0
0

Hi,

I've made a custom widget for retrievieng some information about a case using the $http service (XHR) from AngularJS.

The widget loads successfully the data but it appears by parts (since it loads) then I put a div with te directive ngShow for showing a "loading..." text while the data is loading.

Well, that it works partially, because, randomly, it stuck with the "loading..." text.

Here is the controller code:

function MyCtrl($scope, $http) {
$scope.caso = $scope.properties.caso;
$scope.noOK = false;
if ($scope.properties.tipo == "E") {
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_ent_fechaLim/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdf = response.data;
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_ent_portal_descTarea/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdd = response.data;
if ($scope.rdd.value !== "") {
$scope.desc = $scope.rdd.value;
} else {
$scope.desc = "Sin inicializar.";
}
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
} else {
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_sal_fechaLim/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdf = response.data;
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_sal_portal_descOficio/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdd = response.data;
if ($scope.rdd.value !== "") {
$scope.desc = $scope.rdd.value;
} else {
$scope.desc = "Sin inicializar.";
}
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
}
$scope.cargando = $http.pendingRequests.length === 0;
}

Here is the template code:

<div ng-show="{{ !cargando }}">
<p>Cargando...</p>
</div>
<div ng-show="{{ cargando }}">
<blockquote>
<h5>{{ desc }}, <b>Vence: {{ rdf.value | date }}.</b></h5>
</blockquote>
</div>
<div ng-show="{{ noOK }}">
<p>Error no se pudo cargar :(</p>
</div>

How can I fix this?, I hope you can help me. Thanks in advance.


Problème avec le tutoriel

$
0
0

Bonjour,
J'ai un problème dans la dernière étape du tutoriel, le déploiement de l'application. Je parviens à lancer la home page (Travel Tool) puis, depuis la home page, le formulaire de création d'une demande. Mais quand je valide mon formulaire, rien ne se passe. Dans UI designer, le submit de la page est associé à l'url '/bonita' et ça fonctionne bien depuis le studio. A quelle valeur doit on fixer cet url pour que ça marche en déploiement ?

Merci pour vos retours

Procurement Example

$
0
0

About

This is an official Living Application example for Bonita BPM 7.0

This example demonstrates the following concepts:

  • Living Application
  • Forms, pages and custom widgets built with the UI Designer
  • Process using BDM and contracts

Installation

  1. Download the application bundle (see releases section at the bottom of this page)
  2. Extract the bundle to a temporary folder
  3. Import the .bos file in your Bonita BPM Studio (it contains 3 processes: Procurement request, Init sample procurement data and Create supplier)
  4. Deploy all 3 processes (click on Run in a Studio but do not complete the forms)
  5. Run the sample data initialization process once and remove it from the Portal
  6. In the Portal, as an administrator, go to 'Resources' and add the 2 custom pages .zip files. You can read more about custom pages here.
  7. In the Portal, go to 'Applications' and import the Procurement application.xml file. You can read more about applications here.
  8. Run the Procurement application by accessing to this url (the port number may vary):
    http://localhost:8080/bonita/apps/procurement

Note: this simplified version of the Procurement Request process only uses one actor.
The same user can fill a procurement request and approve it himself.

Screenshots

Procurement Living Application

Procurement Living Application

Procurement Request process - Diagram

Procurement Request process - Diagram

Procurement Request process - Fill request form

Procurement Request process - Fill request form

Procurement Request process - Review request form

Procurement Request process - Review request form

Category: 
Licence: 
LGPL v3
Total downloads: 700
Version BonitaBPM Version Post date Download Link
v1.1 for Bonita BPM 7.0.2 7.0.x 2015-Aug-21 Download
168 downloads
Release note
v1.0 for Bonita BPM 7.0.0 7.0.x 2015-Jun-17 Download
532 downloads
Release note
Downloads: 
375

To reduce elements in select by previous selections

$
0
0

Hi,

controlli.png
I have a container formInput.contract.controlli. controlli is an array.
The select widget value is: $item.
The select widget available values is: controllos (Rest/Json) ['Pippo','Pluto','Paperino','Linux'].

When I add a new select widget with button add, I want that the number of element is reduced by previous selections.

Example:
1° select ['Pippo','Pluto','Paperino','Linux'] - I select 'Pluto' - I add another select
2° select ['Pippo','Paperino','Linux'] - I select 'Pippo' - I add another select
3° select ['Paperino','Linux'] - I select 'Linux' - I add another select
4° select ['Paperino'] - I select 'Paperino' - Now It Is not possible to add another select because there are not elements.

How can I do?

Thanks
Manolo

[closed] how to use Target URL on success to move to next human task

$
0
0

hi,

how can i use the Target URL on success in the button button widget, or the hyperlink widget
to move to the next human task ?

thanks
gj.

Pageflow form example

$
0
0

This sample presents a pageflow (or mutli-page) form created with Bonita BPM 7. This resulting form is equivalent to the pageflow form that existed in Bonita BPM 5 & 6.

Documentation available here: https://github.com/Bonitasoft-Community/pageflow-form-example

Pageflow form created with Bonita BPM 7

Category: 
Total downloads: 0
Version BonitaBPM Version Post date Download Link
v1.0 for Bonita BPM 7.1.0 and onward 7.1.x 2015-Sep-23 Download
0 downloads
Release note

How to refresh a widget

$
0
0

Hi,

I have a process built in Bonita 7.1.2. and I've made a summary page for all the active cases. I use some widgets as a Data Table, texts, etc.

My question is, how can I put a button or something that refreshes the data on the summary page? I don't want implement a method that refreshes the window, I only want to refresh the Data Table.

Thanks in advance.

David.

How to get all tasks for a user via REST API?

$
0
0

Hi,

I want to retrieve all the tasks for a user using the REST API, not only the assigned i want to retrieve the *pending *tasks too as the Bonita Portal does.

I've been using this , but it only retrieves the assigned tasks. I didn't find nothing in the documentation about pending tasks.

Any ideas?

Thank you.


Bonita 7 - Tomcat SQL Server

$
0
0

Bonjour,
Je souhaiterai réaliser une installation Bonita 7.1 - Tomcat 7- MSSQL Server 2012 sur un Windows Server 2008 R2
Dans la configuration des environnements : http://documentation.bonitasoft.com/hardware-and-software-requirements-2 il est dit que qu'un environnement Tomcat/SQL Server ne serait pas supporté et ne fonctionnerait tout simplement pas à cause de Bitronix.
existe-t'il une alternative à Bitronix ? Il existe une documentation pour Bonita 6.3 avec Atomikos. Cette configuration est-elle encore expérimentale ? Que recommandez-vous pour pouvoir utiliser Tomcat avec SQL Server ?

Merci.

How to call process variable into user interface in bonita 7 [ need tutorial ]

$
0
0

Hello guys,

I'm interested about BPM and I've installed bonita 5 and 7 in my computer.
I've created my process business into bpm modeling, and now i'm in phase of developing my business process into application ( UI Designer ).
In my modeling process, i've created a process variable ( Java Object - java.util.List [No Coding, Just Created] ) to stored my MySQL - query ( Created using Graphical Connector In ).

I've tried on bonita 5 and i stored the connector into a suggestbox and it's work but not on bonita 7, it's pretty hard to show the process variable into UI, i did the same thing as bonita 5. I read in bonita documentation it's needed REST API, so i tried REST API.
1. ../API/bpm/caseVariable?p=0&c=10&f=case_id={{caseId}}
2. ../API/bpm/activityVariable/{{ActivityName}}/{{Variable}}
but it still didn't work too.

Can anyone give me a short tutorial how to use or call process variable into user interface on bonita 7 ?

Thank you,
Best Regards.

Dhany Lugina.

Bonita 7.+ REST Anonymous User

$
0
0

In all the 7.+ Release notes Limitations and known issues it says that

Autologin / Anonymous access to form is not available with the new Form application.

Is this a Limitation or a Known Issue as they are different?

Limitation means will never be implemented, Known issues will be fixed at some stage...

Can Bonitasoft please separate them so we know what we are looking at/for.

for example I don't know if AutoLogin will never, or will maybe fixed in the future meaning I will always have to logon to access any process and or form.

regards
Seán

Issue making a "Loading..." text for a widget.

$
0
0

Hi,

I've made a custom widget for retrievieng some information about a case using the $http service (XHR) from AngularJS.

The widget loads successfully the data but it appears by parts (since it loads) then I put a div with te directive ngShow for showing a "loading..." text while the data is loading.

Well, that it works partially, because, randomly, it stuck with the "loading..." text.

Here is the controller code:

function MyCtrl($scope, $http) {
$scope.caso = $scope.properties.caso;
$scope.noOK = false;
if ($scope.properties.tipo == "E") {
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_ent_fechaLim/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdf = response.data;
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_ent_portal_descTarea/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdd = response.data;
if ($scope.rdd.value !== "") {
$scope.desc = $scope.rdd.value;
} else {
$scope.desc = "Sin inicializar.";
}
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
} else {
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_sal_fechaLim/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdf = response.data;
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
$http.get('/bonita/API/bpm/caseVariable/'+$scope.properties.caso+'/var_sal_portal_descOficio/').then(function (response) {
$scope.cargando = $http.pendingRequests.length === 0;
$scope.rdd = response.data;
if ($scope.rdd.value !== "") {
$scope.desc = $scope.rdd.value;
} else {
$scope.desc = "Sin inicializar.";
}
}), function(response) {
$scope.cargando = true;
$scope.noOK = true;
};
}
$scope.cargando = $http.pendingRequests.length === 0;
}

Here is the template code:

<div ng-show="{{ !cargando }}">
<p>Cargando...</p>
</div>
<div ng-show="{{ cargando }}">
<blockquote>
<h5>{{ desc }}, <b>Vence: {{ rdf.value | date }}.</b></h5>
</blockquote>
</div>
<div ng-show="{{ noOK }}">
<p>Error no se pudo cargar :(</p>
</div>

How can I fix this?, I hope you can help me. Thanks in advance.

Custom widget to validate user input

$
0
0

Not really a question but I could not find a lot of information in the documentation or the existing contributed projects.

I have a form with SIREN / SIRET fields (those are identification numbers for french companies). A siren is 9 digits and a siret is 14. I could easily use standard widgets for the length but that was all.

So I created a custom widget starting with pbInput standard widget (workspace/default/web_widgets). I removed minLength, maxLength, type, min value, max value and and added an inputType property which value can be siren or siret (default: siren).

The template I used is derivated from pbInput:

  1. <!-- The custom widget template is defined here
  2. - You can use standard HTML tags and AngularJS built-in directives, scope and interpolation system
  3. - Custom widget properties defined on the right can be used as variables in a templates with properties.newProperty
  4. - Functions exposed in the controller can be used with ctrl.newFunction()
  5. -->
  6.  
  7. <div ng-class="{
  8. 'form-horizontal': properties.labelPosition === 'left'&& !properties.labelHidden,
  9. 'row': properties.labelPosition === 'top'&& !properties.labelHidden || properties.labelHidden
  10. }">
  11. <div class="form-group">
  12. <label
  13. ng-if="!properties.labelHidden"
  14. ng-class="{ 'control-label--required': properties.required }"
  15. class="control-label col-xs-{{ !properties.labelHidden && properties.labelPosition === 'left' ? properties.labelWidth : 12 }}">
  16. {{ properties.label | uiTranslate }}
  17. </label>
  18. <div class="col-xs-{{ 12 - (!properties.labelHidden && properties.labelPosition === 'left' ? properties.labelWidth : 0) }}">
  19. <input
  20. type="text"
  21. class="form-control {{ properties.inputType }}"
  22. placeholder="{{ properties.placeholder | uiTranslate }}"
  23. ng-model="properties.value"
  24. name="{{ ctrl.name }}"
  25. sirensiret
  26. ng-required="properties.required"
  27. ng-readonly="properties.readOnly">
  28. <div ng-messages="$form[ctrl.name].$dirty&& $form[ctrl.name].$error" ng-messages-include="forms-generic-errors.html" role="alert">
  29. <div class="text-danger" ng-show="$form[ctrl.name].$error.integer">Cette valeur n'est pas un nombre valide</div>
  30. <div class="text-danger" ng-show="$form[ctrl.name].$error.inputLength">La longueur d'un {{ properties.inputType | uppercase }} est de {{ ctrl.inputLen }} chiffres.</div>
  31. <div class="text-danger" ng-show="$form[ctrl.name].$error.sirenSiretKey">La clé de validation de ce {{ properties.inputType | uppercase }} est invalide</div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>

You will note the following changes: I added some new messages to the ng-messages div and added a "sirensiret" directive. I also added a class to detect input type.

The controller is really simple:

  1. /**
  2.   * The controller is a JavaScript function that augments the AngularJS scope and exposes functions that can be used in the custom widget template
  3.   *
  4.   * Custom widget properties defined on the right can be used as variables in a controller with $scope.properties
  5.   * To use AngularJS standard services, you must declare them in the main function arguments.
  6.   *
  7.   * You can leave the controller empty if you do not need it.
  8.   */
  9. function($scope,$log, widgetNameFactory){
  10.  
  11. this.name = widgetNameFactory.getName($scope.properties.inputType);
  12. this.inputLen =$scope.properties.inputType =='siren' ? 9:14;
  13.  
  14. $log.error ("tiersSirenSiretInput controler is here to serve!");
  15.  
  16. if(!$scope.properties.isBound('value')){
  17. $log.error('the pbInput property named "value" need to be bound to a variable');
  18. }
  19. }

This is almost the standard controller. I just initialize the default length for error messages.

Then I added a custom asset checkSirenSiret.js that add some directives to bonitasoft.ui.extensions:

  1. var app = angular.module ('bonitasoft.ui.extensions',[]);
  2.  
  3. var INTEGER_REGEXP =/^\-?\d+$/;
  4. var SIREN_REGEXP =/^\d{9}$/;
  5. var SIRET_REGEXP =/^\d{14}$/;
  6.  
  7. app.directive('sirensiret',function(){
  8. return{
  9. require:'ngModel',
  10. link:function(scope, elm, attrs, ctrl){
  11.  
  12. function validateSirenSiret(ngModelValue, ngViewValue){
  13.  
  14. // Default is OK.
  15. ctrl.$setValidity('integer',true);
  16. ctrl.$setValidity('inputLength',true);
  17. ctrl.$setValidity('sirenSiretKey',true);
  18.  
  19. // non empty => make additional controls!
  20. if(!ctrl.$isEmpty(ngModelValue)){
  21. // Only numbers
  22. ctrl.$setValidity('integer', INTEGER_REGEXP.test(ngModelValue));
  23.  
  24. // Check length
  25. var isSiren = angular.element(elm).hasClass('siren');
  26. var lengthOk =false;
  27.  
  28. if(isSiren){
  29. lengthOk = SIREN_REGEXP.test(ngModelValue);
  30. }else{
  31. lengthOk = SIRET_REGEXP.test(ngModelValue);
  32. }
  33.  
  34. ctrl.$setValidity('inputLength', lengthOk);
  35.  
  36. // Check key
  37. if(lengthOk){
  38. var nb = ngModelValue.split('');
  39. var i;
  40. var check =0;
  41. var x;
  42.  
  43. for(i =0; i < nb.length; i++){
  44. x = nb[nb.length - i -1]*((i %2)+1);
  45. if(x <10){
  46. check += x;
  47. }else{
  48. check += Math.floor(x /10)+(x %10);
  49. }
  50. }
  51.  
  52. if((check %10)!=0){
  53. ctrl.$setValidity('sirenSiretKey',false);
  54. }
  55. }
  56. }
  57.  
  58. // Return ngModelValue to display it
  59. return ngModelValue;
  60. }
  61.  
  62. ctrl.$parsers.push(validateSirenSiret);
  63. }
  64. };
  65. });

I use $parsers as it is a little bit more flexible than $validators (I would have to write multiple validators, I can use only one parser). Nothing special about this code: first check if the input is a number, then the length, then the Luhn key used to validate the input.

Hope this helps some others.

Viewing all 34 articles
Browse latest View live