APIs

Show:
  1. /**
  2. * BlockLocation resides inside a scene or timeline and manages internal playback of scenes and resources
  3. * @class BlockLocation
  4. * @extends Block
  5. * @constructor
  6. * @param {string} i_placement location where objects resides which can be scene or timeline
  7. * @param {string} i_campaign_timeline_chanel_player_id required and set as block id when block is inserted onto timeline_channel
  8. * @return {Object} Block instance
  9. */
  10. define(['jquery', 'backbone', 'Block', 'bootstrap-table-editable', 'bootstrap-table-sort-rows'], function ($, Backbone, Block, bootstraptableeditable, bootstraptablesortrows) {
  11.  
  12. var BlockLocation = Block.extend({
  13.  
  14. /**
  15. Constructor
  16. @method initialize
  17. **/
  18. constructor: function (options) {
  19. var self = this;
  20. self.m_blockType = 4105;
  21. _.extend(options, {blockType: self.m_blockType});
  22. Block.prototype.constructor.call(this, options);
  23.  
  24. self.m_locationTable = $(Elements.LOCATION_TABLE);
  25. self.m_selectRowIndex = -1;
  26. self.m_currentIndex = 0;
  27. self.m_pendingAdditionXML = '';
  28. self._initSubPanel(Elements.BLOCK_LOCATION_COMMON_PROPERTIES);
  29. self._listenLocationRowDragged();
  30. self._listenLocationRowDropped();
  31. self._listenAddResource();
  32. self._listenRemoveResource();
  33. self._listenLocationRowChanged();
  34. self._listenLiveInputs();
  35. self._listenMenuControls();
  36. self._listenAddPoint();
  37. self._listenRadiusChange();
  38. self._listenPriorityChange();
  39.  
  40. self.m_blockProperty.locationDatatableInit();
  41. self.m_locationPriorityMeter = self.m_blockProperty.getLocationPriorityMeter();
  42.  
  43. if (self.m_placement == BB.CONSTS.PLACEMENT_CHANNEL) {
  44. self.m_addBlockLocationView = BB.comBroker.getService(BB.SERVICES.ADD_BLOCK_LOCATION_VIEW);
  45. } else if (self.m_placement = BB.CONSTS.PLACEMENT_SCENE) {
  46. self.m_addBlockLocationView = BB.comBroker.getService(BB.SERVICES.ADD_BLOCK_LOCATION_SCENE_VIEW);
  47. }
  48.  
  49. /* can set global mode if we wish */
  50. //$.fn.editable.defaults.mode = 'inline';
  51. },
  52.  
  53. /**
  54. Listen to changes in priority
  55. @method _listenPriorityChange
  56. **/
  57. _listenPriorityChange: function () {
  58. var self = this;
  59. self.m_inputPriorityHandler = function (e) {
  60. if (!self.m_selected)
  61. return;
  62. var domPlayerData = self._getBlockPlayerData();
  63. var value = e.edata;
  64. console.log('get value ' + value);
  65. var total = $(domPlayerData).find('GPS').children().length;
  66. if (total == 0)
  67. return;
  68. var item = $(domPlayerData).find('GPS').children().get(self.m_currentIndex);
  69. $(item).attr('priority', value);
  70. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  71. };
  72. BB.comBroker.listen(BB.EVENTS.LOCATION_PRIORITY_METER_CHANGED, self.m_inputPriorityHandler);
  73. },
  74.  
  75. /**
  76. Populate the priority widget
  77. @method _populatePriority
  78. @param {Number} i_value
  79. **/
  80. _populatePriority: function (i_value) {
  81. var self = this;
  82. //$(Elements.YOUTUBE_VOLUME_WRAP_SLIDER).val(i_value);
  83. self.m_locationPriorityMeter.setMeter(i_value);
  84. },
  85.  
  86. /**
  87. Listen to adding a new point from google maps, and if we pending for addition, take action
  88. @method _listenAddPoint
  89. @param {Number} i_playerData
  90. @return {Number} Unique clientId.
  91. **/
  92. _listenAddPoint: function () {
  93. var self = this;
  94. self.m_onNewMapPointHandler = function (e) {
  95. if (!self.m_selected)
  96. return;
  97. var latLng = e.edata;
  98. if (!latLng) {
  99. self.m_pendingAdditionXML = '';
  100. return;
  101. }
  102. var lat = e.edata.lat;
  103. var lng = e.edata.lng;
  104. var reLat = new RegExp(":LAT:", "ig");
  105. var reLng = new RegExp(":LNG:", "ig");
  106. self.m_pendingAdditionXML = self.m_pendingAdditionXML.replace(reLat, lat);
  107. self.m_pendingAdditionXML = self.m_pendingAdditionXML.replace(reLng, lng);
  108. var domPlayerData = self._getBlockPlayerData();
  109. var xSnippetLocation = $(domPlayerData).find('GPS');
  110. $(xSnippetLocation).append($(self.m_pendingAdditionXML));
  111. self.m_pendingAdditionXML = '';
  112. // since we used append, we have to cleanup for IE case bug
  113. self._setBlockPlayerData(pepper.xmlToStringIEfix(domPlayerData), BB.CONSTS.NO_NOTIFICATION, true);
  114. self._populate();
  115. self._jumpToLocation('last');
  116. };
  117. BB.comBroker.listen(BB.EVENTS.ADD_LOCATION_POINT, self.m_onNewMapPointHandler);
  118. },
  119.  
  120. /**
  121. Listen to changes in radius per selected location
  122. @method _listenRadiusChange
  123. **/
  124. _listenRadiusChange: function () {
  125. var self = this;
  126. self.m_onRadiusHandler = function (e) {
  127. if (!self.m_selected)
  128. return;
  129. var val = e.edata;
  130. var domPlayerData = self._getBlockPlayerData();
  131. var total = $(domPlayerData).find('GPS').children().length;
  132. if (total == 0)
  133. return;
  134. var item = $(domPlayerData).find('GPS').children().get(self.m_currentIndex);
  135. $(item).attr('radios', val);
  136. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  137. self._googleMap(false, true, false);
  138. };
  139. BB.comBroker.listen(BB.EVENTS.LOCATION_RADIUS_CHANGED, self.m_onRadiusHandler);
  140. },
  141.  
  142. /**
  143. Listen to location controls, add remove, next, add ...
  144. @method _listenMenuControls
  145. **/
  146. _listenMenuControls: function () {
  147. var self = this;
  148. self.m_locationControls = function (e) {
  149. if (!self.m_selected)
  150. return;
  151. var buttonType = $(e.target).attr('name') != undefined ? $(e.target).prop('name') : $(e.target).closest('button').attr('name');
  152. if (buttonType == 'removeLocation')
  153. self._removeLocation();
  154. if (buttonType == 'previous')
  155. self._jumpToLocation('prev');
  156. if (buttonType == 'next')
  157. self._jumpToLocation('next');
  158. if (buttonType == 'openLocation')
  159. self._googleMap(false, false, true);
  160. };
  161. $(Elements.LOCATION_CONTROLS + ' button').on('click', self.m_locationControls);
  162. },
  163.  
  164. /**
  165. Remove current selected location
  166. @method _removeLocation
  167. **/
  168. _removeLocation: function () {
  169. var self = this;
  170. var domPlayerData = self._getBlockPlayerData();
  171. var total = $(domPlayerData).find('GPS').children().length;
  172. if (total == 0)
  173. return;
  174.  
  175. bootbox.confirm($(Elements.MSG_BOOTBOX_SURE_DELETE).text(), function (result) {
  176. if (result == true) {
  177. $(domPlayerData).find('GPS').children().eq(self.m_currentIndex).remove();
  178. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  179. self._googleMap(false, true, false);
  180. self._jumpToLocation('first');
  181. self._populateTotalMapLocations(domPlayerData);
  182. }
  183. });
  184. },
  185.  
  186. /**
  187. Listen to changes in row due to drag
  188. @method _listenVolumeChange
  189. **/
  190. _listenLocationRowDragged: function () {
  191. var self = this;
  192. self.m_locationRowDraggedHandler = function (e) {
  193. if (!self.m_selected)
  194. return;
  195. self.m_selectRowIndex = e.edata;
  196. var domPlayerData = self._getBlockPlayerData();
  197. };
  198. BB.comBroker.listen(BB.EVENTS.LOCATION_ROW_DRAG, self.m_locationRowDraggedHandler);
  199. },
  200.  
  201. /**
  202. Listen to changes in LiveInputs including resource names, long and lat values
  203. @method _listenLiveInputs
  204. **/
  205. _listenLiveInputs: function () {
  206. var self = this;
  207.  
  208. self.m_liveInputChanged = function (e) {
  209. if (!self.m_selected)
  210. return;
  211. var reloadMap = false;
  212. var domPlayerData = self._getBlockPlayerData();
  213. var total = $(domPlayerData).find('GPS').children().length;
  214. if (total == 0)
  215. return;
  216. var item = $(domPlayerData).find('GPS').children().get(self.m_currentIndex);
  217. switch (e.edata.el) {
  218. case Elements.LOCATION_RESOURCE_NAME:
  219. {
  220. $(item).attr('page', e.edata.value);
  221. break;
  222. }
  223. case Elements.LOCATION_RESOURCE_LAT:
  224. {
  225. $(item).attr('lat', e.edata.value);
  226. reloadMap = true;
  227. break;
  228. }
  229. case Elements.LOCATION_RESOURCE_LNG:
  230. {
  231. $(item).attr('lng', e.edata.value);
  232. reloadMap = true;
  233. break;
  234. }
  235. case Elements.LOCATION_RESOURCE_DURATION:
  236. {
  237. $(item).attr('duration', e.edata.value);
  238. break;
  239. }
  240. }
  241. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  242. if (reloadMap)
  243. self._googleMap(false, true, false);
  244. };
  245. BB.comBroker.listen(BB.EVENTS.LOCATION_LIVE_INPUT_CHANGED, self.m_liveInputChanged);
  246.  
  247. },
  248.  
  249. /**
  250. Listen to when location row was edited
  251. @method _listenLocationRowChanged
  252. **/
  253. _listenLocationRowChanged: function () {
  254. var self = this;
  255. self.m_locationRowChangedHandler = function (e) {
  256. if (!self.m_selected)
  257. return;
  258. var domPlayerData = self._getBlockPlayerData();
  259. var rowIndex = e.edata.rowIndex;
  260. var newName = e.edata.name;
  261. var newDuration = parseInt(e.edata.duration);
  262. if (_.isNaN(newDuration)) {
  263. bootbox.alert($(Elements.MSG_BOOTBOX_ENTRY_IS_INVALID).text());
  264. self._populateTableDefault(domPlayerData);
  265. return;
  266. }
  267. var item = $(domPlayerData).find('Fixed').children().get(rowIndex);
  268. $(item).attr('page', newName).attr('duration', newDuration);
  269. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  270. self._populateTableDefault(domPlayerData);
  271. };
  272. BB.comBroker.listen(BB.EVENTS.LOCATION_ROW_CHANGED, self.m_locationRowChangedHandler);
  273. },
  274.  
  275. /**
  276. Listen to changes in volume control
  277. @method _listenVolumeChange
  278. **/
  279. _listenLocationRowDropped: function () {
  280. var self = this;
  281. self.m_locationRowDroppedHandler = function (e) {
  282. if (!self.m_selected)
  283. return;
  284. var droppedRowIndex = e.edata;
  285. var domPlayerData = self._getBlockPlayerData();
  286. var target = $(domPlayerData).find('Fixed').children().get(parseInt(droppedRowIndex));
  287. var source = $(domPlayerData).find('Fixed').children().get(self.m_selectRowIndex);
  288. droppedRowIndex > self.m_selectRowIndex ? $(target).after(source) : $(target).before(source);
  289. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  290. self._populateTableDefault(domPlayerData);
  291. };
  292. BB.comBroker.listen(BB.EVENTS.LOCATION_ROW_DROP, self.m_locationRowDroppedHandler);
  293. },
  294.  
  295. /**
  296. The main functions which renders and loads up the entire property panel with both default resource list
  297. as well as map location coordinates list
  298. @method _populate
  299. @return none
  300. **/
  301. _populate: function () {
  302. var self = this;
  303. self._setLocationBlockGlobalValidationOwner(self);
  304. var domPlayerData = self._getBlockPlayerData();
  305. var xSnippetLocation = $(domPlayerData).find('Fixed');
  306. var mode = $(xSnippetLocation).attr('mode');
  307. self._populateTableDefault(domPlayerData);
  308. self._jumpToLocation('first');
  309. self._populateTotalMapLocations(domPlayerData);
  310. },
  311.  
  312. /**
  313. Populate the radius UI element
  314. @method _populateRadius
  315. @param {Object} i_value
  316. **/
  317. _populateRadius: function (i_value) {
  318. var self = this;
  319. $(Elements.LOCATION_RADIUS_WRAP_SLIDER).val(i_value);
  320. },
  321.  
  322. /**
  323. Populate the total map locations set
  324. @method _populateTotalMapLocations
  325. @param {Object} domPlayerData
  326. **/
  327. _populateTotalMapLocations: function (domPlayerData) {
  328. var self = this;
  329. var total = $(domPlayerData).find('GPS').children().length;
  330. if (total == 0) {
  331. $(Elements.LOCATION_SELECTED).hide();
  332. self.m_currentIndex = 0;
  333. } else {
  334. $(Elements.LOCATION_SELECTED).show();
  335. }
  336. $(Elements.TOTAL_MAP_LOCATIONS).text(total);
  337. },
  338.  
  339. /**
  340. Select specific location and populate both the UI as well scroll map to coordinates
  341. @method _jumpToLocation
  342. @param {String} i_index
  343. **/
  344. _jumpToLocation: function (i_index) {
  345. var self = this;
  346. var domPlayerData = self._getBlockPlayerData();
  347. var total = $(domPlayerData).find('GPS').children().length;
  348. var item;
  349. // no locations, done!
  350. if (total == 0) {
  351. self._populateTotalMapLocations(domPlayerData);
  352. return;
  353. }
  354. // load location
  355. switch (i_index) {
  356. case 'first':
  357. {
  358. self.m_currentIndex = 0;
  359. item = $(domPlayerData).find('GPS').children().first();
  360. break;
  361. }
  362. case 'last':
  363. {
  364. self.m_currentIndex = total - 1;
  365. item = $(domPlayerData).find('GPS').children().last();
  366. break;
  367. }
  368. case 'next':
  369. {
  370. if (self.m_currentIndex == (total - 1)) {
  371. item = $(domPlayerData).find('GPS').children().last();
  372. } else {
  373. self.m_currentIndex++;
  374. item = $(domPlayerData).find('GPS').children().get(self.m_currentIndex);
  375. }
  376. break;
  377. }
  378. case 'prev':
  379. {
  380. if (self.m_currentIndex == 0) {
  381. item = $(domPlayerData).find('GPS').children().first();
  382. } else {
  383. self.m_currentIndex--;
  384. item = $(domPlayerData).find('GPS').children().get(self.m_currentIndex);
  385. }
  386. break;
  387. }
  388. }
  389. self._populateRadius($(item).attr('radios'));
  390. self._populatePriority($(item).attr('priority'));
  391. self.m_blockProperty.setLocationLiveInput(Elements.LOCATION_RESOURCE_NAME, $(item).attr('page'));
  392. self.m_blockProperty.setLocationLiveInput(Elements.LOCATION_RESOURCE_LAT, $(item).attr('lat'));
  393. self.m_blockProperty.setLocationLiveInput(Elements.LOCATION_RESOURCE_LNG, $(item).attr('lng'));
  394. self.m_blockProperty.setLocationLiveInput(Elements.LOCATION_RESOURCE_DURATION, $(item).attr('duration'));
  395. self.m_addBlockLocationView.panToPoint($(item).attr('lat'), $(item).attr('lng'));
  396. },
  397.  
  398. /**
  399. Load list into the UI for default content
  400. @method _populateTableDefault
  401. @param {Object} i_domPlayerData
  402. **/
  403. _populateTableDefault: function (i_domPlayerData) {
  404. var self = this;
  405. self.m_locationTable.bootstrapTable('removeAll');
  406. var data = [], rowIndex = 0;
  407. $(i_domPlayerData).find('Fixed').children().each(function (k, page) {
  408. var resource_hResource, scene_hDataSrc;
  409. var type = $(page).attr('type');
  410. if (type == 'resource') {
  411. resource_hResource = $(page).find('Resource').attr('hResource');
  412. } else {
  413. scene_hDataSrc = $(page).find('Player').attr('hDataSrc');
  414. }
  415. log('populating ' + resource_hResource);
  416. data.push({
  417. rowIndex: rowIndex,
  418. checkbox: true,
  419. name: $(page).attr('page'),
  420. duration: $(page).attr('duration'),
  421. type: type,
  422. resource_hResource: resource_hResource,
  423. scene_hDataSrc: scene_hDataSrc
  424. });
  425. rowIndex++;
  426. });
  427. self.m_locationTable.bootstrapTable('load', data);
  428. },
  429.  
  430. /**
  431. Listen to add new resource and when clicked, wait for announcement from AddBlockListView that
  432. a new resource or scene needs to be added to either the default play list (aka Fixed) or
  433. to the Location based play list (aka GPS)
  434. @method _listenAddResource
  435. **/
  436. _listenAddResource: function () {
  437. var self = this;
  438. self.m_addNewLocationListItem = function (e) {
  439.  
  440. BB.comBroker.stopListenWithNamespace(BB.EVENTS.ADD_NEW_BLOCK_LIST, self);
  441. if (!self.m_selected)
  442. return;
  443.  
  444. self.m_listItemType = $(e.target).attr('name') != undefined ? $(e.target).prop('name') : $(e.target).closest('button').attr('name');
  445.  
  446. // open the Add Block Slider
  447. var addBlockView;
  448. if (self.m_placement == BB.CONSTS.PLACEMENT_CHANNEL) {
  449. addBlockView = BB.comBroker.getService(BB.SERVICES.ADD_BLOCK_VIEW);
  450. } else if (self.m_placement = BB.CONSTS.PLACEMENT_SCENE) {
  451. addBlockView = BB.comBroker.getService(BB.SERVICES.ADD_SCENE_BLOCK_VIEW);
  452. }
  453. addBlockView.setPlacement(BB.CONSTS.PLACEMENT_LISTS);
  454. addBlockView.selectView();
  455.  
  456. // wait for a new resource to be added and once it has, open the Google maps for location insertion
  457. BB.comBroker.listenWithNamespace(BB.EVENTS.ADD_NEW_BLOCK_LIST, self, function (e) {
  458. if (!self.m_selected)
  459. return;
  460. e.stopImmediatePropagation();
  461. e.preventDefault();
  462. self._addLocationItem(e, self.m_listItemType);
  463.  
  464. });
  465. };
  466. $(Elements.CLASS_ADD_RESOURCE_LOCATION).on('click', self.m_addNewLocationListItem);
  467. },
  468.  
  469. /**
  470. Check if scene is pointing to itself to avoid cyclic reference
  471. @method _isSceneCyclic
  472. @param {Number} i_playerData
  473. @return {Boolean} true if cyclic reference
  474. **/
  475. _isSceneCyclic: function(i_edata){
  476. var self = this;
  477. if (self.m_placement == BB.CONSTS.PLACEMENT_SCENE) {
  478. var sceneEditView = BB.comBroker.getService(BB.SERVICES['SCENE_EDIT_VIEW']);
  479. if (!_.isUndefined(sceneEditView)) {
  480. var selectedSceneID = sceneEditView.getSelectedSceneID();
  481. selectedSceneID = pepper.getSceneIdFromPseudoId(selectedSceneID);
  482. if (selectedSceneID == i_edata.sceneID) {
  483. return true;
  484. }
  485. }
  486. }
  487. return false;
  488. },
  489.  
  490. /**
  491. Add to our XML a list item item which can be of one of two types
  492. addDefault: a default resource to play when not within radius of GPS coords
  493. addLocation: a particular resource to play within specific GPS coords
  494. @method _addLocationItem
  495. @param {Event} e
  496. @param {String} type addDefault or addLocation
  497. **/
  498. _addLocationItem: function (e, type) {
  499. var self = this;
  500. var domPlayerData = self._getBlockPlayerData();
  501. var buff = '';
  502. var locationBuff;
  503. var xSnippetLocation;
  504.  
  505. // log(e.edata.blockCode, e.edata.resourceID, e.edata.sceneID);
  506. if (self._isSceneCyclic(e.edata)){
  507. bootbox.alert($(Elements.MSG_BOOTBOX_SCENE_REFER_ITSELF).text());
  508. return;
  509. }
  510.  
  511. switch (type) {
  512. case 'addDefault':
  513. {
  514. xSnippetLocation = $(domPlayerData).find('Fixed');
  515. locationBuff = '>';
  516. break;
  517. }
  518. case 'addLocation':
  519. {
  520. locationBuff = 'lat=":LAT:" lng=":LNG:" radios="0.10" duration="5" priority="1">';
  521. xSnippetLocation = $(domPlayerData).find('GPS');
  522. BB.comBroker.fire(BB.EVENTS.BLOCK_SELECTED, this, null, self.m_block_id);
  523. setTimeout(function () {
  524. self._googleMap(true, true, true);
  525. self._populate();
  526. }, 500);
  527. break;
  528. }
  529. }
  530.  
  531. // adding a scene and don't allow cyclic reference of scene
  532. if (e.edata.blockCode == BB.CONSTS.BLOCKCODE_SCENE) {
  533. var sceneRecord = pepper.getScenePlayerRecord(e.edata.sceneID);
  534. var sceneName = $(sceneRecord.player_data_value).attr('label');
  535. var nativeID = sceneRecord['native_id'];
  536. buff = '<Page page="' + sceneName + '" type="scene" duration="5" ' + locationBuff +
  537. ' <Player src="' + nativeID + '" hDataSrc="' + e.edata.sceneID + '" />' +
  538. ' </page>';
  539. } else {
  540. // Add resources to location
  541. var resourceName = pepper.getResourceRecord(e.edata.resourceID).resource_name;
  542. log('updating hResource ' + e.edata.resourceID);
  543. buff = '<Page page="' + resourceName + '" type="resource" duration="5" ' + locationBuff +
  544. ' <Player player="' + e.edata.blockCode + '">' +
  545. ' <Data>' +
  546. ' <Resource hResource="' + e.edata.resourceID + '" />' +
  547. ' </Data>' +
  548. ' </Player>' +
  549. ' </page>';
  550. }
  551.  
  552. // if default item, just add it. if location item, remember it and only add it once user select
  553. // a location for it in google the map as we need to wait for the coordinates.
  554. switch (type) {
  555. case 'addDefault':
  556. {
  557. $(xSnippetLocation).append($(buff));
  558. // since we used append, we have to cleanup for IE case bug
  559. self._setBlockPlayerData(pepper.xmlToStringIEfix(domPlayerData), BB.CONSTS.NO_NOTIFICATION, true);
  560. BB.comBroker.fire(BB.EVENTS.BLOCK_SELECTED, this, null, self.m_block_id);
  561. break;
  562. }
  563. case 'addLocation':
  564. {
  565. self.m_pendingAdditionXML = buff;
  566. }
  567. }
  568. },
  569.  
  570. /**
  571. Open google maps and load it with all current locations
  572. @method _googleMap
  573. @params {Boolean} i_markerOnClick set to true if we are going to expect user to add a new location or false if we just want to open an existing map and not add any new locations
  574. @params {Boolean} i_reloadData reload the map with fresh data, used when we delete map items and want to force a refresh
  575. @params {Boolean} i_loadStackView animate the slider StackView into position
  576. **/
  577. _googleMap: function (i_markerOnClick, i_reloadData, i_loadStackView) {
  578. var self = this;
  579. var map = {
  580. points: []
  581. };
  582. var domPlayerData = self._getBlockPlayerData();
  583. $(domPlayerData).find('GPS').children().each(function (k, v) {
  584. var point = {
  585. center: {
  586. lat: $(v).attr('lat'),
  587. lng: $(v).attr('lng')
  588.  
  589. },
  590. radius: $(v).attr('radios')
  591. };
  592. map.points.push(point);
  593.  
  594. });
  595. self.m_addBlockLocationView.setData(map);
  596. //self.m_addBlockLocationView.setPlacement(BB.CONSTS.PLACEMENT_LISTS);
  597.  
  598. if (i_loadStackView) {
  599. self.m_addBlockLocationView.selectView(i_markerOnClick);
  600. }
  601. if (i_reloadData)
  602. self.m_addBlockLocationView.loadJson();
  603. },
  604.  
  605. /**
  606. Listen to when removing a resource from location list
  607. The algorithm will uses our bootstrap-table own inject rowIndex value
  608. and counts up to match with the order of <Pages/> in msdb location, once matched against same value
  609. we delete the proper ordered location item from msdb and refresh the entire table
  610. @method _listenRemoveResource
  611. **/
  612. _listenRemoveResource: function () {
  613. var self = this;
  614. self.m_removeLocationListItem = function () {
  615. if (!self.m_selected)
  616. return;
  617. if (self.m_locationTable.bootstrapTable('getSelections').length == 0) {
  618. bootbox.alert($(Elements.MSG_BOOTBOX_NO_ITEM_SELECTED).text());
  619. return;
  620. }
  621.  
  622. bootbox.confirm($(Elements.MSG_BOOTBOX_SURE_DELETE).text(), function (result) {
  623. if (result == true) {
  624. var rowIndex = $('input[name=btSelectItem]:checked', Elements.LOCATION_TABLE).closest('tr').attr('data-index');
  625. var domPlayerData = self._getBlockPlayerData();
  626. $(domPlayerData).find('Fixed').children().eq(rowIndex).remove();
  627. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  628. self._populateTableDefault(domPlayerData);
  629. }
  630. });
  631. };
  632. $(Elements.REMOVE_RESOURCE_FOR_LOCATION).on('click', self.m_removeLocationListItem);
  633. },
  634.  
  635. /**
  636. Populate the common block properties panel, called from base class if exists
  637. @method _loadBlockSpecificProps
  638. @return none
  639. **/
  640. _loadBlockSpecificProps: function () {
  641. var self = this;
  642. self._populate();
  643. this._viewSubPanel(Elements.BLOCK_LOCATION_COMMON_PROPERTIES);
  644. },
  645.  
  646. /**
  647. re-take ownership for a caller block instance and register global Validators for bootstrap-table to format data
  648. This function has to run everytime we populate the UI since it is a shared global function
  649. and we have to override it so 'this' refers to correct BlockLocation instance
  650. @method _setLocationBlockGlobalValidationOwner
  651. **/
  652. _setLocationBlockGlobalValidationOwner: function (i_this) {
  653. // add draggable icons
  654. BB.lib.locationDragIcons = function () {
  655. return '<div class="dragIconTable"><i class="fa fa-arrows-v"></i></div>';
  656. };
  657.  
  658. // register a global shared function to validate checkbox state
  659. BB.lib.locationChecks = function (value, row, index) {
  660. return {
  661. checked: false,
  662. disabled: false
  663. }
  664. };
  665. },
  666.  
  667. /**
  668. Get all the location pages names for current location block
  669. this is called against the last block instance that registered the global function of
  670. setLocationBlockGlobalValidationOwner
  671. @method _getLocationPageNames
  672. **/
  673. _getLocationPageNames: function () {
  674. var self = this;
  675. var data = [];
  676. var domPlayerData = self._getBlockPlayerData();
  677. $(domPlayerData).find('Fixed').children().each(function (k, page) {
  678. data.push($(page).attr('page'));
  679. });
  680. return data;
  681. },
  682.  
  683. /**
  684. Delete this block
  685. @method deleteBlock
  686. @params {Boolean} i_memoryOnly if true only remove from existance but not from msdb
  687. **/
  688. deleteBlock: function (i_memoryOnly) {
  689. var self = this;
  690. $(Elements.CLASS_ADD_RESOURCE_LOCATION).off('click', self.m_addNewLocationListItem);
  691. $(Elements.REMOVE_RESOURCE_FOR_LOCATION).off('click', self.m_removeLocationListItem);
  692. $(Elements.LOCATION_CONTROLS + ' button').off('click', self.m_locationControls);
  693. BB.comBroker.stopListen(BB.EVENTS.ADD_NEW_BLOCK_LIST); // removing for everyone which is ok, since gets added in real time
  694. BB.comBroker.stopListen(BB.EVENTS.LOCATION_ROW_DROP, self.m_locationRowDroppedHandler);
  695. BB.comBroker.stopListen(BB.EVENTS.LOCATION_ROW_DRAG, self.m_locationRowDraggedHandler);
  696. BB.comBroker.stopListen(BB.EVENTS.LOCATION_ROW_CHANGED, self.m_locationRowChangedHandler);
  697. BB.comBroker.stopListen(BB.EVENTS.LOCATION_LIVE_INPUT_CHANGED, self.m_liveInputChanged);
  698. BB.comBroker.stopListen(BB.EVENTS.ADD_LOCATION_POINT, self.m_onNewMapPointHandler);
  699. BB.comBroker.stopListen(BB.EVENTS.LOCATION_RADIUS_CHANGED, self.m_onRadiusHandler);
  700. BB.comBroker.stopListen(BB.EVENTS.LOCATION_PRIORITY_METER_CHANGED, self.m_inputPriorityHandler);
  701. self._deleteBlock(i_memoryOnly);
  702. }
  703. });
  704. return BlockLocation;
  705. }
  706. );
  707.