logo

Archive for 1 月, 2008


protocalendar.js 用の rails ヘルパメソッド(のひな形)を公開しました

今回、本当はモデルの特定アトリビュートだけにバリデーションを実行するプラグイン「valid_attributes」を公開しようかと思っていたのですが、

個人的なサイトの方で公開してしまったので、今回は protocalendar.js の ruby on rails 用ヘルパメソッド(のひな形)を公開したいと思います。

オプション関係など完璧ではないのですが、独自ヘルパメソッドを作るベースになればと思います。

action_view_ext.rb

module ActionView
  module Helpers
    module FormHelper
      def date_field(object_name, method, options = {})
        result = text_field_for_date(object_name, method, options)
        styleId = options[:id] ? options[:id] : object_name.to_s + '_' + method.to_s
        contents = "InputCalendar.createOnLoaded('#{styleId}', {";
        lang = options[:lang] ? "lang:#{options[:lang]} " : "lang:'ja'"
        contents << lang
        contents << ", startYear:#{options[:startYear]} " if options[:startYear]
        contents << ", endYear:#{options[:endYear]} " if options[:endYear]
        contents << "});";
        return (result + javascript_tag(contents))
      end  

      protected  

      def text_field_for_date(object_name, method, options = {})
        tag = InstanceTag.new(object_name, method, self, nil, options.delete(:object))
        result = tag.value(tag.object)
        unless result.nil?
          time = result.strftime("%Y/%m/%d")
          tag.object.write_attribute(method, time) unless tag.nil?
        end
        return tag.to_input_field_tag("text", options)
      end
    end
  end
end

デフォルトで lang:’ja’ を使っているため、日付フォーマットが yyyy/mm/dd になるように、

FormHelper を拡張して、text_field_for_date で小細工をしています。

cakephp 用のヘルパメソッドも近々公開します。

シンプルな日時選択ライブラリ protocalendar.js v1.1.2 を公開しました

protocalendar.js v1.1.2 を公開しました。

変更点は以下の通りです。
【変更点】

*prototype.js 1.5 系で動作しない場合があるのを修正。

【使い方はこちら】
http://labs.spookies.co.jp/static/protocalendar-js-1.1.2/sample/calendar_usage.html

【download はこちら】

http://code.google.com/p/protocalendar/downloads/detail?name=protocalendar-js-1.1.2.zip

【今後の展望】
*Appear 以外のエフェクトに対応。
*スタイルの追加。
*「閉じる」、「クリア」を表示するオプションの追加。
*rails, cakephp の helper 作成。

今回は不具合修正のみのリリースです。

時間入力対応などで、英語、中国語、日本語以外の言語ファイルが精査できていないので、

外国語に詳しい方は言語ファイルを修正して頂けると大変助かります!

ラボのサイトもあと少しで公開です。

次回は rails プラグインをリリースします。

シンプルな日時選択ライブラリ protocalendar.js v1.1.1 を公開しました

protocalendar.js v1.1.1 を公開しました。

主な変更点は以下の通りです。
【変更点】

*日付フォーマットの不具合の修正。

*SelectCalendar の不具合の修正。

*言語ファイルの更新。(lang_zh-tw.js)

【使い方はこちら】
http://labs.spookies.co.jp/static/protocalendar-js-1.1.1/sample/calendar_usage.html

【download はこちら】

http://code.google.com/p/protocalendar/downloads/detail?name=protocalendar-js-1.1.1.zip

【今後の展望】
*Appear 以外のエフェクトに対応。
*スタイルの追加。
*「閉じる」、「クリア」を表示するオプションの追加。
*rails, cakephp の helper 作成。

今回のリリースは不具合の修正と言語ファイルの更新のみです。

時間入力対応などで、英語、中国語、日本語以外の言語ファイルは精査できていないので、

外国語に詳しい方は言語ファイルを修正して頂けると大変助かります。

また、今回から min 版もアーカイブに同梱することにしましたので、必要に応じてご利用下さい。


©2007 spookies