Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/transactions/behavior-comment-actions.js
| Show All 37 Lines | for (var ii = 0; ii < options.length; ii++) { | ||||
| if (option.value == key) { | if (option.value == key) { | ||||
| return option; | return option; | ||||
| } | } | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| function add_row(option) { | function remove_action(key) { | ||||
| var action = action_map[option.value]; | var row = rows[key]; | ||||
| if (!action) { | if (row) { | ||||
| return; | JX.DOM.remove(row.node); | ||||
| row.option.disabled = false; | |||||
| delete rows[key]; | |||||
| } | } | ||||
| option.disabled = true; | |||||
| var icon = new JX.PHUIXIconView() | |||||
| .setIcon('fa-times-circle'); | |||||
| var remove = JX.$N('a', {href: '#'}, icon.getNode()); | |||||
| var control = new JX.PHUIXFormControl() | |||||
| .setLabel(action.label) | |||||
| .setError(remove) | |||||
| .setControl(action.type, action.spec) | |||||
| .setClass('phui-comment-action'); | |||||
| var node = control.getNode(); | |||||
| JX.Stratcom.addSigil(node, 'touchable'); | |||||
| var remove_action = function() { | |||||
| JX.DOM.remove(node); | |||||
| delete rows[action.key]; | |||||
| option.disabled = false; | |||||
| }; | |||||
| JX.DOM.listen(node, 'gesture.swipe.end', null, function(e) { | |||||
| var data = e.getData(); | |||||
| if (data.direction != 'left') { | |||||
| // Didn't swipe left. | |||||
| return; | |||||
| } | |||||
| if (data.length <= (JX.Vector.getDim(node).x / 2)) { | |||||
| // Didn't swipe far enough. | |||||
| return; | |||||
| } | |||||
| remove_action(); | |||||
| }); | |||||
| rows[action.key] = control; | |||||
| JX.DOM.listen(remove, 'click', null, function(e) { | |||||
| e.kill(); | |||||
| remove_action(); | |||||
| }); | |||||
| place_node.parentNode.insertBefore(node, place_node); | |||||
| return control; | |||||
| } | } | ||||
| function serialize_actions() { | function serialize_actions() { | ||||
| var data = []; | var data = []; | ||||
| for (var k in rows) { | for (var k in rows) { | ||||
| data.push({ | data.push({ | ||||
| type: k, | type: k, | ||||
| value: rows[k].getValue(), | value: rows[k].control.getValue(), | ||||
| initialValue: action_map[k].initialValue || null | initialValue: action_map[k].initialValue || null | ||||
| }); | }); | ||||
| } | } | ||||
| return JX.JSON.stringify(data); | return JX.JSON.stringify(data); | ||||
| } | } | ||||
| function get_data() { | function get_data() { | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (!response.xactions.length) { | ||||
| { | { | ||||
| rootNode: preview_root | rootNode: preview_root | ||||
| }); | }); | ||||
| }; | }; | ||||
| setTimeout(invoke_preview, 0); | setTimeout(invoke_preview, 0); | ||||
| } | } | ||||
| } | } | ||||
| function force_preview() { | |||||
| if (!config.shouldPreview) { | |||||
| return; | |||||
| } | |||||
| new JX.Request(config.actionURI, onresponse) | |||||
| .setData(get_data()) | |||||
| .send(); | |||||
| } | |||||
| function add_row(option) { | |||||
| var action = action_map[option.value]; | |||||
| if (!action) { | |||||
| return; | |||||
| } | |||||
| // Remove any conflicting actions. For example, "Accept Revision" conflicts | |||||
| // with "Reject Revision". | |||||
| var conflict_key = action.conflictKey || null; | |||||
| if (conflict_key !== null) { | |||||
| for (var k in action_map) { | |||||
| if (k === action) { | |||||
| continue; | |||||
| } | |||||
| if (action_map[k].conflictKey !== conflict_key) { | |||||
| continue; | |||||
| } | |||||
| if (!(k in rows)) { | |||||
| continue; | |||||
| } | |||||
| remove_action(k); | |||||
| } | |||||
| } | |||||
| option.disabled = true; | |||||
| var icon = new JX.PHUIXIconView() | |||||
| .setIcon('fa-times-circle'); | |||||
| var remove = JX.$N('a', {href: '#'}, icon.getNode()); | |||||
| var control = new JX.PHUIXFormControl() | |||||
| .setLabel(action.label) | |||||
| .setError(remove) | |||||
| .setControl(action.type, action.spec) | |||||
| .setClass('phui-comment-action'); | |||||
| var node = control.getNode(); | |||||
| JX.Stratcom.addSigil(node, 'touchable'); | |||||
| JX.DOM.listen(node, 'gesture.swipe.end', null, function(e) { | |||||
| var data = e.getData(); | |||||
| if (data.direction != 'left') { | |||||
| // Didn't swipe left. | |||||
| return; | |||||
| } | |||||
| if (data.length <= (JX.Vector.getDim(node).x / 2)) { | |||||
| // Didn't swipe far enough. | |||||
| return; | |||||
| } | |||||
| remove_action(action); | |||||
| }); | |||||
| rows[action.key] = { | |||||
| control: control, | |||||
| node: node, | |||||
| option: option | |||||
| }; | |||||
| JX.DOM.listen(remove, 'click', null, function(e) { | |||||
| e.kill(); | |||||
| remove_action(action); | |||||
| }); | |||||
| place_node.parentNode.insertBefore(node, place_node); | |||||
| force_preview(); | |||||
| return control; | |||||
| } | |||||
| JX.DOM.listen(form_node, ['submit', 'didSyntheticSubmit'], null, function() { | JX.DOM.listen(form_node, ['submit', 'didSyntheticSubmit'], null, function() { | ||||
| input_node.value = serialize_actions(); | input_node.value = serialize_actions(); | ||||
| }); | }); | ||||
| if (config.showPreview) { | if (config.showPreview) { | ||||
| var request = new JX.PhabricatorShapedRequest( | var request = new JX.PhabricatorShapedRequest( | ||||
| config.actionURI, | config.actionURI, | ||||
| onresponse, | onresponse, | ||||
| get_data); | get_data); | ||||
| var trigger = JX.bind(request, request.trigger); | var trigger = JX.bind(request, request.trigger); | ||||
| JX.DOM.listen(form_node, 'keydown', null, trigger); | JX.DOM.listen(form_node, 'keydown', null, trigger); | ||||
| var always_trigger = function() { | JX.DOM.listen(form_node, 'shouldRefresh', null, force_preview); | ||||
| new JX.Request(config.actionURI, onresponse) | |||||
| .setData(get_data()) | |||||
| .send(); | |||||
| }; | |||||
| JX.DOM.listen(form_node, 'shouldRefresh', null, always_trigger); | |||||
| request.start(); | request.start(); | ||||
| var old_device = JX.Device.getDevice(); | var old_device = JX.Device.getDevice(); | ||||
| var ondevicechange = function() { | var ondevicechange = function() { | ||||
| var new_device = JX.Device.getDevice(); | var new_device = JX.Device.getDevice(); | ||||
| var panel = JX.$(config.panelID); | var panel = JX.$(config.panelID); | ||||
| if (new_device == 'desktop') { | if (new_device == 'desktop') { | ||||
| request.setRateLimit(500); | request.setRateLimit(500); | ||||
| // Force an immediate refresh if we switched from another device type | // Force an immediate refresh if we switched from another device type | ||||
| // to desktop. | // to desktop. | ||||
| if (old_device != new_device) { | if (old_device != new_device) { | ||||
| always_trigger(); | force_preview(); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // On mobile, don't show live previews and only save drafts every | // On mobile, don't show live previews and only save drafts every | ||||
| // 10 seconds. | // 10 seconds. | ||||
| request.setRateLimit(10000); | request.setRateLimit(10000); | ||||
| JX.DOM.hide(panel); | JX.DOM.hide(panel); | ||||
| } | } | ||||
| Show All 11 Lines | |||||