migrated api code in views to javascript files