diff --git a/init.rb b/init.rb index 39c6db3..311a67c 100644 --- a/init.rb +++ b/init.rb @@ -10,7 +10,9 @@ Redmine::Plugin.register :redmine_qbo do - require_dependency 'qbo_hook_listener' + require_dependency 'issues_form_hook_listener' + require_dependency 'issues_save_hook_listener' + require_dependency 'issues_show_hook_listener' name 'Redmine Quickbooks Online plugin' author 'Rick Barrette' diff --git a/lib/issues_form_hook_listener.rb b/lib/issues_form_hook_listener.rb new file mode 100644 index 0000000..bc62070 --- /dev/null +++ b/lib/issues_form_hook_listener.rb @@ -0,0 +1,32 @@ +#The MIT License (MIT) +# +#Copyright (c) 2016 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +class IssuesFormHookListener < Redmine::Hook::ViewListener + + # Edit Issue Form + # Show a dropdown for quickbooks contacts + def view_issues_form_details_bottom(context={}) + selected = "" + + # Check to see if there is a quickbooks user attached to the issue + if not context[:issue].qbo_customer_id.nil? then + selected_customer = context[:issue].qbo_customer_id + selected_item = context[:issue].qbo_item_id + end + + # Generate the drop down list of quickbooks contacts + select_customer = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), :selected => selected_customer, include_blank: true + + # Generate the drop down list of quickbooks contacts + select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id), :selected => selected_item, include_blank: true + return "
#{select_customer}
#{select_item}
" + end + +end \ No newline at end of file diff --git a/lib/qbo_hook_listener.rb b/lib/issues_save_hook_listener.rb similarity index 57% rename from lib/qbo_hook_listener.rb rename to lib/issues_save_hook_listener.rb index 09989cf..acd3ecb 100644 --- a/lib/qbo_hook_listener.rb +++ b/lib/issues_save_hook_listener.rb @@ -8,51 +8,9 @@ # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -class QboHookListener < Redmine::Hook::ViewListener +class IssuesSaveHookListener < Redmine::Hook::ViewListener - # Edit Issue Form - # Show a dropdown for quickbooks contacts - def view_issues_form_details_bottom(context={}) - selected = "" - - # Check to see if there is a quickbooks user attached to the issue - if not context[:issue].qbo_customer_id.nil? then - selected_customer = context[:issue].qbo_customer_id - selected_item = context[:issue].qbo_item_id - end - - # Generate the drop down list of quickbooks contacts - select_customer = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), :selected => selected_customer, include_blank: true - - # Generate the drop down list of quickbooks contacts - select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id), :selected => selected_item, include_blank: true - return "#{select_customer}
#{select_item}
" - end - - # View Issue - # Display the quickbooks contact in the issue - def view_issues_show_details_bottom(context={}) - value = "" - - # Check to see if there is a quickbooks user attached to the issue - if not context[:issue].qbo_customer_id.nil? then - value = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name - end - - output = content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes") - - # Check to see if there is a quickbooks user attached to the issue - if not context[:issue].qbo_customer_id.nil? then - value = QboItem.find_by_id(context[:issue].qbo_item_id).name - end - - output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes") - - # Display the Customers name in the Issue attributes - return output - end - - # New Issue Saved + # New Issue Saved def controller_issues_edit_after_save(context={}) issue = context[:issue] qbo = Qbo.first diff --git a/lib/issues_show_hook_listener.rb b/lib/issues_show_hook_listener.rb new file mode 100644 index 0000000..52005a7 --- /dev/null +++ b/lib/issues_show_hook_listener.rb @@ -0,0 +1,36 @@ +#The MIT License (MIT) +# +#Copyright (c) 2016 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +class IssuesShowHookListener < Redmine::Hook::ViewListener + + # View Issue + # Display the quickbooks contact in the issue + def view_issues_show_details_bottom(context={}) + value = "" + + # Check to see if there is a quickbooks user attached to the issue + if not context[:issue].qbo_customer_id.nil? then + value = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name + end + + output = content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes") + + # Check to see if there is a quickbooks user attached to the issue + if not context[:issue].qbo_customer_id.nil? then + value = QboItem.find_by_id(context[:issue].qbo_item_id).name + end + + output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes") + + # Display the Customers name in the Issue attributes + return output + end + +end \ No newline at end of file