public function savepasswordAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             $isNew = true;
             $password = new LoyaltyCard_Model_Password();
             $application = $this->getApplication();
             $password_id = $datas['password_id'];
             if (!empty($datas['password_id'])) {
                 $password->find($datas['password_id']);
                 if ($password->getAppId() != $application->getId()) {
                     throw new Exception($this->_("An error occurred while saving the password. Please try again later"));
                 }
                 $isNew = false;
             } else {
                 $datas['app_id'] = $application->getId();
             }
             if (empty($datas['is_deleted'])) {
                 if (empty($datas['name'])) {
                     throw new Exception($this->_('Please enter a name'));
                 }
                 if (empty($datas['password'])) {
                     throw new Exception($this->_('Please enter a password'));
                 }
                 if (strlen($datas['password']) < 4 or !ctype_digit($datas['password'])) {
                     throw new Exception($this->_('Your password must be 4 digits'));
                 }
                 $password->setPassword(sha1($datas['password']));
                 if ($datas['password']) {
                     unset($datas['password']);
                 }
             } else {
                 if (!$password->getId()) {
                     throw new Exception($this->_('An error occurred while saving the password. Please try again later.'));
                 }
             }
             $password->addData($datas)->save();
             $html = array('success' => 1, 'id' => $password->getId());
             if (!empty($datas['is_deleted'])) {
                 $html['is_deleted'] = 1;
                 $html['id'] = $password_id;
             } else {
                 if ($isNew) {
                     $html['is_new'] = 1;
                     $html['name'] = $password->getName();
                 }
             }
             //                }
             //                else {
             //                    $employee->delete();
             //                    $html = array();
             //                }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }