Resource functions and bugs fixed

Add resource functions, control, view and js scripts;
Add query uiltities function.
Fixed many of bugs.