note description: "Summary description for {ES_CLOUD_PLANS_ADMIN_HANDLER}." author: "" date: "$Date$" revision: "$Revision$" class ES_CLOUD_PLANS_ADMIN_HANDLER inherit ES_CLOUD_ADMIN_HANDLER WSF_URI_TEMPLATE_HANDLER create make feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) do if api.has_permission ("manage es accounts") then if req.is_get_request_method then if attached {WSF_STRING} req.path_parameter ("pid") as p_pid then if attached es_cloud_api.plan_by_name (p_pid.value) as p then display_plan (p, req, res) else send_bad_request (req, res) end else display_plans (req, res) end elseif req.is_post_request_method then post_plan (req, res) else send_bad_request (req, res) end else send_access_denied (req, res) end end post_plan (req: WSF_REQUEST; res: WSF_RESPONSE) local r: like new_generic_response l_plan: detachable ES_CLOUD_PLAN l_plan_name: detachable READABLE_STRING_8 l_plan_title, l_plan_description, l_plan_data, l_plan_usage_limits, l_op: detachable READABLE_STRING_32 l_plan_id: INTEGER l_confirmation_field: WSF_FORM_SUBMIT_INPUT s: STRING f: CMS_FORM do r := new_generic_response (req, res) add_primary_tabs (r) create s.make_empty f := new_edit_plan_form (req, Void) if f /= Void then f.process (r) if attached f.last_data as fd then l_plan_id := fd.integer_item ("id") if attached fd.string_item ("name") as l_plan_name_32 and then l_plan_name_32.is_valid_as_string_8 then l_plan_name := l_plan_name_32.to_string_8 else l_plan_name := Void end l_plan_title := fd.string_item ("title") l_plan_description := fd.string_item ("description") l_plan_data := fd.string_item ("data") l_plan_usage_limits := fd.string_item ("usage_limitations_data") l_op := fd.string_item ("op") if l_plan_id /= 0 then l_plan := es_cloud_api.plan (l_plan_id) end if l_plan_name = Void then fd.report_invalid_field ("name", "Missing name") else if l_plan = Void then l_plan := es_cloud_api.plan_by_name (l_plan_name) end if l_op /= Void and then ( l_op.same_string (delete_plan_text) or l_op.same_string (confirm_delete_plan_text) ) then if attached fd.string_item (confirmation_field_name) as l_confirmation and then l_confirmation.same_string ("yes") then if l_plan /= Void then es_cloud_api.delete_plan (l_plan) if es_cloud_api.has_error then fd.report_error ("Issue while deleting plan!") else r.add_success_message ("Plan successfully deleted.") r.set_redirection (api.administration_path ("/cloud/plans/")) end else fd.report_error ("Could not find and delete plan %""+ l_plan_name +"%"!") r.add_error_message ("Could not find and delete plan %""+ l_plan_name +"%"!") end else f := new_edit_plan_form (req, l_plan) r.add_notice_message ("Please confirm the plan deletion!") fd.report_error ("Please confirm the plan deletion!") create l_confirmation_field.make ("op") l_confirmation_field.set_text_value (confirm_delete_plan_text) f.extend (l_confirmation_field) f.set_field_text_value (confirmation_field_name, "yes") if attached f.fields_by_name ("op") as lst then across lst as ic loop if attached {WSF_FORM_SUBMIT_INPUT} ic.item as l_op_submit and then attached l_op_submit.default_value as dv and then dv.same_string_general (delete_plan_text) then f.remove (l_op_submit) end end end end else if l_plan /= Void then r.add_warning_message ("Updating existing plan.") l_plan.set_name (l_plan_name) else create l_plan.make (l_plan_name) end l_plan.set_title (l_plan_title) l_plan.set_description (l_plan_description) l_plan.set_data (l_plan_data) l_plan.set_usage_limitations_data (l_plan_usage_limits) es_cloud_api.save_plan (l_plan) if es_cloud_api.has_error then fd.report_error ("Issue while saving plan!") else r.add_success_message ("Plan successfully saved.") r.set_redirection (api.administration_path ("/cloud/plans/")) end end end if fd.has_error then f.append_to_html (r.wsf_theme, s) end end end r.set_main_content (s) r.execute end display_plans (req: WSF_REQUEST; res: WSF_RESPONSE) local r: like new_generic_response s: STRING_8 do r := new_generic_response (req, res) add_primary_tabs (r) create s.make_from_string ("
Name | Title | Description | data | Limitations | ") s.append (" | ||||
---|---|---|---|---|---|---|---|---|---|
") s.append ("") s.append (html_encoded (ic.item.name)) s.append (" | ") if attached ic.item.title as l_title then s.append ("") s.append (html_encoded (l_title)) s.append (" | ") else s.append ("") s.append (" | ") end if attached ic.item.description as l_description then s.append ("") s.append (html_encoded (l_description)) s.append (" | ") else s.append ("") s.append (" | ") end if attached ic.item.data as l_data then s.append ("") s.append (html_encoded (l_data)) s.append (" | ") else s.append ("") s.append (" | ") end if attached ic.item.usage_limitations_data as l_lim_data and then not l_lim_data.is_whitespace then s.append ("Yes | ") else s.append ("") s.append (" | ") end s.append ("") s.append ("Edit | ") s.append ("Subscriptions") s.append (" | ") s.append ("
Subscriptions to plan ") s.append (html_encoded (a_plan.name)) s.append ("
") if attached new_edit_plan_form (req, a_plan) as f then f.append_to_html (r.wsf_theme, s) end else s := "Permission denied!" end r.set_main_content (s) r.execute end new_edit_plan_form (req: WSF_REQUEST; a_plan: detachable ES_CLOUD_PLAN): CMS_FORM local hf: WSF_FORM_HIDDEN_INPUT tf: WSF_FORM_TEXT_INPUT l_area: WSF_FORM_TEXTAREA l_submit: WSF_FORM_SUBMIT_INPUT s: STRING_8 do create Result.make (req.percent_encoded_path_info, "es-cloud-edit-plan") Result.extend_html_text ("