http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88461
Revision: 88461
Author: jeroendedauw
Date: 2011-05-20 16:25:39 +0000 (Fri, 20 May 2011)
Log Message:
-----------
implemented add new group functionality
Modified Paths:
--------------
trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
2011-05-20 15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
2011-05-20 16:25:39 UTC (rev 88461)
@@ -39,6 +39,8 @@
'swl-group-concept' => 'concept',
'swl-group-confirmdelete' => 'Are you sure you want to delete the "$1"
watchlist group?',
'swl-group-save-all' => 'Save all',
+ 'swl-group-add-new-group' => 'Add a new group',
+ 'swl-group-add-group' => 'Add group',
// Special:SemanticWatchlist
'swl-watchlist-position' => "Showing '''$1''' of the last changes
starting with '''#$2'''.",
Modified: trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
2011-05-20 15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
2011-05-20 16:25:39 UTC (rev 88461)
@@ -36,7 +36,23 @@
$params['concepts']
);
- $group->writeToDB();
+ $this->getResult()->addValue(
+ null,
+ 'success',
+ $group->writeToDB()
+ );
+
+ $this->getResult()->addValue(
+ 'group',
+ 'id',
+ $group->getId()
+ );
+
+ $this->getResult()->addValue(
+ 'group',
+ 'name',
+ $group->getName()
+ );
}
public function getAllowedParams() {
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_Group.php 2011-05-20
15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_Group.php 2011-05-20
16:25:39 UTC (rev 88461)
@@ -75,7 +75,7 @@
protected function insertIntoDB() {
$dbr = wfGetDB( DB_MASTER );
- $dbr->insert(
+ $result = $dbr->insert(
'swl_groups',
array(
'group_name' => $this->name,
@@ -85,6 +85,10 @@
'group_concepts' => $this->concepts,
)
);
+
+ $this->id = $dbr->insertId();
+
+ return $result;
}
/**
Modified:
trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
2011-05-20 15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
2011-05-20 16:25:39 UTC (rev 88461)
@@ -70,8 +70,45 @@
$groupsHtml[] = $this->getGroupHtml( $group );
}
- $wgOut->addHTML( implode( '', $groupsHtml ) );
+ $wgOut->addHTML(
+ '<div id="swl-groups">' .
+ implode( '', $groupsHtml ) .
+ '</div>'
+ );
+ $wgOut->addHTML( Html::rawElement(
+ 'fieldset',
+ array(
+
+ ),
+ Html::element(
+ 'legend',
+ array(),
+ wfMsg( 'swl-group-add-new-group' )
+ ) .
+ Html::element(
+ 'span',
+ array(),
+ wfMsg( 'swl-group-name' )
+ ) . ' ' .
+ Html::element(
+ 'input',
+ array(
+ 'type' => 'text',
+ 'value' => '',
+ 'id' => 'swl-add-group-name'
+ )
+ ) . ' ' .
+ Html::element(
+ 'input',
+ array(
+ 'type' => 'button',
+ 'value' => wfMsg( 'swl-group-add-group'
),
+ 'id' => 'swl-add-group-button'
+ )
+ )
+ ) );
+
$wgOut->addHTML( Html::element(
'input',
array(
Modified:
trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
2011-05-20 15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
2011-05-20 16:25:39 UTC (rev 88461)
@@ -17,9 +17,7 @@
return element.attr( attribute ).split( separator );
}
- $( '.swl_group' ).each(function( index, domElement ) {
- var element = $( domElement );
-
+ function initGroupElement( element ) {
element.watchlistcondition(
{
name: element.attr( 'groupname' ),
@@ -30,11 +28,75 @@
concepts: getSplitAttrValue( element,
'concepts', '|' )
},
{}
- );
+ );
+ }
+
+ $( '.swl_group' ).each(function( index, domElement ) {
+ initGroupElement( $( domElement ) );
});
$( '#swl-save-all' ).click( function() {
$( '.swl-save' ).click();
} );
+ function addGroupToDB( groupName, callback ) {
+ $.getJSON(
+ wgScriptPath + '/api.php',
+ {
+ 'action': 'addswlgroup',
+ 'format': 'json',
+ 'name': groupName,
+ 'properties': ''
+ },
+ function( data ) {
+ callback( data.success, data.group );
+ }
+ );
+ }
+
+ function addGroupToGUI( groupName, groupId ) {
+ var newGroup = $( '<fieldset />' ).attr( {
+ 'id': 'swl_group_' + groupId,
+ 'groupid': groupId,
+ 'class': 'swl_group',
+ 'groupname': groupName,
+ 'categories': '',
+ 'namespaces': '',
+ 'properties': '',
+ 'concepts': ''
+ } )
+ .html( $( '<legend />' ).text( groupName ) );
+
+ $( '#swl-groups' ).append( newGroup );
+
+ initGroupElement( newGroup );
+ }
+
+ $( '#swl-add-group-button' ).click( function() {
+ var input = $( '#swl-add-group-name' );
+ var button = this;
+
+ button.disabled = true;
+ input.disabled = true;
+
+ addGroupToDB( input.val(), function( success, group ) {
+ if ( success ) {
+ addGroupToGUI( group.name, group.id );
+ input.val( '' );
+ }
+ else {
+ alert( 'Could not add the group.' );
+ }
+
+ button.disabled = false;
+ input.disabled = false;
+ } );
+ } );
+
+ $( '#swl-add-group-name' ).keypress( function( event ) {
+ if ( event.which == '13' ) {
+ $( '#swl-add-group-button' ).click();
+ }
+ } );
+
} ); })(jQuery);
\ No newline at end of file
Modified:
trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
2011-05-20 15:55:41 UTC (rev 88460)
+++ trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
2011-05-20 16:25:39 UTC (rev 88461)
@@ -153,7 +153,7 @@
self.doDelete( function( success ) {
if ( success ) {
- self.slideUp( 'fast' );
+ self.slideUp( 'fast',
function() { self.remove(); } );
}
else {
alert( 'Could not
delete the watchlist group.' );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs