private function getFractalEditForm($fractal, $sheet, $results) { $user = $this->getUser(); $out = $this->getOutput(); $request = $this->getRequest(); $form_url = $this->getPageTitle()->getSubPage('Edit')->getLinkURL(); $fractal_id = $fractal->fractal_id; $read_only = ''; if ($fractal->user_name) { $read_only = 'readonly'; } // TODO: if a character, display basic attributes some other non-form way $const = FateGameGlobals::getStatConsts(); $condition_categories = $this->getConditionCategoriesJS(); $game_modes = ''; $skills_array = ''; $mode_levels = ''; $mook_levels = $this->getMookLevelsJS(); if ($fractal->fate_game->skill_distribution == FateGameGlobals::SKILL_DISTRIBUTION_MODES) { $game_modes = $this->getGameModesJS($fractal); $mode_levels = $this->getModeLevelsJS(); } else { $game_skills = $this->getGameSkillsJS($fractal); } $form .= <<<EOT <script type='text/javascript'> var TYPE_CONDITION = {$const['condition']}; var TYPE_MODE = {$const['mode']}; var TYPE_SKILL = {$const['skill']}; var TYPE_MOOK = {$const['mook']}; {$condition_categories} {$game_modes} {$mode_levels} {$game_skills} {$mook_levels} var edit_data = new Array(); edit_data[{$const['aspect']}] = { fields: { label: { label: 'Label (Optional)', size: 35 }, field: { label: 'Aspect', size: 35 } }, required: [ 'field' ], unique: 0 }; edit_data[{$const['mode']}] = { fields: { field: { label: 'Mode', type: 'select' }, value: { label: 'Rating', size: 1 } }, required: [ 'field', 'value' ], unique: 0 }; edit_data[{$const['skill']}] = { fields: { label: { label: 'Skill', type: 'select' }, value: { label: 'Rating', size: 1 }, }, required: [ 'label', 'value' ], unique: 0 }; edit_data[{$const['mook']}] = { fields: { field: { label: 'Skill', size: 35 }, value: { label: 'Rating', type: 'select' } }, required: [ 'field', 'value' ], unique: 0 }; edit_data[{$const['stunt']}] = { fields: { field: { label: 'Title', size: 35 }, description: { label: 'Description', type: 'textarea', rows: 3, cols: 80 } }, required: [ 'field', 'description' ], unique: 0 }; edit_data[{$const['consequence']}] = { fields: { label: { label: 'Label', size: 35 }, display_value: { label: 'Modifier', size: 1 }, field: { label: 'Aspect (Optional)', size: 35 } }, required: [ 'label', 'display_value' ], unique: 0 }; edit_data[{$const['condition']}] = { fields: { label: { label: 'Label', size: 35 }, display_value: { label: 'Category', type: 'select' }, value: { label: 'Checked Boxes', size: 1 } }, required: [ 'label', 'display_value', 'value' ], unique: 0 }; edit_data[{$const['stress']}] = { fields: { label: { label: 'Track Name', size: 35 }, max_value: { label: 'Maximum Value', size: 1 }, value: { label: 'Checked Boxes', size: 1 } }, required: [ 'label', 'max_value', 'value' ], unique: 0 }; edit_data[{$const['fate']}] = { fields: { value: { label: 'Current Fate Points', size: 1 } }, required: [ 'value' ], unique: 1 }; edit_data[{$const['refresh']}] = { fields: { value: { label: 'Fate Refresh', size: 1 } }, required: [ 'value' ], unique: 1 }; function createLabelCell(field_info, name) { var cell = document.createElement('td'); cell.className = 'mw-label'; var label = document.createElement('label'); label.setAttribute('for', 'ef' + name); label.appendChild(document.createTextNode(field_info.label + ':')); cell.appendChild(label); return cell; } function createInputSelect(field_info, name, stat_type, new_id, list, mode_skill_label = '', mode_value = 0) { var select = document.createElement('select'); var optionArray = new Array(); select.setAttribute('id', 'ef' + name); select.setAttribute('name', name); if (mode_value) { select.setAttribute('onchange', 'addNewRow(' + stat_type + ',' + new_id + ',"' + mode_skill_label + '",' + mode_value + ');'); } else { select.setAttribute('onchange', 'addNewRow(' + stat_type + ',' + new_id + ');'); } for (var i in list) { var option = document.createElement('option'); option.setAttribute('value', i); option.appendChild(document.createTextNode(list[i])); if (mode_value) { optionArray.push(option); } else { select.appendChild(option); } } // Push-and-pop off a stack to get options for mode skills in the proper order if (mode_value) { optionArray.reverse(); for (var i in optionArray) { select.appendChild(optionArray[i]); } } return select; } function getModeLevelList(mode_value) { var newList = new Array(); for (var i in modeLevels) { newList[parseInt(i) + mode_value] = modeLevels[i] + ' (+' + i + ')'; } return newList; } function createInputCell(field_info, name, stat_type, new_id, field, mode_skill_label, mode_value) { var cell = document.createElement('td'); cell.className = 'mw-input'; if (stat_type == TYPE_CONDITION && field_info.type == 'select') { cell.appendChild(createInputSelect(field_info, name, stat_type, new_id, conditions)); } else if (stat_type == TYPE_MODE && field_info.type == 'select') { cell.appendChild(createInputSelect(field_info, name, stat_type, new_id, modeList)); } else if (stat_type == TYPE_SKILL && field_info.type == 'select') { cell.appendChild(createInputSelect(field_info, name, stat_type, new_id, skillList)); } else if (stat_type == TYPE_MOOK && field_info.type == 'select') { cell.appendChild(createInputSelect(field_info, name, stat_type, new_id, mookLevels)); } else if (stat_type == TYPE_SKILL && field_info.type == 'rankselect') { modeLevelList = getModeLevelList(mode_value); cell.appendChild(createInputSelect(field_info, name, stat_type, new_id, modeLevelList, mode_skill_label, mode_value)); } else if (field_info.type == 'textarea') { var textbox = document.createElement('textarea'); textbox.setAttribute('id', 'ef' + name); textbox.setAttribute('name', name); textbox.setAttribute('oninput', 'addNewRow(' + stat_type + ',' + new_id + ');'); textbox.setAttribute('rows', field_info.rows); textbox.setAttribute('cols', field_info.cols); cell.appendChild(textbox); } else { var input = document.createElement('input'); input.setAttribute('id', 'ef' + name); input.setAttribute('name', name); input.setAttribute('type', 'text'); input.setAttribute('size', field_info.size); if (mode_value) { input.setAttribute('oninput', 'addNewRow(' + stat_type + ',' + new_id + ',"' + mode_skill_label + '",' + mode_value + ');'); } else { input.setAttribute('oninput', 'addNewRow(' + stat_type + ',' + new_id + ');'); } cell.appendChild(input); } return cell; } // Creates extra spaces, to match with delete functionality function emptyCell() { var cell = document.createElement('td'); cell.appendChild(document.createTextNode('\\u00A0')); return cell; } function addNewRow(stat_type, id, mode_skill_label = '', mode_value = 0) { var check = document.getElementById('ef' + stat_type + '_new_' + edit_data[stat_type].required[0] + '_' + (parseInt(id) + 1)); if (!check) { var fields; if (mode_value) { fields = { label: { label: mode_skill_label, size: 35 }, value: { label: 'Ranking', type: 'rankselect', mode_value: mode_value } }; } else { fields = edit_data[stat_type].fields; } var new_id = parseInt(id) + 1; var new_body = document.getElementById('newstat_' + stat_type); var body = document.getElementById('stat_' + stat_type); var row = document.createElement('tr'); for (var field in fields) { var input_name = stat_type + '_new_' + field + '_' + new_id; row.appendChild(createLabelCell(fields[field], input_name)); row.appendChild(createInputCell(fields[field], input_name, stat_type, new_id, field, mode_skill_label, mode_value)); } row.appendChild(emptyCell()); row.appendChild(emptyCell()); new_body.appendChild(row); } } </script> <style type='text/css'> .formerror { border: 2px solid #cc0000; } </style> <form action='{$form_url}' method='post'> <input type='hidden' name='fractal_id' value='{$fractal_id}'/> <input type='hidden' name='sheet' value='{$sheet}'/> <input type='hidden' name='action' value='edit'/> <h2>Edit Fractal</h2> EOT; // Did we have errors? If show, display a big warning here if (count($results) > 0) { if (count($results['error']) > 0) { $form .= "<div class='errorbox'><strong>Editing error.</strong><br/>One or more required fields seem to have been cleared in existing stats. Please correct them below, and resubmit to save edits.</div>"; } else { $form .= "<div class='successbox'><strong>Stat updates saved.</strong></div>"; } } $form .= <<<EOT <fieldset> <legend>Basic Attributes</legend> <table> <tbody> <tr> <td class='mw-label'><label for='efname'>Fractal Name:</label></td> <td class='mw-input'><input id='efname' {$read_only} name='fractal_name' value='{$fractal->name}' type='text' size='35'/></td> </tr> <tr> <td class='mw-label'><label form='eftype'>Fractal Type:</label></td> <td class='mw-input'><input id='eftype' {$read_only} name='fractal_type' value='{$fractal->fractal_type}' type='text' size='35'/></td> </tr> </tbody> </table> </fieldset> EOT; // Dynamically create the rest of this mess $stat_labels = FateGameGlobals::getStatLabels(); foreach ($this->edit_data as $stat_id => $stat_data) { if ($stat_id == FateGameGlobals::STAT_CONDITION && $fractal->fate_game->use_consequences) { continue; } elseif ($stat_id == FateGameGlobals::STAT_CONSEQUENCE && !$fractal->fate_game->use_consequences) { continue; } elseif ($stat_id == FateGameGlobals::STAT_MODE && $fractal->fate_game->skill_distribution != FateGameGlobals::SKILL_DISTRIBUTION_MODES) { continue; } $form .= "<fieldset><legend>" . $stat_labels[$stat_id] . "</legend>"; if ($stat_id == FateGameGlobals::STAT_SKILL && $fractal->fate_game->skill_distribution == FateGameGlobals::SKILL_DISTRIBUTION_MODES) { $form .= $this->getModeSkillSection($stat_id, $fractal, $results); } else { $form .= "<table><tbody id='stat_" . $stat_id . "'>"; $rows = array(); if (array_key_exists($stat_id, $fractal->stats)) { foreach ($fractal->stats[$stat_id] as $stat) { $row = $this->getEditStatRow($stat_id, $stat_data, $stat, $fractal->fate_game, $results); $rows[] = $row; } } foreach ($rows as $r) { $form .= $r; } if (!$stat_data['unique'] || $stat_data['unique'] && count($fractal->stats[$stat_id]) == 0) { $form .= "</tbody></table><h4>Add New " . $stat_labels[$stat_id] . "</h4><table><tbody id='newstat_" . $stat_id . "'>"; $count = count($results) > 0 ? $results['new'][$stat_id]['max'] : 1; for ($i = 1; $i <= $count; $i++) { $form .= $this->getEditStatRow($stat_id, $stat_data, array(), $fractal->fate_game, $results, $i); } } $form .= "</tbody></table>"; } $form .= "</fieldset>"; } $form .= <<<EOT <span class='mw-htmlform-submit-buttons'> <input class='mw-htmlform-submit' type='submit' value='Update'/> </span> </form> EOT; return $form; }