← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21873: tracker/event-capture: custom radio input is now moved to commons directive; event-capture and cu...

 

------------------------------------------------------------
revno: 21873
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-03 16:55:33 +0100
message:
  tracker/event-capture: custom radio input is now moved to commons directive; event-capture and custom form now use custom radio
removed:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/audit/
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/dhis2-radio-button.html
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/radio-button.html
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2016-02-03 10:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2016-02-03 15:55:33 +0000
@@ -466,3 +466,50 @@
     width: 20px !important;
     text-align: center;
 }
+
+.radio-display-none {
+    display: none;
+}
+
+.fa-stack > .fa.fa-stack-1x.fa-circle.radio-save-success {
+    color: #b9ffb9 !important;
+}
+
+.fa-stack > .fa.fa-stack-1x.fa-circle.radio-save-error {
+    color: #ff8a8a !important;
+}
+
+.fa-stack > .fa.fa-stack-1x.fa-circle.radio-white {
+    color: #FFFFFF !important;
+}
+
+.fa-stack > .radio-default{
+    color: #FFFFFF;
+}
+
+.error-text {
+    color: red;
+}
+
+.warning-text {
+    color: #C7C728;
+}
+
+.custom-radio-group {
+    margin-left: -8px;
+}
+
+.custom-radio-container{
+    display: inline-block;
+}
+
+.custom-radio-text {
+    display: inline-block;
+    margin-left: -5px;
+}
+
+.custom-radio-error{
+    margin-left: 5px;
+    width:100px;
+    text-align: center;
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2016-02-03 10:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2016-02-03 15:55:33 +0000
@@ -145,37 +145,15 @@
                                         class="form-control">
                                     </textarea>
                             </div>
-                            <div ng-switch-when="BOOLEAN" class="form-control">
-                                <label class="radio-inline">
-                                    <input  type="radio"
-                                            ng-model="currentEvent[eventGridColumn.id]"                                                                
-                                            ng-required={{eventGridColumn.compulsory}}
-                                            ng-disabled="assignedFields[eventGridColumn.id]"
-                                            input-field-id={{eventGridColumn.id}} 
-                                            ng-change="saveDatavalue()"
-                                           value="">
-                                        {{'no_value'| translate}}
-                                </label>
-                                <label class="radio-inline">
-                                    <input  type="radio"
-                                            ng-model="currentEvent[eventGridColumn.id]"                                                                
-                                            ng-required={{eventGridColumn.compulsory}}
-                                            ng-disabled="assignedFields[eventGridColumn.id]"
-                                            input-field-id={{eventGridColumn.id}} 
-                                            ng-change="saveDatavalue()" 
-                                           value="true"> 
-                                        {{'yes'| translate}}
-                                </label>
-                                <label class="radio-inline">
-                                    <input  type="radio"
-                                            ng-model="currentEvent[eventGridColumn.id]"                                                                
-                                            ng-required={{eventGridColumn.compulsory}}
-                                            ng-disabled="assignedFields[eventGridColumn.id]"
-                                            input-field-id={{eventGridColumn.id}} 
-                                            ng-change="saveDatavalue()" 
-                                            value="false">
-                                           {{'no'| translate}}
-                                </label>
+                            <div ng-switch-when="BOOLEAN">
+                                <d2-radio-button
+                                    dh-required="eventGridColumn.compulsory"
+                                    dh-disabled="assignedFields[eventGridColumn.id]"
+                                    dh-value="currentEvent[eventGridColumn.id]"
+                                    dh-name="foo"
+                                    dh-event="currentEvent.event"
+                                    dh-id="eventGridColumn.id">
+                                </d2-radio-button>
                             </div>
                             <div ng-switch-when="DATE">
                                 <input type="text"
@@ -258,9 +236,6 @@
                         <div ng-messages="innerForm.foo.$error" ng-if="interacted(innerForm.foo)" class="required" ng-messages-include="../dhis-web-commons/angular-forms/error-messages.html">                                         
                         </div>
                     </ng-form>
-                    <!--<span class="hideInPrint audit-icon" ng-if="currentEvent.event && currentEvent.event !== 'SINGLE_EVENT'">
-                        <d2-audit dataelement-id="{{prStDes[eventGridColumn.id].dataElement.id}}" dataelement-name="{{prStDes[eventGridColumn.id].dataElement.name}}"  current-event="{{currentEvent.event}}"></d2-audit>
-                    </span>-->
                 </td>
                 <td ng-if="currentEvent.event && currentEvent.event !== 'SINGLE_EVENT'">
                     <d2-audit dataelement-id="{{prStDes[eventGridColumn.id].dataElement.id}}" dataelement-name="{{prStDes[eventGridColumn.id].dataElement.name}}"  current-event="{{currentEvent.event}}"></d2-audit>
@@ -430,38 +405,14 @@
                                     </textarea>
                                 </div>
                                 <div ng-switch-when="BOOLEAN">
-                                    <span class="form-control">
-                                        <label class="radio-inline">
-                                            <input type="radio"
-                                                ng-model="currentEvent[de.dataElement.id]"
-                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
-                                                ng-disabled="assignedFields[de.dataElement.id]"
-                                                input-field-id={{de.dataElement.id}}
-                                                ng-change="saveDatavalue()"
-                                                value="">
-                                            {{'no_value'| translate}}
-                                        </label>
-                                        <label class="radio-inline">
-                                            <input type="radio"
-                                                ng-model="currentEvent[de.dataElement.id]"
-                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
-                                                ng-disabled="assignedFields[de.dataElement.id]"
-                                                input-field-id={{de.dataElement.id}}
-                                                ng-change="saveDatavalue()"
-                                                value="true">
-                                            {{'yes'| translate}}
-                                        </label>
-                                        <label class="radio-inline">
-                                            <input type="radio"
-                                                ng-model="currentEvent[de.dataElement.id]"
-                                                ng-required={{prStDes[de.dataElement.id].compulsory}}
-                                                ng-disabled="assignedFields[de.dataElement.id]"
-                                                input-field-id={{de.dataElement.id}}
-                                                ng-change="saveDatavalue()"
-                                                value="false">
-                                                {{'no'| translate}}
-                                        </label>
-                                    </span>
+                                    <d2-radio-button
+                                        dh-required="prStDes[de.dataElement.id].compulsory"
+                                        dh-disabled="assignedFields[de.dataElement.id]"
+                                        dh-value="currentEvent[de.dataElement.id]"
+                                        dh-name="foo"
+                                        dh-event="currentEvent.event"
+                                        dh-id="de.dataElement.id">
+                                    </d2-radio-button>
                                 </div>
                                 <div ng-switch-when="DATE">
                                     <input type="text"

=== removed directory 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/audit'
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html	2016-02-03 10:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html	2016-02-03 15:55:33 +0000
@@ -195,7 +195,7 @@
                         <div ng-switch-when="BOOLEAN">
                             <div class="hideInPrint">
                             <span>
-                                <dhis2-radio-button
+                                <d2-radio-button
                                     dh-required="prStDe.compulsory"
                                     dh-disabled="selectedEnrollment.status !== 'ACTIVE' || currentEvent.editingNotAllowed || assignedFields[currentEvent.event][prStDe.dataElement.id] === true"
                                     dh-value="currentEvent[prStDe.dataElement.id]"
@@ -204,7 +204,7 @@
                                     dh-event="currentEvent.event"
                                     dh-id="prStDe.dataElement.id"
                                     dh-click="saveDataValueForRadio(prStDe, currentEvent, value)">
-                                </dhis2-radio-button>
+                                </d2-radio-button>
                               </span>
                             </div>
                             <div class="not-for-screen">
@@ -272,7 +272,7 @@
                             <div class="hideInPrint">
                                 <div class="input-group">
                                     <div class="form-control">
-                                        <a href ng-click="downloadFile(currentEvent.event, prStDe.dataElement.id)" title="{{fileNames[currentEvent.event][prStDe.dataElement.id]}}">{{fileNames[currentEvent.event][prStDe.dataElement.id].length > 20 ? fileNames[currentEvent.event][prStDe.dataElement.id].substr(0,20).concat('...') : fileNames[currentEvent.event][prStDe.dataElement.id])}}</a>
+                                        <a href ng-click="downloadFile(currentEvent.event, prStDe.dataElement.id)" title="{{fileNames[currentEvent.event][prStDe.dataElement.id]}}">{{fileNames[currentEvent.event][prStDe.dataElement.id].length > 20 ? fileNames[currentEvent.event][prStDe.dataElement.id].substring(0,20).concat('...') : fileNames[currentEvent.event][prStDe.dataElement.id]}}</a>
                                     </div>
                                     <span class="input-group-btn">
                                         <span class="btn btn-primary btn-file" ng-if="currentEvent[prStDe.dataElement.id]" ng-click="deleteFile(currentEvent,prStDe.dataElement.id)">
@@ -527,7 +527,7 @@
 
                                     <div ng-switch-when="BOOLEAN">
                                         <div class="hideInPrint">
-                                            <dhis2-radio-button
+                                            <d2-radio-button
                                                 dh-required="prStDes[de.dataElement.id].compulsory"
                                                 dh-disabled="selectedEnrollment.status !== 'ACTIVE' || currentEvent.editingNotAllowed || assignedFields[currentEvent.event][de.dataElement.id] === true"
                                                 dh-value="currentEvent[prStDes[de.dataElement.id].dataElement.id]"
@@ -536,7 +536,7 @@
                                                 dh-event="currentEvent.event"
                                                 dh-id="de.dataElement.id"
                                                 dh-click="saveDataValueForRadio(prStDes[de.dataElement.id], currentEvent, value)">
-                                            </dhis2-radio-button>
+                                            </d2-radio-button>
                                         </div>
                                         <div class="not-for-screen">
                                             <label class="radio-inline"><input type="radio" ng-checked="{{currentEvent[prStDes[de.dataElement.id].dataElement.id] === 'true'}}">{{'yes' | translate}}</label>
@@ -611,7 +611,7 @@
                                         <div class="hideInPrint">
                                             <div class="input-group">
                                                 <div class="form-control">
-                                                    <a href ng-click="downloadFile(currentEvent.event, de.dataElement.id)" title="{{fileNames[currentEvent.event][de.dataElement.id]}}">{{fileNames[currentEvent.event][de.dataElement.id].length > 20 ? fileNames[currentEvent.event][de.dataElement.id].substr(0,20).concat('...') : fileNames[currentEvent.event][de.dataElement.id]}}</a>
+                                                    <a href ng-click="downloadFile(currentEvent.event, de.dataElement.id)" title="fileNames[currentEvent.event][de.dataElement.id]">{{fileNames[currentEvent.event][de.dataElement.id].length > 20 ? fileNames[currentEvent.event][de.dataElement.id].substring(0,20).concat('...') : fileNames[currentEvent.event][de.dataElement.id]}}</a>
                                                 </div>
                                                     <span class="input-group-btn">
                                                         <span class="btn btn-primary btn-file" ng-click="deleteFile(currentEvent,de.dataElement.id)" ng-if="currentEvent[de.dataElement.id]">

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2016-01-11 11:26:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2016-02-03 15:55:33 +0000
@@ -418,186 +418,4 @@
             }
         ]
     };
-})
-.directive('dhis2RadioButton', function (){  
-    return {
-        restrict: 'E',
-        templateUrl: 'views/dhis2-radio-button.html',
-        scope: {
-            required: '=dhRequired',
-            value: '=dhValue',
-            disabled: '=dhDisabled',
-            name: '@dhName',            
-            customOnClick: '&dhClick',
-            currentElement: '=dhCurrentElement',
-            event: '=dhEvent',
-            id: '=dhId'
-        },
-        controller: [
-            '$scope',
-            '$element',
-            '$attrs',
-            '$q',   
-            'CommonUtils',
-            function($scope, $element, $attrs, $q, CommonUtils){
-                
-                $scope.status = "";                
-                $scope.clickedButton = "";
-                
-                $scope.valueClicked = function (buttonValue){
-                                        
-                    $scope.clickedButton = buttonValue;
-                    
-                    var originalValue = $scope.value;
-                    var tempValue = buttonValue;
-                    if($scope.value === buttonValue){
-                        tempValue = "";
-                    }
-                    
-                    if(angular.isDefined($scope.customOnClick)){
-                        var promise = $scope.customOnClick({value: tempValue});
-                        if(angular.isDefined(promise) && angular.isDefined(promise.then)){
-                            promise.then(function(status){
-                                if(angular.isUndefined(status) || status !== "notSaved"){
-                                    $scope.status = "saved";                                    
-                                }
-                                $scope.value = tempValue;                            
-                            }, function(){   
-                                $scope.status = "error";
-                                $scope.value = originalValue;
-                            });
-                        }
-                        else if(angular.isDefined(promise)){
-                            if(promise === false){
-                                $scope.value = originalValue;
-                            }
-                            else {
-                                $scope.value = tempValue;
-                            }
-                        }
-                        else{
-                            $scope.value = tempValue;
-                        }
-                    }
-                    else{
-                        $scope.value = tempValue;
-                    }
-                };
-                
-                $scope.getDisabledValue = function(inValue){                    
-                    return CommonUtils.displayBooleanAsYesNo(inValue);                    
-                };
-                
-                $scope.getDisabledIcon = function(inValue){                    
-                    if(inValue === true || inValue === "true"){
-                        return "fa fa-check";
-                    }
-                    else if(inValue === false || inValue === "false"){
-                        return "fa fa-times";
-                    }
-                    return '';
-                }
-                
-            }],
-        link: function (scope, element, attrs) {
-            
-            scope.radioButtonColor = function(buttonValue){
-                
-                if(scope.value !== ""){
-                    if(scope.status === "saved"){
-                        if(angular.isUndefined(scope.currentElement) || (scope.currentElement.id === scope.id && scope.currentElement.event === scope.event)){
-                            if(scope.clickedButton === buttonValue){
-                                return 'radio-save-success';
-                            }
-                        }                                            
-                    //different solution with text chosen
-                    /*else if(scope.status === "error"){
-                        if(scope.clickedButton === buttonValue){
-                            return 'radio-save-error';
-                        }
-                    }*/
-                    }
-                }                
-                return 'radio-white';
-            };
-            
-            scope.errorStatus = function(){
-                
-                if(scope.status === 'error'){
-                    if(angular.isUndefined(scope.currentElement) || (scope.currentElement.id === scope.id && scope.currentElement.event === scope.event)){
-                        return true;
-                    }
-                }
-                return false;
-            };
-
-            scope.radioButtonImage = function(buttonValue){        
-
-                if(angular.isDefined(scope.value)){
-                    if(scope.value === buttonValue && buttonValue === "true"){
-                        return 'fa fa-stack-1x fa-check';                
-                    }            
-                    else if(scope.value === buttonValue && buttonValue === "false"){
-                        return 'fa fa-stack-1x fa-times';
-                    }
-                }
-                return 'fa fa-stack-1x';        
-            };    
-        }
-    };
-})
-
-.directive('dhis2Deselect', function ($document) {
-    return {
-        restrict: 'A',
-        scope: {
-            onDeselected: '&dhOnDeselected',
-            id: '@dhId',
-            preSelected: '=dhPreSelected'                   
-        },
-        controller: [
-            '$scope',
-            '$element',
-            '$attrs',
-            '$q',            
-            function($scope, $element, $attrs, $q){
-                
-                $scope.documentEventListenerSet = false;
-                $scope.elementClicked = false;
-                
-                $element.on('click', function(event) {                    
-                                        
-                    $scope.elementClicked = true;
-                    if($scope.documentEventListenerSet === false){
-                        $document.on('click', $scope.documentClick);
-                        $scope.documentEventListenerSet = true;
-                    }                             
-                });
-                
-                $scope.documentClick = function(event){
-                    
-                    var modalPresent = $(".modal-backdrop").length > 0;
-                    var calendarPresent = $(".calendars-popup").length > 0;
-                    var calendarPresentInEvent = $(event.target).parents(".calendars-popup").length > 0;
-                    
-                    if($scope.elementClicked === false && 
-                        modalPresent === false && 
-                        calendarPresent === false && 
-                        calendarPresentInEvent === false){                        
-                        $scope.onDeselected({id:$scope.id});
-                        $scope.$apply();  
-                        $document.off('click', $scope.documentClick);
-                        $scope.documentEventListenerSet = false;
-                    }
-                    $scope.elementClicked = false;
-                };
-                
-                if(angular.isDefined($scope.preSelected) && $scope.preSelected === true){                    
-                    $document.on('click', $scope.documentClick);
-                    $scope.documentEventListenerSet = true;
-                }
-                
-            }],
-        link: function (scope, element, attrs) {}
-    };
 });

=== removed file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/dhis2-radio-button.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/dhis2-radio-button.html	2016-01-14 17:33:09 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/dhis2-radio-button.html	1970-01-01 00:00:00 +0000
@@ -1,66 +0,0 @@
-<!--
-Copyright (c) 2015, UiO
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright notice,
-  this list of conditions and the following disclaimer in the documentation
-  and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
--->
- 
-
-<div ng-if="!disabled" class="custom-radio-group custom-radio-container">     
-    <span ng-click="valueClicked('true')">
-        <span class="fa-stack">                                                                                                        
-            <span class='fa fa-stack-1x fa-circle radio-default fa-stack-custom-large' ng-class='radioButtonColor("true")'></span>        
-            <span class="fa fa-stack-1x fa-circle-thin fa-stack-custom-large"></span>
-            <span class="fa-stack-custom-small" ng-class="radioButtonImage('true')"></span>
-        </span>
-        <span class="custom-radio-text cursor-pointer">
-            {{'Yes' | translate }}
-        </span>
-    </span>
-    &nbsp;&nbsp;    
-    <span ng-click="valueClicked('false')">
-        <span class="fa-stack">                                                                                                        
-            <span class='fa fa-stack-1x fa-circle fa-stack-custom-large' ng-class='radioButtonColor("false")'></span>                                                    
-            <span class="fa fa-stack-1x fa-circle-thin fa-stack-custom-large"></span>
-            <span class="fa-stack-custom-small" ng-class="radioButtonImage('false')"></span>
-        </span>
-        <span class="custom-radio-text cursor-pointer">
-            {{'No' | translate }}
-        </span>        
-    </span>
-    <div ng-if="status === 'error'" class="custom-radio-error input-error"><span>{{'save failed' | translate}}</span></div>
-    
-    
-    <div ng-show="false">
-        <label class="radio-inline">                                                    
-            <input class="radio-display-none" ng-required="required" style='margin-top: 1px' type="radio" ng-model="value" ng-disabled="disabled" name="{{name}}" value="true">                                                    
-        </label>                                                
-        <label class="radio-inline">
-            <input class="radio-display-none" ng-required="required" style='margin-top: 1px' type="radio" ng-model="value" ng-disabled="disabled" name="{{name}}" value="false">
-        </label>
-    </div>
-</div>
-<div ng-if="disabled" class="custom-radio-container">
-    <span class="fa-icon-width" ng-class="getDisabledIcon(value)"></span>
-    <span>{{getDisabledValue(value) | translate}}</span>         
-</div>
-                        

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/radio-button.html'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/radio-button.html	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/radio-button.html	2016-02-03 15:55:33 +0000
@@ -0,0 +1,65 @@
+<!--
+Copyright (c) 2015, UiO
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-->
+ 
+
+<div ng-if="!disabled" class="custom-radio-group custom-radio-container">     
+    <span ng-click="valueClicked('true')">
+        <span class="fa-stack">                                                                                                        
+            <span class='fa fa-stack-1x fa-circle radio-default fa-stack-custom-large' ng-class='radioButtonColor("true")'></span>        
+            <span class="fa fa-stack-1x fa-circle-thin fa-stack-custom-large"></span>
+            <span class="fa-stack-custom-small" ng-class="radioButtonImage('true')"></span>
+        </span>
+        <span class="custom-radio-text cursor-pointer">
+            {{'Yes' | translate }}
+        </span>
+    </span>
+    &nbsp;&nbsp;    
+    <span ng-click="valueClicked('false')">
+        <span class="fa-stack">                                                                                                        
+            <span class='fa fa-stack-1x fa-circle fa-stack-custom-large' ng-class='radioButtonColor("false")'></span>                                                    
+            <span class="fa fa-stack-1x fa-circle-thin fa-stack-custom-large"></span>
+            <span class="fa-stack-custom-small" ng-class="radioButtonImage('false')"></span>
+        </span>
+        <span class="custom-radio-text cursor-pointer">
+            {{'No' | translate }}
+        </span>        
+    </span>
+    <div ng-if="status === 'error'" class="custom-radio-error input-error"><span>{{'save failed' | translate}}</span></div>
+    
+    
+    <div ng-show="false">
+        <label class="radio-inline">                                                    
+            <input class="radio-display-none" ng-required="required" style='margin-top: 1px' type="radio" ng-model="value" ng-disabled="disabled" name="{{name}}" value="true">                                                    
+        </label>                                                
+        <label class="radio-inline">
+            <input class="radio-display-none" ng-required="required" style='margin-top: 1px' type="radio" ng-model="value" ng-disabled="disabled" name="{{name}}" value="false">
+        </label>
+    </div>
+</div>
+<div ng-if="disabled" class="custom-radio-container">
+    <span class="fa-icon-width" ng-class="getDisabledIcon(value)"></span>
+    <span>{{getDisabledValue(value) | translate}}</span>         
+</div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js	2016-02-03 10:04:07 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js	2016-02-03 15:55:33 +0000
@@ -383,63 +383,244 @@
 })
 
 .directive('d2Audit', function () {
-        return {
-            restrict: 'E',
-            template: '<span class="hideInPrint audit-icon" title="{{\'audit_history\' | translate}}"><i class="glyphicon glyphicon-user" data-ng-click="showAuditHistory()" ng-if="showAuditIcon()"></i></span>',
-            scope:{
-                dataElementId: '@dataelementId',
-                dataElementName: '@dataelementName',
-                currentEvent:'@',
-                type:'@',
-                selectedTeiId:'@',
-                isAuditIconPresent:'=?'
-            },
-            controller:function($scope, $modal) {
-                if (!$scope.dataElementId) {
-                    return;
-                }
-
-                $scope.showAuditIcon = function() {
-                    if ($scope.currentEvent && $scope.currentEvent !== 'SINGLE_EVENT') {
-                        $scope.isAuditIconPresent = true;
-                        return true;
-                    }
-                    if ($scope.type === "attribute" && $scope.selectedTeiId) {
-                        $scope.isAuditIconPresent = true;
-                        return true;
-                    }
-                    $scope.isAuditIconPresent = false;
-                    return false;
-                }
-
-                $scope.showAuditHistory = function() {
-
-                    $modal.open({
-                        templateUrl: "../dhis-web-commons/angular-forms/audit-history.html",
-                        controller: "AuditHistoryController",
-                        resolve: {
-                            dataElementId: function () {
-                                return $scope.dataElementId;
-                            },
-                            dataElementName: function () {
-                                return $scope.dataElementName;
-                            },
-                            dataType: function() {
-                                return $scope.type;
-                            },
-                            currentEvent: function() {
-                                return $scope.currentEvent;
-                            },
-                            selectedTeiId: function() {
-                                return $scope.selectedTeiId;
-                            }
-                        }
-                    })
-
-                }
-
-            }
-        };
-    });
-
-
+    return {
+        restrict: 'E',
+        template: '<span class="hideInPrint audit-icon" title="{{\'audit_history\' | translate}}"><i class="glyphicon glyphicon-user" data-ng-click="showAuditHistory()" ng-if="showAuditIcon()"></i></span>',
+        scope:{
+            dataElementId: '@dataelementId',
+            dataElementName: '@dataelementName',
+            currentEvent:'@',
+            type:'@',
+            selectedTeiId:'@',
+            isAuditIconPresent:'=?'
+        },
+        controller:function($scope, $modal) {
+            if (!$scope.dataElementId) {
+                return;
+            }
+
+            $scope.showAuditIcon = function() {
+                if ($scope.currentEvent && $scope.currentEvent !== 'SINGLE_EVENT') {
+                    $scope.isAuditIconPresent = true;
+                    return true;
+                }
+                if ($scope.type === "attribute" && $scope.selectedTeiId) {
+                    $scope.isAuditIconPresent = true;
+                    return true;
+                }
+                $scope.isAuditIconPresent = false;
+                return false;
+            }
+
+            $scope.showAuditHistory = function() {
+
+                $modal.open({
+                    templateUrl: "../dhis-web-commons/angular-forms/audit-history.html",
+                    controller: "AuditHistoryController",
+                    resolve: {
+                        dataElementId: function () {
+                            return $scope.dataElementId;
+                        },
+                        dataElementName: function () {
+                            return $scope.dataElementName;
+                        },
+                        dataType: function() {
+                            return $scope.type;
+                        },
+                        currentEvent: function() {
+                            return $scope.currentEvent;
+                        },
+                        selectedTeiId: function() {
+                            return $scope.selectedTeiId;
+                        }
+                    }
+                })
+
+            }
+
+        }
+    };
+})
+
+.directive('d2RadioButton', function (){  
+    return {
+        restrict: 'E',
+        templateUrl: '../dhis-web-commons/angular-forms/radio-button.html',
+        scope: {
+            required: '=dhRequired',
+            value: '=dhValue',
+            disabled: '=dhDisabled',
+            name: '@dhName',            
+            customOnClick: '&dhClick',
+            currentElement: '=dhCurrentElement',
+            event: '=dhEvent',
+            id: '=dhId'
+        },
+        controller: [
+            '$scope',
+            '$element',
+            '$attrs',
+            '$q',   
+            'CommonUtils',
+            function($scope, $element, $attrs, $q, CommonUtils){
+                
+                $scope.status = "";                
+                $scope.clickedButton = "";
+                
+                $scope.valueClicked = function (buttonValue){
+                                        
+                    $scope.clickedButton = buttonValue;
+                    
+                    var originalValue = $scope.value;
+                    var tempValue = buttonValue;
+                    if($scope.value === buttonValue){
+                        tempValue = "";
+                    }
+                    
+                    if(angular.isDefined($scope.customOnClick)){
+                        var promise = $scope.customOnClick({value: tempValue});
+                        if(angular.isDefined(promise) && angular.isDefined(promise.then)){
+                            promise.then(function(status){
+                                if(angular.isUndefined(status) || status !== "notSaved"){
+                                    $scope.status = "saved";                                    
+                                }
+                                $scope.value = tempValue;                            
+                            }, function(){   
+                                $scope.status = "error";
+                                $scope.value = originalValue;
+                            });
+                        }
+                        else if(angular.isDefined(promise)){
+                            if(promise === false){
+                                $scope.value = originalValue;
+                            }
+                            else {
+                                $scope.value = tempValue;
+                            }
+                        }
+                        else{
+                            $scope.value = tempValue;
+                        }
+                    }
+                    else{
+                        $scope.value = tempValue;
+                    }
+                };
+                
+                $scope.getDisabledValue = function(inValue){                    
+                    return CommonUtils.displayBooleanAsYesNo(inValue);                    
+                };
+                
+                $scope.getDisabledIcon = function(inValue){                    
+                    if(inValue === true || inValue === "true"){
+                        return "fa fa-check";
+                    }
+                    else if(inValue === false || inValue === "false"){
+                        return "fa fa-times";
+                    }
+                    return '';
+                }
+                
+            }],
+        link: function (scope, element, attrs) {
+            
+            scope.radioButtonColor = function(buttonValue){
+                
+                if(scope.value !== ""){
+                    if(scope.status === "saved"){
+                        if(angular.isUndefined(scope.currentElement) || (scope.currentElement.id === scope.id && scope.currentElement.event === scope.event)){
+                            if(scope.clickedButton === buttonValue){
+                                return 'radio-save-success';
+                            }
+                        }                                            
+                    //different solution with text chosen
+                    /*else if(scope.status === "error"){
+                        if(scope.clickedButton === buttonValue){
+                            return 'radio-save-error';
+                        }
+                    }*/
+                    }
+                }                
+                return 'radio-white';
+            };
+            
+            scope.errorStatus = function(){
+                
+                if(scope.status === 'error'){
+                    if(angular.isUndefined(scope.currentElement) || (scope.currentElement.id === scope.id && scope.currentElement.event === scope.event)){
+                        return true;
+                    }
+                }
+                return false;
+            };
+
+            scope.radioButtonImage = function(buttonValue){        
+
+                if(angular.isDefined(scope.value)){
+                    if(scope.value === buttonValue && buttonValue === "true"){
+                        return 'fa fa-stack-1x fa-check';                
+                    }            
+                    else if(scope.value === buttonValue && buttonValue === "false"){
+                        return 'fa fa-stack-1x fa-times';
+                    }
+                }
+                return 'fa fa-stack-1x';        
+            };    
+        }
+    };
+})
+
+.directive('dhis2Deselect', function ($document) {
+    return {
+        restrict: 'A',
+        scope: {
+            onDeselected: '&dhOnDeselected',
+            id: '@dhId',
+            preSelected: '=dhPreSelected'                   
+        },
+        controller: [
+            '$scope',
+            '$element',
+            '$attrs',
+            '$q',            
+            function($scope, $element, $attrs, $q){
+                
+                $scope.documentEventListenerSet = false;
+                $scope.elementClicked = false;
+                
+                $element.on('click', function(event) {                    
+                                        
+                    $scope.elementClicked = true;
+                    if($scope.documentEventListenerSet === false){
+                        $document.on('click', $scope.documentClick);
+                        $scope.documentEventListenerSet = true;
+                    }                             
+                });
+                
+                $scope.documentClick = function(event){
+                    
+                    var modalPresent = $(".modal-backdrop").length > 0;
+                    var calendarPresent = $(".calendars-popup").length > 0;
+                    var calendarPresentInEvent = $(event.target).parents(".calendars-popup").length > 0;
+                    
+                    if($scope.elementClicked === false && 
+                        modalPresent === false && 
+                        calendarPresent === false && 
+                        calendarPresentInEvent === false){                        
+                        $scope.onDeselected({id:$scope.id});
+                        $scope.$apply();  
+                        $document.off('click', $scope.documentClick);
+                        $scope.documentEventListenerSet = false;
+                    }
+                    $scope.elementClicked = false;
+                };
+                
+                if(angular.isDefined($scope.preSelected) && $scope.preSelected === true){                    
+                    $document.on('click', $scope.documentClick);
+                    $scope.documentEventListenerSet = true;
+                }
+                
+            }],
+        link: function (scope, element, attrs) {}
+    };
+});
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2016-02-03 10:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2016-02-03 15:55:33 +0000
@@ -442,11 +442,21 @@
                                                 commonInputFieldProperty + '></span><span class="not-for-screen"><input type="text" value={{currentEvent.' + fieldId + '}}></span>';
                                         }
                                         else if (prStDe.dataElement.valueType === "BOOLEAN") {
-                                            newInputField = '<span class="hideInPrint"><label class="radio-inline"><input type="radio" ng-change="saveDatavalue()" ' + commonInputFieldProperty + ' value="">{{\'no_value\'| translate}}</label>' +
+                                        	newInputField = '<d2-radio-button ' +
+                                                                        ' dh-required="prStDes.' + fieldId + '.compulsory" ' +
+                                                                        ' dh-disabled="isHidden(prStDes.' + fieldId + '.dataElement.id) || selectedEnrollment.status===\'CANCELLED\' || selectedEnrollment.status===\'COMPLETED\' || currentEvent[uid]==\'uid\' || currentEvent.editingNotAllowed" ' +
+                                                                        ' dh-value="currentEvent.' + fieldId + '" ' +
+                                                                        ' dh-name="foo" ' +
+                                                                        ' dh-current-element="currentElement" ' +
+                                                                        ' dh-event="currentEvent.event" ' +
+                                                                        ' dh-id="prStDes.' + fieldId + '.dataElement.id" ' +
+                                                                        ' dh-click="saveDatavalue(prStDes.' + fieldId + ', currentEvent, value )"' +
+                                                                ' </d2-radio-button>';	
+                                            /*newInputField = '<span class="hideInPrint"><label class="radio-inline"><input type="radio" ng-change="saveDatavalue()" ' + commonInputFieldProperty + ' value="">{{\'no_value\'| translate}}</label>' +
                                                 '<label class="radio-inline"><input type="radio" ng-change="saveDatavalue(prStDes.' + fieldId + ', outerForm.' + fieldId + ')" ' + commonInputFieldProperty + ' value="true">{{\'yes\'| translate}}</label>' +
                                                 '<label class="radio-inline"><input type="radio" ng-change="saveDatavalue(prStDes.' + fieldId + ', outerForm.' + fieldId + ')" ' + commonInputFieldProperty + ' value="false">{{\'no\'| translate}}</label></span>' +
                                                 '<span class="not-for-screen"><label class="radio-inline"><input type="radio" ng-checked="{{\'true\' === currentEvent.' + fieldId + '}}">{{\'yes\'| translate}}</label>' +
-                                                '<label class="radio-inline"><input type="radio" ng-checked="{{\'false\' === currentEvent.' + fieldId + '}}">{{\'no\'| translate}}</label></span>';
+                                                '<label class="radio-inline"><input type="radio" ng-checked="{{\'false\' === currentEvent.' + fieldId + '}}">{{\'no\'| translate}}</label></span>';*/
                                         }
                                         else if (prStDe.dataElement.valueType === "DATE") {
                                             var maxDate = prStDe.allowFutureDate ? '' : 0;
@@ -474,7 +484,7 @@
                                         else if (prStDe.dataElement.valueType === "FILE_RESOURCE") {
                                             newInputField = '<span class="input-group">\n\
                                                             <span ng-if="currentEvent.' + fieldId + '">\n\
-                                                                <a href ng-click="downloadFile(null, \'' + fieldId + '\', null)" title="{{fileNames[currentEvent.event][' + fieldId + ']}}" >{{fileNames[currentEvent.event][' + fieldId + '].length > 20 ? fileNames[currentEvent.event][' + fieldId + '].substring(0,20).concat(\'...\') : fileNames[currentEvent.event][' + fieldId + ']}}</a>\n\
+                                                                <a href ng-click="downloadFile(null, \'' + fieldId + '\', null)" title="fileNames[currentEvent.event][' + fieldId + ']" >{{fileNames[currentEvent.event][' + fieldId + '].length > 20 ? fileNames[currentEvent.event][' + fieldId + '].substring(0,20).concat(\'...\') : fileNames[currentEvent.event][' + fieldId + ']}}</a>\n\
                                                             </span>\n\
                                                             <span class="input-group-btn">\n\
                                                                 <span class="btn btn-primary btn-file">\n\