Showing posts with label Bootstrap. Show all posts
Showing posts with label Bootstrap. Show all posts

Thursday, 17 December 2015

Bootstrap Modal Using AngularJS and Javascript in #Salesforce

This blog is about using bootstrap modal using AngularJS and Javascript, there are two different ways of using the modal and fetching the values from the modal.

I have added few fields in the modal and accessing the fields from the modal using two different buttons, below are the buttons

Modals code is same but only the function of fetching the values is different.
Here is how the modal looks


Here is the code of the page with the modal code and accessing the values of the modal in different ways.
Check out the code and if any issue or queries just comment I would be happy to help.

1:  <apex:page sidebar="false" showHeader="false" docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">  
2:    <html lang="en">  
3:      <title>Manage Users</title>  
4:      <head>  
5:        <meta charset="utf-8"></meta>  
6:        <meta name="viewport" content="width=device-width, initial-scale=1"></meta>  
7:        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"></link>  
8:        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
9:        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>  
10:        <script>  
11:          $(document).on("click","#myReset",function() {  
12:            $('#myModal').modal('hide');  
13:          });  
14:          //click to save data filled in the modal using javascript  
15:          $(document).on("click", "#btnCreateContact", function(event){  
16:            var fn = document.getElementById("firstname").value;  
17:            var ln = document.getElementById("lastname").value;  
18:            var ph = document.getElementById("phone").value;  
19:            var em = document.getElementById("email").value;  
20:            var title = document.getElementById("title").value;  
21:            if(em == '' || ln == '' || fn == '' || title == '') {  
22:              alert('First Name, Last Name, Email and Title are required.');  
23:            } else {  
24:              //calling remote action  
25:              YOUR_APEX_CLASS.REMOTE_ACTION_METHOD(fn, ln, em, title, ph, function(response,event) {   
26:                $('#myModal').modal('hide');    
27:                if (event.status) {  
28:                  //debugger;   
29:                  if (response == null || response == '') {  
30:                    //Reload window and close modal  
31:                    //window.location.assign(window.location.href);  
32:                    window.location.reload(true);  
33:                    $('#myModal').modal('hide');  
34:                  } else {  
35:                    $('#myModal').modal('hide');  
36:                    alert(response);  
37:                    window.location.reload(true);  
38:                  }  
39:                } else {  
40:                  $('#myModal').modal('hide');  
41:                  alert(event.message);  
42:                  window.location.reload(true);  
43:                }  
44:              },{escape:false, buffer: false});  
45:            }  
46:          });  
47:          // USING ANGULAR NOW  
48:          //Initialling controller  
49:          myapp.controller('MainController',['$q','$log','$scope',function($q,$log,$scope){  
50:            $scope.firstname = '';  
51:            $scope.lastname = '';  
52:            $scope.phone = '';  
53:            $scope.email = '';  
54:            $scope.title = '';  
55:            //CALL REMOTE ACTION METHOD   
56:            MY_CLASS_NAME.REMOTE_ACTION(firstname, lastname, phone, email, title, function(response,event) {   
57:              // DO YOUR STUFF HERE  
58:            });  
59:          }]);  
60:         </script>  
61:      </head>  
62:       <!-- Modal -->  
63:       <div class="modal fade" id="myModal">  
64:        <div class="modal-dialog">  
65:         <!-- Modal content-->  
66:         <div class="modal-content">  
67:          <div class="modal-header">  
68:           <button type="button" class="close" data-dismiss="modal">&times;</button>  
69:           <h4 class="modal-title">Contact Details</h4>  
70:          </div>  
71:            <div class="col-xs-12 form-group">  
72:            </div>  
73:            <div class="col-xs-12 form-group">  
74:              <label>First Name<font color="red">*</font></label>  
75:              <input class="form-control" id="firstname" value="" ng-model="firstname"/>  
76:            </div>  
77:            <div class="col-xs-12 form-group">  
78:              <label>Last Name<font color="red">*</font></label>  
79:              <input class="form-control" id="lastname" value="" ng-model="lastname"/>  
80:            </div>  
81:            <div class="col-xs-12 form-group">  
82:              <label>Email<font color="red">*</font></label>  
83:              <input class="form-control" id="email" value="" ng-model="email"/>  
84:            </div>  
85:            <div class="col-xs-12 form-group">  
86:              <label>Title<font color="red">*</font></label>  
87:              <input class="form-control" id="title" value="" ng-model="title"/>  
88:            </div>  
89:            <div class="col-xs-12 form-group">  
90:              <label>Phone</label>  
91:              <input class="form-control phone" id="phone" onchange="formatPhone(this);" ng-model="phone"/>  
92:            </div>  
93:            <div class="btn-group" align="center">  
94:              <button id="btnCreateContact" class="btn btn-primary btn-md center-block" style="margin-left: 216px;">Save</button>  
95:              <a href="#" id="myReset" class="btn btn-primary btn-md center-block" style="margin-left: 15px;">Cancel</a>  
96:            </div>  
97:            <br></br>  
98:            <br></br>  
99:            <div class="modal-footer">  
100:            </div>  
101:           </div>  
102:         <br></br>  
103:       </div>  
104:       <br></br>  
105:      </div>  
106:      <br></br>  
107:      <div >  
108:       <div class="container">  
109:         <div class="panel panel-default">  
110:           <br></br>  
111:           <div class="btn-group" align="center" style="left: 27%;">   
112:             <button id="blocds" data-toggle="modal" data-target="#myModal" class="btn btn-primary btn-md center-block" style="margin-left: 15px;">Modal Using Javascript</button>   
113:             <button id="blocds" data-toggle="modal" data-target="#myModal" class="btn btn-primary btn-md center-block" style="margin-left: 15px;background-color:#DF4720">Modal Using AngularJS</button>   
114:           </div>  
115:           <br></br>  
116:           <br></br>     
117:         </div>  
118:       </div>  
119:      </div>   
120:    </html>   
121:  </apex:page>  

Happy coding!!

Tuesday, 11 August 2015

Bootstrap Datepicker for Salesforce1, Google Chrome and Firefox mozilla

Was working on something and got a change for implemtation which should work with Google chrome, Salesforce1 and firefox mozilla as well, with chrome it starts working normally without any modifications, but not in firefox mozilla, I have added comments in the code where I am referring libraries to make datepicker to work in Mozilla.

this is how bootstrap datepicker looks in chrome


This is how it looks in Firefox mozilla


And now in datepicker Salesforce1


Here is the code of the above datepicker

1:  <apex:page showHeader="false" sidebar="false" docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">  
2:      <html lang="en">  
3:        <head>  
4:          <meta charset="utf-8"></meta>  
5:          <meta name="viewport" content="width=device-width, initial-scale=1"></meta>  
6:          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"></link>  
7:          <!-- script for mozilla without these datepicker will work in chrome but not in mozilla-->  
8:          <script src="https://cdn.jsdelivr.net/webshim/1.14.5/polyfiller.js"></script>  
9:          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>  
10:          <script type="text/javascript">  
11:            webshims.setOptions('forms-ext', {types: 'date'});  
12:            webshims.polyfill('forms forms-ext');  
13:          </script>  
14:        </head>  
15:        <body>  
16:          <div class="panel-body">  
17:            <div class="form-group" ng-hide="hideformobile">  
18:              <div class="col-xs-12 form-group input-append datepicker">  
19:                <label>Datepicker</label>  
20:                <input type="date" id="mydate" size="16" class="form-control"></input>  
21:              </div>  
22:            </div>  
23:          </div>  
24:        </body>  
25:      </html>   
26:    </apex:page>  

Felt like posting it, as datepicker can take time to implement as it took mine, it works awesome on Salesforce1.

Thanks Happy coding!!

Friday, 19 June 2015

Paging using AngularJS and Bootstrap in Salesforce


AngularJS is a toolset for building the framework most suited to your application development. It is fully extensible and works well with other libraries. Every feature can be modified or replaced to suit your unique development workflow and feature needs.
Want to know more and learn about angularJS Click here this is a re-post of the blog written by Vivek Deepak

Here is the page how its looks, the awesome thing about this page is angular the functionality in too much less coding, that what I just loved about AngularJS
Take a look at this


Here is the small controller class using remote Action to fetch the account records.

1:  global class BlogOneController {  
2:    @RemoteAction  
3:    global static List<Account> getAllAccounts() {    
4:      return [SELECT Id,Name,BillingStreet,BillingCity,BillingState FROM Account];  
5:    }  
6:  }  

Here is the code of the page using AngularJS to show the data on the page, using AngularJS and Bootstrap

1:  <apex:page showHeader="false" sidebar="false" docType="html-5.0" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false" controller="BlogOneController" >  
2:  <html ng-app="SampleApp" lang="en">  
3:    <apex:stylesheet value="{!URLFOR($Resource.bootstrap,'/boostrapStyle/css/bootstrap.css')}"/>  
4:    <apex:stylesheet value="{!URLFOR($Resource.bootstrap,'/boostrapStyle/css/ng-table.min.css')}"/>  
5:    <head>  
6:    <!-- Add CSS Files HERE -->     
7:    <script type="text/javascript">  
8:    var myapp = angular.module('SampleApp',['ui.bootstrap','mgcrea.ngStrap','ngTable']);  
9:      myapp.factory('FETCH_ACCOUNTS', ['$q','$log', function($q,$log){  
10:    var handleReq = function(remoteCall) {  
11:      var defer = $q.defer();  
12:        remoteCall(  
13:         function(result, event) {  
14:          if(event.status) {  
15:           defer.resolve(result);  
16:          }  
17:          else {  
18:           $log.error(event.message);  
19:           defer.reject(event.message);  
20:          }  
21:         },  
22:         {escape:false, buffer: false}  
23:        );  
24:        return defer.promise;  
25:       }  
26:    return {  
27:        getAllCustomers: function() {  
28:          return handleReq(BlogOneController.getAllAccounts);  
29:        }  
30:      }  
31:  }]);  
32:  myapp.controller('MainController',['$q','$log','$scope','FETCH_ACCOUNTS','ngTableParams',function($q,$log,$scope,FETCH_ACCOUNTS,ngTableParams){  
33:        $scope.loadingH = true;  
34:        var data = [];  
35:        var promise = FETCH_ACCOUNTS.getAllCustomers();  
36:        $scope.account_list = [];  
37:        promise.then(function(response){  
38:          data = response;  
39:              $scope.accountRecords.reload();  
40:          $scope.loadingH = false;      
41:        },function(error){  
42:          $log.error('ERROR' + JSON.stringify(error));  
43:          $scope.loadingH = false;  
44:        });  
45:        $scope.accountRecords = new ngTableParams({  
46:                 page: 1,      // show first page  
47:                 count: 5  
48:                           // count per page  
49:              }, {  
50:                 counts:[],  
51:                 total: data.length, // length of data  
52:                 getData: function($defer, params) {  
53:               params.total(data.length);  
54:                 $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));  
55:              }  
56:            });  
57:      }]);  
58:    </script>  
59:    </head>  
60:    <body ng-controller="MainController" >  
61:    <div class="panel panel-primary">  
62:       <div class="panel-heading">  
63:        <h3 class="panel-title">Account Information</h3>  
64:       </div>  
65:       <div class="panel-body">  
66:          <table ng-table="accountRecords" class="table table-striped table-hover">  
67:           <thead>  
68:            <tr>  
69:             <th>#</th>  
70:             <th>Account Name</th>  
71:             <th>Street</th>  
72:             <th>State</th>  
73:            </tr>  
74:           </thead>  
75:           <tbody>  
76:            <tr ng-repeat="account in $data">  
77:             <td>{{$index+1}}</td>  
78:             <td>{{account.Name}}</td>  
79:             <td>{{account.BillingStreet}}</td>  
80:             <td>{{account.BillingCity}}</td>  
81:            </tr>  
82:           </tbody>  
83:          </table>    
84:       </div>  
85:      </div>  
86:      <apex:includeScript value="{!URLFOR($Resource.bootstraptpls, 'bootrapangular/angular.min.js')}"/>  
87:    <apex:includeScript value="{!URLFOR($Resource.bootstraptpls, 'bootrapangular/angular-strap.min.js')}"/>  
88:    <apex:includeScript value="{!URLFOR($Resource.bootstraptpls, 'bootrapangular/angular-strap.tpl.min.js')}"/>  
89:    <apex:includeScript value="{!URLFOR($Resource.bootstraptpls, 'bootrapangular/ng-table.min.js')}"/>  
90:    <apex:includeScript value="{!URLFOR($Resource.bootstraptpls, 'bootrapangular/ui-bootstrap-tpls-0.11.0.js')}"/>  
91:  <!-- Add JS Files HERE -->  
92:  </body>  
93:  </html>  
94:  </apex:page>  

For the Angular and Boostrap files please click here

Happy coding!!