OANotes
JavaScript Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app/cells
lib
public
test
MIT-LICENSE
README
Rakefile
init.rb
install.rb
uninstall.rb

README

OANotes for rails
=======

"OANotes" as in "Orion's Apotomo Notes".
This Notes widget makes easy to add notes functionality to any rails application.


Pre-requisits
=============

OAWidget, see: http://github.com/Orion98MC/oa_widget
will_paginate for notes pagination, see: http://github.com/mislav/will_paginate


Install
=======

$ cd my_rails_app
$ ./script/plugins install git://github.com/Orion98MC/oa_notes.git

Then, you have to sync the public resources of the plugin to your app's public directory:

$ rake oa_notes:sync_resources

Since you want to manage Notes, you need to have a note model.
By default, OANotes assumes you have a "Note" model. You may create one with the following:

$ ./script/generate model Note content:text
$ rake db:migrate

If you already have a model for the notes you must specify :notes => "MyNoteClass"



About styling and javascript include:
-------------------------------------

Since the OAWidget and OANotes widgets use custom styling and javascript tools, you must include the stylesheets and javacripts in the head of your layout. To help you include the correct set of files, there are helper methods which output the list of required files:

  #oa_widget_javascripts
  #oa_notes_javascripts
  #oa_widget_stylesheets
  #oa_notes_stylesheets

Example of includes to add in app/views/layouts/application.html.haml:
...
  %head
    ...
    = javascript_include_tag oa_widget_javascripts, oa_notes_javascripts
    = stylesheet_link_tag oa_widget_stylesheets, oa_notes_stylesheets


Usage
=====

 OANotes::Container.new("notes", OPTIONS)

 OPTIONS: A hash with following options:

 :notes => string (ex: :notes => "@intervention.notes" or :notes => "MyNote")
 :save => lambda {|config| ...save config hash... } 

scopes:
 :search => a named scope of the model used for searches, it receives self as parameter when called.
 :views => [['My scope 1', :scope1], ...] an array of named scopes for view filter 
 :sorts => [['My filter 1', :filter1], ...] an array of named scopes for the sorting filter

marks:
 :has_markings? => true or false (default: false)
 :toogle_mark! => a model method name, the method is called when the user marks or unmarks a note and is passed the note as parameter
 :marked? => a model method name, the method is called with note as parameter. Must return true or false

customizations:
 :hide => [:search, :filters, :content, :form]
 :pages => [['5', 5], ['Many', 100], ...] an array of per_pages for the per_page filter
 :note_partial => 'partial/path' the partial to use when rendering notes. it is passed a :note locals
 :form_partial => 'partial/path' the partial to use when rendering the form. it is passed a :note locals
 :title => string, this is the title to be displayed in the widget's title bar

params:
 :search_text => string, the text searched using the :search scope
 :view => integer, the index of the current view scope used in the views array
 :sort => integer, the index of the current sort scope used in the sorts array
 :per_page => integer, the number of notes per page used in pagination


Authorizations:
===============
By default, all is allowed, to allow/forbid delete/create/update/mark notes you can create a Authorizations module in OANote module
Put it in app/cells/oa_notes.rb, here is an example:

module OANotes
  module Authorizations
    def delete?(note)
      can? :delete, note
    end

    def create?(note)
      can? :create, note.class
    end

    def update?(note)
      can? :update, note
    end
    
    def toogle_mark?(note)
      can? :toogle_mark, note
    end
  end
end


Examples:
=========
Checkout the wiki page for a simple tutorial: http://github.com/Orion98MC/oa_notes/wiki


Copyright (c) 2010 Thierry Passeron (thierry.passeron@gmail.com), released under the MIT license