action.js.orig 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. $axure.internal(function($ax) {
  2. var _actionHandlers = {};
  3. var _action = $ax.action = {};
  4. var animationQueue = {};
  5. var getAnimation = function(id) {
  6. return animationQueue[id] && animationQueue[id][0];
  7. };
  8. var _addAnimation = _action.addAnimation = function(id, func) {
  9. var wasEmpty = !getAnimation(id);
  10. // Add the func to the queue. Create the queue if necessary.
  11. var queue = animationQueue[id];
  12. if(!queue) {
  13. animationQueue[id] = queue = [];
  14. }
  15. queue[queue.length] = func;
  16. // If it was empty, there isn't a callback waiting to be called on this. You have to fire it manually.
  17. if(wasEmpty) func();
  18. };
  19. var _fireAnimationFromQueue = _action.fireAnimationFromQueue = function(id) {
  20. // Remove the function that was just fired
  21. if(animationQueue[id]) $ax.splice(animationQueue[id], 0, 1);
  22. // Fire the next func if there is one
  23. var func = getAnimation(id);
  24. if(func) func();
  25. };
  26. var _refreshing;
  27. _action.refreshStart = function(repeaterId) { _refreshing = repeaterId; };
  28. _action.refreshEnd = function() { _refreshing = undefined; };
  29. var _repeatersToRefeash = _action.repeatersToRefresh = [];
  30. var _ignoreAction = function(repeaterId) {
  31. return _refreshing == repeaterId;
  32. };
  33. var _addRefresh = function(repeaterId) {
  34. if(_repeatersToRefeash.indexOf(repeaterId) == -1) _repeatersToRefeash.push(repeaterId);
  35. };
  36. var _dispatchAction = $ax.action.dispatchAction = function(eventInfo, actions, currentIndex) {
  37. currentIndex = currentIndex || 0;
  38. //If no actions, you can bubble
  39. if(currentIndex >= actions.length) return;
  40. //actions are responsible for doing their own dispatching
  41. _actionHandlers[actions[currentIndex].action](eventInfo, actions, currentIndex);
  42. };
  43. _actionHandlers.wait = function(eventInfo, actions, index) {
  44. var action = actions[index];
  45. var infoCopy = $ax.eventCopy(eventInfo);
  46. window.setTimeout(function() {
  47. _dispatchAction(infoCopy, actions, index + 1);
  48. }, action.waitTime);
  49. };
  50. _actionHandlers.expr = function(eventInfo, actions, index) {
  51. var action = actions[index];
  52. $ax.expr.evaluateExpr(action.expr, eventInfo); //this should be a block
  53. _dispatchAction(eventInfo, actions, index + 1);
  54. };
  55. _actionHandlers.setFunction = _actionHandlers.expr;
  56. _actionHandlers.linkWindow = function(eventInfo, actions, index) {
  57. linkActionHelper(eventInfo, actions, index);
  58. };
  59. _actionHandlers.closeCurrent = function(eventInfo, actions, index) {
  60. $ax.closeWindow();
  61. _dispatchAction(eventInfo, actions, index + 1);
  62. };
  63. _actionHandlers.linkFrame = function(eventInfo, actions, index) {
  64. linkActionHelper(eventInfo, actions, index);
  65. };
  66. var linkActionHelper = function(eventInfo, actions, index) {
  67. var action = actions[index];
  68. eventInfo.link = true;
  69. if(action.linkType != 'frame') {
  70. var includeVars = _includeVars(action.target, eventInfo);
  71. if(action.target.targetType == "reloadPage") {
  72. $ax.reload(action.target.includeVariables);
  73. } else if(action.target.targetType == "backUrl") {
  74. $ax.back();
  75. }
  76. var url = action.target.url;
  77. if(!url && action.target.urlLiteral) {
  78. url = $ax.expr.evaluateExpr(action.target.urlLiteral, eventInfo, true);
  79. }
  80. if(url) {
  81. if(action.linkType == "popup") {
  82. $ax.navigate({
  83. url: url,
  84. target: action.linkType,
  85. includeVariables: includeVars,
  86. popupOptions: action.popup
  87. });
  88. } else {
  89. $ax.navigate({
  90. url: url,
  91. target: action.linkType,
  92. includeVariables: includeVars
  93. });
  94. }
  95. }
  96. } else linkFrame(eventInfo, action);
  97. eventInfo.link = false;
  98. _dispatchAction(eventInfo, actions, index + 1);
  99. };
  100. var _includeVars = function(target, eventInfo) {
  101. if(target.includeVariables) return true;
  102. // If it is a url literal, that is a string literal, that has only 1 sto, that is an item that is a page, include vars.
  103. if(target.urlLiteral) {
  104. var literal = target.urlLiteral;
  105. var sto = literal.stos[0];
  106. if(literal.exprType == 'stringLiteral' && literal.value.indexOf('[[') == 0 && literal.value.indexOf(']]' == literal.value.length - 2) && literal.stos.length == 1 && sto.sto == 'item' && eventInfo.item) {
  107. var data = $ax.repeater.getData(eventInfo.item.repeater.elementId, eventInfo.item.index, sto.name, 'data');
  108. if(data && data.type == 'page') return true;
  109. }
  110. }
  111. return false;
  112. };
  113. var linkFrame = function(eventInfo, action) {
  114. for(var i = 0; i < action.framesToTargets.length; i++) {
  115. var framePath = action.framesToTargets[i].framePath;
  116. var target = action.framesToTargets[i].target;
  117. var includeVars = _includeVars(target, eventInfo);
  118. var url = target.url;
  119. if(!url && target.urlLiteral) {
  120. url = $ax.expr.evaluateExpr(target.urlLiteral, eventInfo, true);
  121. }
  122. $ax('#' + $ax.getElementIdsFromPath(framePath, eventInfo)[0]).openLink(url, includeVars);
  123. }
  124. };
  125. var _repeatPanelMap = {};
  126. _actionHandlers.setPanelState = function(eventInfo, actions, index) {
  127. var action = actions[index];
  128. for(var i = 0; i < action.panelsToStates.length; i++) {
  129. var panelToState = action.panelsToStates[i];
  130. var stateInfo = panelToState.stateInfo;
  131. var elementIds = $ax.getElementIdsFromPath(panelToState.panelPath, eventInfo);
  132. for(var j = 0; j < elementIds.length; j++) {
  133. var elementId = elementIds[j];
  134. // Need new scope for elementId and info
  135. (function(elementId, stateInfo) {
  136. _addAnimation(elementId, function() {
  137. var stateNumber = stateInfo.stateNumber;
  138. if(stateInfo.setStateType == "value") {
  139. var oldTarget = eventInfo.targetElement;
  140. eventInfo.targetElement = elementId;
  141. var stateName = $ax.expr.evaluateExpr(stateInfo.stateValue, eventInfo);
  142. eventInfo.targetElement = oldTarget;
  143. stateNumber = Number(stateName);
  144. var panelCount = $('#' + elementId).children().length;
  145. // If not number, or too low or high, try to get it as a name rather than id
  146. if(isNaN(stateNumber) || stateNumber <= 0 || stateNumber > panelCount) {
  147. var states = $ax.getObjectFromElementId(elementId).diagrams;
  148. var stateNameFound = false;
  149. for(var k = 0; k < states.length; k++) {
  150. if(states[k].label == stateName) {
  151. stateNumber = k + 1;
  152. stateNameFound = true;
  153. }
  154. }
  155. // Wasn't a state number, or a state name, so return
  156. if(!stateNameFound) {
  157. return $ax.action.fireAnimationFromQueue(elementId);
  158. }
  159. }
  160. } else if(stateInfo.setStateType == 'next' || stateInfo.setStateType == 'previous') {
  161. var info = $ax.deepCopy(stateInfo);
  162. var repeat = info.repeat;
  163. // Only map it, if repeat exists.
  164. if(typeof (repeat) == 'number') _repeatPanelMap[elementId] = info;
  165. return _progessPanelState(elementId, info);
  166. }
  167. delete _repeatPanelMap[elementId];
  168. // If setting to current (to stop repeat) break here
  169. if(stateInfo.setStateType == 'current') return $ax.action.fireAnimationFromQueue(elementId);
  170. $ax('#' + elementId).SetPanelState(stateNumber, stateInfo.options, stateInfo.showWhenSet);
  171. });
  172. })(elementId, stateInfo);
  173. }
  174. }
  175. _dispatchAction(eventInfo, actions, index + 1);
  176. };
  177. var _progessPanelState = function(id, info) {
  178. var direction = info.setStateType;
  179. var loop = info.loop;
  180. var repeat = info.repeat;
  181. var options = info.options;
  182. var hasRepeat = typeof (repeat) == 'number';
  183. var currentStateId = $ax.visibility.GetPanelState(id);
  184. var stateNumber = '';
  185. if(currentStateId != '') {
  186. currentStateId = $ax.repeater.getScriptIdFromElementId(currentStateId);
  187. var currentStateNumber = Number(currentStateId.substr(currentStateId.indexOf('state') + 5));
  188. if(direction == "next") {
  189. stateNumber = currentStateNumber + 2;
  190. if(stateNumber > $('#' + id).children().length) {
  191. if(loop) stateNumber = 1;
  192. else {
  193. delete _repeatPanelMap[id];
  194. return $ax.action.fireAnimationFromQueue(id);
  195. }
  196. }
  197. } else if(direction == "previous") {
  198. stateNumber = currentStateNumber;
  199. if(stateNumber <= 0) {
  200. if(loop) stateNumber = $('#' + id).children().length;
  201. else {
  202. delete _repeatPanelMap[id];
  203. return $ax.action.fireAnimationFromQueue(id);
  204. }
  205. }
  206. }
  207. $ax('#' + id).SetPanelState(stateNumber, options, info.showWhenSet);
  208. if(hasRepeat) {
  209. var animate = options && options.animateIn;
  210. if(animate && animate.easing && animate.easing != 'none' && animate.duration > repeat) repeat = animate.duration;
  211. animate = options && options.animateOut;
  212. if(animate && animate.easing && animate.easing != 'none' && animate.duration > repeat) repeat = animate.duration;
  213. window.setTimeout(function() {
  214. // Either new repeat, or no repeat anymore.
  215. if(_repeatPanelMap[id] != info) return;
  216. _addAnimation(id, function() {
  217. _progessPanelState(id, info);
  218. });
  219. }, repeat);
  220. } else delete _repeatPanelMap[id];
  221. }
  222. };
  223. _actionHandlers.fadeWidget = function(eventInfo, actions, index) {
  224. var action = actions[index];
  225. for(var i = 0; i < action.objectsToFades.length; i++) {
  226. var fadeInfo = action.objectsToFades[i].fadeInfo;
  227. var elementIds = $ax.getElementIdsFromPath(action.objectsToFades[i].objectPath, eventInfo);
  228. for(var j = 0; j < elementIds.length; j++) {
  229. var elementId = elementIds[j];
  230. // Need new scope for elementId and info
  231. (function(elementId, fadeInfo) {
  232. _addAnimation(elementId, function() {
  233. if(fadeInfo.fadeType == "hide") {
  234. $ax('#' + elementId).hide(fadeInfo.options);
  235. } else if(fadeInfo.fadeType == "show") {
  236. $ax('#' + elementId).show(fadeInfo.options, eventInfo);
  237. } else if(fadeInfo.fadeType == "toggle") {
  238. $ax('#' + elementId).toggleVisibility(fadeInfo.options);
  239. }
  240. });
  241. })(elementId, fadeInfo);
  242. }
  243. }
  244. _dispatchAction(eventInfo, actions, index + 1);
  245. };
  246. _actionHandlers.moveWidget = function(eventInfo, actions, index) {
  247. var action = actions[index];
  248. for(var i = 0; i < action.objectsToMoves.length; i++) {
  249. var moveInfo = action.objectsToMoves[i].moveInfo;
  250. var elementIds = $ax.getElementIdsFromPath(action.objectsToMoves[i].objectPath, eventInfo);
  251. for(var j = 0; j < elementIds.length; j++) {
  252. var elementId = elementIds[j];
  253. // Need new scope for elementId and info
  254. (function(elementId, moveInfo) {
  255. var oldTarget = eventInfo.targetElement;
  256. eventInfo.targetElement = elementId;
  257. var xValue = $ax.expr.evaluateExpr(moveInfo.xValue, eventInfo);
  258. var yValue = $ax.expr.evaluateExpr(moveInfo.yValue, eventInfo);
  259. eventInfo.targetElement = oldTarget;
  260. var widgetDragInfo = eventInfo.dragInfo;
  261. _addAnimation(elementId, function() {
  262. if(moveInfo.moveType == "location") {
  263. $ax('#' + elementId).moveTo(xValue, yValue, moveInfo.options);
  264. } else if(moveInfo.moveType == "delta") {
  265. $ax('#' + elementId).moveBy(xValue, yValue, moveInfo.options);
  266. } else if(moveInfo.moveType == "drag") {
  267. $ax('#' + elementId).moveBy(widgetDragInfo.xDelta, widgetDragInfo.yDelta, moveInfo.options);
  268. } else if(moveInfo.moveType == "dragX") {
  269. $ax('#' + elementId).moveBy(widgetDragInfo.xDelta, 0, moveInfo.options);
  270. } else if(moveInfo.moveType == "dragY") {
  271. $ax('#' + elementId).moveBy(0, widgetDragInfo.yDelta, moveInfo.options);
  272. } else if(moveInfo.moveType == "locationBeforeDrag") {
  273. var loc = widgetDragInfo.movedWidgets[elementId];
  274. if(loc) $ax('#' + elementId).moveTo(loc.x, loc.y, moveInfo.options);
  275. else _fireAnimationFromQueue(elementId);
  276. } else if(moveInfo.moveType == "withThis") {
  277. var widgetMoveInfo = $ax.move.GetWidgetMoveInfo();
  278. var srcElementId = $ax.getElementIdsFromEventAndScriptId(eventInfo, eventInfo.srcElement)[0];
  279. var delta = widgetMoveInfo[srcElementId];
  280. $ax('#' + elementId).moveBy(delta.x, delta.y, delta.options);
  281. }
  282. });
  283. })(elementId, moveInfo);
  284. }
  285. }
  286. _dispatchAction(eventInfo, actions, index + 1);
  287. };
  288. _actionHandlers.setWidgetSize = function(eventInfo, actions, index) {
  289. var action = actions[index];
  290. for(var i = 0; i < action.objectsToResize.length; i++) {
  291. var resizeInfo = action.objectsToResize[i].sizeInfo;
  292. var elementIds = $ax.getElementIdsFromPath(action.objectsToResize[i].objectPath, eventInfo);
  293. for(var j = 0; j < elementIds.length; j++) {
  294. var elementId = elementIds[j];
  295. // Need new scope for elementId and info
  296. (function(elementId, resizeInfo) {
  297. var oldTarget = eventInfo.targetElement;
  298. eventInfo.targetElement = elementId;
  299. var width = $ax.expr.evaluateExpr(resizeInfo.width, eventInfo);
  300. var height = $ax.expr.evaluateExpr(resizeInfo.height, eventInfo);
  301. eventInfo.targetElement = oldTarget;
  302. // TODO:[bf] Does this merit it's own file? Is there another file it should be refactored out to? Just refactored out to another function?
  303. _addAnimation(elementId, function() {
  304. var query = $jobj(elementId);
  305. // Get the current width and height
  306. var oldWidth = query.css('width');
  307. oldWidth = Number(oldWidth && oldWidth.substring(0, oldWidth.length - 2));
  308. var oldHeight = query.css('height');
  309. oldHeight = Number(oldHeight && oldHeight.substring(0, oldHeight.length - 2));
  310. // If either one is not a number, use the old value
  311. width = width != "" ? Number(width) : oldWidth;
  312. height = height != "" ? Number(height) : oldHeight;
  313. width = isNaN(width) ? oldWidth : width;
  314. height = isNaN(height) ? oldHeight : height;
  315. // can't be negative
  316. width = Math.max(width, 0);
  317. height = Math.max(height, 0);
  318. if(height == oldHeight && width == oldWidth) {
  319. _fireAnimationFromQueue(elementId);
  320. return;
  321. }
  322. var css = { width: width, height: height };
  323. var obj = $obj(elementId);
  324. if(obj.percentWidth) css = { height: height };
  325. // No longer fitToContent, calculate additional styling that needs to be done.
  326. $ax.dynamicPanelManager.setFitToContentCss(elementId, false, oldWidth, oldHeight);
  327. var easing = resizeInfo.easing || 'none';
  328. var duration = resizeInfo.duration || 0;
  329. var stateCss = $ax.deepCopy(css);
  330. // This will move panel if fixed. The callback will make sure resizing ends there.
  331. if((obj.fixedHorizontal && obj.fixedHorizontal == 'center') || (obj.fixedVertical && obj.fixedVertical == 'middle')) {
  332. var loc = $ax.dynamicPanelManager.getFixedPosition(elementId, oldWidth, oldHeight, width, height);
  333. if(loc) {
  334. if(loc[0] != 0 && !$ax.dynamicPanelManager.isPercentWidthPanel(obj)) css['margin-left'] = '+=' + loc[0];
  335. if(loc[1] != 0) css['margin-top'] = '+=' + loc[1];
  336. }
  337. }
  338. var onComplete = function() {
  339. $ax.flyoutManager.updateFlyout(elementId);
  340. $ax.dynamicPanelManager.fitParentPanel(elementId);
  341. $ax.dynamicPanelManager.updatePanelPercentWidth(elementId);
  342. $ax.dynamicPanelManager.updatePanelContentPercentWidth(elementId);
  343. $ax.event.raiseSyntheticEvent(elementId, 'onResize');
  344. _fireAnimationFromQueue(elementId);
  345. };
  346. // This does the resize animation. Moving is handled elsewhere.
  347. if(easing == 'none') {
  348. query.animate(css, 0);
  349. query.children().animate(css, 0);
  350. onComplete();
  351. } else {
  352. query.children().animate(stateCss, duration, easing);
  353. query.animate(css, duration, easing, onComplete);
  354. }
  355. });
  356. })(elementId, resizeInfo);
  357. }
  358. }
  359. _dispatchAction(eventInfo, actions, index + 1);
  360. };
  361. _actionHandlers.setPanelOrder = function(eventInfo, actions, index) {
  362. var action = actions[index];
  363. for(var i = 0; i < action.panelPaths.length; i++) {
  364. var func = action.panelPaths[i].setOrderInfo.bringToFront ? 'bringToFront' : 'sendToBack';
  365. var elementIds = $ax.getElementIdsFromPath(action.panelPaths[i].panelPath, eventInfo);
  366. for(var j = 0; j < elementIds.length; j++) $ax('#' + elementIds[j])[func]();
  367. }
  368. _dispatchAction(eventInfo, actions, index + 1);
  369. };
  370. _actionHandlers.modifyDataSetEditItems = function(eventInfo, actions, index) {
  371. var action = actions[index];
  372. var add = action.repeatersToAddTo;
  373. var repeaters = add || action.repeatersToRemoveFrom;
  374. var itemId;
  375. for(var i = 0; i < repeaters.length; i++) {
  376. var data = repeaters[i];
  377. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  378. var id = $ax.getElementIdsFromPath(data.path, eventInfo)[0];
  379. if(data.addType == 'this') {
  380. var scriptId = $ax.repeater.getScriptIdFromElementId(eventInfo.srcElement);
  381. itemId = $ax.repeater.getItemIdFromElementId(eventInfo.srcElement);
  382. var repeaterId = $ax.getParentRepeaterFromScriptId(scriptId);
  383. if(add) $ax.repeater.addEditItems(repeaterId, [itemId]);
  384. else $ax.repeater.removeEditItems(repeaterId, [itemId]);
  385. } else if(data.addType == 'all') {
  386. var allItems = $ax.repeater.getAllItemIds(id);
  387. if(add) $ax.repeater.addEditItems(id, allItems);
  388. else $ax.repeater.removeEditItems(id, allItems);
  389. } else {
  390. var oldTarget = eventInfo.targetElement;
  391. var itemIds = $ax.repeater.getAllItemIds(id);
  392. var itemIdsToAdd = [];
  393. for(var j = 0; j < itemIds.length; j++) {
  394. itemId = itemIds[j];
  395. eventInfo.targetElement = $ax.repeater.createElementId(id, itemId);
  396. if($ax.expr.evaluateExpr(data.query, eventInfo) == "true") {
  397. itemIdsToAdd[itemIdsToAdd.length] = String(itemId);
  398. }
  399. eventInfo.targetElement = oldTarget;
  400. }
  401. if(add) $ax.repeater.addEditItems(id, itemIdsToAdd);
  402. else $ax.repeater.removeEditItems(id, itemIdsToAdd);
  403. }
  404. }
  405. _dispatchAction(eventInfo, actions, index + 1);
  406. };
  407. _action.repeaterInfoNames = { addItemsToDataSet: 'dataSetsToAddTo', deleteItemsFromDataSet: 'dataSetItemsToRemove', updateItemsInDataSet: 'dataSetsToUpdate',
  408. addFilterToRepeater: 'repeatersToAddFilter', removeFilterFromRepeater: 'repeatersToRemoveFilter',
  409. addSortToRepeater: 'repeaterToAddSort', removeSortFromRepeater: 'repeaterToRemoveSort',
  410. setRepeaterToPage: 'repeatersToSetPage', setItemsPerRepeaterPage: 'repeatersToSetItemCount'
  411. };
  412. _actionHandlers.addItemsToDataSet = function(eventInfo, actions, index) {
  413. var action = actions[index];
  414. for(var i = 0; i < action.dataSetsToAddTo.length; i++) {
  415. var datasetInfo = action.dataSetsToAddTo[i];
  416. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  417. var id = $ax.getElementIdsFromPath(datasetInfo.path, eventInfo)[0];
  418. if(_ignoreAction(id)) continue;
  419. var dataset = datasetInfo.data;
  420. for(var j = 0; j < dataset.length; j++) $ax.repeater.addItem(id, $ax.deepCopy(dataset[j]), eventInfo);
  421. if(dataset.length) _addRefresh(id);
  422. }
  423. _dispatchAction(eventInfo, actions, index + 1);
  424. };
  425. _actionHandlers.deleteItemsFromDataSet = function(eventInfo, actions, index) {
  426. var action = actions[index];
  427. for(var i = 0; i < action.dataSetItemsToRemove.length; i++) {
  428. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  429. var deleteInfo = action.dataSetItemsToRemove[i];
  430. var id = $ax.getElementIdsFromPath(deleteInfo.path, eventInfo)[0];
  431. if(_ignoreAction(id)) continue;
  432. $ax.repeater.deleteItems(id, eventInfo, deleteInfo.type, deleteInfo.rule);
  433. _addRefresh(id);
  434. }
  435. _dispatchAction(eventInfo, actions, index + 1);
  436. };
  437. _actionHandlers.updateItemsInDataSet = function(eventInfo, actions, index) {
  438. var action = actions[index];
  439. for(var i = 0; i < action.dataSetsToUpdate.length; i++) {
  440. var dataSet = action.dataSetsToUpdate[i];
  441. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  442. var id = $ax.getElementIdsFromPath(dataSet.path, eventInfo)[0];
  443. if(_ignoreAction(id)) continue;
  444. $ax.repeater.updateEditItems(id, dataSet.props, eventInfo, dataSet.type, dataSet.rule);
  445. _addRefresh(id);
  446. }
  447. _dispatchAction(eventInfo, actions, index + 1);
  448. };
  449. _actionHandlers.setRepeaterToDataSet = function(eventInfo, actions, index) {
  450. var action = actions[index];
  451. for(var i = 0; i < action.repeatersToSet.length; i++) {
  452. var setRepeaterInfo = action.repeatersToSet[i];
  453. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  454. var id = $ax.getElementIdsFromPath(setRepeaterInfo.path, eventInfo)[0];
  455. $ax.repeater.setDataSet(id, setRepeaterInfo.localDataSetId);
  456. }
  457. _dispatchAction(eventInfo, actions, index + 1);
  458. };
  459. _actionHandlers.addFilterToRepeater = function(eventInfo, actions, index) {
  460. var action = actions[index];
  461. for(var i = 0; i < action.repeatersToAddFilter.length; i++) {
  462. var addFilterInfo = action.repeatersToAddFilter[i];
  463. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  464. var id = $ax.getElementIdsFromPath(addFilterInfo.path, eventInfo)[0];
  465. if(_ignoreAction(id)) continue;
  466. $ax.repeater.addFilter(id, addFilterInfo.label, addFilterInfo.filter, eventInfo.srcElement);
  467. _addRefresh(id);
  468. }
  469. _dispatchAction(eventInfo, actions, index + 1);
  470. };
  471. _actionHandlers.removeFilterFromRepeater = function(eventInfo, actions, index) {
  472. var action = actions[index];
  473. for(var i = 0; i < action.repeatersToRemoveFilter.length; i++) {
  474. var removeFilterInfo = action.repeatersToRemoveFilter[i];
  475. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  476. var id = $ax.getElementIdsFromPath(removeFilterInfo.path, eventInfo)[0];
  477. if(_ignoreAction(id)) continue;
  478. if(removeFilterInfo.removeAll) $ax.repeater.removeFilter(id);
  479. else if(removeFilterInfo.filterName != '') {
  480. $ax.repeater.removeFilter(id, removeFilterInfo.filterName);
  481. }
  482. _addRefresh(id);
  483. }
  484. _dispatchAction(eventInfo, actions, index + 1);
  485. };
  486. _actionHandlers.addSortToRepeater = function(eventInfo, actions, index) {
  487. var action = actions[index];
  488. for(var i = 0; i < action.repeatersToAddSort.length; i++) {
  489. var addSortInfo = action.repeatersToAddSort[i];
  490. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  491. var id = $ax.getElementIdsFromPath(addSortInfo.path, eventInfo)[0];
  492. if(_ignoreAction(id)) continue;
  493. $ax.repeater.addSort(id, addSortInfo.label, addSortInfo.columnName, addSortInfo.ascending, addSortInfo.toggle, addSortInfo.sortType);
  494. _addRefresh(id);
  495. }
  496. _dispatchAction(eventInfo, actions, index + 1);
  497. };
  498. _actionHandlers.removeSortFromRepeater = function(eventInfo, actions, index) {
  499. var action = actions[index];
  500. for(var i = 0; i < action.repeatersToRemoveSort.length; i++) {
  501. var removeSortInfo = action.repeatersToRemoveSort[i];
  502. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  503. var id = $ax.getElementIdsFromPath(removeSortInfo.path, eventInfo)[0];
  504. if(_ignoreAction(id)) continue;
  505. if(removeSortInfo.removeAll) $ax.repeater.removeSort(id);
  506. else if(removeSortInfo.sortName != '') $ax.repeater.removeSort(id, removeSortInfo.sortName);
  507. _addRefresh(id);
  508. }
  509. _dispatchAction(eventInfo, actions, index + 1);
  510. };
  511. _actionHandlers.setRepeaterToPage = function(eventInfo, actions, index) {
  512. var action = actions[index];
  513. for(var i = 0; i < action.repeatersToSetPage.length; i++) {
  514. var setPageInfo = action.repeatersToSetPage[i];
  515. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  516. var id = $ax.getElementIdsFromPath(setPageInfo.path, eventInfo)[0];
  517. if(_ignoreAction(id)) continue;
  518. var oldTarget = eventInfo.targetElement;
  519. eventInfo.targetElement = id;
  520. $ax.repeater.setRepeaterToPage(id, setPageInfo.pageType, setPageInfo.pageValue, eventInfo);
  521. eventInfo.targetElement = oldTarget;
  522. _addRefresh(id);
  523. }
  524. _dispatchAction(eventInfo, actions, index + 1);
  525. };
  526. _actionHandlers.setItemsPerRepeaterPage = function(eventInfo, actions, index) {
  527. var action = actions[index];
  528. for(var i = 0; i < action.repeatersToSetItemCount.length; i++) {
  529. var setItemCountInfo = action.repeatersToSetItemCount[i];
  530. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  531. var id = $ax.getElementIdsFromPath(setItemCountInfo.path, eventInfo)[0];
  532. if(_ignoreAction(id)) continue;
  533. if(setItemCountInfo.noLimit) $ax.repeater.setNoItemLimit(id);
  534. else $ax.repeater.setItemLimit(id, setItemCountInfo.itemCountValue, eventInfo);
  535. _addRefresh(id);
  536. }
  537. _dispatchAction(eventInfo, actions, index + 1);
  538. };
  539. _actionHandlers.refreshRepeater = function(eventInfo, actions, index) {
  540. // We use this as a psudo action now.
  541. var action = actions[index];
  542. for(var i = 0; i < action.repeatersToRefresh.length; i++) {
  543. var id = $ax.getElementIdsFromPath(action.repeatersToRefresh[i], eventInfo)[i];
  544. var idIndex = _repeatersToRefeash.indexOf(id);
  545. if(idIndex == -1) continue;
  546. $ax.repeater.refreshRepeater(id, eventInfo);
  547. $ax.splice(_repeatersToRefeash, index, 1);
  548. }
  549. _dispatchAction(eventInfo, actions, index + 1);
  550. };
  551. _actionHandlers.scrollToWidget = function(eventInfo, actions, index) {
  552. var action = actions[index];
  553. var elementIds = $ax.getElementIdsFromPath(action.objectPath, eventInfo);
  554. if(elementIds.length > 0) $ax('#' + elementIds[0]).scroll(action.options);
  555. _dispatchAction(eventInfo, actions, index + 1);
  556. };
  557. _actionHandlers.enableDisableWidgets = function(eventInfo, actions, index) {
  558. var action = actions[index];
  559. for(var i = 0; i < action.pathToInfo.length; i++) {
  560. var elementIds = $ax.getElementIdsFromPath(action.pathToInfo[i].objectPath, eventInfo);
  561. var enable = action.pathToInfo[i].enableDisableInfo.enable;
  562. for(var j = 0; j < elementIds.length; j++) $ax('#' + elementIds[j]).enabled(enable);
  563. }
  564. _dispatchAction(eventInfo, actions, index + 1);
  565. };
  566. _actionHandlers.setImage = function(eventInfo, actions, index) {
  567. var oldTarget = eventInfo.targetElement;
  568. var action = actions[index];
  569. var view = $ax.adaptive.currentViewId;
  570. eventInfo.image = true;
  571. for(var i = 0; i < action.imagesToSet.length; i++) {
  572. var imgInfo = action.imagesToSet[i];
  573. imgInfo = view ? imgInfo.adaptive[view] : imgInfo.base;
  574. var elementIds = $ax.getElementIdsFromPath(action.imagesToSet[i].objectPath, eventInfo);
  575. for(var j = 0; j < elementIds.length; j++) {
  576. var elementId = elementIds[j];
  577. eventInfo.targetElement = elementId;
  578. var evaluatedImgs = _evaluateImages(imgInfo, eventInfo);
  579. var img = evaluatedImgs.normal;
  580. if($ax.style.IsWidgetDisabled(elementId)) {
  581. if(imgInfo.disabled) img = evaluatedImgs.disabled;
  582. } else if($ax.style.IsWidgetSelected(elementId)) {
  583. if(imgInfo.selected) img = evaluatedImgs.selected;
  584. } else if($ax.event.mouseDownObjectId == elementId && imgInfo.mouseDown) img = evaluatedImgs.mouseDown;
  585. else if($ax.event.mouseOverIds.indexOf(elementId) != -1 && imgInfo.mouseOver) {
  586. img = evaluatedImgs.mouseOver;
  587. //Update mouseOverObjectId
  588. var currIndex = $ax.event.mouseOverIds.indexOf($ax.event.mouseOverObjectId);
  589. var imgIndex = $ax.event.mouseOverIds.indexOf(elementId);
  590. if(currIndex < imgIndex) $ax.event.mouseOverObjectId = elementId;
  591. }
  592. // $('#' + $ax.repeater.applySuffixToElementId(elementId, '_img')).attr('src', img);
  593. $jobj($ax.style.GetImageIdFromShape(elementId)).attr('src', img);
  594. //Set up overrides
  595. $ax.style.mapElementIdToImageOverrides(elementId, evaluatedImgs);
  596. $ax.style.updateElementIdImageStyle(elementId);
  597. }
  598. }
  599. eventInfo.targetElement = oldTarget;
  600. eventInfo.image = false;
  601. _dispatchAction(eventInfo, actions, index + 1);
  602. };
  603. var _evaluateImages = function(imgInfo, eventInfo) {
  604. var retVal = {};
  605. for(var state in imgInfo) {
  606. if(!imgInfo.hasOwnProperty(state)) continue;
  607. var img = imgInfo[state].path || $ax.expr.evaluateExpr(imgInfo[state].literal, eventInfo);
  608. if(!img) img = $axure.utils.getTransparentGifPath();
  609. retVal[state] = img;
  610. }
  611. return retVal;
  612. };
  613. $ax.clearRepeaterImageOverrides = function(repeaterId) {
  614. var childIds = $ax.getChildElementIdsForRepeater(repeaterId);
  615. for(var i = childIds; i < childIds.length; i++) $ax.style.deleteElementIdToImageOverride(childIds[i]);
  616. };
  617. _actionHandlers.setFocusOnWidget = function(eventInfo, actions, index) {
  618. var action = actions[index];
  619. if(action.objectPaths.length > 0) {
  620. var elementIds = $ax.getElementIdsFromPath(action.objectPaths[0], eventInfo);
  621. if(elementIds.length > 0) {
  622. $ax('#' + elementIds[0]).focus();
  623. }
  624. }
  625. _dispatchAction(eventInfo, actions, index + 1);
  626. };
  627. _actionHandlers.expandCollapseTree = function(eventInfo, actions, index) {
  628. var action = actions[index];
  629. for(var i = 0; i < action.pathToInfo.length; i++) {
  630. var pair = action.pathToInfo[i];
  631. var elementIds = $ax.getElementIdsFromPath(pair.treeNodePath, eventInfo);
  632. for(var j = 0; j < elementIds.length; j++) $ax('#' + elementIds[j]).expanded(pair.expandCollapseInfo.expand);
  633. }
  634. _dispatchAction(eventInfo, actions, index + 1);
  635. };
  636. _actionHandlers.other = function(eventInfo, actions, index) {
  637. var action = actions[index];
  638. $ax.navigate({
  639. url: $axure.utils.getOtherPath() + "#other=" + encodeURI(action.otherDescription),
  640. target: "popup",
  641. includeVariables: false,
  642. popupOptions: action.popup
  643. });
  644. _dispatchAction(eventInfo, actions, index + 1);
  645. };
  646. _actionHandlers.raiseEvent = function(eventInfo, actions, index) {
  647. var action = actions[index];
  648. //look for the nearest element id
  649. if(eventInfo.srcElement) {
  650. var objId = eventInfo.srcElement;
  651. var obj = $ax.getObjectFromElementId(objId);
  652. var rdoId = $ax.getRdoParentFromElementId(objId);
  653. var rdo = $ax.getObjectFromElementId(rdoId);
  654. // Check if rdo should be this
  655. var oldIsMasterEvent = eventInfo.isMasterEvent;
  656. if(obj.type == 'referenceDiagramObject' && eventInfo.isMasterEvent) {
  657. rdoId = objId;
  658. rdo = obj;
  659. // It is now an rdo event
  660. eventInfo.isMasterEvent = false;
  661. }
  662. for(var i = 0; i < action.raisedEvents.length; i++) {
  663. var raisedEvent = action.raisedEvents[i];
  664. var oldRaisedId = eventInfo.raisedId;
  665. var event = rdo.interactionMap && rdo.interactionMap && rdo.interactionMap.raised[raisedEvent];
  666. // raised event will optimize away if it doesn't do anything. Whole interaction map may be optimized away as well.
  667. if(event) {
  668. var oldSrc = eventInfo.srcElement;
  669. eventInfo.srcElement = rdoId;
  670. eventInfo.raisedId = rdoId;
  671. $ax.event.handleEvent(rdoId, eventInfo, event, false, true);
  672. eventInfo.raisedId = oldRaisedId;
  673. eventInfo.srcElement = oldSrc;
  674. }
  675. }
  676. eventInfo.isMasterEvent = oldIsMasterEvent;
  677. }
  678. _dispatchAction(eventInfo, actions, index + 1);
  679. };
  680. });