require_dependency "phcscriptcdnpro/application_controller" module Phcscriptcdnpro class Script::ListingsController < ApplicationController # Security & Action Filters before_action :require_user before_action :authrocket_membership_info before_action :set_paper_trail_whodunnit before_action :set_script_listing, only: [:show, :edit, :update, :destroy] # INDEX - Script Listings def index @script_listings = Script::Listing.where(oganization_id: authrocket_membership_info.org_id) end # DETAILS - Script Listings def show @script_listings = Script::Listing.friendly.find(params[:id]) @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcmemberspro::Directory::Category') end # NEW - Script Listings def new @script_listing = Script::Listing.new end # EDIT - Script Listings def edit end # POST - Script Listings def create @script_listing = Script::Listing.new(script_listing_params) @script_listing.user_id = current_user.id @script_listing.user_name = current_user.username @script_listing.membership_id = authrocket_membership_info.id @script_listing.oganization_id = authrocket_membership_info.org_id if @script_listing.save redirect_to script_listings_path, notice: 'Listing was successfully created.' else render :new end end # PATCH/PUT - Script Listings def update @script_listing.user_id = current_user.id @script_listing.user_name = current_user.username @script_listing.membership_id = authrocket_membership_info.id @script_listing.oganization_id = authrocket_membership_info.org_id if @script_listing.update(script_listing_params) redirect_to script_listings_path, notice: 'Listing was successfully updated.' else render :edit end end # DELETE - Script Listings def destroy @script_listing.destroy redirect_to script_listings_path, notice: 'Listing was successfully destroyed.' end private # Common Callbacks def set_script_listing @script_listing = Script::Listing.friendly.find(params[:id]) end # Whitelist def script_listing_params params.require(:script_listing).permit(:scripttitle, :scriptdescription, :descriptionsource, :scriptwebsite, :scripttwitter, :scriptgithub, :scriptinitialrelease, :scriptlastestrelease, :scriptbetarelease, :scriptstatus, :slug, :user_id, :user_name, :membership_id, :oganization_id, :version_id, :author_id, :licence_id) end end end