Winn Scriptatype: 1.7

Posted by gregwinn

Rails Plugin: WinnScriptatype

This very simple plugin was built for my own use. The idea was to make one call for my checkbox, update to the database, and an effect. This plugin is easy to use and install, i don't have v1.5 setup in an svn so you will need to download it and place it in RAILS_ROOT/vendor/plugins/HERE. If your going to download version 1.7 it's as easy as calling the script/plugin command below in the root of your rails application.

Support/Help

This plugin is 100% supported and you can find help at our RubyForge project. All support questions need to be directed at the project page, thanks for you help!

Install

Version 1.7+
script/plugin install http://winnscriptatype.rubyforge.org/svn/plugins/
Version 1.5 and below
  • Download and unzip the file.
  • Upload the files to your rails project under "RAILS_ROOT/vendor/plugins/HERE"
  • Your all done, restart mongrel and you can start using.

Samples

NOTE: Include Prototype and Scriptaculous or just include the defaults. So why would you use this plugin? By installing this plugin you will be able to make one call to include your checkbox, ajax update and an effect.

So lets say your building a todo list application and want to use checkboxes to finish the todos. So once the user clicks the checkbox the todo is set to finished in the database then fades out from the view. To accomplish this we will make one call with this plugin.


# Lets say this is our finish method for the todo's
def finish
  @user = User.find(params[:userid])
  @todo = Todo.update(params[:id], :finish => 1)
  @todo.save
    render :text => 'true, updated by: ' + @user.name
  else
    render :text => 'false'
  end
end

# Now in the view we call this
checkbox_do_fade('theDiv', 'CheckboxID', {:controller => 'todo', :action => 'finish', :id => todo.id}, {:userid => user.id})

In the above sample i am making a call to get a checkbox, then once the user clicks it will update the database and set 'finish' to '1'. After that it will return true or false if it fails, if true it will Fade the id 'theDiv'.

Other options:


# Below are the ONLY supported calls
checkbox_do_fade # This will fade the element
checkbox_do_puff # This will puff the element
checkbox_do_blindup # and so on...
checkbox_do_dropout # again...

# Added V1.5
checkbox_do_fade_and_appear
checkbox_do_fade_and_blindup
checkbox_do_fade_and_blinddown
checkbox_do_fade_and_puff
checkbox_do_puff_and_fade
checkbox_do_puff_and_appear
checkbox_do_puff_and_blindup
checkbox_do_puff_and_blinddown

# Added V1.7b
textlink_do_fade
textlink_do_puff
textlink_do_blindup
textlink_do_dropout


# Building the call for two effects
checkbox_do_fade_and_appear('*','**','***',{****},{*****})
[Element ID]* This element will receive the first effect (In this example it will be fade)
[Element ID two]** This element will receive the second effect (In this example it will be appear)
[Checkbox ID]*** This is the id of the checkbox it self
**** URL like below
***** URL options like below


# Building the call for textlink
textlink_do_fade('Link Text','divYouWantToUpdate',{***},{****})

# Building the call for one effect
checkbox_do_fade('*', '**', {***}, {****})

[Element ID]* This is the name of the element you want to effect such as a div or table (tr,td)...

[Checkbox ID]** This is the id of the checkbox it self

[URL/path]*** this is the url for the update to take place NOTE: always use controller, 
              action, and id DO NOT place other variables in this block that is for the next block.

[URL/path options]**** This block is used for url options like so: (/path/to/1?userid=1) as you see
                       userid is 1, this is done by using the url options block. You may send an unlimited number of
                       url options with this.

Updates will be made often so keep on the lookout for the latest version.

Now available: Winn Scriptatype: 1.7 Beta plugin.

Latest available stable version: Download Winn Scriptatype: 1.5 Stable plugin

Also available is the nightly dump located here.