Index: trunk/extensions/GPoC/SpecialFilterRatings.php |
— | — | @@ -21,8 +21,6 @@ |
22 | 22 | $importance = $wgRequest->getVal('importance'); |
23 | 23 | $quality = $wgRequest->getVal('quality'); |
24 | 24 | $categories = $wgRequest->getVal('categories'); |
25 | | - $action = $wgRequest->getVal('action'); |
26 | | - $selection_name = $wgRequest->getVal('selection'); |
27 | 25 | |
28 | 26 | $filters = array( |
29 | 27 | 'r_project' => $project, |
— | — | @@ -37,19 +35,33 @@ |
38 | 36 | } |
39 | 37 | $entries = Rating::filterArticles($filters); |
40 | 38 | |
| 39 | + if( $wgRequest->wasPosted() ) { |
| 40 | + $wgOut->disable(); |
| 41 | + |
| 42 | + $action = $wgRequest->getVal('action'); |
| 43 | + $selection_name = $wgRequest->getVal('selection'); |
| 44 | + |
| 45 | + if( $action == 'addtoselection' ) { |
| 46 | + $success = Selection::addEntries($selection_name, $entries); |
| 47 | + $sel_page = new SpecialSelection(); |
| 48 | + |
| 49 | + $url = $sel_page->getTitle()->getLinkUrl( array( 'name' => $selection_name ) ); |
| 50 | + $return = array( |
| 51 | + 'status' => $success, |
| 52 | + 'selection_url' => $url |
| 53 | + ); |
| 54 | + } |
| 55 | + echo json_encode($return); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
41 | 59 | $this->setHeaders(); |
42 | 60 | |
43 | 61 | $wgOut->setPageTitle("Filter Articles by Ratings"); |
44 | 62 | |
45 | | - if( $action == 'addtoselection' ) { |
46 | | - Selection::addEntries($selection_name, $entries); |
47 | | - } |
48 | | - |
49 | 63 | $template = new FilterRatingsTemplate(); |
50 | 64 | $template->set( 'filters', $filters ); |
51 | 65 | $template->set( 'articles', $entries ); |
52 | | - $template->set( 'action', $action ); |
53 | | - $template->set( 'selection', $selection_name ); |
54 | 66 | |
55 | 67 | $wgOut->addTemplate( $template ); |
56 | 68 | } |
Index: trunk/extensions/GPoC/SpecialSelection.php |
— | — | @@ -32,10 +32,6 @@ |
33 | 33 | fclose( $outstream ); |
34 | 34 | } |
35 | 35 | |
36 | | - public function onSubmit( $data ) { |
37 | | - var_dump($data); |
38 | | - } |
39 | | - |
40 | 36 | public function execute( $par ) { |
41 | 37 | global $wgOut, $wgRequest; |
42 | 38 | |
Index: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php |
— | — | @@ -7,8 +7,6 @@ |
8 | 8 | public function execute() { |
9 | 9 | $articles = $this->data['articles']; |
10 | 10 | $filters = $this->data['filters']; |
11 | | - $action = $this->data['action']; |
12 | | - $selection = $this->data['selection']; |
13 | 11 | ?> |
14 | 12 | |
15 | 13 | <form method="GET" id="filterForm"> |
— | — | @@ -20,17 +18,13 @@ |
21 | 19 | Categories (comma separated): <input type="text" name="categories" value="<?php echo $filters['categories']?>" /> |
22 | 20 | <input type="submit" id="submit-query" /> |
23 | 21 | </p> |
| 22 | +</form> |
24 | 23 | <div> |
25 | 24 | Add to Selection: |
26 | 25 | <input type="text" name="selection" id="selection" /> |
27 | | -<input type="hidden" name="action" id="action" /> |
28 | 26 | <input type="button" id="add-to-selection" value="Add" /> |
29 | 27 | </div> |
30 | | -</form> |
31 | 28 | <div id="notice"> |
32 | | -<?php if( $action == 'addtoselection' ) { ?> |
33 | | -Articles successfully added to selection <?php echo $selection; ?> |
34 | | -<?php } ?> |
35 | 29 | </div> |
36 | 30 | <div id=""> |
37 | 31 | <?php if( count($articles) > 0 ) { ?> |
— | — | @@ -59,16 +53,16 @@ |
60 | 54 | <script type="text/javascript"> |
61 | 55 | // Should I use RL for tiny snippets like this too? |
62 | 56 | $("#add-to-selection").click(function() { |
63 | | - $("#action").val("addtoselection"); |
64 | | - $("#filterForm").submit(); |
| 57 | + var selection = $("#selection").val(); |
| 58 | + $.post("", { |
| 59 | + action: "addtoselection", |
| 60 | + selection: selection |
| 61 | + }, function(raw_data) { |
| 62 | + var data = $.parseJSON(raw_data); |
| 63 | + $("#notice").html("Added to selection <a href='" + data.selection_url + "'>" + selection + "</a>"); |
| 64 | + }); |
65 | 65 | return false; |
66 | 66 | }); |
67 | | - $("#submit-query").click(function() { |
68 | | - $("#selection").val(""); |
69 | | - // Hitting submit shouldn't add to selection |
70 | | - $("#filterForm").submit(); |
71 | | - return false; |
72 | | - }); |
73 | 67 | </script> |
74 | 68 | |
75 | 69 | <?php |