Giter Club home page Giter Club logo

contacts's Introduction

Contacts

Experimenting node.js.

JavaScript Object

Extended Object and Array a bit.

Object.extend(from, replace)

Add properties of from object to current object. If same property exists, then replace if replace is true. Default true.

Object.subset(names)

Return a new object with subset of properties of current object.

Array.merge(ary)

Merge ary into current array.

Context

A context object is added to each request. It is used for template rendering.

Flash message

Context object handles flash messages. Flash message is a kind of message that generated on business logic layer, supposed to be displayed to user once, and only once. It needs to handle case of redirect. Here we use session object to persist messages util they are renderred once.

Currently two type: error, info.

context.error(msg)

Add error message[s]. msg can be string or array of strings. If no msg supplied then return all errors.

context.info(msg)

Add info message[s]. msg can be string or array of strings. If no msg supplied then return all info messages.

conext.clearFlash()

Clear flash messages from session.

Model

The first goal is to implemente Active Record pattern talk to MongoDB.

Models are defined unser models/ directory. To use:


var Contact = require('../models').Contact;
var contact = new Contact();
...
contact.bind(data);
contact.save(caller, callback);
...

Each model only need to define FIELD_MAP to have basic methods

  • validate
  • bind
  • find
  • save
  • delete

Example:


module.exports.name = 'Contact';

module.exports.klass = function(data) {
  this.collection_name = 'contact';

  this.FIELDMAP = {
    name: {default: '', type: 'string', required: true},
    owner_id: {default: '', type: 'ObjectId', required: true},
    primary_contact_type: {default: '', type: 'string', required: true}, // email|phone|skype
    primary_contact: {default: '', type: 'string', required: true},
    created_on: {default: new Date(), type: 'datetime'},
    modified_on: {default: new Date(), type: 'datetime'}
  }

  if (this.init) {
    this.init(data);
  }
}

Not finished yet...

contacts's People

Contributors

richardzcode avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.