Refactor directive.js
Refactor code and Add submit method