Created
December 19, 2018 17:46
-
-
Save jstanden/3026b6232e2d6da92f53ed3422860a6f to your computer and use it in GitHub Desktop.
[Cerb] An importable 'Owner' widget for ticket profiles that provides take/assign/unassign shortcuts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"widget": { | |
"uid": "profile_widget_168", | |
"_context": "cerberusweb.contexts.profile.widget", | |
"name": "Owner", | |
"extension_id": "cerb.profile.tab.widget.html", | |
"pos": 2, | |
"width_units": 2, | |
"zone": "sidebar", | |
"extension_params": { | |
"template": "{% set is_writeable = cerb_record_writeable(record__context,record_id,current_worker__context,current_worker_id) %}\r\n<div id=\"widget{{widget_id}}\">\r\n\t<div style=\"float:left;padding:0 10px 5px 5px;\">\r\n\t\t<img src=\"{{cerb_avatar_url(record_owner__context,record_owner_id,record_owner_updated)}}\" width=\"50\" style=\"border-radius:50px;\">\r\n\t</div>\r\n\t<div style=\"position:relative;\">\r\n\t\t<div>\r\n\t\t\t{% if record_owner_id == 0 %}\r\n\t\t\t\t<span style=\"font-size:2em;color:rgb(100,100,100);font-weight:bold;\">\r\n\t\t\t\t\t({{'common.nobody'|cerb_translate|lower}})\r\n\t\t\t\t</span>\r\n\t\t\t{% else %}\r\n\t\t\t\t\t<a href=\"javascript:;\" class=\"cerb-peek-trigger no-underline\" style=\"font-size:2em;color:rgb(100,100,100);font-weight:bold;\" data-context=\"cerberusweb.contexts.worker\" data-context-id=\"{{record_owner_id}}\">{{record_owner__label}}</a>\r\n\t\t\t\t\t<div>\r\n\t\t\t\t\t\t{{record_owner_title}}\r\n\t\t\t\t\t</div>\r\n\t\t\t{% endif %}\r\n\r\n\t\t\t{% if is_writeable %}\r\n\t\t\t<div class=\"cerb-buttons-toolbar\" style=\"display:none;position:absolute;top:0;right:0;\">\r\n\t\t\t\t<button type=\"button\" title=\"{{'common.assign'|cerb_translate|capitalize}} (Shift+T)\" class=\"cerb-button-assign cerb-chooser-trigger\" data-context=\"cerberusweb.contexts.worker\" data-single=\"true\" data-query=\"group:(id:{{record_group_id}}) isDisabled:n\">\r\n\t\t\t\t\t<span class=\"glyphicons glyphicons-send\"></span>\r\n\t\t\t\t</button>\r\n\t\t\t\t\r\n\t\t\t\t{% if record_owner_id %}\r\n\t\t\t\t<button type=\"button\" title=\"{{'common.unassign'|cerb_translate|capitalize}} (U)\" class=\"cerb-button-unassign\">\r\n\t\t\t\t\t<span class=\"glyphicons glyphicons-circle-remove\"></span>\r\n\t\t\t\t</button>\r\n\t\t\t\t{% endif %}\r\n\t\t\t</div>\r\n\t\t\t{% endif %}\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n\r\n<script type=\"text/javascript\">\r\n$(function() {\r\n\tvar $widget = $('#widget{{widget_id}}');\r\n\tvar $parent = $widget.closest('.cerb-profile-widget')\r\n\t\t.off('.widget{{widget_id}}')\r\n\t\t;\r\n\tvar $toolbar = $widget.find('div.cerb-buttons-toolbar');\r\n\tvar $tab = $parent.closest('.cerb-profile-layout');\r\n\t\r\n\tvar $button_take = $widget.find('button.cerb-button-take');\r\n\tvar $button_assign = $widget.find('.cerb-chooser-trigger');\r\n\tvar $button_unassign = $widget.find('button.cerb-button-unassign');\r\n\r\n\t$widget.find('.cerb-peek-trigger')\r\n\t\t.cerbPeekTrigger()\r\n\t\t;\r\n\t\t\r\n\t{% if is_writeable %}\r\n\t$widget\r\n\t\t.on('mouseover', function() {\r\n\t\t\t$toolbar.show();\r\n\t\t})\r\n\t\t.on('mouseout', function() {\r\n\t\t\t$toolbar.hide();\r\n\t\t})\r\n\t\t;\r\n\t{% endif %}\r\n\t\r\n\t{% if is_writeable %}\r\n\t$button_assign\r\n\t\t.cerbChooserTrigger()\r\n\t\t.on('cerb-chooser-selected', function(e) {\r\n\t\t\tif(!e.values || !$.isArray(e.values))\r\n\t\t\t\treturn;\r\n\t\t\t\t\r\n\t\t\tif(e.values.length != 1)\r\n\t\t\t\treturn;\r\n\r\n\t\t\tvar owner_id = e.values[0];\r\n\t\t\t\r\n\t\t\tvar params = {\r\n\t\t\t\t'c': 'display',\r\n\t\t\t\t'a': 'doAssign',\r\n\t\t\t\t'ticket_id': {{record_id}},\r\n\t\t\t\t'owner_id': owner_id\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tgenericAjaxGet('',$.param(params), function(response) {\r\n\t\t\t\t// Refresh the entire page\r\n\t\t\t\tdocument.location.reload();\r\n\t\t\t});\r\n\t\t})\r\n\t\t;\r\n\t\t\r\n\t$button_unassign\r\n\t\t.on('click', function(e) {\r\n\t\t\tvar params = {\r\n\t\t\t\t'c': 'display',\r\n\t\t\t\t'a': 'doAssign',\r\n\t\t\t\t'ticket_id': {{record_id}},\r\n\t\t\t\t'owner_id': 0\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tgenericAjaxGet('',$.param(params), function(response) {\r\n\t\t\t\t// Refresh the entire page\r\n\t\t\t\tdocument.location.reload();\r\n\t\t\t});\r\n\t\t})\r\n\t\t;\r\n\t\t\r\n\t\t{# Allow the (t)ake shortcut for 'assign to me' if unassigned #}\r\n\t\t{% if record_owner_id == 0%}\r\n\t\t$parent.on('keydown.widget{{widget_id}}', null, 'T', function(e) {\r\n\t\t\te.stopPropagation();\r\n\t\t\te.preventDefault();\r\n\t\t\t\r\n\t\t\tvar params = {\r\n\t\t\t\t'c': 'display',\r\n\t\t\t\t'a': 'doAssign',\r\n\t\t\t\t'ticket_id': {{record_id}},\r\n\t\t\t\t'owner_id': {{current_worker_id}}\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tgenericAjaxGet('',$.param(params), function(response) {\r\n\t\t\t\t// Refresh the entire page\r\n\t\t\t\tdocument.location.reload();\r\n\t\t\t});\r\n\t\t});\r\n\t\t{% endif %}\r\n\t\t\r\n\t\t$parent.on('keydown.widget{{widget_id}}', null, 'Shift+T', function(e) {\r\n\t\t\te.stopPropagation();\r\n\t\t\te.preventDefault();\r\n\t\t\t$button_assign.click();\r\n\t\t});\r\n\r\n\t\t$parent.on('keydown.widget{{widget_id}}', null, 'U', function(e) {\r\n\t\t\te.stopPropagation();\r\n\t\t\te.preventDefault();\r\n\t\t\t$button_unassign.click();\r\n\t\t});\r\n\r\n\t{% endif %}\r\n});\r\n</script>" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment