diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb new file mode 100644 index 0000000..bfff993 --- /dev/null +++ b/app/controllers/documents_controller.rb @@ -0,0 +1,71 @@ +class DocumentsController < ApplicationController + + load_and_authorize_resource + def index + respond_to do |format| + format.html {redirect_to rubriken_path} + end + end + def new + @document=Document.new + @document.parent=params[:parent_typ].constantize.find(params[:parent_id]) + @document.typ = 1 + respond_to do |format| + format.js + end + end + def edit + @document = Document.find(params[:id]) + respond_to do |format| + format.js + end + + end + + def create + @document = Document.new(params[:document]) + + respond_to do |format| + if @document.save + # format.html { redirect_to @document, notice: 'Document was successfully created.' } + #format.json { render json: @document, status: :created, location: @document } + format.js + else + # format.html { render action: "new" } + # format.json { render json: @document.errors, status: :unprocessable_entity } + format.js { render action: "new" } + end + end + end + +def update + @document = Document.find(params[:id]) + + respond_to do |format| + if @document.update_attributes(params[:document]) + format.html { redirect_to @document, notice: 'Document was successfully updated.' } + format.json { head :no_content } + format.js + else + # format.html { render action: "edit" } + # format.json { render json: @document.errors, status: :unprocessable_entity } + format.js { render action: "edit"} + end + end + end + def destroy + logger.info("-------------delete------------------") + @document = Document.find(params[:id]) + @document_id = params[:id] + @object=@document.object + @document.destroy + + respond_to do |format| + #format.html { redirect_to @object} + #format.json { head :no_content } + format.js + end + end + + +end diff --git a/app/models/document.rb b/app/models/document.rb new file mode 100644 index 0000000..e7fa2f7 --- /dev/null +++ b/app/models/document.rb @@ -0,0 +1,3 @@ +class Document < ActiveRecord::Base + attr_accessible :etherpadkey, :name, :parent, :text, :typ +end diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb new file mode 100644 index 0000000..d76b082 --- /dev/null +++ b/app/views/documents/_document.html.erb @@ -0,0 +1,8 @@ +
+ <% image_tag("/iconnavy/time.png") %> + <% fa_icon("calendar 2x") %> + + <%= document.title %> + <%= link_to "edit", edit_document_path(document),:remote=>true if can? :edit, document %> + <%= link_to 'Delete', document, method: :delete, data: { confirm: 'Are you sure?' } , remote: true if can? :delete, document %> +
diff --git a/app/views/documents/_nested_form.html.erb b/app/views/documents/_nested_form.html.erb new file mode 100644 index 0000000..8421935 --- /dev/null +++ b/app/views/documents/_nested_form.html.erb @@ -0,0 +1,15 @@ +<%= fa_icon("calendar 2x") %> +

<%= notice %>

+ +<%= semantic_form_for @calentry, :remote=>true, :html=>{:class=>"inline"} do |f| %> + + <%= f.input :start, :as => :datetimepicker %> + <%= f.input :dauer , :as => :string, :append=>"h" %> + <%= f.input :object_id , :as => :hidden %> + <%= f.input :object_type , :as => :hidden %> +<%= f.input :typ , :as => :hidden %> + + + <%= f.action :submit, :as => :input_ %> + +<% end %> diff --git a/app/views/documents/destroy.js.erb b/app/views/documents/destroy.js.erb new file mode 100644 index 0000000..41b315b --- /dev/null +++ b/app/views/documents/destroy.js.erb @@ -0,0 +1 @@ +$("#document_<%= @document_id %>").remove(); diff --git a/app/views/documents/edit.js.erb b/app/views/documents/edit.js.erb new file mode 100644 index 0000000..a63cb2c --- /dev/null +++ b/app/views/documents/edit.js.erb @@ -0,0 +1,6 @@ + +$("#document_<%= @document.id %>").html("<%=escape_javascript( render :partial=>"nested_form" ,:object=>@document)%>"); + + + + \ No newline at end of file diff --git a/app/views/documents/new.js.erb b/app/views/documents/new.js.erb new file mode 100644 index 0000000..28248bb --- /dev/null +++ b/app/views/documents/new.js.erb @@ -0,0 +1,3 @@ +$("#document_new").replaceWith("
<%=escape_javascript( render :partial=>"nested_form" ,:object=>@document) %>
"); + + \ No newline at end of file diff --git a/app/views/documents/update.js.erb b/app/views/documents/update.js.erb new file mode 100644 index 0000000..f5986eb --- /dev/null +++ b/app/views/documents/update.js.erb @@ -0,0 +1 @@ +$("#document_<%= @document.id %>").replaceWith("<%=escape_javascript( render :partial=>"document", :object=>@document)%>"); diff --git a/db/migrate/20141119200355_create_documents.rb b/db/migrate/20141119200355_create_documents.rb new file mode 100644 index 0000000..fc4d30e --- /dev/null +++ b/db/migrate/20141119200355_create_documents.rb @@ -0,0 +1,13 @@ +class CreateDocuments < ActiveRecord::Migration + def change + create_table :documents do |t| + t.integer :typ + t.string :name + t.text :text + t.string :etherpadkey + t.references{polymorphic} :parent + + t.timestamps + end + end +end diff --git a/spec/factories/documents.rb b/spec/factories/documents.rb new file mode 100644 index 0000000..e7d4a9c --- /dev/null +++ b/spec/factories/documents.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :document do + typ 1 +name "MyString" +text "MyText" +etherpadkey "MyString" +parent "" + end + +end diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb new file mode 100644 index 0000000..d39f418 --- /dev/null +++ b/spec/models/document_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Document, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end