function createForm() { $form = new Am_Form_Admin(); $form->addAdvRadio('is_custom')->loadOptions(array(0 => ___('Use Pre-Defined Template'), 1 => ___('Define Custom Html Message')))->setValue(0); $form->addTextarea('content', array('rows' => '7', 'class' => 'row-wide el-wide'))->setLabel(___("Content\n" . 'You can use all user specific placeholders here eg. %user.login%, %user.name_f%, %user.name_l% etc.'))->addRule('required'); $form->addText('url', array('class' => 'el-wide', 'rel' => 'form-pre-defined'))->setLabel(___('Link')); $form->addAdvcheckbox('is_blank', array('rel' => 'form-pre-defined'))->setLabel(___('Open Link in New Window')); $form->addScript()->setScript(<<<CUT \$('[name=is_custom]').change(function(){ \$('[rel=form-pre-defined]').closest('.row').toggle(\$('[name=is_custom]:checked').val() == 0) }).change(); CUT ); $sel = $form->addMagicSelect('_target')->setLabel(___('Target By User')); $cats = $pr = $gr = array(); foreach ($this->getDi()->userGroupTable->getSelectOptions() as $k => $v) { $gr['user_group_id-' . $k] = 'Group: ' . $v; } $options = array('free' => ___('All'), 'user_id' => ___('Specific User')) + ($cats ? array(___('Product Categories') => $cats) : array()) + ($gr ? array(___('User Groups') => $gr) : array()) + ($pr ? array(___('Products') => $pr) : array()); $sel->loadOptions($options); //$sel->addRule('required'); $sel->setJsOptions('{onChange:function(val){ $("input[name^=_loginOrEmail]").closest(\'.row\').toggle(val.hasOwnProperty("user_id")); }}'); $loginGroup = $form->addGroup(''); $loginGroup->setLabel(___('E-Mail Address or Username')); $loginGroup->addHidden('_savedLoginOrEmail')->setValue(''); $login = $loginGroup->addText('_loginOrEmail[]'); $label_add_user = ___('Add User'); $loginGroup->addHtml()->setHtml(<<<CUT <div><a href="javascript:void(null);" id="target-user_id-add" class="local">{$label_add_user}</a></div> CUT ); $form->addElement(new Am_Form_Element_ResourceAccess('_raccess', array('without_free' => true)))->setLabel('Target By Product'); $gr = $form->addGroup()->setSeparator(' ')->setLabel(___("Dates\n" . 'date range when notification is shown')); $gr->addDate('begin', array('placeholder' => ___('Begin Date'))); $gr->addDate('expire', array('placeholder' => ___('Expire Date'))); $form->addScript('script')->setScript(<<<CUT \$("input[name^=_loginOrEmail]").autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); CUT ); $delIcon = $this->getDi()->view->icon('delete'); $form->addScript('script2')->setScript(<<<CUT var arr = \$('[name=_savedLoginOrEmail]').val().split(',').reverse(); \$('[name^=_loginOrEmail]').val(arr.pop()); for (var i in arr) { var \$field = addEmailOrLogin(\$('#target-user_id-add')); \$field.val(arr[i]); } function addEmailOrLogin(context) { var \$field = \$('<input tyep="text" name="_loginOrEmail[]" />'); \$(context).before('<br />'); \$(context).before(\$field); \$(context).before('<a href="javascript:void(null)" onclick="\$(this).prev().remove();\$(this).prev().remove();\$(this).next().remove();\$(this).remove()">{$delIcon}</a>'); \$(context).before('<br />'); \$field.autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); return \$field; } \$('#target-user_id-add').click(function(){ addEmailOrLogin(this); }) CUT ); $form->addText('limit', array('placeholder' => ___('Unlimited')))->setLabel(___("Limit Number of Display per User\n" . 'keep it empty for unlimited')); return $form; }