Posts

Recent

Upload Profile Picture, Preview Image and image validation

var   image  =  new   Image (); var   file ; function   readImage ( file ) {  //  function for image preview before upload    var   useBlob  =  false  &&  window . URL ;    var   reader  =  new   FileReader ();    reader . addEventListener ( "load" ,  function  () {      image . addEventListener ( "load" ,  function  () {        var   preview  =  $ ( ".preview" );        preview . html ( this );        if  ( useBlob )  window . URL . revokeObjectURL ( image . src );     });      image . style  =  "margin-left:auto;margin-right: auto;display:block;;max-height:400px;max-width:570px;" ;      image ....

Check if property exists, return property as string, add new json array to existing

function   utilityJson ( obj ,  obj2 ,  name ,  type ) {    if  ( type  ===  "b" ) {  // return true if Property named name exists > getObjectByStringJSON(obj, [], "PropertyName to find in object", "b")      Object . byString  =  function  ( o ,  n ) {        n  =  n . replace ( / ^ \. / ,  '' );        if  ( n   in   o )  return   true ;        else   return   false ;     }      return   Object . byString ( obj ,  name );   }    else   if  ( type  ===  "s" ) {  // return property name as string of arrays > getObjectByS...

Export Kendo Chart as Grid

function exportChartToGrid(ds, name, colNames, title) { // $("#main-content") replace with your main container id or can use class selector     var element = $("#main-content").find("#gridExport"); // append element only when not present     if (element.length === 0) $("#main-content").append("<div style='display:none !important;' id='gridExport'></div>");     // make dynamic clumn definations     var columnDefs = [];     var cols = colNames.split(",");     var colTitles = title.split(",");     for (var i = 0; i < cols.length; i++) {         columnDefs.push({ title: colTitles[i], field: cols[i] });     }     $("#main-content").find("#gridExport").empty().kendoGrid({         dataSource: {             data: ds,             pageSize: 20         },     ...

Ajax Request with Callback function

// Implementation makeAjaxCall ( "/Controller/Action" ,  "GET" , {  arg1 : "value1" ,  arg2 : "value2" },  "Error loading data !" ,  "error" ,  function ( response ) {    ds  =  response ; }); function   makeAjaxCall ( url ,  methodType ,  jsonData ,  errorText ,  errorType ,  callback ) {    $ . ajax ({      url :   url ,      method :   methodType ,      dataType :   "json" ,      contentType :   'application/json; charset=utf-8' ,      data :   jsonData ,      async :   false ,      success :   function  ( result ) {        result  =  result  ===  null  ? [] :  result ;       ...

Validate StartTime before current time using moment.js

function   checkTime ( Time ) {    var   currentTime  =  moment (). format ( 'HH:mma' );    currentTime  =  convert24To12 ( currentTime );    currentTime  =  moment ( currentTime ,  "HH:mma" );    Time  =  moment ( Time ,  "HH:mma" );    var   $res  =  currentTime . isBefore ( Time );    if  (! $res ) {      return   "StartTime time should be after current time !" ;   }    else  {      return   "" ;   } } function   convert24To12 ( timeString ) {    var   H  = + timeString . substr ( 0 ,  2 );    var   h  = ( H  %  12 ) ||  12 ;    var   ampm  =  H  <  12  ?  " AM"  :  " ...

Multiple Email tags, add multiple email using basic input, JQuery

// Implementation $ ( '#email' ). multiple_emails (); // Refresh the email input $ ( '.multiple_emails-container' ). find ( '.multiple_emails-ul' ). empty (); $ ( '.multiple_emails-container' ). remove (); $ ( '#email' ). multiple_emails (); // hide email remove tag $ ( '.multiple_emails-container' ). find ( '.glyphicon-remove' ). addClass ( 'hidden' ); $ ( '.multiple_emails-container' ). css ( 'background' , '#eee' ); // validation if ( $ ( '#email' ). next ( '.multiple_emails-container' ). find ( '.multiple_emails-ul' ) . find ( 'li' ). length  <=  0 ) {    $ ( '#email' ). parent (). find ( '.vld-email-mail' ). removeClass ( 'hidden' );    //.vld-email-mail => validation text for email } multiple_email.js ( function  ( $ ) {    $ . fn . multiple_emails  =  function  ( options ) {      // Default options ...

Saving image to server, create dir and upload image Asp.Net C#

[HttpPost] public ActionResult UploadPicture(UserModel model) {     string result = "";     string path = "";     string DirectoryName = "";     string createDirectoryPath = "";     string DirectoryPath = "";     string imageToSave = "";     string imageName = "";     string Imagepath = "";     string ImagepathDB = "";     if (Request.Files.Count > 0)// Checking if image file exists in the request     {         //  Getting Image details from the request         HttpFileCollectionBase files = Request.Files;         HttpPostedFileBase file = files[0];         imageName = CurrentUser.PersonId + file.FileName;         DirectoryName = CurrentUser.PersonId;         path = "~/Images/ProfileImage/";         DirectoryPath = path + DirectoryN...