Posts Tagged ‘CRUD’

rajax.js

// RAjax Namespace
var RAjax = {};

// Basic Logger facility that supports logging to
// an HTMLElement, the Firebug console and alerts.
// If provided with a valid DOM id, it will append
// log messages to this element. If it can't find
// the DOM id you provided, it will try to use
// the Firebug console instead (you can make sure
// that this will be found by installing Firebug Lite
// from http://www.getfirebug.com/lite.html website).
// Finally, if it can't find a console Object to log to,
// and you tell it so by passing true as the
// second parameter to initialize, it will fall back
// to those nasty alerts, that can lead to very unfortunate
// situations dependending on which situations (events)
// you use them!

RAjax.Logger = Class.create({

  initialize: function(stream, performAlerts) {
    this.stream = (s = $(stream)) ? s : console; // maybe null
    this.performAlerts = performAlerts || false;
  },

  log: function(message) {
    if(PERFORM_LOGGING) {
      if(this.stream) {
        // Firebug console or HTMLElement present
        if(this.logsToFirebug()) {
          // Logging to Firebug console
          this.stream.log(message);
        } else {
          // Logging to HTMLElement
          this.stream.insert({bottom: this.formattedMessage(message)});
        }
      } else { // no stream present
        // fallback to annoying alerts
        alert(this.formattedMessage(message));
      }
    }
  },

  clear: function() {
    if(this.logsToPage()) {
      this.stream.update('');
    }
  },

  // override this if you need different formatting
  formattedMessage: function(message) {
    return "
  • ” + message + “
  • “; }, debug: function(message) { this.log(message); }, error: function(message) { this.log(”ERROR: ” + message); }, // utility methods logsToFirebug: function() { return !!this.stream.log; }, logsToPage: function() { return this.stream && !this.firebugPresent(); } }); // additional supported callbacks RAjax.EXTENDED_CALLBACKS = [ “onPOSTSuccess” , “onPOSTFailure”, “onGETSuccess” , “onGETFailure”, “onPUTSuccess” , “onPUTFailure”, “onDELETESuccess”, “onDELETEFailure” ];

    Read more »

    my resource_controller rails plugin

    # Specify not more than this to get a restful controller
    # with the actions of your choice. You can always override
    # the generated actions if the default implementation
    # doesn't fit your needs. Of course, should you need more
    # than the standard CRUD actions, you're free to add them
    # to the class body. If your resource shall be audited
    # (by referencing a creator) you must have either a
    # current_user or current_account instance method defined
    # on your controller (restful_authentication will provide
    # one). If for any reason you choose to name your
    # current_user getter different from the 2 examples above,
    # simply override current_user_getters in your controller
    # (most probably ApplicationController) to include your
    # method name, and you're all set. By default, this plugin
    # assumes that you have 'will_paginate' installed and will
    # paginate your index actions. If you don't want this to
    # happen, pass false to the will_paginate method in your
    # resource spec.
    # ------------------------------------------------------
    #
    # class PostsController < ApplicationController
    #   resource :posts do |posts|
    #     posts.actions = [ :index, :show, :edit ] # all if omitted
    #     posts.audit_column = :creator # :created_by if omitted
    #     posts.will_paginate = false # true if omitted
    #     posts.index, :include => :creator # eager load this when calling find
    #     posts.show,  :include => [ :creator, :comments ]
    #   end
    # end

    Read more »