Renamed tab to type

- renamed getExtraParams to getParams
- fixed issue with String.contains by replacing it with indexOf
- removed useless break; statement
This commit is contained in:
Jonathan Labreuille
2016-07-15 12:12:26 +02:00
parent ef0cbb3e9f
commit 3d706414b7
6 changed files with 18 additions and 20 deletions

View File

@ -348,15 +348,15 @@ const Listing = React.createClass({
this.getItems(); this.getItems();
}.bind(this)); }.bind(this));
}, },
getExtraParams: function() { getParams: function() {
// get all route parameters (without the "splat") // get all route parameters (without the "splat")
let extras = _.omit(this.props.params, 'splat'); let params = _.omit(this.props.params, 'splat');
// TO REFACTOR: // TO REFACTOR:
// set the "tab" in the routes definition // find a way to set the "type" in the routes definition
if (this.props.tab) { if (this.props.type) {
extras.tab = this.props.tab; params.type = this.props.type;
} }
return extras; return params;
}, },
setParams: function() { setParams: function() {
if (this.props.location) { if (this.props.location) {
@ -409,10 +409,10 @@ const Listing = React.createClass({
} }
}, },
setBaseUrlParams: function(base_url) { setBaseUrlParams: function(base_url) {
if (base_url.contains(':') === true) { if (base_url.indexOf(':') !== -1) {
const params = this.getExtraParams(); const params = this.getParams();
Object.keys(params).map((key) => { Object.keys(params).map((key) => {
if (base_url.contains(':'+key)) { if (base_url.indexOf(':'+key) !== -1) {
base_url = base_url.replace(':'+key, params[key]); base_url = base_url.replace(':'+key, params[key]);
} }
}); });
@ -446,7 +446,7 @@ const Listing = React.createClass({
endpoint: this.props.endpoint, endpoint: this.props.endpoint,
action: 'listing', action: 'listing',
data: { data: {
params: this.getExtraParams(), params: this.getParams(),
offset: (this.state.page - 1) * this.state.limit, offset: (this.state.page - 1) * this.state.limit,
limit: this.state.limit, limit: this.state.limit,
group: this.state.group, group: this.state.group,
@ -561,7 +561,7 @@ const Listing = React.createClass({
var data = params || {}; var data = params || {};
data.listing = { data.listing = {
params: this.getExtraParams(), params: this.getParams(),
offset: 0, offset: 0,
limit: 0, limit: 0,
filter: this.state.filter, filter: this.state.filter,

View File

@ -301,7 +301,7 @@ const NewsletterListNotification = React.createClass({
location={ this.props.location } location={ this.props.location }
params={ this.props.params } params={ this.props.params }
endpoint="newsletters" endpoint="newsletters"
tab="notification" type="notification"
base_url="notification" base_url="notification"
onRenderItem={ this.renderItem } onRenderItem={ this.renderItem }
columns={ columns } columns={ columns }

View File

@ -234,7 +234,7 @@ const NewsletterListNotificationHistory = React.createClass({
location={ this.props.location } location={ this.props.location }
params={ this.props.params } params={ this.props.params }
endpoint="newsletters" endpoint="newsletters"
tab="notification_history" type="notification_history"
base_url="notification/history/:parent_id" base_url="notification/history/:parent_id"
onRenderItem={ this.renderItem } onRenderItem={ this.renderItem }
columns={columns} columns={columns}

View File

@ -321,7 +321,7 @@ const NewsletterListStandard = React.createClass({
location={ this.props.location } location={ this.props.location }
params={ this.props.params } params={ this.props.params }
endpoint="newsletters" endpoint="newsletters"
tab="standard" type="standard"
base_url="standard" base_url="standard"
onRenderItem={this.renderItem} onRenderItem={this.renderItem}
columns={columns} columns={columns}

View File

@ -343,7 +343,7 @@ const NewsletterListWelcome = React.createClass({
location={ this.props.location } location={ this.props.location }
params={ this.props.params } params={ this.props.params }
endpoint="newsletters" endpoint="newsletters"
tab="welcome" type="welcome"
base_url="welcome" base_url="welcome"
onRenderItem={ this.renderItem } onRenderItem={ this.renderItem }
columns={ columns } columns={ columns }

View File

@ -219,8 +219,6 @@ class Newsletter extends Model {
->where('queues.newsletter_id', $this->id) ->where('queues.newsletter_id', $this->id)
->where('queues.status', SendingQueue::STATUS_COMPLETED) ->where('queues.status', SendingQueue::STATUS_COMPLETED)
->findOne(); ->findOne();
break;
default: default:
if($this->queue === false) { if($this->queue === false) {
return false; return false;
@ -259,7 +257,7 @@ class Newsletter extends Model {
} }
static function filters($data = array()) { static function filters($data = array()) {
$type = isset($data['params']['tab']) ? $data['params']['tab'] : null; $type = isset($data['params']['type']) ? $data['params']['type'] : null;
// newsletter types without filters // newsletter types without filters
if(in_array($type, array( if(in_array($type, array(
@ -311,7 +309,7 @@ class Newsletter extends Model {
} }
// filter by type // filter by type
$type = isset($data['params']['tab']) ? $data['params']['tab'] : null; $type = isset($data['params']['type']) ? $data['params']['type'] : null;
if($type !== null) { if($type !== null) {
$orm->filter('filterType', $type); $orm->filter('filterType', $type);
} }
@ -358,7 +356,7 @@ class Newsletter extends Model {
} }
static function groups($data = array()) { static function groups($data = array()) {
$type = isset($data['params']['tab']) ? $data['params']['tab'] : null; $type = isset($data['params']['type']) ? $data['params']['type'] : null;
// newsletter types without groups // newsletter types without groups
if(in_array($type, array( if(in_array($type, array(