Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- /*
- All modal HTML goes here
- */
- /*
- All initialization logic goes here
- */
- var leadList = []
- var components;
- //chrome.runtime.sendMessage({'function': 'loadTypekit'})
- // Check if salesforce page is a lead page and push leads (assume if there are query params, leadId is always first)
- if (getPageType() == "instant") {
- $("#topButtonRow").append("<input value='Sendbloom 1-to-1' id='sendbloomModal' class='btn' name='sendbloom' type='button'>")
- leadList.push(components[3].split("?")[0])
- // Check if salesforce page is a report page
- checkForClickToCall();
- } else if (getPageType() == "prospects") {
- // If the report is a lead report, then each row contains exactly one lead with many links to that lead
- // Get the first lead link of each row
- $(".tabularReportTable").find("tr").find("a[href*='00Q']:first").each(function () {
- if(components[2].includes("dbx.my.salesforce.com")){
- leadList.push(this.pathname.split("/")[1].split("?")[0])
- } else {
- leadList.push(this.pathname.split("/")[1])
- }
- })
- // The same but for contact reports
- $(".tabularReportTable").find("tr").find("a[href*='003']:first").each(function () {
- if(components[2].includes("dbx.my.salesforce.com")){
- leadList.push(this.pathname.split("/")[1].split("?")[0])
- } else {
- leadList.push(this.pathname.split("/")[1])
- }
- })
- // Only add the add to sendbloom button if there is at least one lead on the page
- if(leadList.length > 0) {
- $(".reportActions").append("<input value='Add to Sendbloom Prospects' id='sendbloomReportButton' class='btn' name='sendbloom' type='button'>")
- }
- }
- function addLeadsToProspects() {
- // delegate to the background page, which will do the actual work
- var data = {
- 'loading':true,
- "prospects": leadList,
- 'report-name': $(".noSecondHeader").text()
- }
- var reports_url = sendbloomDomain + "/labs/gmail/";
- var loading_reports_url = reports_url + "?loading=true"
- loadSendbloomOneToOne(loading_reports_url);
- // Need to make a POST request to upload a list of prospects
- // GET request supports 2047 char max and limits the number of sf ids we can send
- sendbloomApiCall({
- endpoint:'/api/prospects/',
- data:data,
- method:'POST',
- successCallback: function(data) {
- var reports_url_data = {
- report_name: $(".noSecondHeader").text(),
- reports: true,
- success: true,
- //loading: false,
- eligible_count: data.eligibleCount,
- ineligible_count: data.ineligibleCount,
- };
- var reports_url = sendbloomDomain + "/labs/gmail/?" + $.param(reports_url_data);
- $('#sb-iframe-container-modal').remove()
- loadSendbloomOneToOne(reports_url);
- },
- errorCallback: function(response) {
- var error = JSON.parse(response.responseText);
- var reports_url_data = {
- report_name: $(".noSecondHeader").text(),
- reports: true,
- success: false,
- //loading: false,
- ineligible_count: leadList.length
- };
- var reports_url = sendbloomDomain + "/labs/gmail/?" + $.param(reports_url_data);
- $('#sb-iframe-container-modal').remove()
- loadSendbloomOneToOne(reports_url);
- },
- });
- }
- function checkForClickToCall(){
- $.ajax({
- url: sendbloomDomain + '/settings/calling/verify',
- type : "POST",
- method: 'POST',
- dataType: 'json',
- }).done(function(data) {
- if(data.flag == "true"){
- $("#topButtonRow").append("<input value='Phone' id='phoneButton' class='btn' name='sendbloom' type='button'>");
- $("#topButtonRow").append("<input value='Mobile' id='mobileButton' class='btn' name='sendbloom' type='button'>");
- $('#phoneButton').bind('click', phoneButton);
- $('#mobileButton').bind('click', mobileButton);
- }
- }).fail(function(error) {
- });
- }
- function getPageType() {
- components = document.location.href.split("/")
- if(components.length == 4
- // Adding in dropbox custom url hardcoded. Will generalize this for other users later
- // Either no query params and standard url or query params allowed with dbx.my.salesforce
- && (components[2].match(/.salesforce\.com/) || components[2].match(/dbx.my.salesforce.com/))
- && (components[3].match(/^00Q/) || components[3].match(/^003/))) {
- return "instant"
- } else if (components.length == 4
- && ((!components[3].match(/\?/)
- && components[2].match(/.salesforce\.com/)) ||
- components[2].match(/dbx.my.salesforce.com/))
- && components[3].match(/^00O/)) {
- return "prospects"
- } else {
- return null
- }
- }
- /*Method to get prospect salesforce id from the url*/
- function getProspectSalesforceId() {
- components = document.location.pathname.split("/");
- for (var i=0; i<components.length; i++) {
- if (components[i].match(/^00Q/) || components[i].match(/^003/)) {
- return components[i];
- }
- }
- return null;
- }
- var modal_active = false;
- $('#sendbloomModal').bind('click',function() {
- var lead_id = getProspectSalesforceId();
- var labs_url = sendbloomDomain + "/labs/gmail/?source=sfdc";
- if (lead_id) {
- labs_url = labs_url + "&prospect=" + lead_id.toString()
- }
- loadSendbloomOneToOne(labs_url)
- });
- $('#sendbloomReportButton').bind('click',function() {
- addLeadsToProspects();
- });
- function phoneButton(){
- var tds = document.getElementsByClassName("labelCol");
- var phoneLabel = {};
- for(var i = 0; i<tds.length; i++){
- if(tds[i].textContent == "Phone"){
- phoneLabel = tds[i];
- break;
- }
- }
- var phoneNumber = $.parseHTML(phoneLabel.nextSibling.innerHTML)[0].innerHTML;
- if(phoneNumber != " "){
- callProspect(phoneNumber);
- }else{
- alert("Prospect has no phone number");
- }
- }
- function mobileButton(){
- var tds = document.getElementsByClassName("labelCol");
- var phoneLabel = {};
- for(var i = 0; i<tds.length; i++){
- if(tds[i].textContent == "Mobile"){
- phoneLabel = tds[i];
- break;
- }
- }
- var phoneNumber = $.parseHTML(phoneLabel.nextSibling.innerHTML)[0].innerHTML;
- if(phoneNumber != " "){
- callProspect(phoneNumber);
- }else{
- alert("Prospect has no mobile number");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement