From 4895dc03be0017c5b91f94cc111f25ed2bf00947 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 21 Mar 2017 20:58:11 +0800 Subject: [PATCH] code merged and requests and contract page for frontend with filter --- .../javascripts/client_management/default.js | 8 +- .../admin/client_managements_controller.rb | 2 +- .../client_managements_controller.rb | 62 +++++++- .../_contract_partial.html.erb | 46 ++++++ .../_history_partial.html.erb | 42 ++++++ .../client_managements/contracts.html.erb | 89 ++++++++++++ app/views/client_managements/history.html.erb | 103 +++++++++----- app/views/client_managements/index.html.erb | 6 +- .../client_managements/see_contract.html.erb | 133 ++++++++++++++++++ app/views/client_managements/show.html.erb | 8 +- config/locales/en.yml | 4 +- config/locales/zh_tw.yml | 4 +- config/routes.rb | 5 + 13 files changed, 455 insertions(+), 57 deletions(-) create mode 100644 app/views/client_managements/_contract_partial.html.erb create mode 100644 app/views/client_managements/_history_partial.html.erb create mode 100644 app/views/client_managements/contracts.html.erb create mode 100644 app/views/client_managements/see_contract.html.erb diff --git a/app/assets/javascripts/client_management/default.js b/app/assets/javascripts/client_management/default.js index f79d1f0..7cbe8e9 100644 --- a/app/assets/javascripts/client_management/default.js +++ b/app/assets/javascripts/client_management/default.js @@ -37,7 +37,7 @@ function goBackTop(txt, speed) { }); } -var constructPagination = function(current_page, total_pages, type){ +var constructPagination = function(current_page, total_pages){ var ul = $(""), first_li = $("
  • First
  • "), last_li = $("
  • Last
  • "), @@ -77,11 +77,7 @@ var constructPagination = function(current_page, total_pages, type){ } ul.find("a").on("click",function(){ $("*").animate({scrollTop:0}, '300'); - if(type == "tickets"){ - getTickets($(this).data("page")); - }else if(type == "sites"){ - getSites($(this).data("page")); - } + getObjects($(this).data("page")) return false; }) paginationArea.show(); diff --git a/app/controllers/admin/client_managements_controller.rb b/app/controllers/admin/client_managements_controller.rb index 8ee3f8f..3d622d5 100644 --- a/app/controllers/admin/client_managements_controller.rb +++ b/app/controllers/admin/client_managements_controller.rb @@ -84,7 +84,7 @@ class Admin::ClientManagementsController < OrbitAdminController end def contracts - @contracts = RequestContract.all.order_by(:confirmed => 'desc', :created_at => "desc").page(params[:page]).per(10) + @contracts = RequestContract.all.order_by(:created_at => "desc", :confirmed => 'desc').page(params[:page]).per(10) end private diff --git a/app/controllers/client_managements_controller.rb b/app/controllers/client_managements_controller.rb index 038cb9a..453eb1c 100644 --- a/app/controllers/client_managements_controller.rb +++ b/app/controllers/client_managements_controller.rb @@ -181,9 +181,19 @@ class ClientManagementsController < CPanelController end def history - case params[:type] - when nil - @objects = SiteRequest.where(:c_panel_user_id => current_cpanel_user.id).desc(:created_at) + if !params[:query].present? + @objects = SiteRequest.where(:c_panel_user_id => current_cpanel_user.id).desc(:created_at).page(params[:page]).per(15) + elsif params[:query] == "addsites" + @objects = SiteRequest.where(:type => "addsites", :c_panel_user_id => current_cpanel_user.id).desc(:created_at).page(params[:page]).per(15) + else + @objects = SiteRequest.where(:site_id => params[:query], :c_panel_user_id => current_cpanel_user.id).desc(:created_at).page(params[:page]).per(15) + end + if request.xhr? + render :partial => "history_partial" + else + @user_sites = current_cpanel_user.registered_sites.collect{|rs|[rs.title, rs.id.to_s]} + @user_sites << ["New site request", "newsite"] + @user_sites << ["Addition of sites request", "addsites"] end end @@ -191,6 +201,48 @@ class ClientManagementsController < CPanelController @site_request = SiteRequest.where(:uid => params[:request_uid]).first rescue nil end + def see_contract + @contract = RequestContract.where(:uid => params[:contract_uid]).first rescue nil + @site_request = @contract.site_request + end + + def update_contract + contract = RequestContract.where(:uid => params[:contract_uid]).first rescue nil + contract.update_attributes(contract_params) + redirect_to cpanel_contract_show_path(contract.uid) + end + + def cancel_request + request = SiteRequest.where(:uid => params[:request_uid]).first rescue nil + request.destroy if !request.nil? + redirect_to cpanel_myhistory_path(:page => params[:page]) + end + + def contracts + if !params[:query].present? + @objects = SiteRequest.any_of({:site_id.in => current_cpanel_user.registered_site_ids.collect{|id| id.to_s}, :request_contract.ne => nil},{:c_panel_user_id => current_cpanel_user.id, :request_contract.ne => nil}).desc(:created_at).page(params[:page]).per(15) + else + @objects = SiteRequest.where(:site_id => params[:query], :request_contract.ne => nil).desc(:created_at).page(params[:page]).per(15) + end + if request.xhr? + render :partial => "contract_partial" + else + @user_sites = current_cpanel_user.registered_sites.collect{|rs|[rs.title, rs.id.to_s]} + @user_sites << ["New site request", "newsite"] + end + end + + def confirm_contract + contract = RequestContract.where(:uid => params[:contract_uid]).first rescue nil + contract.confirmed = true + contract.save + if params[:ref] == "contract_page" + redirect_to cpanel_contract_show_path(contract.uid) + else + redirect_to cpanel_mycontracts_path(:page => params[:page]) + end + end + private def is_site_authorized_to_user? @@ -229,4 +281,8 @@ class ClientManagementsController < CPanelController params.require(:site_request).permit! end + def contract_params + params.require(:request_contract).permit! + end + end \ No newline at end of file diff --git a/app/views/client_managements/_contract_partial.html.erb b/app/views/client_managements/_contract_partial.html.erb new file mode 100644 index 0000000..c82ff12 --- /dev/null +++ b/app/views/client_managements/_contract_partial.html.erb @@ -0,0 +1,46 @@ + <% if !@objects.empty? %> + <% @objects.each do |object| %> + <% obj = object.request_contract %> +
    + <% case object.type %> + <% when "newsite" %> + + New Site + <% if obj.confirmed %> + Confirmed + <% else %> + Pending + <% end %> + + <% when "existing" %> + + New Request for <%= obj.get_site.title %> + <% if obj.confirmed %> + Confirmed + <% else %> + Pending + <% end %> + + <% end %> +
    + Contract ID: <%= obj.uid %> + <% if object.type == "existing" %> + <%= obj.get_site.site_domain %> + <% end %> + Time :  <%= obj.created_at.strftime("%d %B %Y - %H:%M") %> +
    + + <% if !obj.confirmed && !obj.signed_contract_file.url.nil? %> + Confirm + <% end %> + +
    +<% end %> + +<% else %> +
    +
    + Sorry, we found nothing. +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/client_managements/_history_partial.html.erb b/app/views/client_managements/_history_partial.html.erb new file mode 100644 index 0000000..5176c41 --- /dev/null +++ b/app/views/client_managements/_history_partial.html.erb @@ -0,0 +1,42 @@ +<% if !@objects.empty? %> + <% @objects.each do |obj| %> +
    + <% case obj.type %> + <% when "newsite" %> + New Site + <% when "existing" %> + New Request for <%= obj.get_site.title %> + <% when "addsites" %> + Request for adding sites + <% end %> +
    + Request ID: <%= obj.uid %> + <% if obj.type == "existing" %> + <%= obj.get_site.site_domain %> + <% end %> + Time :  <%= obj.created_at.strftime("%d %B %Y - %H:%M") %> +
    + <% if obj.completed %> + Completed + <% else %> + Requested + <% end %> + + <% if !obj.completed %> + Cancel + <% else %> + <% if (obj.type == "newsite" || obj.type == "existing") && !obj.request_contract.nil? %> + Contract + <% end %> + <% end %> + +
    + <% end %> + +<% else %> +
    +
    + Sorry, we found nothing. +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/client_managements/contracts.html.erb b/app/views/client_managements/contracts.html.erb new file mode 100644 index 0000000..1f08882 --- /dev/null +++ b/app/views/client_managements/contracts.html.erb @@ -0,0 +1,89 @@ +<% content_for :page_menu do %> + +<% end %> +
    +

    + History +

    +
    + Requests + Contracts + Purchases +
    +
    + <%= select_tag "q", options_for_select(@user_sites, params[:q]), :prompt => "All", :class => "form-control" %> + + <% if params[:q].present? %> + Clear + <% end %> +
    +
    +
    +
    +
    +

    Contracts

    + +
    +
    + Sorry, we found nothing. +
    +
    +
    +
    +
    +
    + +
    +
    +
    + \ No newline at end of file diff --git a/app/views/client_managements/history.html.erb b/app/views/client_managements/history.html.erb index e05c49a..5c39931 100644 --- a/app/views/client_managements/history.html.erb +++ b/app/views/client_managements/history.html.erb @@ -12,51 +12,78 @@ History
    - Requests - Contracts + Requests + Contracts Purchases
    - +
    + <%= select_tag "q", options_for_select(@user_sites, params[:q]), :prompt => "All", :class => "form-control" %> + + <% if params[:q].present? %> + Clear + <% end %> +

    Requests

    - <% @objects.each do |obj| %> -
    - <% case obj.type %> - <% when "newsite" %> - New Site - <% when "existing" %> - New Request for <%= obj.get_site.title %> - <% when "addsites" %> - Request for adding sites - <% end %> -
    - Request ID: <%= obj.uid %> - - <% if obj.type == "existing" %> - <%= obj.get_site.site_domain %> - <% end %> - Time :  <%= obj.created_at.strftime("%d %B %Y - %H:%M") %> -
    - Requested - - <% if !obj.completed %> - Cancel - <% else %> - <% if (obj.type == "newsite" || obj.type == "existing") && !obj.request_contract.nil? %> - Contract - <% end %> - <% end %> - + +
    +
    + Sorry, we found nothing.
    - <% end %> +
    +
    +
    +
    +
    +
    - \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/client_managements/index.html.erb b/app/views/client_managements/index.html.erb index 8b615cd..5ae344c 100644 --- a/app/views/client_managements/index.html.erb +++ b/app/views/client_managements/index.html.erb @@ -67,10 +67,10 @@ sitesArea = $("#sites-area"), paginationArea = $("#pagination-area"); $(document).ready(function(){ - getSites(pageNo); + getObjects(pageNo); }) - var getSites = function(page){ + var getObjects = function(page){ pageNo = page; sitesArea.hide(); siteLoading.show(); @@ -87,7 +87,7 @@ $("#total-site-count").text( $("input[type=hidden].total-sites").val()); var total_pages = parseInt(sitesArea.find("input[type=hidden].total-pages").val()); if (total_pages > 1){ - constructPagination(page, total_pages, "sites"); + constructPagination(page, total_pages); } },500) }) diff --git a/app/views/client_managements/see_contract.html.erb b/app/views/client_managements/see_contract.html.erb new file mode 100644 index 0000000..b288daf --- /dev/null +++ b/app/views/client_managements/see_contract.html.erb @@ -0,0 +1,133 @@ +<% content_for :page_menu do %> + +<% end %> +
    +

    + Contract info +

    +
    +
    Contract info
    +
    + Contract Number : + <%= @contract.uid %> +
    +
    + Contract Date : + <%= @contract.created_at.strftime("%d %B %Y") %> +
    +
    + Contract Status : + + <% if @contract.confirmed %> + Confirmed + <% else %> + Not-Confirmed + <% end %> + +
    +
    Request
    +
    + Type : + <%= @site_request.get_request_type %> +
    + <% if @site_request.type == "existing" %> +
    Site Info
    +
    + Site ID : + <%= @site_request.get_site.uid %> +
    +
    + Site Name : + <%= @site_request.get_site.title %> +
    + + <% end %> + <% if !@contract.contract_file.url.nil? || !@contract.signed_contract_file.url.nil? %> +
    Contract Files
    + <% if !@contract.contract_file.url.nil? %> +
    + Contract : + Download +
    + <% end %> + <% if !@contract.signed_contract_file.url.nil? %> +
    + Contract Signed : + Download +
    + <% end %> + <% end %> + +
    Quotaion
    + +
    + Item + Cost in NTD. +
    + <% total_amount = 0 %> + <% ["new_site_cost","hosting_with_rulingdigital_cost","service_cost","option_module_cost","customized_module_cost","template_cost","customized_template_cost","rwd_cost"].each do |attrib| %> + <% amount = @contract.send(attrib.to_sym) %> + <% if amount > 0 %> +
    + <% if attrib == "option_module_cost" %> + <%= t("client_management.#{attrib}") %> +
      + <% rsm = RegisteredModule.find(@site_request.optional_modules) %> + <% rsm.each do |rs|%> +
    1. <%= rs.name %>
    2. + <% end %> +
    +
    + <% else %> + <%= t("client_management.#{attrib}") %> + <% end %> + <%= amount %> +
    + <% end %> + <% total_amount = total_amount + amount %> + <% end %> + +
    + Total : + <%= total_amount %> +
    + + <% if !@contract.confirmed %> + <%= form_for @contract, :url => "/cpanel/contract/#{@contract.uid}/update_contract" do |f| %> +
    + Signed Contract File : + + <%= f.file_field :signed_contract_file, :class=>"file-box" %> + + +
    + <% end %> + <% end %> + +
    + <% if !@contract.confirmed && !@contract.signed_contract_file.url.nil? %> + Confirm Contract + <% end %> + +
    +
    +
    + \ No newline at end of file diff --git a/app/views/client_managements/show.html.erb b/app/views/client_managements/show.html.erb index 376fe18..453cab4 100644 --- a/app/views/client_managements/show.html.erb +++ b/app/views/client_managements/show.html.erb @@ -70,7 +70,7 @@ }); $(document).ready(function(){ - getTickets(pageNo); + getObjects(pageNo); if(category){ $("select#category").val(category); $("#search-clear-btn").removeClass("hide"); @@ -94,7 +94,7 @@ dataType : "json" }).done(function(data){ if(data.success){ - getTickets(pageNo); + getObjects(pageNo); }else{ errorArea.find(".message-text").text("Sorry, we were unable to perform the requested action."); errorArea.removeClass("hide"); @@ -105,7 +105,7 @@ return false; }) - var getTickets = function(page){ + var getObjects = function(page){ pageNo = page; ticketsDom.hide(); loader.show(); @@ -122,7 +122,7 @@ loader.hide(); var total_pages = parseInt(ticketsDom.find("input[type=hidden].total-pages").val()); if (total_pages > 1){ - constructPagination(page, total_pages, "tickets"); + constructPagination(page, total_pages); } }, 500); }) diff --git a/config/locales/en.yml b/config/locales/en.yml index baaacaf..fbe71f7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,4 +44,6 @@ en: contracts: Contracts contract_uid: Contract ID site: Site - created_on: Created On \ No newline at end of file + created_on: Created On + loading_history: Loading History + loading_contracts: Loading Contracts \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7b3476a..e0e6e28 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -44,4 +44,6 @@ zh_tw: contracts: Contracts contract_uid: Contract ID site: Site - created_on: Created On \ No newline at end of file + created_on: Created On + loading_history: Loading History + loading_contracts: Loading Contracts \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8930d85..ddb6d14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,7 +40,12 @@ Rails.application.routes.draw do # history get "history" => "client_managements#history", as: "cpanel_myhistory" + get "contracts" => "client_managements#contracts", as: "cpanel_mycontracts" get "request/:request_uid" => "client_managements#see_request" + get "contract/:contract_uid" => "client_managements#see_contract", as: "cpanel_contract_show" + patch "contract/:contract_uid/update_contract" => "client_managements#update_contract" + get "request/:request_uid/cancel" => "client_managements#cancel_request", as: "cpanel_cancel_request" + get "contract/:contract_uid/confirm" => "client_managements#confirm_contract" # ticket get "site/:site_uid/new_ticket" => "client_managements#new_ticket"