Subversion Repositories SmartDukaan

Rev

Rev 21987 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21627 kshitij.so 1
var context = "/profitmandi-fofo";
2
var googleProfile;
3
 
4
var startApp = function() {
5
  gapi.load('auth2', function(){
6
    // Retrieve the singleton for the GoogleAuth library and set up the client.
7
    auth2 = gapi.auth2.init({
8
      client_id: '968353813927-c7eb4mm2lmm451kb6plk9cdmtf47e3mk.apps.googleusercontent.com',
9
      cookiepolicy: 'single_host_origin',
10
      // Request scopes in addition to 'profile' and 'email'
11
      //scope: 'additional_scope'
12
    });
13
    attachSignin(document.getElementById('customBtn'));
14
  });
15
};
16
 
17
function attachSignin(element) {
18
    console.log(element.id);
19
    auth2.attachClickHandler(element, {},
20
        function(googleUser) {
21
    		googleProfile = googleUser.getBasicProfile();
22
        	console.log(googleProfile.getImageUrl());
23
        	submitUser(googleUser);
24
        }, function(error) {
25
          console.log(JSON.stringify(error, undefined, 2));
26
        });
27
  }
28
 
29
function submitUser(googleUser){
30
	jQuery.ajax({
31
        type : "POST",
32
        url : context+"/login",
33
        data: {"token":googleUser.getAuthResponse().id_token},
34
        success: function(data, textStatus, request){
35
        	console.log(data);
36
        	addProfileInLocalDb();
37
        	window.location.href= "/profitmandi-fofo/dashboard";
38
   		}
39
    });  
40
}
41
 
42
function addProfileInLocalDb(){
43
	var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
44
	localStorage.setItem("profile",JSON.stringify(profile));
45
}
46
 
47
 
48
function loadNewGrn(domId){
49
	jQuery.ajax({
50
        type : "GET",
51
        url : context+"/purchase",
52
        success : function(response) {
53
            $('#' + domId).html(response);
54
        }
55
    });  
56
}
57
 
58
function findDuplicateSerialNumbers(value){
59
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
60
    return result;
61
}