Advertisement
Guest User

Integrate

a guest
Jul 16th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 76.44 KB | None | 0 0
  1. /*
  2. * Salesforce.com Integration Toolkit 33.0
  3. * Copyright, 2014, salesforce.com, inc.
  4. * All Rights Reserved
  5. */
  6.  
  7. window.sforce = window.sforce || {};
  8.  
  9. sforce.console = (function() {
  10. var VERSION = '33.0'; //TODO: changed this to mark this toolkit as an internal API, also update Sfdc.xdomain.Util.usePostMessage() accordingly
  11. var CALLEE_NAME = 'sfdc-console';
  12. var txn_id = 0;
  13. var ON_CALL_END = 'onCallEnd';
  14. var ADD_EVENT_LISTENER = 'addEventListener';
  15. var ADD_PUSH_NOTIFICATION_LISTENER = 'addPushNotificationListener';
  16. var caller;
  17. var registry;
  18.  
  19. /**
  20. * A class representing a generic registry for storing event and regular function callbacks
  21. */
  22. var Registry = function() {
  23. this.registry = {};
  24. };
  25.  
  26. Registry.prototype.registerFunction = function(funcName, func, scope) {
  27. this.registry[funcName] = {func : func, scope : scope};
  28. };
  29.  
  30. Registry.prototype.getFunction = function(funcName) {
  31. return this.registry[funcName];
  32. };
  33.  
  34. Registry.prototype.removeFunction = function(funcName) {
  35. delete this.registry[funcName];
  36. };
  37.  
  38. var canvasClient = (function() {
  39. var parsedRequest = null;
  40.  
  41. return {
  42. isCanvasContext : function() {
  43. return !!(typeof Sfdc !== 'undefined' && Sfdc.canvas && Sfdc.canvas.client);
  44. },
  45.  
  46. getParsedRequest : function() {
  47. if (!parsedRequest) {
  48. var signedRequest = Sfdc.canvas.client.signedrequest();
  49. if (signedRequest) {
  50. if (typeof signedRequest === "string") {
  51. try {
  52. parsedRequest = JSON.parse(signedRequest);
  53. } catch (e) {
  54. return null;
  55. }
  56. } else {
  57. // assume we're using OAuth
  58. parsedRequest = signedRequest;
  59. }
  60. }
  61. }
  62. return parsedRequest;
  63. },
  64.  
  65. parseAuthenticationParams : function (postMessageClient) {
  66. // if sfdc frame origin or nonce is missing and context is a canvas app,
  67. // try to parse params from canvas signedrequest
  68. if (this.isCanvasContext()) {
  69. parsedRequest = this.getParsedRequest();
  70.  
  71. if (parsedRequest) {
  72. var environment;
  73. if (parsedRequest.context) {
  74. environment = parsedRequest.context.environment;
  75. } else if (parsedRequest.payload) {
  76. environment = parsedRequest.payload.environment;
  77. }
  78. if (environment && environment.parameters) {
  79. postMessageClient.sfdcIFrameOrigin = environment.parameters.sfdcIframeOrigin;
  80. postMessageClient.nonce = environment.parameters.nonce;
  81. }
  82. }
  83. }
  84. },
  85.  
  86. // this is called from isInConsole API
  87. // need to make sure canvas is enabled and JSON is available because isInConsole
  88. // can be called from standard app with older browsers (IE7)
  89. isInConsole : function () {
  90. if (this.isCanvasContext()) {
  91. parsedRequest = this.getParsedRequest();
  92.  
  93. if (parsedRequest) {
  94. var environment = parsedRequest.context.environment;
  95. if (environment && environment.parameters.isInConsole) {
  96. return true;
  97. }
  98. }
  99. }
  100. return false;
  101. }
  102. };
  103. })();
  104.  
  105. var postMessageClient = {
  106. nonce : null,
  107. sfdcIFrameOrigin : null,
  108. INTEGRATION_API : 'integrationApi/',
  109.  
  110. usePostMessage : function () {
  111. if (window.postMessage && this.sfdcIFrameOrigin && this.nonce) {
  112. return true;
  113. }
  114.  
  115. this.parseAuthenticationParams();
  116.  
  117. return !!(window.postMessage && this.sfdcIFrameOrigin && this.nonce);
  118. },
  119.  
  120. parseAuthenticationParams : function () {
  121. // parse SFDC frame origin and nonce needed by API calls
  122. var params = this.parseUrlQueryString(location.search);
  123.  
  124. this.sfdcIFrameOrigin = params.sfdcIFrameOrigin ? params.sfdcIFrameOrigin.toLowerCase() : null;
  125. this.nonce = params.nonce;
  126.  
  127. if (!(this.sfdcIFrameOrigin && this.nonce)) {
  128. canvasClient.parseAuthenticationParams(this);
  129. }
  130. },
  131.  
  132. initialize : function() {
  133. if (window.attachEvent) {
  134. window.attachEvent('onmessage', this.processPostMessage);
  135. } else {
  136. window.addEventListener('message', this.processPostMessage, false);
  137. }
  138. },
  139.  
  140. registry : new Registry(),
  141.  
  142. parser : (function() {
  143. var BOOLEAN_TYPE = 'b';
  144. var STRING_TYPE = 's';
  145. var ARRAY_TYPE = 'a';
  146. var ARG_DELIM = '&';
  147. var ARRAY_DELIM = ';';
  148. var TYPE_DELIM = ':';
  149. var VAL_DELIM = '=';
  150.  
  151. function isArray(a) {
  152. return Object.prototype.toString.apply(a) === '[object Array]';
  153. }
  154.  
  155. function flattenArray(arr) {
  156. var arr_delim = '';
  157. var arr_str = '';
  158. for (var i = 0; i < arr.length; i++) {
  159. arr_str += arr_delim + encodeURIComponent(arr[i]);
  160. arr_delim = ARRAY_DELIM;
  161. }
  162. return arr_str;
  163. }
  164.  
  165. return {
  166. parse:function(message) {
  167. var query = {};
  168. var parts = message.split(ARG_DELIM);
  169.  
  170. for(var i = 0; i < parts.length; i++) {
  171. var pair = parts[i].split(VAL_DELIM);
  172. var value = pair[1].split(TYPE_DELIM);
  173. var parsedValue;
  174. if (value[0] === ARRAY_TYPE) {
  175. var arr = value[1].split(ARRAY_DELIM);
  176. parsedValue = [];
  177. for(var j = 0; j < arr.length; j++) {
  178. parsedValue[j] = decodeURIComponent(arr[j]);
  179. }
  180. } else {
  181. parsedValue = decodeURIComponent(value[1]);
  182. }
  183. if (value[0] === BOOLEAN_TYPE) {
  184. parsedValue = parsedValue === 'true';
  185. }
  186. query[decodeURIComponent(pair[0])] = parsedValue;
  187. }
  188. return query;
  189. },
  190. stringify:function(obj) {
  191. var delim = '';
  192. var str = '';
  193. for (var key in obj) {
  194. if (obj.hasOwnProperty(key)) {
  195. var type;
  196. if (isArray(obj[key])) {
  197. str += delim + encodeURIComponent(key) + VAL_DELIM + ARRAY_TYPE + TYPE_DELIM + flattenArray(obj[key]);
  198. } else {
  199. type = typeof(obj[key]) === 'boolean' ? BOOLEAN_TYPE : STRING_TYPE;
  200. str += delim + encodeURIComponent(key) + VAL_DELIM + type + TYPE_DELIM + encodeURIComponent(obj[key]);
  201. }
  202.  
  203. delim = ARG_DELIM;
  204. }
  205. }
  206. return str;
  207. }
  208. };
  209. })(),
  210.  
  211. /**
  212. * send message to sfdc client side using HTML5 postMessages
  213. */
  214. doPostMessage: function(event) {
  215. var id = event.calleeName + '_' + 'proxyFrame' + '_' + event.txn_id;
  216.  
  217. var argsContext = {};
  218. if (typeof(event.name) !== 'undefined') { argsContext.xdomain_name = event.name; }
  219. if (typeof(event.calleeName) !== 'undefined') { argsContext.xdomain_targetFrame = event.calleeName; }
  220. if (typeof(event.txn_id) !== 'undefined') { argsContext.xdomain_txnId = event.txn_id; }
  221. if (typeof(event.pathToOriginProxy) !== 'undefined') { argsContext.xdomain_pathToOriginProxy = event.pathToOriginProxy; }
  222. if (typeof(event.targetParentFrame) !== 'undefined') { argsContext.xdomain_targetParentFrame = event.targetParentFrame; }
  223. argsContext.xdomain_originFrame = window.name;
  224. argsContext.nonce = this.nonce;
  225.  
  226. var message = this.parser.stringify(argsContext);
  227. if (typeof(event.args) !== 'undefined') {
  228. message += '&' + this.parser.stringify(event.args);
  229. }
  230.  
  231. top.postMessage(this.INTEGRATION_API + message, this.sfdcIFrameOrigin);
  232. },
  233.  
  234. /**
  235. * Receives message from sfdc and executes callback
  236. */
  237. processPostMessage: function(event) {
  238. var xdomainArgs = {};
  239. var targetParentFrame;
  240. var callRegistry;
  241. var result;
  242.  
  243. if (event.origin !== postMessageClient.sfdcIFrameOrigin) {
  244. // Only trust messages coming from SFDC origin
  245. return;
  246. }
  247.  
  248. if (event.data && event.data.indexOf(postMessageClient.INTEGRATION_API) !== 0) {
  249. return;
  250. }
  251.  
  252. // strip off API target
  253. var message = event.data.replace(postMessageClient.INTEGRATION_API, '');
  254.  
  255. // parse message received from sfdc
  256. result = postMessageClient.parser.parse(message);
  257. result.args = postMessageClient.parser.parse(result.args);
  258.  
  259. callRegistry = registry.getFunction(result.name);
  260. xdomainArgs.frameId = result.originFrame;
  261.  
  262. if (typeof(callRegistry) !== 'undefined') {
  263. callRegistry.func.call(callRegistry.scope, result.args, xdomainArgs);
  264. }
  265. },
  266.  
  267. /**
  268. * Utility method to create a query string object.
  269. */
  270. parseUrlQueryString: function(queryString) {
  271. var params = {};
  272. if (typeof queryString !== 'string') {
  273. return params;
  274. }
  275.  
  276. if (queryString.charAt(0) === '?') {
  277. queryString = queryString.slice(1);
  278. }
  279.  
  280. if (queryString.length === 0) {
  281. return params;
  282. }
  283.  
  284. var pairs = queryString.split('&');
  285. for (var i = 0; i < pairs.length; i++) {
  286. var pair = pairs[i].split('=');
  287. params[pair[0]] = !!pair[1] ? decodeURIComponent(pair[1]) : null;
  288. }
  289.  
  290. return params;
  291. }
  292. };
  293.  
  294. /**
  295. * Returns true if the current page is a Salesforce native page, i.e. the page is served from the same origin as the console main page
  296. */
  297. function isSalesforceNativePage() {
  298. var accessible = null;
  299. try {
  300. accessible = top.location.href;
  301. } catch (e) {}
  302. return (typeof accessible === 'string') && top.isServiceDeskPage;
  303. }
  304.  
  305. /**
  306. * Initialize cross domain communication using iframe proxy or HTML5 PostMessage.
  307. * If browser supports PostMessage, use this approach.
  308. * Else use iframe proxy approach.
  309. */
  310. if (isSalesforceNativePage()) {
  311. // create a registry for tab event listeners
  312. registry = new Registry();
  313. } else if (postMessageClient.usePostMessage()) {
  314. // use postMessage framework
  315. registry = postMessageClient.registry;
  316. postMessageClient.initialize();
  317. } else if (window.Sfdc && Sfdc.xdomain) {
  318. // use iframe proxy
  319. caller = Sfdc.xdomain.Caller;
  320. registry = Sfdc.xdomain.CrossDomainApiRegistry;
  321. } else {
  322. if (window.console && console.log) {
  323. console.log('Service Cloud Toolkit API cannot be used with your browser.');
  324. }
  325. }
  326.  
  327. /**
  328. * Wrap a callback to remove the callback from the registry and execute the callback
  329. */
  330. function wrapCallback(fname, callback, args) {
  331. if (args.event) {
  332. var handlers, ConstructorFn;
  333. var isGlobalEvent = fname === ADD_EVENT_LISTENER;
  334. var isLiveAgentChatEvent = (fname === "chatOnNewMessage" || fname === "chatOnTypingUpdate"
  335. || fname === "chatOnCustomEvent" || fname === "chatOnCriticalWaitState"
  336. || fname === "chatOnAgentSend" || fname === "chatOnFileTransferCompleted");
  337. if (fname === ON_CALL_END) {
  338. // special CTI event handlers
  339. // if call object id is provided associate event handler with it, otherwise event handler is called for all call object ids
  340. handlers = [{fn:callback, id:args.callObjectId}];
  341. } else if (isGlobalEvent) {
  342. // global event handlers
  343. handlers = {};
  344. handlers[args.eventType] = [callback];
  345. } else if (isLiveAgentChatEvent) {
  346. handlers = {};
  347. //Some Live Agent events are sent for specific chats, or even specific chats on specific eventTypes. The code in here
  348. // assumes that fname is the only unique identifier for events. We need to handle things differently for Live Agent. If
  349. // the event is one of the Live Agent events specific to a chat, we take an eventId that contains the rest of the uniqueness
  350. // and use that as the identifier.
  351. handlers[fname+args.eventId] = [callback];
  352. } else {
  353. // standard event handlers
  354. handlers = [callback];
  355. }
  356.  
  357. ConstructorFn = function() {
  358. // add an event handler, return true if the event type already exists, false otherwise
  359. // for standard event types, it always return true
  360. this.add = function(eventHandler, args) {
  361. var isExistingEventType = true;
  362. if (fname === ON_CALL_END) {
  363. handlers.push({fn:eventHandler, id:args.callObjectId});
  364. } else if (isGlobalEvent) {
  365. if (!handlers[args.eventType]) {
  366. isExistingEventType = false;
  367. handlers[args.eventType] = [];
  368. }
  369. handlers[args.eventType].push(eventHandler);
  370. } else if (isLiveAgentChatEvent) {
  371. if (!handlers[fname+args.eventId]) {
  372. isExistingEventType = false;
  373. handlers[fname+args.eventId] = [];
  374. }
  375. handlers[fname+args.eventId].push(eventHandler);
  376. } else {
  377. handlers.push(eventHandler);
  378. }
  379. return isExistingEventType;
  380. };
  381.  
  382. // delete an event handler, return true if cross-domain clean-up is needed, false otherwise
  383. this.del = function(eventHandler, args) {
  384. if (isGlobalEvent) {
  385. var handlerFns = handlers[args.eventType];
  386. var cleanUpOptions = {unregisterFrameForEvent : false, unregisterFrameForEveryEvent : false};
  387.  
  388. if (!handlerFns) {
  389. return cleanUpOptions;
  390. }
  391.  
  392. for (var i = 0; i < handlerFns.length; i++) {
  393. if (handlerFns[i] === eventHandler) {
  394. handlerFns.splice(i, 1);
  395. break;
  396. }
  397. }
  398.  
  399. if (handlerFns.length === 0) {
  400. // this frame no longer has handlers for this event type
  401. cleanUpOptions.unregisterFrameForEvent = true;
  402. }
  403.  
  404. for (var eventType in handlers) {
  405. if (handlers.hasOwnProperty(eventType)) {
  406. if (handlers[eventType].length > 0) {
  407. return cleanUpOptions;
  408. }
  409. }
  410. }
  411.  
  412. // this frame no longer has handlers for any global event
  413. cleanUpOptions.unregisterFrameForEveryEvent = true;
  414. registry.removeFunction(ADD_EVENT_LISTENER);
  415. return cleanUpOptions;
  416. }
  417. // implicitly return undefined if it's called upon a non-global event handler
  418. };
  419.  
  420. this.call = function(scope, args, xdomainArgs, callback) {
  421. var handlerFns, i;
  422. if (isGlobalEvent) {
  423. handlerFns = handlers[args.eventType] ? handlers[args.eventType] : [];
  424.  
  425. // no need to pass eventType to the listeners
  426. delete args.eventType;
  427. for (i = 0; i < handlerFns.length; i++) {
  428. handlerFns[i].call(scope, args, xdomainArgs, callback);
  429. }
  430. } else if (isLiveAgentChatEvent) {
  431. handlerFns = handlers[fname+args.eventId] ? handlers[fname+args.eventId] : [];
  432. // no need to pass eventId to the listeners
  433. delete args.eventId;
  434. for (i=0; i < handlerFns.length; i++) {
  435. handlerFns[i].call(scope, args, xdomainArgs, callback);
  436. }
  437. } else {
  438. i = 0;
  439. while (i<handlers.length) {
  440. if (typeof handlers[i].fn === 'function') {
  441.  
  442. // skip if id is null or id not equal to call object id
  443. if (!!handlers[i].id && handlers[i].id !== args.id) {
  444. continue;
  445. }
  446.  
  447. handlers[i].fn.call(scope, args, xdomainArgs, callback);
  448.  
  449. // remove handler if id equals call object id
  450. if (handlers[i].id === args.id) {
  451. handlers.splice(i, 1);
  452. i--;
  453. }
  454. } else {
  455. handlers[i].call(scope, args, xdomainArgs, callback);
  456. }
  457. i++;
  458. }
  459. }
  460. };
  461. };
  462. return new ConstructorFn();
  463. } else {
  464. return function(args) {
  465. registry.removeFunction(fname);
  466. callback.call(this, args);
  467. };
  468. }
  469. }
  470.  
  471. function getPathToOriginProxy() {
  472. var url = window.location.toString();
  473. var protocolDelim = "://";
  474. var domainDelims = ["/", "?", "#"];
  475. var start = url.indexOf(protocolDelim);
  476. var protocol = "";
  477. if (-1 !== start) {
  478. var parts = url.split(protocolDelim);
  479. protocol = parts[0] + protocolDelim;
  480. url = parts[1];
  481. for(var i = 0; i < domainDelims.length; i++) {
  482. var end = url.indexOf(domainDelims[i]);
  483. if (-1 !== end) {
  484. url = url.substring(0, end);
  485. break;
  486. }
  487. }
  488. }
  489. return protocol + url;
  490. }
  491.  
  492. /**
  493. * Make a call to the callee domain
  494. */
  495. function execute(fname, args, callback) {
  496. var isExistingEventType;
  497. if (isSalesforceNativePage()) {
  498. // no need to do cross-domain messaging
  499. var targetCallRegistry = top.Sfdc.crossdomain.CrossDomainApiRegistry.getFunction(fname),
  500. embeddedVFPages = top.Sfdc.xdomain.EmbeddedVFPages;
  501. frameId = window.name;
  502.  
  503. if (window.parent !== window.top && embeddedVFPages) {
  504. // in an embedded VF page
  505. frameId = embeddedVFPages[frameId] || frameId;
  506. }
  507.  
  508. // register event callback if needed
  509. if (typeof(callback) === 'function' && args.event) {
  510. if (registry.getFunction(fname)) {
  511. isExistingEventType = registry.getFunction(fname).func.add(callback, args);
  512. if (isExistingEventType) {
  513. // since the event type already exists, return right away to avoid an unnecessary x-domain call
  514. return {success : true};
  515. } // TODO: wrong comment, remove it after verification. for global event, do an x-domain call to update the registry
  516. } else {
  517. registry.registerFunction(fname, wrapCallback(fname, callback, args), this);//TODO: check the scope
  518. }
  519.  
  520. return targetCallRegistry.func.call(targetCallRegistry.scope, args, {frameId : frameId}, function(result) {
  521. registry.getFunction(fname).func.call(this, result); //TODO: check the scope
  522. });
  523. }
  524.  
  525. return targetCallRegistry.func.call(targetCallRegistry.scope, args, {frameId : frameId}, callback);
  526. } else {
  527. // register callback if needed
  528. if (typeof(callback) === 'function') {
  529. var functionName = args.event ? fname : fname + '_' + txn_id;
  530. if (args.event && registry.getFunction(functionName)) {
  531. isExistingEventType = registry.getFunction(functionName).func.add(callback, args);
  532. if (isExistingEventType) {
  533. // since the event type already exists, return right away to avoid an unnecessary x-domain call
  534. return;
  535. } // for global event, do an x-domain call to update the registry
  536. } else {
  537. registry.registerFunction(functionName, wrapCallback(functionName, callback, args), this);
  538. }
  539. }
  540. var callContext = {};
  541. callContext.pathToTargetProxy = caller ? Sfdc.xdomain.sfdcXDomainProxy : '';
  542. callContext.name = fname;
  543. callContext.args = args;
  544. callContext.calleeName = CALLEE_NAME;
  545. callContext.txn_id = txn_id;
  546. callContext.pathToOriginProxy = getPathToOriginProxy() + (caller ? '/support/console/xdomain/30.0/crossDomainProxy.html' : '');
  547. txn_id++;
  548.  
  549. if (postMessageClient.usePostMessage()) {
  550. postMessageClient.doPostMessage(callContext);
  551. } else {
  552. caller.call(callContext);
  553. }
  554. }
  555. }
  556.  
  557. /**
  558. * Encode boolean parameter
  559. *
  560. * if true, return string "true"
  561. * false, return an empty string [represent false value in js]
  562. */
  563. function encodeBooleanParam(param) {
  564. return !!param;
  565. }
  566.  
  567. /**
  568. * Validate the event type used in Global Event Model. Return true if valid, false otherwise.
  569. */
  570. function validateEventType(eventType) {
  571. return eventType && (typeof eventType === 'string');
  572. }
  573.  
  574. /**
  575. * Validate the event handler used in Global Event Model. Return true if valid, false otherwise.
  576. */
  577. function validateEventHandler(eventHandler) {
  578. return eventHandler && (typeof eventHandler === 'function');
  579. }
  580.  
  581. /**
  582. * An object responsible for managing console events and providing helper functions around them
  583. */
  584. var ConsoleEventManager = (function() {
  585. var CONSOLE_EVENT_PREFIX = 'SFORCE_CONSOLE';
  586. var CONSOLE_EVENT_NAME_SEPERATOR = ':';
  587. var TAB_EVENT_SUFFIX = '_TAB';
  588. var PRESENCE_EVENT_PREFIX = 'SFORCE_PRESENCE';
  589.  
  590. // Supported event types
  591. var EVENT_TYPES = {
  592. CLOSE_TAB : CONSOLE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'CLOSE_TAB',
  593. OPEN_TAB : CONSOLE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'OPEN_TAB',
  594. CONSOLE_LOGOUT : CONSOLE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'LOGOUT',
  595. PRESENCE : {
  596. LOGIN_SUCCESS : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'LOGIN_SUCCESS',
  597. STATUS_CHANGED : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'STATUS_CHANGED',
  598. SFDC_LOGOUT : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'LOGOUT',
  599. LOGOUT : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'LOGOUT',
  600. WORK_ASSIGNED : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'WORK_ASSIGNED',
  601. WORK_ACCEPTED : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'WORK_ACCEPTED',
  602. WORK_DECLINED : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'WORK_DECLINED',
  603. WORK_CLOSED : PRESENCE_EVENT_PREFIX + CONSOLE_EVENT_NAME_SEPERATOR + 'WORK_CLOSED'
  604. }
  605. };
  606.  
  607. var isTypeEndWith = function(eventType, suffix) {
  608. if (eventType && suffix) {
  609. return (eventType.indexOf(suffix) + suffix.length) === eventType.length;
  610. }
  611.  
  612. return false;
  613. };
  614.  
  615. return {
  616. getTypes : function() {
  617. return EVENT_TYPES;
  618. },
  619.  
  620. getFullyQualifiedEventType : function(eventType, additionalParams) {
  621. if (isTypeEndWith(eventType, TAB_EVENT_SUFFIX) && additionalParams && additionalParams.tabId) {
  622. // it's a tab event
  623. eventType = [eventType, additionalParams.tabId].join(CONSOLE_EVENT_NAME_SEPERATOR);
  624. }
  625.  
  626. return eventType;
  627. },
  628.  
  629. isConsoleEventType : function(eventType) {
  630. for (var type in EVENT_TYPES) {
  631. if (EVENT_TYPES.hasOwnProperty(type) && EVENT_TYPES[type] === eventType) {
  632. return true;
  633. }
  634. }
  635.  
  636. return false;
  637. }
  638. };
  639. })();
  640.  
  641. return {
  642. /**
  643. * Create a Workspace with the given url. If the workspace already exists, navigate it to the url.
  644. * @param version
  645. * @param id (optional) id of an existing Workspace
  646. * @param url url of the Workspace
  647. * @param activate true to make the Workspace activate, false otherwise
  648. * @param label String text to put into the Workspace tab
  649. * @param callback (optional) a callback function to be invoked after the function exits.
  650. */
  651. openPrimaryTab: function (id, url, activate, label, callback, name) {
  652. var args = {};
  653. if (id) { args.id = id; }
  654. if (typeof(url) !== 'undefined') { args.url = url; }
  655. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  656. if (typeof(label) !== 'undefined') { args.label = label; }
  657. if (typeof(name) !== 'undefined') { args.name = name; }
  658. args.version = VERSION;
  659. execute('openPrimaryTab', args, callback);
  660. },
  661.  
  662. /**
  663. * Open a subtab
  664. * @param id (optional) id of an existing view
  665. * @param workspaceId id of an existing workspace
  666. * @param url
  667. * @param activate
  668. * @param label
  669. * @param name
  670. */
  671. openSubtab:function(workspaceId, url, activate, label, id, callback, name) {
  672. var args = {};
  673. if (workspaceId) { args.workspaceId = workspaceId; }
  674. if (typeof(url) !== 'undefined') { args.url = url; }
  675. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  676. if (typeof(label) !== 'undefined') { args.label = label; }
  677. if (id) { args.id = id; }
  678. if (name) { args.name = name; }
  679. args.version = VERSION;
  680. execute('openSubTab', args, callback);
  681. },
  682. /**
  683. * Open a subtab
  684. * @param id (optional) id of an existing view
  685. * @param workspaceName name of an existing workspace
  686. * @param url
  687. * @param activate
  688. * @param label
  689. * @param name
  690. */
  691. openSubtabByPrimaryTabName:function(workspaceName, url, activate, label, id, callback, name) {
  692. var args = {};
  693. if (workspaceName) { args.workspaceName = workspaceName; }
  694. if (typeof(url) !== 'undefined') { args.url = url; }
  695. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  696. if (typeof(label) !== 'undefined') { args.label = label; }
  697. if (id) { args.id = id; }
  698. if (name) { args.name = name; }
  699. args.version = VERSION;
  700. execute('openSubtabByWorkSpaceName', args, callback);
  701. },
  702.  
  703. /**
  704. * Get enclosing tab id of this frame
  705. */
  706. getEnclosingTabId:function(callback) {
  707. var args = {};
  708. args.version = VERSION;
  709. execute('getEnclosingTabId', args, callback);
  710. },
  711.  
  712. /**
  713. * Get the primary tab id of this subtab
  714. * @param frameId id of of the current frame
  715. */
  716. getEnclosingPrimaryTabId:function(callback) {
  717. var args = {};
  718. args.version = VERSION;
  719. return execute('getEnclosingPrimaryTabId', args, callback);
  720. },
  721.  
  722. /**
  723. * Gets the primary tab object id of this subtab
  724. */
  725. getEnclosingPrimaryTabObjectId:function(callback) {
  726. var args = {};
  727. args.version = VERSION;
  728. execute('getEnclosingPrimaryTabObjectId', args, callback);
  729. },
  730.  
  731. /**
  732. * Returns the currently opened primary tab ids
  733. */
  734. getPrimaryTabIds:function(callback) {
  735. var args = {};
  736. args.version = VERSION;
  737. execute('getPrimaryTabIds', args, callback);
  738. },
  739.  
  740. /**
  741. * Returns the currently opened sub tab ids
  742. */
  743. getSubtabIds:function(primaryTabId, callback) {
  744. var args = {};
  745. args.version = VERSION;
  746. if (primaryTabId) {
  747. args.primaryTabId = primaryTabId;
  748. }
  749. execute('getSubtabIds', args, callback);
  750. },
  751.  
  752. /**
  753. * Returns the page info of the entity specified by the tab
  754. */
  755. getPageInfo:function(tabId, callback) {
  756. var args = {};
  757. args.version = VERSION;
  758. if (tabId) {
  759. args.tabId = tabId;
  760. }
  761. execute('getPageInfo', args, callback);
  762. },
  763.  
  764. /**
  765. * Gets the object id of the focused subtab
  766. */
  767. getFocusedSubtabObjectId:function(callback) {
  768. var args = {};
  769. args.version = VERSION;
  770. execute('getFocusedSubtabObjectId', args, callback);
  771. },
  772.  
  773. resetSessionTimeOut:function() {
  774. var args = {};
  775. args.version = VERSION;
  776. execute('resetSessionTimeOut', args);
  777. },
  778.  
  779. /**
  780. * Sets the tab title of the enclosing tab
  781. * @param frameId
  782. * @param label
  783. * @param tabId
  784. */
  785. setTabTitle:function(label, tabId) {
  786. var args = {};
  787. args.label = label;
  788. if (tabId) {
  789. args.tabId = tabId;
  790. }
  791. args.version = VERSION;
  792. execute('setTabTitle', args);
  793. },
  794.  
  795. /**
  796. * Closes the tab with the given id. Note that closing the first tab in a primary tab closes the primary tab itself
  797. * @param id id of the view or workspace to close
  798. */
  799. closeTab:function(id) {
  800. var args = {};
  801. args.id = id;
  802. args.version = VERSION;
  803. execute('closeTab', args);
  804. },
  805.  
  806. /**
  807. * Return true if this page is a console page
  808. */
  809. isInConsole: function() {
  810. var qs = location.search;
  811.  
  812. return !(typeof sforce != "undefined" && sforce.one) &&
  813. (qs.length !== 0 && ((qs.indexOf("?isdtp=") > -1)
  814. || (qs.indexOf("&isdtp=") > -1)))
  815. || canvasClient.isInConsole();
  816. },
  817.  
  818. /**
  819. * Refreshes the tab with the given id with the last known url. Note that if the frame is cross-domain, our knowledge of the last known
  820. * url could be very stale. Api users should really be handling their own refreshes
  821. * @param version
  822. * @param id id of the view to refresh with last known url
  823. * @param activate true to activate this tab
  824. */
  825. refreshSubtabById: function(id, activate, callback) {
  826. var args = {};
  827. if (id) { args.id = id; }
  828. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  829. args.version = VERSION;
  830. execute('refreshSubtabById', args, callback);
  831. },
  832. /**
  833. * Refreshes the tab with the given subtab name and its workspace name with the last known url. Note that if the frame is cross-domain, our knowledge of the last known
  834. * url could be very stale. Api users should really be handling their own refreshes
  835. * @param version
  836. * @param name name of the subtab to refresh with last known url
  837. * @param workspaceName name of the primary tab of the subtab
  838. * @param activate true to activate this tab
  839. */
  840. refreshSubtabByNameAndPrimaryTabName: function(name, workspaceName, activate, callback) {
  841. var args = {};
  842. if (name) { args.name = name; }
  843. if (workspaceName) { args.workspaceName = workspaceName; }
  844. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  845. args.version = VERSION;
  846. execute('refreshSubtabByNameAndWorkspaceName', args, callback);
  847. },
  848.  
  849. /**
  850. * Refreshes the tab with the given subtab name and its workspace id with the last known url. Note that if the frame is cross-domain, our knowledge of the last known
  851. * url could be very stale. Api users should really be handling their own refreshes
  852. * @param version
  853. * @param name name of the subtab to refresh with last known url
  854. * @param workspaceId id of the primary tab of the subtab
  855. * @param activate true to activate this tab
  856. */
  857. refreshSubtabByNameAndPrimaryTabId: function(name, workspaceId, activate, callback) {
  858. var args = {};
  859. if (name) { args.name = name; }
  860. if (workspaceId) { args.workspaceId = workspaceId; }
  861. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  862. args.version = VERSION;
  863. execute('refreshSubtabByNameAndWorkspaceId', args, callback);
  864. },
  865.  
  866. /**
  867. * Refreshes the primary tab with the given id. Note the each tab refresh behavior is the same as refreshSubtab methods
  868. * @param workspaceId id of the primary tab
  869. * @param activate true to activate this tab
  870. */
  871. refreshPrimaryTabById: function(id, activate, callback) {
  872. var args = {};
  873. if (id) { args.id = id; }
  874. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  875. args.version = VERSION;
  876. execute('refreshPrimaryTabById', args, callback);
  877. },
  878.  
  879. /**
  880. * Refreshes the primary tab with the given name. Note the each tab refresh behavior is the same as refreshSubtab methods
  881. */
  882. refreshPrimaryTabByName: function(name, activate, callback) {
  883. var args = {};
  884. if (name) { args.name = name; }
  885. if (typeof(activate) !== 'undefined') { args.activate = encodeBooleanParam(activate); }
  886. args.version = VERSION;
  887. execute('refreshPrimaryTabByName', args, callback);
  888. },
  889.  
  890. /**
  891. * Activates the tab with the given id
  892. * @param version
  893. * @param id id of the view
  894. */
  895. focusSubtabById: function(id, callback) {
  896. var args = {};
  897. if (id) { args.id = id; }
  898. args.version = VERSION;
  899. execute('focusSubtabById', args, callback);
  900. },
  901.  
  902. /**
  903. * Activates the tab with the given subtab name and its workspace name
  904. * @param version
  905. * @param name name of the subtab
  906. * @param workspaceName name of the primary tab of the subtab
  907. */
  908. focusSubtabByNameAndPrimaryTabName: function(name, workspaceName, callback) {
  909. var args = {};
  910. if (name) { args.name = name; }
  911. if (workspaceName) { args.workspaceName = workspaceName; }
  912. args.version = VERSION;
  913. execute('focusSubtabByNameAndWorkspaceName', args, callback);
  914. },
  915.  
  916. /**
  917. * Activates the tab with the given subtab name and its workspace id
  918. * @param version
  919. * @param name name of the subtab to refresh with last known url
  920. * @param workspaceId id of the primary tab of the subtab
  921. */
  922. focusSubtabByNameAndPrimaryTabId: function(name, workspaceId, callback) {
  923. var args = {};
  924. if (name) { args.name = name; }
  925. if (workspaceId) { args.workspaceId = workspaceId; }
  926. args.version = VERSION;
  927. execute('focusSubtabByNameAndWorkspaceId', args, callback);
  928. },
  929.  
  930. /**
  931. * Activates the primary tab with the given id.
  932. * @param workspaceId id of the primary tab
  933. */
  934. focusPrimaryTabById: function(id, callback) {
  935. var args = {};
  936. if (id) { args.id = id; }
  937. args.version = VERSION;
  938. execute('focusPrimaryTabById', args, callback);
  939. },
  940.  
  941. /**
  942. * Activates the primary tab with the given name.
  943. */
  944. focusPrimaryTabByName: function(name, callback) {
  945. var args = {};
  946. if (name) { args.name = name; }
  947. args.version = VERSION;
  948. execute('focusPrimaryTabByName', args, callback);
  949. },
  950.  
  951. /**
  952. * sets myself dirty
  953. * @param dirtyState to set current tab to dirty, can be true or false
  954. * @param callback
  955. * @param subtabId
  956. */
  957. setTabUnsavedChanges:function(dirtyState, callback, subtabId) {
  958. var args = {};
  959. if (typeof(dirtyState) !== 'undefined') { args.isDirty = encodeBooleanParam(dirtyState); }
  960. args.version = VERSION;
  961. if (subtabId) {
  962. args.subtabId = subtabId;
  963. }
  964. execute('setTabDirty', args, callback);
  965. },
  966.  
  967. /**
  968. * Register event handler that will be called when the user clicks 'Save'
  969. * from the 'Unsaved Changes' dialog upon closing a dirty tab.
  970. */
  971. onTabSave:function(eventHandler) {
  972. var args = {};
  973. args.version = VERSION;
  974. args.event = true;
  975. execute('onTabSave', args, eventHandler);
  976. },
  977.  
  978. /**
  979. * Register event handler that will be fired when focus changes to a different subtab
  980. */
  981. onFocusedSubtab:function(eventHandler) {
  982. var args = {};
  983. args.version = VERSION;
  984. args.event = true;
  985. execute('onFocusedSubtab', args, eventHandler);
  986. },
  987.  
  988. /**
  989. * Register event handler that will be fired when focus changes to a different subtab
  990. */
  991. onFocusedPrimaryTab:function(eventHandler) {
  992. var args = {};
  993. args.version = VERSION;
  994. args.event = true;
  995. execute('onFocusedPrimaryTab', args, eventHandler);
  996. },
  997.  
  998. /**
  999. * Register event handler that will be fired when enclosing tab refreshes
  1000. */
  1001. onEnclosingTabRefresh:function(eventHandler) {
  1002. var args = {};
  1003. args.version = VERSION;
  1004. args.event = true;
  1005. execute('onEnclosingTabRefresh', args, eventHandler);
  1006. },
  1007.  
  1008. /**
  1009. * Console-level API
  1010. */
  1011.  
  1012. /**
  1013. * Get the id of the currently focused primary tab
  1014. */
  1015. getFocusedPrimaryTabId:function(callback) {
  1016. var args = {};
  1017. args.version = VERSION;
  1018. execute('getFocusedPrimaryTabId', args, callback);
  1019. },
  1020.  
  1021. /**
  1022. * Get the object id of the currently focused primary tab
  1023. */
  1024. getFocusedPrimaryTabObjectId:function(callback) {
  1025. var args = {};
  1026. args.version = VERSION;
  1027. execute('getFocusedPrimaryTabObjectId', args, callback);
  1028. },
  1029.  
  1030. /**
  1031. * Get the id of the currently focused subtab
  1032. */
  1033. getFocusedSubtabId:function(callback) {
  1034. var args = {};
  1035. args.version = VERSION;
  1036. execute('getFocusedSubtabId', args, callback);
  1037. },
  1038.  
  1039. /**
  1040. * Custom Console Component API
  1041. */
  1042.  
  1043. /**
  1044. * Check if the current page is rendered within a Custom Console Component
  1045. */
  1046. isInCustomConsoleComponent:function(callback) {
  1047. var args = {};
  1048. args.version = VERSION;
  1049. execute('isInCustomConsoleComponent', args, callback);
  1050. },
  1051.  
  1052. /**
  1053. * Set the button text of the Custom Console Component in which the page is rendered
  1054. */
  1055. setCustomConsoleComponentButtonText:function(text, callback) {
  1056. var args = {};
  1057. args.version = VERSION;
  1058. args.text = text;
  1059. execute('setCustomConsoleComponentButtonText', args, callback);
  1060. },
  1061.  
  1062. /**
  1063. * Set the button style of the Custom Console Component in which the page is rendered
  1064. */
  1065. setCustomConsoleComponentButtonStyle:function(style, callback) {
  1066. var args = {};
  1067. args.version = VERSION;
  1068. args.style = style;
  1069. execute('setCustomConsoleComponentButtonStyle', args, callback);
  1070. },
  1071.  
  1072. /**
  1073. * Set the button icon URL of the Custom Console Component in which the page is rendered
  1074. */
  1075. setCustomConsoleComponentButtonIconUrl:function(iconUrl, callback) {
  1076. var args = {};
  1077. args.version = VERSION;
  1078. args.iconUrl = iconUrl;
  1079. execute('setCustomConsoleComponentButtonIconUrl', args, callback);
  1080. },
  1081.  
  1082. /**
  1083. * Set the window visibility of the Custom Console Component in which the page is rendered
  1084. */
  1085. setCustomConsoleComponentVisible:function(visible, callback) {
  1086. var args = {};
  1087. args.version = VERSION;
  1088. args.visible = encodeBooleanParam(visible);
  1089. execute('setCustomConsoleComponentWindowVisible', args, callback);
  1090. },
  1091.  
  1092. /**
  1093. * Know if the Custom Console Component window is visible or not
  1094. */
  1095. isCustomConsoleComponentHidden:function(callback) {
  1096. var args = {};
  1097. args.version = VERSION;
  1098. execute('isCustomConsoleComponentWindowHidden', args, callback);
  1099. },
  1100.  
  1101. /**
  1102. * Set the window width of the Custom Console Component in which the page is rendered
  1103. */
  1104. setCustomConsoleComponentWidth:function(width, callback) {
  1105. var args = {};
  1106. args.version = VERSION;
  1107. args.width = width;
  1108. execute('setCustomConsoleComponentWidth', args, callback);
  1109. },
  1110.  
  1111. /**
  1112. * Set the window height of the Custom Console Component in which the page is rendered
  1113. */
  1114. setCustomConsoleComponentHeight:function(height, callback) {
  1115. var args = {};
  1116. args.version = VERSION;
  1117. args.height = height;
  1118. execute('setCustomConsoleComponentHeight', args, callback);
  1119. },
  1120.  
  1121. /**
  1122. * Register event handler that will be called when the Custom Console Component button is clicked
  1123. */
  1124. onCustomConsoleComponentButtonClicked:function(eventHandler) {
  1125. var args = {};
  1126. args.version = VERSION;
  1127. args.event = true;
  1128. execute('onCustomConsoleComponentButtonClicked', args, eventHandler);
  1129. },
  1130.  
  1131. /**
  1132. * Scroll the button text of the Custom Console Component in a fixed interval
  1133. */
  1134. scrollCustomConsoleComponentButtonText:function(interval, pixelsToScroll, isLeftScrolling, callback) {
  1135. var args = {};
  1136. args.version = VERSION;
  1137. args.interval = interval;
  1138. args.pixelsToScroll = pixelsToScroll;
  1139. args.isLeftScrolling = encodeBooleanParam(isLeftScrolling);
  1140. execute('scrollCustomConsoleComponentButtonText', args, callback);
  1141. },
  1142.  
  1143. /**
  1144. * Cancel the scrolling of Custom Console Component button text
  1145. */
  1146. removeScrollCustomConsoleComponentButtonText:function(callback) {
  1147. var args = {};
  1148. args.version = VERSION;
  1149. execute('removeScrollCustomConsoleComponentButtonText', args, callback);
  1150. },
  1151.  
  1152. /**
  1153. * Blink the button text of the Custom Console Component in a fixed interval
  1154. */
  1155. blinkCustomConsoleComponentButtonText:function(alternateText, interval, callback) {
  1156. var args = {};
  1157. args.version = VERSION;
  1158. args.alternateText = alternateText;
  1159. args.interval = interval;
  1160. execute('blinkCustomConsoleComponentButtonText', args, callback);
  1161. },
  1162.  
  1163. /**
  1164. * Cancel the blinking of Custom Console Component button text
  1165. */
  1166. removeBlinkCustomConsoleComponentButtonText:function(callback) {
  1167. var args = {};
  1168. args.version = VERSION;
  1169. execute('removeBlinkCustomConsoleComponentButtonText', args, callback);
  1170. },
  1171.  
  1172. /**
  1173. * Set whether the Custom Console Component is popoutable or not
  1174. */
  1175. setCustomConsoleComponentPopoutable:function(popoutable, callback) {
  1176. var args = {};
  1177. args.version = VERSION;
  1178. args.popoutable = !!popoutable;
  1179. execute('setCustomConsoleComponentPopoutable', args, callback);
  1180. },
  1181.  
  1182. /**
  1183. * Know if the Custom Console Component is popped out or not
  1184. */
  1185. isCustomConsoleComponentPoppedOut:function(callback) {
  1186. var args = {};
  1187. args.version = VERSION;
  1188. execute('isCustomConsoleComponentPoppedOut', args, callback);
  1189. },
  1190.  
  1191. /**
  1192. * Add a listener for the specified event type
  1193. */
  1194. addEventListener:function(eventType, eventHandler, additionalParams) {
  1195. if (!(validateEventType(eventType) && validateEventHandler(eventHandler))) {
  1196. return;
  1197. }
  1198.  
  1199. if (ConsoleEventManager.isConsoleEventType(eventType)) {
  1200. // additional processing for console events
  1201. eventType = ConsoleEventManager.getFullyQualifiedEventType(eventType, additionalParams);
  1202. }
  1203.  
  1204. var args = {};
  1205. args.version = VERSION;
  1206. args.event = true;
  1207. args.eventType = eventType;
  1208. execute(ADD_EVENT_LISTENER, args, eventHandler);
  1209. },
  1210.  
  1211. /**
  1212. * Remove a listener for the specified event type
  1213. */
  1214. removeEventListener:function(eventType, eventHandler, additionalParams) {
  1215. if (!(validateEventType(eventType) && validateEventHandler(eventHandler))) {
  1216. return;
  1217. }
  1218.  
  1219. if (ConsoleEventManager.isConsoleEventType(eventType)) {
  1220. // additional processing for console events
  1221. eventType = ConsoleEventManager.getFullyQualifiedEventType(eventType, additionalParams);
  1222. }
  1223.  
  1224. var args = {};
  1225. args.version = VERSION;
  1226. args.eventType = eventType;
  1227. var cleanUpOptions = registry.getFunction(ADD_EVENT_LISTENER).func.del(eventHandler, args);
  1228. if (cleanUpOptions) {
  1229. args.unregisterFrameForEvent = cleanUpOptions.unregisterFrameForEvent;
  1230. args.unregisterFrameForEveryEvent = cleanUpOptions.unregisterFrameForEveryEvent;
  1231. }
  1232.  
  1233. if (args.removeFrameFromEvent || args.removeFrameFromEveryEvent) {
  1234. execute('removeEventListener', args);
  1235. }
  1236. },
  1237.  
  1238. /**
  1239. * Fire an event of the specified type
  1240. */
  1241. fireEvent:function(eventType, message, callback) {
  1242. if (!validateEventType(eventType)) {
  1243. return;
  1244. }
  1245.  
  1246. var args = {};
  1247. args.version = VERSION;
  1248. args.eventType = eventType;
  1249. args.message = message;
  1250. execute('fireEvent', args, callback);
  1251. },
  1252.  
  1253. /**
  1254. * enum representing the types of console events
  1255. */
  1256. ConsoleEvent: ConsoleEventManager.getTypes(),
  1257.  
  1258. /**
  1259. * add a listener to a push notification based on given entities
  1260. */
  1261. addPushNotificationListener:function(entities, callback) {
  1262. var args = {};
  1263. // only allow one listener
  1264. if (registry.getFunction(ADD_PUSH_NOTIFICATION_LISTENER)) {
  1265. if (window.console && console.log) {
  1266. console.log('There already exists a listener for the push notification on this page');
  1267. }
  1268. return false;
  1269. }
  1270. args.version = VERSION;
  1271. args.entities = entities;
  1272. args.event = true;
  1273. execute(ADD_PUSH_NOTIFICATION_LISTENER, args, callback);
  1274. },
  1275.  
  1276. removePushNotificationListener:function(callback) {
  1277. if (registry.getFunction(ADD_PUSH_NOTIFICATION_LISTENER)) {
  1278. registry.removeFunction(ADD_PUSH_NOTIFICATION_LISTENER);
  1279. var args = {};
  1280. args.version = VERSION;
  1281. execute('removePushNotificationListener', args, callback);
  1282. }
  1283. },
  1284.  
  1285. /**
  1286. * add a browser tab title to a list of titles rotating every three seconds
  1287. */
  1288. addToBrowserTitleQueue:function(title, callback) {
  1289. var args = {};
  1290. args.version = VERSION;
  1291. if (title) {
  1292. args.title = title;
  1293. }
  1294. execute('addToBrowserTitleQueue', args, callback);
  1295. },
  1296.  
  1297. /**
  1298. * remove a browser tab title from the list of titles rotating every three seconds
  1299. */
  1300. removeFromBrowserTitleQueue:function(title, callback) {
  1301. var args = {};
  1302. args.version = VERSION;
  1303. if (title) {
  1304. args.title = title;
  1305. }
  1306. execute('removeFromBrowserTitleQueue', args, callback);
  1307. },
  1308.  
  1309. /**
  1310. * retrieve tab link based on level & id passed in
  1311. */
  1312. getTabLink:function(level, tabId, callback) {
  1313. var args = {};
  1314. args.version = VERSION;
  1315. if(level) {
  1316. args.level = level;
  1317. }
  1318. if(tabId) {
  1319. args.tabId = tabId;
  1320. }
  1321. execute('getTabLink', args, callback);
  1322. },
  1323.  
  1324. /**
  1325. * customize the CSS styling of a tab based on the passed-in tabId and style
  1326. */
  1327. setTabStyle:function(style, tabId, callback) {
  1328. var args = {};
  1329.  
  1330. if (style) {
  1331. args.css = style;
  1332. }
  1333.  
  1334. if (tabId) {
  1335. args.tabId = tabId;
  1336. }
  1337.  
  1338. args.version = VERSION;
  1339. execute('setTabStyle', args, callback);
  1340. },
  1341.  
  1342. /**
  1343. * customize the CSS styling of a tab's text based on the passed-in tabId and style
  1344. */
  1345. setTabTextStyle:function(style, tabId, callback) {
  1346. var args = {};
  1347.  
  1348. if (style) {
  1349. args.css = style;
  1350. }
  1351.  
  1352. if (tabId) {
  1353. args.tabId = tabId;
  1354. }
  1355.  
  1356. args.version = VERSION;
  1357. execute('setTabTextStyle', args, callback);
  1358. },
  1359.  
  1360. /**
  1361. * customize the icon of a tab based on the passed-in tabId and iconUrl
  1362. */
  1363. setTabIcon:function(iconUrl, tabId, callback) {
  1364. var args = {};
  1365.  
  1366. if (iconUrl) {
  1367. args.iconUrl = iconUrl;
  1368. }
  1369.  
  1370. if (tabId) {
  1371. args.tabId = tabId;
  1372. }
  1373.  
  1374. args.version = VERSION;
  1375. execute('setTabIcon', args, callback);
  1376. },
  1377.  
  1378. /**
  1379. * enum representing the level of tab link you want, for getTabLink
  1380. */
  1381. TabLink: {
  1382. PARENT_AND_CHILDREN:'complete',
  1383. TAB_ONLY:'thistabonly',
  1384. SALESFORCE_URL:'standard'
  1385. },
  1386.  
  1387. /**
  1388. * enum representing the console regions, for setSidebarVisible
  1389. */
  1390. Region: {
  1391. LEFT:'left',
  1392. RIGHT:'right',
  1393. TOP:'top',
  1394. BOTTOM:'bottom'
  1395. },
  1396.  
  1397. /**
  1398. * set the link for the current external subtab
  1399. */
  1400. setTabLink:function(callback) {
  1401. var args = {};
  1402. args.version = VERSION;
  1403. args.link = window.location.href;
  1404. execute('setTabLink', args, callback);
  1405. },
  1406.  
  1407. /**
  1408. * generate a console url based on a number of passed in urls
  1409. */
  1410. generateConsoleUrl:function(urls, callback) {
  1411. var args = {};
  1412. args.version = VERSION;
  1413. if(urls) {
  1414. args.urls = urls;
  1415. }
  1416. execute('generateConsoleUrl', args, callback);
  1417. },
  1418.  
  1419. /**
  1420. * Opens a console URL
  1421. * 1. The passed-in console link will always be opened as a primary tab.
  1422. * 2. The target tab id is optional, if passed-in, it must be a primary tab ID
  1423. * 3. The first entry in tabLabels as well as tabNames is used to override primary tab, the rest are the subsequent subtabs
  1424. */
  1425. openConsoleUrl:function(tabId, consoleUrl, active, tabLabels, tabNames, callback) {
  1426. var args = {};
  1427. args.version = VERSION;
  1428. if(tabId) {
  1429. args.tabId = tabId;
  1430. }
  1431.  
  1432. if(consoleUrl) {
  1433. args.consoleUrl = consoleUrl;
  1434. }
  1435.  
  1436. if (typeof(active) !== 'undefined') {
  1437. args.active = encodeBooleanParam(active);
  1438. }
  1439.  
  1440. if(tabLabels) {
  1441. args.tabLabels = tabLabels;
  1442. }
  1443.  
  1444. if(tabNames) {
  1445. args.tabNames = tabNames;
  1446. }
  1447. execute('openConsoleUrl', args, callback);
  1448. },
  1449.  
  1450. /**
  1451. * Method to get the unique identifier of selected tab
  1452. */
  1453. getSelectedNavigationTab : function(callback) {
  1454. var args = {};
  1455. args.version = VERSION;
  1456. execute('getSelectedNavigationTab', args, callback);
  1457. },
  1458.  
  1459.  
  1460. /**
  1461. * Method to set Navigation tab with tab unique identifier
  1462. */
  1463. setSelectedNavigationTab : function(callback, navigationTabId,listViewUrl) {
  1464. var args = {};
  1465. args.version = VERSION;
  1466.  
  1467. if (listViewUrl) {
  1468. args.listViewUrl = listViewUrl;
  1469. }
  1470. if (navigationTabId) {
  1471. args.navigationTabId = navigationTabId;
  1472. }
  1473.  
  1474. execute('setSelectedNavigationTab', args, callback);
  1475. },
  1476. /**
  1477. * Method to get all the items in the navigation panel
  1478. */
  1479. getNavigationTabs : function(callback) {
  1480. var args = {};
  1481. args.version = VERSION;
  1482. execute('getNavigationTabs', args, callback);
  1483. },
  1484.  
  1485.  
  1486. /**
  1487. * Method to focus on the navigation panel
  1488. */
  1489. focusNavigationTab : function(callback) {
  1490. var args = {};
  1491. args.version = VERSION;
  1492. execute('focusNavigationTab', args, callback);
  1493. },
  1494.  
  1495. /**
  1496. * Method to refresh on the navigation panel
  1497. */
  1498. refreshNavigationTab : function(callback) {
  1499. var args = {};
  1500. args.version = VERSION;
  1501. execute('refreshNavigationTab', args, callback);
  1502. },
  1503.  
  1504. /**
  1505. * Method to set sidebar visible or not
  1506. */
  1507. setSidebarVisible:function(visible, tabId, region, callback) {
  1508. var args = {};
  1509. args.version = VERSION;
  1510. if (typeof visible === 'boolean'){
  1511. args.visible = visible;
  1512. }
  1513. if (tabId) {
  1514. args.tabId = tabId;
  1515. }
  1516. if (region) {
  1517. args.region = region.toLowerCase();
  1518. }
  1519. execute('setSidebarVisible', args, callback);
  1520. },
  1521.  
  1522. /**
  1523. * Modules supported by the integration toolkit
  1524. */
  1525. modules : {
  1526. CTI : 'CTI',
  1527. CHAT : 'CHAT'
  1528. },
  1529.  
  1530. helper : (function() {
  1531. return {
  1532. execute : function() {
  1533. // delegate to the private execute() function
  1534. return execute.apply(null, arguments);
  1535. },
  1536.  
  1537. getVersion : function() {
  1538. return VERSION;
  1539. }
  1540. };
  1541. })(),
  1542.  
  1543. /**
  1544. * Dynamically load the specified module
  1545. */
  1546. include : function(moduleName, callback, scope) {
  1547. var pathToModule = '/support/console/' + this.helper.getVersion() + '/integration_' + moduleName + '.js';
  1548. var head = document.getElementsByTagName('head')[0];
  1549. var script = document.createElement('script');
  1550. var onLoadHandler = function() {
  1551. // invoke callback and remove the script element which is no longer needed
  1552. callback.call(scope);
  1553. head.removeChild(script);
  1554. };
  1555.  
  1556. // load the module via a script element
  1557. script.type = 'text/javascript';
  1558. script.onreadystatechange = function() {
  1559. if (this.readyState === 'complete') {
  1560. onLoadHandler();
  1561. }
  1562. };
  1563. script.onload = onLoadHandler;
  1564. script.src = pathToModule;
  1565. head.appendChild(script);
  1566. }
  1567. };
  1568. })();
  1569.  
  1570. /**
  1571. * CTI Toolkit API
  1572. */
  1573. sforce.console.cti = (function(consoleApiHelper) {
  1574. var execute = function(fname, args, callback) {
  1575. args.version = consoleApiHelper.getVersion();
  1576. return consoleApiHelper.execute(fname, args, callback);
  1577. };
  1578.  
  1579. return {
  1580. /**
  1581. * Returns active call object ids in the order in which they arrived.
  1582. */
  1583. getCallObjectIds:function(callback) {
  1584. var args = {};
  1585. execute('getCallObjectIds', args, callback);
  1586. },
  1587.  
  1588. /**
  1589. * Set active call object ids, where object id at index 0 arrived first
  1590. * and object id at index n-1 arrived last.
  1591. */
  1592. setCallObjectIds:function(callObjectIds, callback) {
  1593. var args = {};
  1594. args.callObjectIds = callObjectIds;
  1595. execute('setCallObjectIds', args, callback);
  1596. },
  1597.  
  1598. /**
  1599. * Returns JSON formatted call attached data of current call, taken from screen pop payload.
  1600. */
  1601. getCallAttachedData:function(callObjectId, callback, additionalParams) {
  1602. var args = {};
  1603. args.callObjectId = callObjectId;
  1604. if (typeof additionalParams === 'object' && additionalParams.hasOwnProperty('getCallType')) {
  1605. args.getCallType = additionalParams.getCallType;
  1606. }
  1607. execute('getCallAttachedData', args, callback);
  1608. },
  1609.  
  1610. /**
  1611. * Sets the call data associated with a call object id.
  1612. */
  1613. setCallAttachedData:function(callObjectId, callData, callType, callback) {
  1614. var args = {};
  1615. args.callObjectId = callObjectId;
  1616. args.callData = callData;
  1617. args.callType = callType;
  1618. execute('setCallAttachedData', args, callback);
  1619. },
  1620.  
  1621. /**
  1622. * Register event handler that will be fired when a call begins.
  1623. */
  1624. onCallBegin:function(eventHandler) {
  1625. var args = {};
  1626. args.event = true;
  1627. execute('onCallBegin', args, eventHandler);
  1628. },
  1629.  
  1630. /**
  1631. * Fires CTI begin call event to notify that a call has started.
  1632. */
  1633. fireOnCallBegin:function(callObjectId, callType, callLabel, callback) {
  1634. var args = {};
  1635. args.callObjectId = callObjectId;
  1636. args.callType = callType;
  1637. args.callLabel = callLabel;
  1638. execute('fireOnCallBegin', args, callback);
  1639. },
  1640.  
  1641. /**
  1642. * Fires CTI end call event to notify that a call has ended.
  1643. */
  1644. fireOnCallEnd:function(callObjectId, callDuration, callDisposition, callback) {
  1645. var args = {};
  1646. args.callObjectId = callObjectId;
  1647. args.callDuration = callDuration;
  1648. args.callDisposition = callDisposition;
  1649. execute('fireOnCallEnd', args, callback);
  1650. },
  1651.  
  1652. /**
  1653. * Register event handler that will be fired when a call ends.
  1654. * CallObjectId is optional, and if specified, event handler is removed after it is fired.
  1655. */
  1656. onCallEnd:function(eventHandler, callObjectId) {
  1657. var args = {};
  1658. args.callObjectId = callObjectId ? callObjectId : null;
  1659. args.event = true;
  1660. execute('onCallEnd', args, eventHandler);
  1661. },
  1662.  
  1663. /**
  1664. * Sends a CTI message
  1665. */
  1666. sendCTIMessage:function(msg, callback) {
  1667. var args = {};
  1668. args.msg = msg;
  1669. execute('sendCTIMessage', args, callback);
  1670. },
  1671.  
  1672. /**
  1673. * Registers a function that is fired when a message is sent with sendCTIMessage API.
  1674. */
  1675. onSendCTIMessage:function(eventHandler) {
  1676. var args = {};
  1677. args.event = true;
  1678. execute('onSendCTIMessage', args, eventHandler);
  1679. },
  1680.  
  1681. /**
  1682. * Registers a function that is fired when the interaction log saves a call log.
  1683. */
  1684. onCallLogSaved:function(eventHandler) {
  1685. var args = {};
  1686. args.event = true;
  1687. execute('onCallLogSaved', args, eventHandler);
  1688. },
  1689.  
  1690. /**
  1691. * Fires onCallLogSaved event to notify listeners that a call log was saved.
  1692. */
  1693. fireOnCallLogSaved:function(id, callback) {
  1694. var args = {};
  1695. args.id = id;
  1696. execute('fireOnCallLogSaved', args, callback);
  1697. }
  1698. };
  1699. })(sforce.console.helper);
  1700.  
  1701. /**
  1702. * Chat Toolkit API
  1703. */
  1704. sforce.console.chat = (function(consoleApiHelper) {
  1705. var execute = function(fname, args, callback) {
  1706. args.version = consoleApiHelper.getVersion();
  1707. return consoleApiHelper.execute(fname, args, callback);
  1708. };
  1709.  
  1710. return {
  1711. /**
  1712. * Retrieves the details for a given primary tab.
  1713. */
  1714. getDetailsByPrimaryTabId: function(primaryTabId, callback) {
  1715. var args = {};
  1716. args.primaryTabId = primaryTabId;
  1717. execute('chatGetDetailsByPrimaryTabId', args, function(res) {
  1718. callback.call(this, {"success": res.success, "primaryTabId": res.primaryTabId ? res.primaryTabId : null, "details": res.result ? JSON.parse(res.result) : null});
  1719. });
  1720. },
  1721.  
  1722. /**
  1723. * Retrieves the details for a given chat
  1724. */
  1725. getDetailsByChatKey: function(chatKey, callback) {
  1726. var args = {};
  1727. args.chatKey = chatKey;
  1728. execute('chatGetDetailsByChatKey', args, function(res) {
  1729. callback.call(this, {"success": res.success, "primaryTabId": res.primaryTabId ? res.primaryTabId : null, "details": res.result ? JSON.parse(res.result) : null});
  1730. });
  1731. },
  1732.  
  1733. /**
  1734. * Retrieves the chat log for a given chat
  1735. */
  1736. getChatLog: function(chatKey, callback) {
  1737. var args = {};
  1738. args.chatKey = chatKey;
  1739. execute('chatGetChatLog', args, function(res) {
  1740. var resultObj = res.result ? JSON.parse(res.result) : null;
  1741. callback.call(this, {"success": res.success, "messages": resultObj ? resultObj.messages : null, "customEvents": resultObj ? resultObj.customEvents : null});
  1742. });
  1743. },
  1744.  
  1745. /**
  1746. * Retrieves the current text entered in the agent's input box
  1747. */
  1748. getAgentInput: function(chatKey, callback) {
  1749. var args = {};
  1750. args.chatKey = chatKey;
  1751. execute('chatGetAgentInput', args, callback);
  1752. },
  1753.  
  1754. /**
  1755. * Sets the current text entered in the agent's input box
  1756. */
  1757. setAgentInput: function(chatKey, text, callback) {
  1758. var args = {};
  1759. args.chatKey = chatKey;
  1760. args.text = text;
  1761. execute('chatSetAgentInput', args, callback);
  1762. },
  1763.  
  1764. /**
  1765. * Sends a message to the chat client
  1766. */
  1767. sendMessage: function(chatKey, message, callback) {
  1768. var args = {};
  1769. args.chatKey = chatKey;
  1770. args.message = message;
  1771. execute('chatSendMessage', args, callback);
  1772. },
  1773.  
  1774. /**
  1775. * on new chat message
  1776. */
  1777. onNewMessage: function(chatKey, callback) {
  1778. var args = {};
  1779. args.chatKey = chatKey;
  1780. args.event = true;
  1781. args.eventId = chatKey;
  1782. execute('chatOnNewMessage', args, callback);
  1783. },
  1784.  
  1785. /**
  1786. * on agent message from UI
  1787. */
  1788. onAgentSend: function(chatKey, callback) {
  1789. var args = {};
  1790. args.chatKey = chatKey;
  1791. args.event = true;
  1792. args.eventId = chatKey;
  1793. execute('chatOnAgentSend', args, callback);
  1794. },
  1795.  
  1796. /**
  1797. * on typing update
  1798. */
  1799. onTypingUpdate: function(chatKey, callback) {
  1800. var args = {};
  1801. args.chatKey = chatKey;
  1802. args.event = true;
  1803. args.eventId = chatKey;
  1804. execute('chatOnTypingUpdate', args, callback);
  1805. },
  1806.  
  1807. /**
  1808. * on custom event
  1809. */
  1810. onCustomEvent: function(chatKey, type, callback) {
  1811. var args = {};
  1812. args.chatKey = chatKey;
  1813. args.type = type;
  1814. args.event = true;
  1815. args.eventId = chatKey+type;
  1816. execute('chatOnCustomEvent', args, callback);
  1817. },
  1818.  
  1819. /**
  1820. * Sends a custom event to the chat client
  1821. */
  1822. sendCustomEvent: function(chatKey, type, data, callback) {
  1823. var args = {};
  1824. args.chatKey = chatKey;
  1825. args.type = type;
  1826. args.data = data;
  1827. execute('chatSendCustomEvent', args, callback);
  1828. },
  1829.  
  1830. /**
  1831. * Get the maximum number of chats an agent is allowed to handle concurrently
  1832. **/
  1833. getMaxCapacity: function(callback) {
  1834. var args = {};
  1835. execute('getMaxCapacity', args, callback);
  1836. },
  1837.  
  1838. /**
  1839. * Get the current number of engaged chats
  1840. **/
  1841. getEngagedChats: function(callback) {
  1842. var args = {};
  1843. execute('getEngagedChats', args, function(res) { callback.call(this, {success:res.success, chatKey: (res.chatKey.length ===1 && res.chatKey[0].length===0)? []:res.chatKey}); });
  1844. },
  1845.  
  1846. /**
  1847. * Get the current number of engaged chats
  1848. **/
  1849. getChatRequests: function(callback) {
  1850. var args = {};
  1851. execute('getChatRequests', args, function(res) { callback.call(this, {success:res.success, chatKey: (res.chatKey.length ===1 && res.chatKey[0].length===0)? []:res.chatKey}); });
  1852. },
  1853.  
  1854. /**
  1855. * get agent's current state
  1856. **/
  1857. getAgentState: function(callback) {
  1858. var args = {};
  1859. execute('getAgentState', args, callback);
  1860. },
  1861.  
  1862. /**
  1863. * set agent state
  1864. **/
  1865. setAgentState: function(state, callback) {
  1866. var args = {};
  1867. args.state = state;
  1868. execute('setAgentState', args, callback);
  1869. },
  1870.  
  1871. /**
  1872. * on agent state changed
  1873. **/
  1874. onAgentStateChanged: function(callback) {
  1875. var args = {};
  1876. args.event = true;
  1877. execute('onAgentStateChanged', args, callback);
  1878. },
  1879.  
  1880. /**
  1881. * on capacity changed
  1882. **/
  1883. onCurrentCapacityChanged: function(callback) {
  1884. var args = {};
  1885. args.event = true;
  1886. execute('onCurrentCapacityChanged', args, callback);
  1887. },
  1888.  
  1889. /**
  1890. * on chat requested
  1891. **/
  1892. onChatRequested: function(callback) {
  1893. var args = {};
  1894. args.event = true;
  1895. execute('onChatRequested', args, callback);
  1896. },
  1897.  
  1898. /**
  1899. * on chat started
  1900. **/
  1901. onChatStarted: function(callback) {
  1902. var args = {};
  1903. args.event = true;
  1904. execute('onChatStarted', args, callback);
  1905. },
  1906.  
  1907. /**
  1908. * on chat ended
  1909. **/
  1910. onChatEnded: function(callback) {
  1911. var args = {};
  1912. args.event = true;
  1913. execute('onChatEnded', args, callback);
  1914. },
  1915.  
  1916. /**
  1917. * on chat declined
  1918. **/
  1919. onChatDeclined: function(callback) {
  1920. var args = {};
  1921. args.event = true;
  1922. execute('onChatDeclined', args, callback);
  1923. },
  1924.  
  1925. /**
  1926. * on chat transferred out
  1927. **/
  1928. onChatTransferredOut: function(callback) {
  1929. var args = {};
  1930. args.event = true;
  1931. execute('onChatTransferredOut', args, callback);
  1932. },
  1933.  
  1934. /**
  1935. * on the event when user cancels chat request before chat was accepted by the agent
  1936. **/
  1937. onChatCanceled: function(callback) {
  1938. var args = {};
  1939. args.event = true;
  1940. execute('onChatCanceled', args, callback);
  1941. },
  1942.  
  1943. /**
  1944. * on chat going in or out of critical wait state
  1945. **/
  1946. onChatCriticalWaitState: function(chatKey, callback) {
  1947. var args = {};
  1948. args.event = true;
  1949. args.chatId = chatKey;
  1950. execute('onChatCriticalWaitState', args, callback);
  1951. },
  1952.  
  1953. /**
  1954. * accept chat
  1955. **/
  1956. acceptChat: function(chatKey, callback) {
  1957. var args = {};
  1958. args.chatKey = chatKey;
  1959. args.eventId = chatKey;
  1960. execute('acceptChat', args, callback);
  1961. },
  1962.  
  1963. /**
  1964. * end chat
  1965. **/
  1966. endChat: function(chatKey, callback) {
  1967. var args = {};
  1968. args.chatKey = chatKey;
  1969. execute('endChat', args, callback);
  1970. },
  1971. /**
  1972. * decline chat
  1973. **/
  1974. declineChat: function(chatKey, callback) {
  1975. var args = {};
  1976. args.chatKey = chatKey;
  1977. execute('declineChat', args, callback);
  1978. },
  1979. /**
  1980. * file transfer, init by agent
  1981. */
  1982. initFileTransfer: function(chatKey, entityId, callback) {
  1983. var args = {};
  1984. args.chatKey = chatKey;
  1985. args.entityId = entityId;
  1986. execute('initFileTransfer', args, callback);
  1987. },
  1988. /**
  1989. * file transfer, cancel by agent
  1990. */
  1991. cancelFileTransferByAgent: function(chatKey, callback) {
  1992. var args = {};
  1993. args.chatKey = chatKey;
  1994. execute('cancelFileTransfer', args, callback);
  1995. },
  1996. /**
  1997. * file transfer, file completed
  1998. */
  1999. onFileTransferCompleted: function(chatKey, callback) {
  2000. var args = {};
  2001. args.chatKey = chatKey;
  2002. execute('onFileTransferCompleted', args, callback);
  2003. }
  2004. };
  2005. })(sforce.console.helper);
  2006.  
  2007. /**
  2008. * Service Presence Toolkit API
  2009. */
  2010. sforce.console.presence = (function(consoleApiHelper) {
  2011. var execute = function(fname, args, callback) {
  2012. args.version = consoleApiHelper.getVersion();
  2013. return consoleApiHelper.execute(fname, args, callback);
  2014. };
  2015.  
  2016. function validateStringArg(arg) {
  2017. return (typeof arg === 'string' && arg.length > 0);
  2018. }
  2019.  
  2020. return {
  2021.  
  2022. /**
  2023. * login a presence user with given status id
  2024. **/
  2025. login: function(statusId, callback) {
  2026. var args = {};
  2027. if (validateStringArg(statusId)) {
  2028. args.statusId = statusId;
  2029. }
  2030. execute('loginPresence', args, callback);
  2031. },
  2032.  
  2033. /**
  2034. * get presence user's status id
  2035. **/
  2036. getServicePresenceStatusId: function(callback) {
  2037. var args = {};
  2038. execute('getPresenceStatusId', args, callback);
  2039. },
  2040.  
  2041. /**
  2042. * get presence user current status' channels
  2043. */
  2044. getServicePresenceStatusChannels: function(callback) {
  2045. var args = {};
  2046. execute('getPresenceStatusChannels', args, callback);
  2047. },
  2048.  
  2049. /**
  2050. * set presence user's status with give status id
  2051. **/
  2052. setServicePresenceStatus: function(statusId, callback) {
  2053. var args = {};
  2054. if (validateStringArg(statusId)) {
  2055. args.statusId = statusId;
  2056. }
  2057. execute('setPresenceStatus', args, callback);
  2058. },
  2059.  
  2060. /**
  2061. * logout a presence user
  2062. **/
  2063. logout: function(callback) {
  2064. var args = {};
  2065. execute('logoutPresence', args, callback);
  2066. },
  2067.  
  2068. /**
  2069. * Get all works assigned/opened by presence user
  2070. */
  2071. getAgentWorks: function(callback) {
  2072. var args = {};
  2073. execute('getPresenceWorks', args, callback);
  2074. },
  2075.  
  2076. /**
  2077. * Accept an assigned work
  2078. */
  2079. acceptAgentWork: function(workId, callback) {
  2080. var args = {};
  2081. if (validateStringArg(workId)) {
  2082. args.workId = workId;
  2083. }
  2084. execute('acceptPresenceWork', args, callback);
  2085. },
  2086.  
  2087. /**
  2088. * Decline an assigned work
  2089. */
  2090. declineAgentWork: function(workId, callback) {
  2091. var args = {};
  2092. if (validateStringArg(workId)) {
  2093. args.workId = workId;
  2094. }
  2095. execute('declinePresenceWork', args, callback);
  2096. },
  2097.  
  2098. /**
  2099. * Close an engaged work
  2100. */
  2101. closeAgentWork: function(workId, callback) {
  2102. var args = {};
  2103. if (validateStringArg(workId)) {
  2104. args.workId = workId;
  2105. }
  2106. execute('closePresenceWork', args, callback);
  2107. }
  2108. };
  2109. })(sforce.console.helper);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement