Tuesday, 19 September 2017

SIGNUP Form With Validation AngularJs

No comments
HTML

<form class="register-form" name="formRegister">
                    <p class="form_logo">
                        <img title="" alt="" src="img/logo.png" class="">
                    </p>
                    <label ng-class="{ 'has-errors' : formRegister.userEmail.$invalid && !formRegister.userEmail.$pristine, 'no-errors' : formRegister.userEmail.$valid}">
                        <input focus id="registerEmails" type="email" placeholder="Email" ng-model="userEmail">
                    </label>              
                    <label ng-class="{ 'has-errors' : formRegister.userPassword.$invalid && !formRegister.userPassword.$pristine, 'no-errors' : formRegister.userPassword.$valid}">
                        <input focus type="password" placeholder="Password" id="userPassword" name="userPassword" ng-model="userPassword" required />
                    </label>
                    <label ng-class="{ 'has-errors' : formRegister.confirmPassword.$invalid && !formRegister.confirmPassword.$pristine, 'no-errors' : formRegister.confirmPassword.$valid}">
                        <input focus type="password" id="confirmPassword" name="confirmPassword" placeholder="Retype Password" ng-model="confirmPassword" required compare-to="userPassword">
                    </label>
                    <div class="msg-block ng-invalid" ng-show="formRegister.$error">
                        <span class="msg-error ng-invalid" ng-show="formRegister.confirmPassword.$error.pwmatch">
                            Password doesn't match.
                        </span>
                    </div>
                    <button ng-click="doRegister()" class="button button-block button-balanced" ng-disabled="formRegister.$invalid" style="padding:0 !important">
                        SIGN UP
                    </button>
                    <p class="message">Already registered? <a ng-href="#/app/login">Sign In</a></p>
                 
                </form>


Directive


//password compare
app.directive('compareTo', [function () {
    return {
        require: "ngModel",
        scope: {
            otherModelValue: "=compareTo"
        },
        link: function (scope, element, attributes, ngModel) {
            var firstPassword = '#' + attributes.compareTo;
            element.on('keyup', function () {
                scope.$apply(function () {
                    var v = element.val() === $(firstPassword).val();
                    ngModel.$setValidity('pwmatch', v);
                });
            });
        }
    };

}]);


//move to next input when enter
app.directive('focus', function () {
    return {
        restrict: 'A',
        link: function ($scope, elem, attrs) {
            elem.bind('keydown', function (e) {
                var code = e.keyCode || e.which;
                if (code === 13) {
                    e.preventDefault();
                    //          elem.next().focus();

                    if (elem.attr('id') == "registerEmail") {
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').on('focus', function () {
                            $(this).attr('type', 'date');
                        });
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').focus().click();
                    }
                    else {
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').focus();
                    }
                }
            });
        }
    }
});
read more

Friday, 21 July 2017

Textbox with autocomplete dropdown Ionic

No comments
Directive

app.directive('ionSelect', function ($rootScope) {
    'use strict';
    return {
        restrict: 'EAC',
        scope: {
            label: '@',
            labelField: '@',
            provider: '=',
            ngModel: '=?',
            ngValue: '=?',
            labelId: '@',
            placeholderValue: '@',
            globalClass: '@',
            placeholderClass: '@',
        },
        require: '?ngModel',
        transclude: false,
        replace: false,
        template: '<div class="item item-input-inset noBorderTop noPadding divSlectText">'
                + '<label class="item-input-wrapper">'
                + '<input id="filtro" class="{{placeholderClass}}" type="search" intype="placeholder" language-seletion key="{{placeholderValue}}"   ng-model="ngModel" ng-value="ngValue" /></label>'
                + '<button class="button button-small button-clear inputOpen"><i class="icon ion-chevron-down"></i>'
                + '</button></div><div class="optionList padding-left padding-right hideSelectText">'
                + '<ion-scroll class="selectScroll"><ul class="list">'
                + '<li class="item  {{globalClass}}" ng-click="selecionar($event,item,labelField,labelId)" ng-repeat="item in provider | filter:ngModel">{{item[labelField]}}</li></ul>'
                + '</ion-scroll></div>',
        link: function (scope, element, attrs, ngModel) {
            scope.ngValue = scope.ngValue !== undefined ? scope.ngValue : 'item';
            scope.selecionar = function ($event,item, name, id) {
               
                ngModel.$setViewValue(item[name]);              
                if (name == 'SpecialityName') {
                    $rootScope.medicalProviderData.SpecialityId = { SpecialityId: item[id] };
                }
                scope.showHide = false;                $event.target.parentElement.parentElement.parentElement.classList.remove("showSelectText");
                $event.target.parentElement.parentElement.parentElement.classList.add("hideSelectText");
            };
            element.bind('click', function () {
                element.find('input').focus();
            });
            element.find('button').bind('click', function () {
                var $this = $(this);
                $('.divSlectText').each(function () {
                    if ($this.parent().parent().find('.optionList').html() != $(this).parent().find('.optionList').html()) {
                        if ($(this).find('button').hasClass('inputOpen')) {
                            $(this).parent().find('.optionList').removeClass('showSelectText');
                            $(this).parent().find('.optionList').addClass('hideSelectText');
                        }
                    }
                });
                if ($this.parent().parent().find('.optionList').hasClass('hideSelectText')) {
                    $this.parent().parent().find('.optionList').removeClass('hideSelectText');
                    $this.parent().parent().find('.optionList').addClass('showSelectText');
                }
                else {
                    $this.parent().parent().find('.optionList').addClass('hideSelectText');
                }
            });
            element.find('input').bind('keydown', function () {              
                var $this = $(this);              
                $this.parent().parent().parent().find('.optionList').addClass('showSelectText')
                $this.parent().parent().parent().find('.optionList').removeClass('hideSelectText')
            });
        },
    };

});

CSS


.showSelectText {
    display:block;
}
.hideSelectText {
    display:none;

}

HTML

  <div>
       <ion-select label="SpecialityName" global-class="{{globalClass}} {{textAlign}}" placeholder-class="{{globalClass}} {{textAlign}}" placeholder-value="Speciality" label-field="SpecialityName" itemname="SpecialityName" label-id="SpecialityId" provider="SpecialityList" ng-model="speciality" />

                    </div>
read more

Tuesday, 30 May 2017

Convert Language From English To Arabic From Directive

No comments
Directive

app.directive('languageSeletion', function (languageData) {
    return {
        restrict: 'EA',
        replace: true,
        scope: {
            key: "@"
        },
        link: function (scope, element, attr) {
           
            var value = languageData.convertData(scope.key);
            debugger
            element.html(value);          
        }
    }
});


Factory


app.factory('languageData', function (xmlTojson,$rootScope) {
    function xmlToString(xmlData) {
        return  (new XMLSerializer()).serializeToString(xmlData);        
    }
    return {
        convertData: function (key) {            
            var result;
            $.ajax({
                url: 'data/arabic.xml',
                dataType: 'xml',
                contentType:'application/xml',
                async: false,
                success: function (data) {                   
                    var jsonData = JSON.parse(xmlTojson.convertXMLToJSON(xmlToString(data))).Resources.key;                    
                    $.each(jsonData, function (index, value) {
                        if (value._value == key) {
                            if ($rootScope.language == 'EN') {
                                result = value.EN;
                            }
                            else {
                                result = value.AE;
                            }
                            return false;
                        }
                    });
                    
                }
            });
            return result;
        }
    }
});

app.factory('xmlTojson', function () {
    var x2js = new X2JS();
    return {
        convertXMLToJSON: function (data) {
            return JSON.stringify(x2js.xml_str2json(data));
        }
    }

});

HTML

<script src="scripts/xml2json.js"></script>
<span class="input-label textAlignCenter colorTheme" language-seletion key="About"></span>
read more

Monday, 29 May 2017

Ionic Datepicker With date range

No comments
var todayDate = new Date();
    todayDate.setFullYear(todayDate.getFullYear() - 90);
    $scope.getAge = function (DOB) {
        var today = new Date();
        var birthDate = new Date(DOB);
        var age = today.getFullYear() - birthDate.getFullYear();
        var m = today.getMonth() - birthDate.getMonth();
        if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
            age--;
        }
        return age;
    }
  var objFromDate = {
        callback: function (val) {
            var output = $scope.getAge(val);
            if (output < 18 || output > 99) {
                alert("User age should be between 18 years to 99 years.");
                return;
            }          
           $scope.profile.Birth_date = $filter('date')(new Date(val), 'MM/dd/yyyy');
        },
        inputDate: new Date(),
        mondayFirst: true,
        templateType: 'popup',
        showTodayButton: false,
        from: todayDate,
        to: new Date(),
        dateFormat: 'MM/dd/yyyy',
        closeOnSelect: false,
    };
    $scope.dobDatePicker = function () {
        ionicDatePicker.openDatePicker(objFromDate);
    };
read more

Formate Date to mm-dd-yyyy

No comments
//Formate Date to mm-dd-yyyy
    $scope.formatDate = function (date) {
        var d = new Date(date),
            month = '' + (d.getMonth() + 1),
            day = '' + d.getDate(),
            year = d.getFullYear();

        if (month.length < 2) month = '0' + month;
        if (day.length < 2) day = '0' + day;

        return [year, month, day].join('-');
    }

//To Get

 data.data.Birth_date=$scope.formatDate(data.data.Birth_date);
read more

Wednesday, 12 April 2017

Send Push Notification With Cordova And Webapi

No comments
Cordova Plugin

https://github.com/phonegap/phonegap-plugin-push

Push Plugin


var push = PushNotification.init({
           android: {
               senderID: "628523812525"
           },
           browser: {
               pushServiceURL: 'your url'
           },
           ios: {
               alert: "true",
               badge: "true",
               sound: "true"
           },
           windows: {}
       });
       PushNotification.hasPermission(function (permissionResult) {
          if (permissionResult.isEnabled) {           
            push.on('registration'function (data) {
              alert(data.registrationId,data.registrationId);          
            });
 
            push.on('notification'function (data) {
              alert(JSON.stringify(data));
            });
 
            push.on('error'function (e) {      
              alert("e.message: " + e.message);
            });
          }
        });
      

WebAPI

//RegisterId you got from Android Developer.
string deviceId = "APA91bExfJOpM0vmKW8q200RSPs5iSPugD1mKf4PSYaFaz5TyZP2QYwmYUCDVHdNV7";
 
string message = "Demo Notification";
string tickerText = "Patient Registration";
string contentTitle = "Titlesss";
string postData =
"{ \"registration_ids\": [ \"" + deviceId + "\" ], " +
  "\"data\": {\"tickerText\":\"" + tickerText + "\", " +
             "\"contentTitle\":\"" + contentTitle + "\", " +
             "\"message\": \"" + message + "\"}}";
 
//  
//  MESSAGE CONTENT  
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 
//  
//  CREATE REQUEST  
HttpWebRequest Requests = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
Requests.Method = "POST";
//  Request.KeepAlive = false;  
 
Requests.ContentType = "application/json";
Requests.Headers.Add(string.Format("Authorization: key={0}""AIzaSyBKz7u6jeat1p09cO1"));
Requests.ContentLength = byteArray.Length;
 
Stream dataStream = Requests.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
 
//  
//  SEND MESSAGE  
 
WebResponse Response = Requests.GetResponse();
 
HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
{
    var text = "Unauthorized - need new token";
}
else if (!ResponseCode.Equals(HttpStatusCode.OK))
{
    var text = "Response from web service isn't OK";
}
 
StreamReader Reader = new StreamReader(Response.GetResponseStream());
string responseLine = Reader.ReadToEnd();
Reader.Close();
 
 
read more

Saturday, 8 April 2017

show image and text side by side in middle

No comments
<div class="game-menu" style="margin-top:10%">
           <img src="img/play.png" class="iconMenu" />
           <span class="iconSpan iconHeadFont">Play Again</span>
       </div>

<style type="text/css">
           .iconMenu {
               font-size50px;
               colorgreen;
               displayinline-block;
               vertical-alignmiddle;
               margin-top10px;
           }
 
           .iconSpan {
               displayinline-block;
               vertical-alignmiddle;
               color:white;
               font-size:40px;
               font-weight:bold;
           }
       </style>
read more

Friday, 31 March 2017

Redirect To Another Page If User Have No Right TO Access Page

No comments
public class ValidateUserAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (SessionFactory.Instance.CurrentUsers == null)
                filterContext.Result = new RedirectResult(string.Format("/Home/Login?ReturnUrl={0}"HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsolutePath)));
            else if (SessionFactory.Instance.CurrentUsers.clientid == 0)
                filterContext.Result = new RedirectResult(string.Format("/Home/Login"HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsolutePath)));
        }
    }
 
    public class ValidateSetupAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (SessionFactory.Instance.CurrentUsers.roleid == (int)Constant.Roles.user)
                filterContext.Result = new RedirectResult(string.Format("/Dashboard/Dashboard"HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsolutePath)));
        }
    }




Controller

[ValidateUser]
[ValidateSetup]
public class MasterController : Controller
{
}
read more

Sunday, 26 March 2017

Delete Multiple Items With Checkbox MVC

No comments
JQUERY

$('#selectAllCheck').click(function (e) {
                   var table = $(e.target).closest('table');
                   $('td input:checkbox', table).prop('checked'this.checked);
               });

function Inactivate() {
                debugger
                var mainForm = $("#frmDrugsView");
                var serializeData = JSON.stringify(mainForm.serializeArray());
                $.ajax({
                    type: "POST",
                    url: "@Url.Action("Inactivate", "Master")",
                    data: "{ 'jsonString': '" + serializeData.toString() + "' }",
                    async: true,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (responseData) {
                        debugger
                        location.reload();
                    },
                    error: function (e) {
                         
                    }
                });
            }


HTML

@using (@Html.BeginForm(nullnullFormMethod.Post, new { id = "frmDrugsView", @class = "form-horizontal bordered-group", role = "form" }))
{
<table class="table">
<tr>
 <th><input type="checkbox" id="selectAllCheck" /></th>                                            
</tr>
@foreach (var item in @Model.lstDrugRel)
 {
   <tr class='@(item.IsActive==false?"deletedPatient":"")'>
   <td><input type="checkbox" name="inactiveDrug" id="inactiveDrug" value="@item.drugid" />
   </td>                                               
   </tr>
 }
</table>
<input type="submit" class="btn btn-primary " id="btnInactive" value="Save" 
onclick="Inactivate();return false;">
}                 

Controller


//Inactivate Drugs
        public ActionResult Inactivate(string jsonString)
        {
            List<serializeJsonRequest> serializeJsonRequest = JsonConvert.DeserializeObject<List<serializeJsonRequest>>(jsonString); 
            foreach (var item in serializeJsonRequest)
            {
                if (item.name == "inactiveDrug")
                {
                    var drugRepository = uom.Repository<DrugRepository>();
                    var drugData = drugRepository.GetDrugById(int.Parse(item.value));
                    drugData.IsActive = false;
                    drugRepository.UpdateDrug(drugData);
                }
            }
            return Json("Sucess"JsonRequestBehavior.AllowGet);
        }
read more

Wednesday, 22 March 2017

Accordian In Ionic

No comments
Controller


//Accordian Start
    $scope.accordian = [
     { title: "CallList", id: 1 },
     { title: "Schedule", id: 2 },
     { title: "CallHistory", id: 3 },
    ];
 
    $scope.toggleAccordian = function (accordian) {
        if ($scope.isAccordianShown(accordian)) {
            $scope.shownaccordian = null;
        } else {
            $scope.shownaccordian = accordian;
        }
    };
    $scope.isAccordianShown = function (accordian) {
        return $scope.shownaccordian === accordian;
    };
    $scope.toggleAccordian('1');


HTML

<div ng-repeat="(key, value) in accordian| groupBy: 'id'">
                <ion-item class="item-stable" ng-click="toggleAccordian(key)"
                          ng-class="{active: isAccordianShown(key)}">
                    <i class="icon" ng-class="isAccordianShown(key) ? 'ion-minus' : 'ion-plus'"></i>
                    &nbsp;
                    <span style="margin:5px;color#7fa42d;font-weightbold;">{{key=='1'?'Call List':key=='2'?'Next 7 Days Schedule':key=='3'?'Call History':''}}</span>
                </ion-item> 
                <ion-item class="" ng-repeat="items in value" ng-show="isAccordianShown(key)">                   
                    <div class="col-lg-12" ng-repeat="x in xx" ng-show="key=='1'">                      
                    </div>                   
                    <div class="list" ng-repeat="z in zz" ng-show="key=='2'">                       
                    </div>
                    <div class="col list" ng-show="key=='3'">                       
                    </div>                                      
                </ion-item>
            </div>
read more

Friday, 10 March 2017

Required Environment Variables To Setup Cordova Project

No comments
User Variable
------------------

ANDROID_HOME
C:\Program Files (x86)\Android\android-sdk

JAVA_HOME
C:\Program Files\Java\jdk1.8.0_111

PATH:-
C:\Users\vikas\AppData\Roaming\npm\node_modules\cordova\bin
C:\Program Files\Java\jdk1.8.0_111\bin
C:\Users\vikas\AppData\Roaming\npm



system variables
---------------------------
JAVA_HOME
C:\Program Files\Java\jdk1.8.0_111
read more

Thursday, 2 March 2017

make Checkbox to work as radiobutton

No comments
JS


$scope.doctorStatus = [
     { title: "Available", checked: true },
     { title: "Busy", checked: false },
     { title: "NA", checked: false },
    ];
 
    $scope.UpdateSelection = function (position, itens, title) {
        angular.forEach(itens, function (subscription, index) {
            if (position != index)
                subscription.checked = false;
            else
                subscription.checked = true;
        }
        );
    }

HTML


<div class="card" ng-show="!callList.length">           
            <ion-item class="item-checkbox" ng-repeat="item in doctorStatus" style="padding:0 !important">
                <ion-checkbox ng-model="item.checked" ng-click="UpdateSelection($index, doctorStatus, item.title);">{{item.title}}</ion-checkbox>
            </ion-item>
 
        </div>
read more

Wednesday, 1 March 2017

Show Default Load Image Till Image Is Fully Loaded From Server

No comments
src is default image

<img load-image="{{item.ImageURL}}" src="img/rolling.gif" />

Directive

app.directive('loadImage'function () {
    return {
        restrict: 'A',
        scope: { loadImage: '@' },
        link: function (scope, element, attrs) {
            element.one('load'function () {
                element.attr('src', scope.loadImage);
            });
        }
    };
}); 
read more

Focus On Next Input On Enter

No comments
Directive


//move to next input when enter
app.directive('focus'function () {
    return {
        restrict: 'A',
        link: function ($scope, elem, attrs) {
            elem.bind('keydown'function (e) {
                var code = e.keyCode || e.which;
                if (code === 13) {
                    e.preventDefault();
                    //          elem.next().focus();
 
                    if (elem.attr('id') == "registerEmail") {
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').on('focus'function () {
                            $(this).attr('type''date');
                        });
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').focus().click();
                    }
                    else {
                        $(':input:eq(' + ($(':input').index(this) + 1) + ')').focus();
                    }
                }
            });
        }
    }
});

HTML

<label>
  <input id="email" focus type="email" ng-model="userEmail" required>
/label>
<label>
  <input id="password" focus type="password" ng-model="userPassword" required>
</label> 
read more

Validation In ModalPopUp

No comments

HTML
<script id="templates/changePassword.html" type="text/ng-template">
    <ion-modal-view class="grey_bg">
        <ion-nav-bar class="bar-balanced">
            <ion-nav-title>
                Change Password
            </ion-nav-title>
            <ion-nav-buttons side="right">
                <button class="button button-icon button-clear ion-close-round"
 ng-click="ChangePassword()"></button>
            </ion-nav-buttons>
        </ion-nav-bar>
        <ion-content class="has-header toTransofrm" padding="10">
            <div class="list">
                <form class="register-form" name="formRegister">
                    <label class="item item-input" 
ng-class="{ 'has-errors' : formRegister.oldPassword.$invalid && 
!formRegister.oldPassword.$pristine, 'no-errors' : formRegister.oldPassword.$valid}">
                        <input focus type="password" placeholder="Current Password" 
id="oldPassword" name="oldPassword" ng-model="oldPassword" required />
                    </label>
                    <label class="item item-input" 
ng-class="{ 'has-errors' : formRegister.userPassword.$invalid 
&& !formRegister.userPassword.$pristine, 'no-errors' : formRegister.userPassword.$valid}">
                        <input focus type="password" placeholder="New Password" 
id="userPassword" name="userPassword" ng-model="userPassword" required />
                    </label>
                    <label class="item item-input" 
ng-class="{ 'has-errors' : formRegister.confirmPassword.$invalid && 
!formRegister.confirmPassword.$pristine, 'no-errors' : formRegister.confirmPassword.$valid}">
                        <input focus type="password" id="confirmPassword" 
name="confirmPassword" placeholder="Confirm New Password" 
ng-model="confirmPassword" required compare-to="userPassword">
                    </label>
                    <div class="msg-block ng-invalid" ng-show="formRegister.$error">
                        <span class="msg-error ng-invalid" 
ng-show="formRegister.confirmPassword.$error.pwmatch">
                            Password doesn't match.
                        </span>
                    </div>
                    <div class="button-bar bar-balanced">
                        <a class="button" ng-click="openPasswordModal()" 
ng-disabled="formRegister.$invalid" style="font-size:25px">Change Password</a>
                    </div>
                </form>
 
            </div>
 
        </ion-content>
    </ion-modal-view>
</script>

JS

//open popup model
   $scope.openPasswordModal = function (animation) {
       $ionicModal.fromTemplateUrl('templates/changePassword.html', {
           scope: $scope,
           animation: animation
       }).then(function (modal) {
           $scope.passwordModal = modal;
           $scope.passwordModal.show();
       });
   };
   //close popup model
   $scope.closePasswordModal = function () {
       $scope.passwordModal.hide();
   };

Directive

//password compare
app.directive('compareTo', [function () {
    return {
        require: "ngModel",
        scope: {
            otherModelValue: "=compareTo"
        },
        link: function (scope, element, attributes, ngModel) {
            var firstPassword = '#' + attributes.compareTo;
            element.on('keyup'function () {
                scope.$apply(function () {
                    var v = element.val() === $(firstPassword).val();
                    ngModel.$setValidity('pwmatch', v);
                });
            });
        }
    };
}]);
read more