r88433 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88432‎ | r88433 | r88434 >
Date:22:00, 19 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on watchlist groups management
Modified paths:
  • /trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
@@ -51,29 +51,32 @@
5252 break;
5353 }
5454
55 - var conditionTypeInput = $( '<select />' );
 55+ this.conditionTypeInput = $( '<select />' );
5656 var conditionTypes = [ 'category', 'namespace', 'concept' ];
 57+ var conditionTypeGroups = [ 'categories', 'namespaces', 'concepts' ];
5758
5859 for ( i in conditionTypes ) {
59 - var optionElement = $( '<option />' ).text( mediaWiki.msg( 'swl-group-' + conditionTypes[i] ) ).attr( 'value', conditionTypes[i] );
 60+ var optionElement = $( '<option />' )
 61+ .text( mediaWiki.msg( 'swl-group-' + conditionTypes[i] ) )
 62+ .attr( { 'value': conditionTypes[i], 'type': conditionTypeGroups[i] } );
6063
6164 if ( conditionType == conditionTypes[i] ) {
6265 optionElement.attr( 'selected', 'selected' );
6366 }
6467
65 - conditionTypeInput.append( optionElement );
 68+ this.conditionTypeInput.append( optionElement );
6669 }
6770
68 - var conditionNameInput = $( '<input />' ).attr( {
 71+ this.conditionNameInput = $( '<input />' ).attr( {
6972 'type': 'text',
7073 'value': conditionValue,
7174 'size': 30
7275 } );
7376 var conditionTd = $( '<td />' ).html(
7477 $( '<p />' ).text( mediaWiki.msg( 'swl-group-page-selection' ) + ' ' )
75 - .append( conditionTypeInput )
 78+ .append( this.conditionTypeInput )
7679 .append( '&nbsp;' )
77 - .append( conditionNameInput )
 80+ .append( this.conditionNameInput )
7881 );
7982
8083 table.append( $( '<tr />' ).html( conditionTd ) );
@@ -86,7 +89,18 @@
8790 'value': mediaWiki.msg( 'swl-group-save' )
8891 } ).click( function() {
8992 this.disabled = true;
90 - self.doSave( function() { this.disabled = false; } );
 93+ var button = this;
 94+
 95+ self.doSave( function( success ) {
 96+ if ( success ) {
 97+ // TODO: indicate success?
 98+ }
 99+ else {
 100+ alert( 'Could not update the watchlist group.' );
 101+ }
 102+
 103+ button.disabled = false;
 104+ } );
91105 } )
92106 );
93107
@@ -99,6 +113,7 @@
100114 } ).click( function() {
101115 if ( confirm( mediaWiki.msg( 'swl-group-confirmdelete', self.nameInput.val() ) ) ) {
102116 this.disabled = true;
 117+ var button = this;
103118
104119 self.doDelete( function( success ) {
105120 if ( success ) {
@@ -106,7 +121,7 @@
107122 }
108123 else {
109124 alert( 'Could not delete the watchlist group.' );
110 - this.disabled = false;
 125+ button.disabled = false;
111126 }
112127 } );
113128 }
@@ -120,7 +135,8 @@
121136 var propInput = $( '<input />' ).attr( {
122137 'type': 'text',
123138 'value': property,
124 - 'size': 30
 139+ 'size': 30,
 140+ 'class': 'swl-group-prop'
125141 } );
126142
127143 var removeButton = $( '<input />' ).attr( {
@@ -135,15 +151,32 @@
136152 return propDiv.html( propInput ).append( removeButton );
137153 }
138154
 155+ this.getProperties = function() {
 156+ var props = [];
 157+
 158+ this.find( '.swl-group-prop' ).each( function( index, domElement ) {
 159+ props.push( $( domElement ).val() );
 160+ } );
 161+
 162+ return props;
 163+ }
 164+
139165 this.doSave = function( callback ) {
 166+ var args = {
 167+ 'action': 'editswlgroup',
 168+ 'format': 'json',
 169+ 'id': this.group.id,
 170+ 'name': this.nameInput.val(),
 171+ 'properties': this.getProperties().join( '|' )
 172+ };
 173+
 174+ args[this.conditionTypeInput.find( 'option:selected' ).attr( 'type' )] = this.conditionNameInput.val();
 175+
140176 $.getJSON(
141177 wgScriptPath + '/api.php',
142 - {
143 - 'action': 'editswlgroup',
144 - 'format': 'json',
145 - },
 178+ args,
146179 function( data ) {
147 - callback();
 180+ callback( data.success );
148181 }
149182 );
150183 }
Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
@@ -31,6 +31,6 @@
3232 },
3333 {}
3434 );
35 - }) ;
 35+ });
3636
3737 } ); })(jQuery);
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -49,24 +49,24 @@
5050
5151 public function writeToDB() {
5252 if ( is_null( $this->id ) ) {
53 - $this->insertIntoDB();
 53+ return $this->insertIntoDB();
5454 }
5555 else {
56 - $this->updateInDB();
 56+ return $this->updateInDB();
5757 }
5858 }
5959
6060 protected function updateInDB() {
6161 $dbr = wfGetDB( DB_MASTER );
6262
63 - $dbr->update(
 63+ return $dbr->update(
6464 'swl_groups',
6565 array(
6666 'group_name' => $this->name,
67 - 'group_properties' => $this->properties,
68 - 'group_categories' => $this->categories,
69 - 'group_namespaces' => $this->namespaces,
70 - 'group_concepts' => $this->concepts,
 67+ 'group_properties' => implode( '|', $this->properties ),
 68+ 'group_categories' => implode( '|', $this->categories ),
 69+ 'group_namespaces' => implode( '|', $this->namespaces ),
 70+ 'group_concepts' => implode( '|', $this->concepts ),
7171 ),
7272 array( 'group_id' => $this->id )
7373 );
Index: trunk/extensions/SemanticWatchlist/api/ApiEditWatchlistGroup.php
@@ -36,7 +36,11 @@
3737 $params['concepts']
3838 );
3939
40 - $group->writeToDB();
 40+ $this->getResult()->addValue(
 41+ null,
 42+ 'success',
 43+ $group->writeToDB()
 44+ );
4145 }
4246
4347 public function getAllowedParams() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r88435follow up to r88433jeroendedauw22:44, 19 May 2011

Status & tagging log