function testRenderAsEdit_newNotebook() { global $USER; $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB); $n = Notebook::createNewNotebookForUser($USER->user_id, $this->DB); // $this->fail(); // $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="'.$n->created_at.'" data-updated_at="'.$n->updated_at.'" data-user_id="101" data-name="'.htmlentities($n->name).'" data-notes="'.htmlentities(util_lang('new_notebook_notes')).'" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> //<form action="'.APP_ROOT_PATH.'/app_code/notebook.php"> // <input type="hidden" name="action" value="update"/> // <input type="hidden" name="notebook_id" value="NEW"/> // <h3 class="notebook_title">'.ucfirst(util_lang('notebook')).': <input id="notebook-name" type="text" name="name" value="'.htmlentities($n->name).'"/></h3> // <span class="created_at">'.util_lang('created_at').' '.util_datetimeFormatted($n->created_at).'</span>, <span class="updated_at">'.util_lang('updated_at').' '.util_datetimeFormatted($n->updated_at).'</span><br/> // <span class="owner">'.util_lang('owned_by').' <a href="'.APP_ROOT_PATH.'/app_code/user.php?action=view&user_id=101">'.$USER->screen_name.'</a></span><br/> // <div class="notebook-notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">'.htmlentities(util_lang('new_notebook_notes')).'</textarea></div> // <input id="edit-submit-control" class="btn" type="submit" name="edit-submit-control" value="'.util_lang('save','properize').'"/> // <a id="edit-cancel-control" class="btn" href="/digitalfieldnotebooks/app_code/notebook.php?action=list">'.util_lang('cancel','properize').'</a> //</form> // <h4>'.ucfirst(util_lang('pages')).'</h4> // '.util_lang('new_notebook_must_be_saved').' //</div>'; $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="' . $n->created_at . '" data-updated_at="' . $n->updated_at . '" data-user_id="101" data-name="' . htmlentities($n->name) . '" data-notes="' . htmlentities(util_lang('new_notebook_notes')) . '" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> <form action="' . APP_ROOT_PATH . '/app_code/notebook.php"> <div id="actions"> <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('save', 'properize') . '</button> <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=list"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a> </div> <input type="hidden" name="action" value="update"/> <input type="hidden" name="notebook_id" value="NEW"/> <h3 class="notebook_title">' . ucfirst(util_lang('notebook')) . ': <input id="notebook-name" type="text" name="name" value="' . htmlentities($n->name) . '"/></h3> <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($n->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($n->updated_at) . '</span></div> <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . $USER->screen_name . '</a></div> <div class="control-workflows"></div> <div class="notebook_notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">' . htmlentities(util_lang('new_notebook_notes')) . '</textarea></div> </form> <h4>' . ucfirst(util_lang('pages')) . '</h4> ' . util_lang('new_notebook_must_be_saved') . ' </div>'; $rendered = $n->renderAsEdit(); // echo "<pre>\n".htmlentities($canonical)."\n-----------------\n".htmlentities($rendered)."\n</pre>"; $this->assertEqual($canonical, $rendered); $this->assertNoPattern('/IMPLEMENTED/', $rendered); }
public function renderAsEdit() { $this->loadPageFields(); $this->loadSpecimens(); $n = $this->getNotebook(); $ap = ''; if ($this->notebook_page_id != 'NEW') { $ap = $this->getAuthoritativePlant(); } // util_prePrintR('TO BE IMPLEMENTED: handle auth plant for new pages (i.e. where auth plant id == 0)'); // util_prePrintR($this); global $USER, $ACTIONS; $actions_attribs = ''; // $add_field_button_li = ''; if ($USER->canActOnTarget($ACTIONS['edit'], $this)) { $actions_attribs .= ' data-can-edit="1"'; // $add_field_button_li = ' <li><a href="" id="btn-add-notebook-page-field" class="creation_link btn">'.util_lang('add_notebook_page_field').'</a></li>'."\n"; } $owner = $USER; if ($n->user_id != $USER->user_id) { $owner = $n->getUser(); } $rendered = '<div id="rendered_notebook_page_' . $this->notebook_page_id . '" class="rendered_notebook_page edit_rendered_notebook_page" ' . $this->fieldsAsDataAttribs() . $actions_attribs . ">\n" . '<form id="form-edit-notebook-page-base-data" action="' . APP_ROOT_PATH . '/app_code/notebook_page.php">' . "\n" . ' <input type="hidden" name="action" value="update"/>' . "\n" . ' <input type="hidden" id="notebook_page_id" name="notebook_page_id" value="' . $this->notebook_page_id . '"/>' . "\n" . ' <input type="hidden" id="notebook_id" name="notebook_id" value="' . $this->notebook_id . '"/>' . "\n"; $rendered .= ' <div id="actions">'; $rendered .= '<button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control" value="update"><i class="icon-ok-sign icon-white"></i> ' . util_lang($this->notebook_page_id != 'NEW' ? 'update' : 'save', 'properize') . '</button>' . "\n"; if ($this->notebook_page_id != 'NEW') { $rendered .= ' <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=view¬ebook_page_id=' . $this->notebook_page_id . '"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>'; $rendered .= ' <a id="edit-delete-notebook-page-control" class="btn btn-danger" href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=delete¬ebook_page_id=' . $this->notebook_page_id . '"><i class="icon-trash icon-white"></i> ' . util_lang('delete', 'properize') . '</a>'; } else { $rendered .= ' <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=edit¬ebook_id=' . $this->notebook_id . '"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>'; } $rendered .= '</div>' . "\n"; $rendered .= '<h4>' . util_lang('page_in_notebook', 'ucfirst') . ' <a href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view¬ebook_id=' . $n->notebook_id . '" id="parent-notebook-link">' . htmlentities($n->name) . '</a></h4>' . "\n"; if ($this->notebook_page_id != 'NEW') { $rendered .= '<a class="show-hide-control" href="#" data-for_elt_id="select_new_authoritative_plant_' . $this->notebook_page_id . '">' . util_lang('change_authoritative_plant') . '</a>'; $rendered .= ' <div id="select_new_authoritative_plant_' . $this->notebook_page_id . '" class="select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants($this->notebook_page_id != 'NEW' ? $ap->authoritative_plant_id : 0) . '</div>' . "\n"; $rendered .= ' ' . $ap->renderAsViewEmbed() . "\n"; } else { $rendered .= ' <div id="select_new_authoritative_plant_' . $this->notebook_page_id . '" class="NEW_select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants(0) . '</div>' . "\n"; } $rendered .= ' <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($this->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($this->updated_at) . "</span></div>\n" . ' <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=' . $owner->user_id . '">' . htmlentities($owner->screen_name) . '</a></div>' . "\n"; $rendered .= '<div class="control-workflows">'; if ($this->notebook_page_id != 'NEW') { if ($USER->canActOnTarget('publish', $this)) { $rendered .= ' <span class="published_state workflow-control"><input id="notebook-page-workflow-publish-control" type="checkbox" name="flag_workflow_published" value="1"' . ($this->flag_workflow_published ? ' checked="checked"' : '') . ' /> ' . util_lang('publish') . '</span>,'; } else { $rendered .= ' <span class="published_state workflow-info">' . ($this->flag_workflow_published ? util_lang('published_true') : util_lang('published_false')) . '</span>,'; } if ($USER->canActOnTarget('verify', $this)) { $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-control"><input id="notebook-page-workflow-validate-control" type="checkbox" name="flag_workflow_validated" value="1"' . ($this->flag_workflow_validated ? ' checked="checked"' : '') . ' /> ' . util_lang('verify') . '</span>'; } else { $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-info">' . ($this->flag_workflow_validated ? util_lang('verified_true') : util_lang('verified_false')) . '</span>'; } $rendered .= '<br/>' . "\n"; } else { $rendered .= ' <span class="published_state workflow-info">' . ($this->flag_workflow_published ? util_lang('published_true') : util_lang('published_false')) . '</span>,'; $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-info">' . ($this->flag_workflow_validated ? util_lang('verified_true') : util_lang('verified_false')) . '</span>'; } $rendered .= "</div>\n"; $rendered .= ' <div class="notebook_page_notes"><textarea id="notebook-page-notes" name="notes" rows="4" cols="120">' . htmlentities($this->notes) . '</textarea></div>' . "\n"; if ($this->notebook_page_id != 'NEW') { $rendered .= ' <h4>' . ucfirst(util_lang('metadata')) . "</h4>\n"; $rendered .= ' <ul class="notebook-page-fields">' . "\n"; $rendered .= ' <li><a href="#" id="add_new_notebook_page_field_button" class="btn">' . util_lang('add_notebook_page_field') . '</a></li>' . "\n"; if ($this->page_fields) { $prev_pf_structure_id = $this->page_fields[0]->label_metadata_structure_id; foreach ($this->page_fields as $pf) { $spacer_class = ''; if ($pf->label_metadata_structure_id != $prev_pf_structure_id) { $spacer_class = 'spacing-list-item'; } $rendered .= ' ' . $pf->renderAsListItemEdit('list_item-notebook_page_field_' . $pf->notebook_page_field_id, [$spacer_class]) . "\n"; $prev_pf_structure_id = $pf->label_metadata_structure_id; } } else { $rendered .= '<li>' . util_lang('no_metadata', 'ucfirst') . '</li>' . "\n"; } $rendered .= ' </ul>' . "\n"; $rendered .= Specimen::renderSpecimenListBlock($this->specimens); // $rendered .= ' <h4>'.ucfirst(util_lang('specimens'))."</h4>\n". // ' <ul class="specimens">'."\n"; // $rendered .= ' <li><a href="#" id="add_new_specimen_button" class="btn">'.util_lang('add_specimen').'</a></li>'."\n"; // if ($this->specimens) { // foreach ($this->specimens as $specimen) { // $rendered .= ' <li id="list_item-specimen_'.$specimen->specimen_id.'">'.$specimen->renderAsEditEmbed()."</li>\n"; // } // } else { // $rendered .= '<li>'.util_lang('no_metadata','ucfirst').'</li>'."\n"; // } // $rendered .= " </ul>\n"; $rendered .= '<input type="hidden" id="initial_page_field_ids" name="initial_page_field_ids" value="' . implode(',', Db_Linked::arrayOfAttrValues($this->page_fields, 'notebook_page_field_id')) . '"/>' . "\n"; $rendered .= '<input type="hidden" id="created_page_field_ids" name="created_page_field_ids" value=""/>' . "\n"; $rendered .= '<input type="hidden" id="deleted_page_field_ids" name="deleted_page_field_ids" value=""/>' . "\n"; $rendered .= '<input type="hidden" id="initial_specimen_ids" name="initial_specimen_ids" value="' . implode(',', Db_Linked::arrayOfAttrValues($this->specimens, 'specimen_id')) . '"/>' . "\n"; $rendered .= '<input type="hidden" id="created_specimen_ids" name="created_specimen_ids" value=""/>' . "\n"; $rendered .= '<input type="hidden" id="deleted_specimen_ids" name="deleted_specimen_ids" value=""/>' . "\n"; } $rendered .= '</form>' . "\n"; $rendered .= "</div>"; return $rendered; }
function renderAsEdit() { global $USER, $ACTIONS; $actions_attribs = ''; if ($USER->user_id == $this->user_id) { $actions_attribs .= ' data-can-edit="1"'; } elseif ($USER->canActOnTarget($ACTIONS['edit'], $this)) { $actions_attribs .= ' data-can-edit="1"'; } $notebook_owner = $USER; if ($this->user_id != $USER->user_id) { $notebook_owner = $this->getUser(); } if ($this->notebook_id) { $this->cachePages(); } else { $this->notebook_id = 'NEW'; } $rendered = '<div id="edit_rendered_notebook_' . $this->notebook_id . '" class="edit_rendered_notebook" ' . $this->fieldsAsDataAttribs() . $actions_attribs . '>' . "\n" . '<form action="' . APP_ROOT_PATH . '/app_code/notebook.php">' . "\n"; $rendered .= '<div id="actions">' . "\n"; if ($this->notebook_id == 'NEW') { // $rendered .= ' <input id="edit-submit-control" class="btn" type="submit" name="edit-submit-control" value="'.util_lang('save','properize').'"/>'."\n"; $rendered .= ' <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('save', 'properize') . '</button>' . "\n"; $rendered .= ' <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=list"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>' . "\n"; } else { // $rendered .= ' <input id="edit-submit-control" class="btn" type="submit" name="edit-submit-control" value="'.util_lang('update','properize').'"/>'."\n"; $rendered .= ' <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize') . '</button>' . "\n"; $rendered .= ' <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view¬ebook_id=' . $this->notebook_id . '"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>' . "\n"; } $rendered .= "</div>\n"; $rendered .= ' <input type="hidden" name="action" value="update"/>' . "\n" . ' <input type="hidden" name="notebook_id" value="' . $this->notebook_id . '"/>' . "\n" . ' <h3 class="notebook_title">' . ucfirst(util_lang('notebook')) . ': <input id="notebook-name" type="text" name="name" value="' . $this->name . '"/></h3>' . "\n" . ' <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($this->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($this->updated_at) . '</span></div>' . "\n" . ' <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=' . $notebook_owner->user_id . '">' . htmlentities($notebook_owner->screen_name) . '</a></div>' . "\n"; $rendered .= '<div class="control-workflows">'; if ($this->notebook_id != 'NEW') { if ($USER->canActOnTarget('publish', $this)) { $rendered .= ' <span class="published_state workflow-control"><input id="notebook-workflow-publish-control" type="checkbox" name="flag_workflow_published" value="1"' . ($this->flag_workflow_published ? ' checked="checked"' : '') . ' /> ' . util_lang('publish') . '</span>,'; } else { $rendered .= ' <span class="published_state workflow-info">' . ($this->flag_workflow_published ? util_lang('published_true') : util_lang('published_false')) . '</span>,'; } if ($USER->canActOnTarget('verify', $this)) { $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-control"><input id="notebook-workflow-validate-control" type="checkbox" name="flag_workflow_validated" value="1"' . ($this->flag_workflow_validated ? ' checked="checked"' : '') . ' /> ' . util_lang('verify') . '</span>'; } else { $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-info">' . ($this->flag_workflow_validated ? util_lang('verified_true') : util_lang('verified_false')) . '</span>'; } } $rendered .= "</div>\n"; $rendered .= ' <div class="notebook_notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">' . htmlentities($this->notes) . '</textarea></div>' . "\n"; $rendered .= '</form>' . "\n"; if ($this->notebook_id == 'NEW') { $rendered .= ' <h4>' . ucfirst(util_lang('pages')) . '</h4>' . "\n" . ' ' . util_lang('new_notebook_must_be_saved') . "\n"; } else { $rendered .= ' <h4>' . ucfirst(util_lang('pages')) . '</h4>' . "\n" . ' <ul id="list-of-notebook-pages" data-notebook-page-count="' . count($this->pages) . '">' . "\n"; // NOTE: add page control only in edit mode, not view mode! if ($USER->canActOnTarget($ACTIONS['edit'], $this)) { $rendered .= ' <li><a href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=create¬ebook_id=' . $this->notebook_id . '" id="btn-add-notebook-page" class="creation_link btn">' . htmlentities(util_lang('add_notebook_page')) . '</a></li>' . "\n"; } if (count($this->pages) > 0) { $page_counter = 0; foreach ($this->pages as $p) { $page_counter++; $rendered .= ' ' . $p->renderAsListItem('notebook-page-item-' . $page_counter) . "\n"; } } else { $rendered .= ' <li>' . util_lang('zero_pages') . '</li>' . "\n"; } $rendered .= ' </ul>' . "\n"; } $rendered .= '</div>'; return $rendered; }
function testRenderAsEdit_newNotebookPage() { $np = Notebook_Page::createNewNotebookPageForNotebook(1001, $this->DB); $n = $np->getNotebook(); global $USER, $DB; $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB); $DB = $this->DB; $canonical = '<div id="rendered_notebook_page_NEW" class="rendered_notebook_page edit_rendered_notebook_page" ' . $np->fieldsAsDataAttribs() . ' data-can-edit="1"> <form id="form-edit-notebook-page-base-data" action="' . APP_ROOT_PATH . '/app_code/notebook_page.php"> <input type="hidden" name="action" value="update"/> <input type="hidden" id="notebook_page_id" name="notebook_page_id" value="NEW"/> <input type="hidden" id="notebook_id" name="notebook_id" value="1001"/> <div id="actions"><button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control" value="update"><i class="icon-ok-sign icon-white"></i> Save</button> <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=edit¬ebook_id=1001"><i class="icon-remove"></i> Cancel</a></div> <h4>In notebook <a href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view¬ebook_id=1001" id="parent-notebook-link">testnotebook1</a></h4> <div id="select_new_authoritative_plant_NEW" class="NEW_select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants() . '</div> <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($np->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($np->updated_at) . '</span></div> <div class="info-owner">owned by <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . htmlentities($USER->screen_name) . '</a></div> <div class="control-workflows"> <span class="published_state workflow-info">' . util_lang('published_false') . '</span>, <span class="verified_state verified_state_false workflow-info">' . util_lang('verified_false') . '</span></div> <div class="notebook_page_notes"><textarea id="notebook-page-notes" name="notes" rows="4" cols="120">' . util_lang('new_notebook_page_notes') . '</textarea></div> </form> </div>'; $rendered = $np->renderAsEdit(); // echo "<pre> //----------- //".htmlentities($canonical)." //----------- //".htmlentities($rendered)." //----------- //</pre>"; $this->assertEqual($canonical, $rendered); $this->assertNoPattern('/IMPLEMENTED/', $rendered); }