Changeset 276 for ether_megapoli


Ignore:
Timestamp:
12/01/11 15:03:49 (12 years ago)
Author:
vmipsl
Message:

BO User _ accept, refuse

Location:
ether_megapoli/trunk/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/web/backoffice/user-script.jsp

    r275 r276  
    5454                url: "backoffice?methodName=addUser&" + parametersUrl, 
    5555                success:jQuery.proxy( this.handleUser, this ), 
    56                 error: function ( result ) 
    57                 { 
    58                     window.alert( 'Erreur de transmission au serveur' + result.responseText ); 
    59                 } 
     56                error: jQuery.proxy( this.showErrors, [this] ) 
    6057            } ); 
    6158        } 
     
    8077                url: "backoffice?methodName=modifyUser&" + parametersUrl, 
    8178                success:jQuery.proxy( this.handleModifyUser, this ), 
    82                 error: jQuery.proxy( function ( result ) 
    83                 { 
    84                     this.containerErrors.show(); 
    85                     this.containerErrors.html( interfaceTexts[result.responseText] ); 
    86                 }, this ) 
    87             } ); 
    88         } 
     79                error: jQuery.proxy( this.showErrors, [this] ) 
     80            } ); 
     81        } 
     82    }, 
     83 
     84    requestAcceptUser: function( waitingUser ) 
     85    { 
     86        if( waitingUser ) 
     87            $.ajax( { 
     88                url: "backoffice?methodName=acceptOrRefuseUser&id=" + waitingUser.id + "&ok=true", 
     89                success: jQuery.proxy( this.handleUser, this ), 
     90                error: jQuery.proxy( this.showErrors, [this, waitingUser.email ] ) 
     91            } ); 
     92    }, 
     93 
     94    requestRefuseUser: function( waitingUser ) 
     95    { 
     96        if( waitingUser ) 
     97            $.ajax( { 
     98                url: "backoffice?methodName=acceptOrRefuseUser&id=" + waitingUser.id + "&ok=false", 
     99                success: jQuery.proxy( this.handleUser, this ), 
     100                error: jQuery.proxy( this.showErrors, [this, waitingUser.email ] ) 
     101            } ); 
    89102    }, 
    90103 
     
    138151        this.containerWaitingUsers.empty(); 
    139152 
    140         if( this.jsonWaitingUsers && this.jsonWaitingUsers.length > 0 ) 
     153        if( this.jsonWaitingUsers && 0 < this.jsonWaitingUsers.length ) 
    141154        { 
    142155            jQuery.each( this.jsonWaitingUsers, jQuery.proxy( function( i, waitingUser ) 
     
    146159                // Buttons 
    147160                var tdAccept = $( document.createElement( "td" ) ); 
    148                 var buttonAccept = new Button( {value:interfaceTexts["bo.accept"], parent:tdAccept, id:"button_accept", className: "small positive action_button", onClick:jQuery.proxy( this.onClickAccept, waitingUser )} ); 
     161                var buttonAccept = new Button( {value:interfaceTexts["bo.accept"], parent:tdAccept, id:"button_accept", className: "small positive action_button", contextToSave: waitingUser, onClick:jQuery.proxy( this.requestAcceptUser, this )} ); 
    149162                tr.append( tdAccept ); 
    150163 
    151164                var tdRefuse = $( document.createElement( "td" ) ); 
    152                 var buttonRefuse = new Button( {value:interfaceTexts["bo.refuse"], parent:tdRefuse, id:"button_refuse", className: "small negative action_button", onClick:jQuery.proxy( this.onClickRefuse, waitingUser )} ); 
     165                var buttonRefuse = new Button( {value:interfaceTexts["bo.refuse"], parent:tdRefuse, id:"button_refuse", className: "small negative action_button", contextToSave: waitingUser, onClick:jQuery.proxy( this.requestRefuseUser, this )} ); 
    153166                tr.append( tdRefuse ); 
    154167 
     
    322335        } 
    323336        return errors; 
     337    }, 
     338 
     339    showErrors: function( result ) 
     340    { 
     341        var context = this[0]; 
     342        var text = this[1]; 
     343        context.containerErrors.show(); 
     344        if( text ) 
     345            context.containerErrors.html( interfaceTexts[result.responseText] + " " + text ); 
     346        else 
     347            context.containerErrors.html( interfaceTexts[result.responseText] ); 
    324348    } 
    325349 
  • ether_megapoli/trunk/web/src/com/ether/ControllerBackoffice.java

    r275 r276  
    66import com.ether.user.UserRole; 
    77import com.ether.user.UserState; 
     8import com.medias.mail.Mail; 
     9import com.medias.mail.MailFactory; 
    810import net.sf.json.JSONObject; 
    911import org.apache.commons.logging.Log; 
     
    7981        } 
    8082        else 
    81             throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User" ); 
     83            throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getBoThrowable() ); 
    8284 
    8385        return getAllAndWaitingUsers(); 
     
    124126    } 
    125127 
     128    @ControllerMethod(jsonResult = true) 
     129    public JSONObject acceptOrRefuseUser( @NotNull @ParamName(ParameterConstants.PARAMETER_ID) final Integer userId, 
     130                                          @ParamName(ParameterConstants.PARAMETER_OK) final boolean isAccepted ) 
     131            throws WebException, ServiceException 
     132    { 
     133        _etherService.acceptOrRefuseUser( userId, isAccepted ); 
     134 
     135        // Send email to the user 
     136        final User user = _etherService.getUserById( userId ); 
     137        final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 
     138        final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 
     139        final String to = user.getEmail(); 
     140        final String subject = "[MEGAPOLI] User"; 
     141        final Mail mail = new Mail( from, to, null, "", subject ); 
     142        try 
     143        { 
     144            mailFactory.sendMail( mail ); 
     145        } 
     146        catch( Exception e ) 
     147        { 
     148            throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the user : " + user.getEmail(), WebException.getBoThrowable() ); 
     149        } 
     150 
     151        return getAllAndWaitingUsers(); 
     152    } 
     153 
     154 
    126155    private JSONObject getAllAndWaitingUsers() 
    127156            throws ServiceException 
Note: See TracChangeset for help on using the changeset viewer.