stuck at this js problem. Too complicated. will use hidden views to deal with problem instead of encoding everything in javascript. last progress is commited here.