Index: trunk/extensions/SemanticForms/specials/SF_CreateClass.php |
— | — | @@ -19,6 +19,28 @@ |
20 | 20 | SFUtils::loadMessages(); |
21 | 21 | } |
22 | 22 | |
| 23 | + static function addJavascript( $numStartingRows ) { |
| 24 | + global $wgOut; |
| 25 | + |
| 26 | + SFUtils::addJavascriptAndCSS(); |
| 27 | + |
| 28 | + $jsText =<<<END |
| 29 | +<script> |
| 30 | +var rowNum = $numStartingRows; |
| 31 | +function createClassAddRow() { |
| 32 | + rowNum++; |
| 33 | + newRow = jQuery('#starterRow').clone().css('display', ''); |
| 34 | + newHTML = newRow.html().replace(/starter/g, rowNum); |
| 35 | + newRow.html(newHTML); |
| 36 | + jQuery('#mainTable').append(newRow); |
| 37 | +} |
| 38 | + |
| 39 | +</script> |
| 40 | + |
| 41 | +END; |
| 42 | + $wgOut->addScript( $jsText ); |
| 43 | + } |
| 44 | + |
23 | 45 | function execute( $query ) { |
24 | 46 | global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; |
25 | 47 | global $wgLang, $smwgContLang; |
— | — | @@ -31,8 +53,8 @@ |
32 | 54 | |
33 | 55 | $this->setHeaders(); |
34 | 56 | $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); |
35 | | - |
36 | 57 | $numStartingRows = 10; |
| 58 | + self::addJavascript( $numStartingRows ); |
37 | 59 | |
38 | 60 | $create_button_text = wfMsg( 'create' ); |
39 | 61 | |
— | — | @@ -130,57 +152,14 @@ |
131 | 153 | $list_of_values_label = wfMsg( 'sf_createclass_listofvalues' ) . '?'; |
132 | 154 | |
133 | 155 | $text = <<<END |
134 | | - <script> |
135 | | - |
136 | | -var NumOfRow = $numStartingRows; |
137 | | -function addRowDynamic(options) { |
138 | | - NumOfRow++; |
139 | | - // get the reference of the main div |
140 | | - var mainDiv = document.getElementById('addrows'); |
141 | | - |
142 | | - // create new div that will work as a container |
143 | | - var newDiv = document.createElement('div'); |
144 | | - newDiv.setAttribute('id','innerDiv' + NumOfRow); |
145 | | - |
146 | | - //create span to contain the text |
147 | | - var newtable = document.createElement('table'); |
148 | | - var newRow = document.createElement('tr'); |
149 | | - var newCol1 = document.createElement('td'); |
150 | | - newCol1.innerHTML="<input type=\"text\" size=\"25\" name=\"property_name_" + NumOfRow + "\" />"; |
151 | | - var newCol2 = document.createElement('td'); |
152 | | - newCol2.innerHTML="<input type=\"text\" size=\"25\" name=\"field_name_" + NumOfRow + "\" />"; |
153 | | - var newCol3 = document.createElement('td'); |
154 | | - newCol3.innerHTML = "<input type=\"text\" size=\"25\" name=\"allowed_values_" + NumOfRow + "\" />"; |
155 | | - var newCol4 = document.createElement('td'); |
156 | | - newCol4.innerHTML = "<input type=\"checkbox\" name=\"is_list_" + NumOfRow + "\" />"; |
157 | | - |
158 | | - var selectCol = document.createElement('td'); |
159 | | - var s = "<select id=\"property_dropdown_" + NumOfRow + "\" name=\"property_type_" + NumOfRow + "\">" + options + "</select>"; |
160 | | - var optionString = ""; |
161 | | - var myArray = options.split(','); |
162 | | - |
163 | | - for (i=0; i<myArray.length-1; i++) { |
164 | | - optionString += "<option>" + myArray[i] + "</option>"; |
165 | | - } |
166 | | - selectCol.innerHTML = "<select id=\"property_dropdown_" + NumOfRow + "\" name=\"property_type_" + NumOfRow + "\">" + optionString + "</select>"; |
167 | | - |
168 | | - newRow.innerHTML = newCol1.innerHTML+newCol2.innerHTML + newCol3.innerHTML; |
169 | | - newtable.innerHTML = "<tr>" + "<td>" + NumOfRow + ". " + newCol1.innerHTML + "</td>" + "<td>" + newCol2.innerHTML + "</td>" + "<td>" + selectCol.innerHTML + "</td>" + "<td>" + newCol3.innerHTML + "</td>" + "<td>" + newCol4.innerHTML + "</td></tr>"; |
170 | | - newDiv.appendChild(newtable); |
171 | | - |
172 | | - // finally append the new div to the main div |
173 | | - mainDiv.appendChild(newDiv); |
174 | | -} |
175 | | -</script> |
176 | | - |
177 | 156 | <form action="" method="post"> |
178 | 157 | <p>$create_class_docu</p> |
179 | 158 | <p>$leave_field_blank</p> |
180 | 159 | <p>$template_name_label <input type="text" size="30" name="template_name"></p> |
181 | 160 | <p>$form_name_label: <input type="text" size="30" name="form_name"></p> |
182 | 161 | <p>$category_name_label <input type="text" size="30" name="category_name"></p> |
183 | | - <div id="addrows"> |
184 | | - <table> |
| 162 | + <div> |
| 163 | + <table id="mainTable"> |
185 | 164 | <tr> |
186 | 165 | <th colspan="2">$property_name_label</th> |
187 | 166 | <th>$field_name_label</th> |
— | — | @@ -190,14 +169,24 @@ |
191 | 170 | </tr> |
192 | 171 | |
193 | 172 | END; |
194 | | - for ( $i = 1; $i <= $numStartingRows; $i++ ) { |
| 173 | + // Make one more row than what we're displaying - use the |
| 174 | + // last row as a "starter row", to be cloned when the |
| 175 | + // "Add another" button is pressed. |
| 176 | + for ( $i = 1; $i <= $numStartingRows + 1; $i++ ) { |
| 177 | + if ( $i == $numStartingRows + 1 ) { |
| 178 | + $rowString = 'id="starterRow" style="display: none"'; |
| 179 | + $n = 'starter'; |
| 180 | + } else { |
| 181 | + $rowString = ''; |
| 182 | + $n = $i; |
| 183 | + } |
195 | 184 | $text .= <<<END |
196 | | - <tr> |
197 | | - <td>$i.</td> |
198 | | - <td><input type="text" size="25" name="property_name_$i" /></td> |
199 | | - <td><input type="text" size="25" name="field_name_$i" /></td> |
| 185 | + <tr $rowString> |
| 186 | + <td>$n.</td> |
| 187 | + <td><input type="text" size="25" name="property_name_$n" /></td> |
| 188 | + <td><input type="text" size="25" name="field_name_$n" /></td> |
200 | 189 | <td> |
201 | | - <select id="property_dropdown_$i" name="property_type_$i"> |
| 190 | + <select name="property_type_$n"> |
202 | 191 | |
203 | 192 | END; |
204 | 193 | $optionsStr =""; |
— | — | @@ -208,8 +197,8 @@ |
209 | 198 | $text .= <<<END |
210 | 199 | </select> |
211 | 200 | </td> |
212 | | - <td><input type="text" size="25" name="allowed_values_$i" /></td> |
213 | | - <td><input type="checkbox" name="is_list_$i" /></td> |
| 201 | + <td><input type="text" size="25" name="allowed_values_$n" /></td> |
| 202 | + <td><input type="checkbox" name="is_list_$n" /></td> |
214 | 203 | |
215 | 204 | END; |
216 | 205 | } |
— | — | @@ -223,7 +212,7 @@ |
224 | 213 | array( |
225 | 214 | 'type' => 'button', |
226 | 215 | 'value' => wfMsg( 'sf_formedit_addanother' ), |
227 | | - 'onclick' => "addRowDynamic('$optionsStr')" |
| 216 | + 'onclick' => "createClassAddRow()" |
228 | 217 | ) |
229 | 218 | ); |
230 | 219 | $text .= Xml::tags( 'p', null, $add_another_button ) . "\n"; |