Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
var base = require( './base' ),
delete_modal = require( '../modals/delete' );
module.exports = base.extend( {
className: 'tvd-col tvd-l3 tvd-m6',
template: TVE_Dash.tpl( 'html-archived-variation-card' ),
initialize: function ( args ) {
base.prototype.initialize.apply( this, args );
this.published_variations = args.published_variations;
this.archived_variations = args.archived_variations;
},
delete: function () {
TVE_Dash.modal( delete_modal, {
submit: _.bind( function () {
this.remove();
this.model.destroy();
}, this ),
model: this.model,
btn_yes_txt: ThriveAB.t.delete_title,
btn_no_txt: ThriveAB.t.cancel,
title: ThriveAB.t.delete_variation,
description: TVE_Dash.sprintf( ThriveAB.t.about_to_delete, this.model.get( 'post_title' ) )
} );
return false;
},
restore: function () {
var self = this;
this.model.set( 'action', 'publish' );
TVE_Dash.showLoader();
this.model.save( null, {
success: function ( model ) {
model.collection = self.published_variations;
self.published_variations.add( model );
self.published_variations.equalize_traffic();
self.published_variations.save_distributed_traffic();
self.remove();
self.archived_variations.remove( model );
TVE_Dash.success( ThriveAB.t.variation_added, 1000 );
},
error: function () {
TVE_Dash.err( ThriveAB.t.add_variation_error );
},
complete: function () {
TVE_Dash.hideLoader();
}
} );
},
render: function () {
this.$el.html( this.template( {item: this.model} ) );
}
} );

View File

@@ -0,0 +1,60 @@
/**
* @description Base View
* @extends Backbone.View
*/
module.exports = Backbone.View.extend( {
events: {
'click .click': '_call',
'input .input': '_call',
'change .change': '_call',
'mousedown .mousedown': '_call',
'mouseenter .mouseenter': '_call',
'mouseup .mouseup': '_call',
'keyup .keyup-enter': '_keyup_enter'
},
initialize: function () {
this.render();
},
_call: function ( e ) {
/**
* Do not allow actions on disabled controls
*/
if ( e.currentTarget.disabled || e.currentTarget.classList.contains( 'tve-disabled' ) ) {
return false;
}
var m = e.currentTarget.getAttribute( 'data-fn-' + e.type ) || e.currentTarget.getAttribute( 'data-fn' );
if ( m && m === '__return_false' ) {
e.stopPropagation();
e.preventDefault();
return false;
}
if ( typeof this[m] === 'function' ) {
return this[m].call( this, e, e.currentTarget );
}
/**
* call external function on the base TVE object
*/
if ( m && m.indexOf( 'f:' ) === 0 ) {
var fn = TVE, parts = m.split( ':' )[1].split( '.' ), context = window;
while ( fn && parts.length ) {
context = fn;
fn = fn[parts.shift()];
}
if ( typeof fn === 'function' ) {
return fn.call( context, e );
}
}
},
render: function () {
}
} );

View File

@@ -0,0 +1,143 @@
/**
* Created by PhpStorm.
* User: Ovidiu
* Date: 12/5/2017
* Time: 10:56 AM
*/
module.exports = Backbone.Model.extend( {
defaults: function () {
return {
id: '',
title: '',
renderTo: '',
type: 'line',
suffix: '',
data: []
};
},
initialize: function () {
var title = this.get( 'title' ),
type = this.get( 'type' ),
renderTo = this.get( 'renderTo' );
this.chart = this.dochart( title, type, renderTo );
},
empty: function () {
while ( this.chart.series.length > 0 ) {
this.chart.series[0].remove( true );
}
},
redraw: function () {
var title = this.get( 'title' ),
data = this.get( 'data' ),
x_axis = this.get( 'x_axis' ),
y_axis = this.get( 'y_axis' ),
ids = [],
x_axis_length = this.get( 'x_axis' ).length;
//add series or update data if it already exists
for ( var i in data ) {
ids.push( data[i].id );
var series = this.chart.get( data[i].id );
if ( ! series ) {
this.chart.addSeries( data[i], false, false )
} else {
series.setData( data[i].data );
}
}
//delete old series
for ( i = 0; i < this.chart.series.length; i ++ ) {
if ( ids.indexOf( this.chart.series[i].options.id ) < 0 ) {
this.chart.series[i].remove( false );
i --;
}
}
this.chart.get( 'time_interval' ).setCategories( x_axis );
this.chart.xAxis[0].update( {
tickInterval: x_axis_length > 13 ? Math.ceil( x_axis_length / 13 ) : 1
} );
this.chart.setTitle( {text: title} );
if ( this.chart.yAxis[0].axisTitle ) {
this.chart.yAxis[0].axisTitle.attr( {
text: y_axis
} );
}
this.chart.redraw();
this.chart.hideLoading();
},
showLoading: function () {
this.chart.showLoading();
},
hideLoading: function () {
this.chart.hideLoading();
},
dochart: function ( title, type, renderTo ) {
var self = this;
return new Highcharts.Chart( {
chart: {
type: type,
renderTo: renderTo,
style: {
fontFamily: 'Open Sans,sans-serif'
}
},
colors: ThriveAB.chart_colors,
yAxis: {
allowDecimals: false,
title: {
text: 'Engagements'
},
min: 0
},
xAxis: {
id: 'time_interval'
},
credits: {
enabled: false
},
title: {
text: title
},
tooltip: {
shared: false,
useHTML: true,
formatter: function () {
if ( this.series.type == 'scatter' ) {
/* We don't display tooltips for the scatter graph */
return false;
} else {
return this.x + '<br/>' +
this.series.name + ': ' + '<b>' + this.y + '</b>' + self.get( 'suffix' );
}
}
},
plotOptions: {
series: {
dataLabels: {
shape: 'callout',
backgroundColor: 'rgba(0, 0, 0, 0.75)',
style: {
color: '#FFFFFF',
textShadow: 'none'
}
},
events: {
legendItemClick: function () {
if ( this.type == 'scatter' ) {
/* The labels are not hidden by clicking on the legend so we have to do it manually */
if ( this.visible ) {
jQuery( '.highcharts-data-labels' ).hide();
} else {
jQuery( '.highcharts-data-labels' ).show();
}
}
}
}
}
}
} );
}
} );

View File

@@ -0,0 +1,137 @@
var base_view = require( './base' ),
variation_view = require( './variation' ),
archived_variation_view = require( './archived_variation' ),
test_model = require( '../models/test' ),
variation_model = require( '../models/variation' ),
modal_test = require( '../modals/test' );
module.exports = base_view.extend( {
template: TVE_Dash.tpl( 'dashboard/dashboard' ),
initialize: function ( args ) {
this.archived = args.archived;
base_view.prototype.initialize.apply( this, arguments );
this.listenTo( this.collection, 'add', function ( model ) {
this.render_variation( model );
this.render_action_button();
this.toggle_traffic_control();
} );
this.listenTo( this.collection, 'remove', function ( model ) {
this.render_action_button();
this.toggle_traffic_control();
} );
this.listenTo( this.archived, 'add', function ( model ) {
this.render_archived_variation( model );
} );
},
render_action_button: function () {
this.$( '#thrive-ab-start-test' ).toggleClass( 'top-hide-action', this.collection.length < 2 );
this.$( '.thrive-ab-display-archived-container' ).toggleClass( 'hide', this.archived.length < 1 );
},
render: function () {
this.$el.html( this.template() );
this.$list = this.$( '#thrive-ab-card-list' );
this.$archived_list = this.$( '#thrive-ab-card-list-archived' );
this.render_action_button();
this.collection.each( function ( item, index, list ) {
this.render_variation( item );
}, this );
this.archived.each( function ( item, index, list ) {
this.render_archived_variation( item );
}, this );
},
render_archived_variation: function ( item ) {
var _view = new archived_variation_view( {
model: item,
archived_variations: this.archived,
published_variations: this.collection
} );
this.$archived_list.append( _view.$el );
},
render_variation: function ( item ) {
var _view = new variation_view( {
model: item,
archived_variations: this.archived,
published_variations: this.collection
} );
var $add_new_card = this.$list.find( '> .tvd-col' ).last();
$add_new_card.remove();
this.$list.append( _view.$el );
this.$list.append( $add_new_card );
},
display_archived: function () {
this.$archived_list.toggle();
this.$( '.thrive-ab-display-archived' ).toggleClass( 'active' );
},
add_new_variation: function () {
var _new_traffic = parseInt( 100 / ( this.collection.length + 1 ) ),
_model = new variation_model( {
post_parent: this.model.get( 'ID' ),
post_title: TVE_Dash.sprintf( ThriveAB.t.variation_no, this.collection.length + 1 ),
traffic: _new_traffic
} );
TVE_Dash.showLoader();
_model.save( null, {
success: _.bind( function ( model ) {
this.collection.add( model );
model.collection.distribute_traffic( model );
model.collection.save_distributed_traffic();
TVE_Dash.success( ThriveAB.t.variation_added, 1000 );
}, this ),
error: function () {
TVE_Dash.err( ThriveAB.t.add_variation_error );
},
complete: _.bind( function () {
TVE_Dash.hideLoader();
}, this )
} );
},
start_test: function () {
var new_test_model = new test_model( {
page_id: ThriveAB.page.ID,
items: this.collection
} );
TVE_Dash.modal( modal_test, {
model: new_test_model,
'max-width': '80%'
} );
return false;
},
toggle_traffic_control: function () {
if ( this.collection.length === 1 ) {
this.$( '.thrive-ab-card-footer input' ).attr( 'disabled', 'disabled' );
} else {
this.$( '.thrive-ab-card-footer input' ).removeAttr( 'disabled' );
}
},
equalize_traffic: function () {
this.collection.equalize_traffic();
this.collection.save_distributed_traffic();
return false;
}
} );

View File

@@ -0,0 +1,71 @@
var base_view = require( '../base' ),
page_search = require( './../../controls/page_search' );
module.exports = base_view.extend( {
className: 'test-item-form tvd-col tvd-s12',
template: TVE_Dash.tpl( 'goals/page' ),
type: null,
events: {
'click .thrive-ab-remove-page': 'remove_page'
},
initialize: function ( args ) {
if ( args.test && args.test instanceof Backbone.Model ) {
this.test = args.test
}
this.model.set('type', this.test.get('type'));
this.page_search_view = new page_search.view( {
model: this.model,
goal_pages: this.test.get('goal_pages')
} );
this.page_search_view.test = this.test;
this.goal_pages = this.test.get( 'goal_pages' );
if ( ! this.goal_pages ) {
this.goal_pages = {};
}
this.listenTo( this.model, 'change:revenue', this.onRevenueChange );
this.listenTo( this.model, 'change:post_id', this.onPostChange );
},
onPostChange: function () {
if ( this.model.get( 'post_id' ) != null ) {
this.goal_pages[this.model.get( 'post_id' )] = {
post_id: this.model.get( 'post_id' ),
post_title: this.model.get( 'post_title' ),
revenue: this.model.get( 'revenue' )
};
this.test.set( 'goal_pages', this.goal_pages );
}
},
onRevenueChange: function () {
if ( this.model.get( 'post_id' ) ) {
this.onPostChange();
}
},
render: function () {
this.$el.html( this.template( {item: this.page_search_view.model, test: this.test} ) );
setTimeout( _.bind( function () {
TVE_Dash.materialize( this.$el );
}, this ), 0 );
TVE_Dash.data_binder( this );
this.$( '.page-search' ).html( this.page_search_view.render().$el );
return this;
},
remove_page: function () {
delete this.goal_pages[this.model.get( 'post_id' )];
this.test.set( 'goal_pages', this.goal_pages );
this.$el.unbind();
this.remove();
}
} );

View File

@@ -0,0 +1,71 @@
var settings = require( './settings' );
( function ( $ ) {
module.exports = settings.extend( {
template: TVE_Dash.tpl( 'goals/monetary-settings' ),
events: function () {
var parent_settings = settings.prototype.events.apply( this, arguments );
return _.extend( parent_settings, {
'change #thrive-ab-monetary-services': 'on_service_change'
} );
},
render: function () {
this.$el.html( this.template( {item: this.model} ) );
this.$( '.thrive-ab-monetary-service' ).hide();
this.init_services();
this.render_goal_pages();
return this;
},
on_service_change: function ( event ) {
var $services = this.$( '.thrive-ab-monetary-service' ),
service = event.currentTarget.value;
$services.hide();
this.model.set( 'service', service );
if ( service.length <= 0 ) {
return;
}
$services.closest( '#' + service ).css( 'display', 'block' );
},
init_services: function () {
if ( typeof ThriveAB.monetary_services === 'undefined' || ThriveAB.monetary_services.length <= 0 ) {
return;
}
var $dropdown = this.$( '#thrive-ab-monetary-services' ),
services = Object.keys( ThriveAB.monetary_services );
_.each( ThriveAB.monetary_services, function ( service, slug ) {
var $option = $( '<option/>' )
.attr( 'value', slug )
.text( typeof service.label ? service.label : slug );
$dropdown.append( $option );
}, this );
if ( services.length === 1 ) {
$dropdown.val( services[ 0 ] ).change();
$dropdown.parents( '.tvd-row' ).first().hide();
}
}
} );
} )( jQuery );

View File

@@ -0,0 +1,12 @@
var base_view = require( '../base' );
module.exports = base_view.extend( {
template: TVE_Dash.tpl( 'goals/optins-settings' ),
render: function () {
this.$el.html( this.template() );
return this;
}
} );

View File

@@ -0,0 +1,65 @@
var base_view = require( '../base' ),
goal_page = require( './goal_page' ),
base_model = require( './../../models/base' ),
page_search = require( '../../controls/page_search' );
module.exports = base_view.extend( {
className: 'tvd-col tvd-s12',
events: function () {
return _.extend( base_view.prototype.events, {
'click .thrive-ab-add-new-goal': 'add_goal_page_field'
} );
},
initialize: function () {
this.item_form_views = [];
},
render: function () {
this.$el.html( this.template( {item: this.model} ) );
this.render_goal_pages();
return this;
},
render_goal_pages: function () {
var goal_pages = this.model.get( 'goal_pages' ),
form_view,
self = this;
if ( goal_pages ) {
_.each( goal_pages, function ( element, index ) {
form_view = new goal_page( {
test: self.model,
model: new base_model( element )
} );
self.item_form_views.push( form_view );
self.$( '#item-forms' ).append( self.create_goal_page( form_view ) );
} );
} else {
this.add_goal_page_field();
}
},
add_goal_page_field: function () {
var form_view = new goal_page( {
test: this.model,
model: new base_model()
} );
this.item_form_views.push( form_view );
this.$( '#item-forms' ).append( this.create_goal_page( form_view ) );
},
create_goal_page: function ( input_view ) {
return input_view.render().$el;
}
} );

View File

@@ -0,0 +1,6 @@
var settings = require( './settings' );
module.exports = settings.extend( {
template: TVE_Dash.tpl( 'goals/visits-settings' )
} );

View File

@@ -0,0 +1,72 @@
/**
* Created by PhpStorm.
* User: Ovidiu
* Date: 11/29/2017
* Time: 11:42 AM
*/
var base_view = require( '../base' ),
line_chart = require( '../charts/line-chart' );
module.exports = base_view.extend( {
current_interval: 'day',
type: 'conversion_rate',
render_to: '',
initialize: function ( options ) {
base_view.prototype.initialize.apply( this, arguments );
this.render_to = options.render_to;
this.update_chart();
},
draw_chart: function ( render_to ) {
this.chart = new line_chart( {
title: '',
type: 'spline',
data: [],
renderTo: render_to
} );
this.chart.showLoading();
},
interval_changed: function ( type, interval ) {
var self = this;
if ( interval === this.current_interval && type === this.type ) {
return;
}
this.current_interval = interval;
this.type = type;
if ( typeof this.chart !== 'undefined' ) {
this.chart.showLoading();
}
this.model.fetch( {
data: jQuery.param( {
type: type,
interval: interval
} ),
success: function () {
self.update_chart();
}
} );
},
update_chart: function () {
if ( typeof this.chart === 'undefined' ) {
this.draw_chart( this.render_to );
}
this.chart.set( 'data', this.model.get( 'data' ) );
this.chart.set( 'title', '' );
this.chart.set( 'x_axis', this.model.get( 'x_axis' ) );
this.chart.set( 'y_axis', this.model.get( 'y_axis' ) );
this.chart.redraw();
this.update_description();
},
update_description: function () {
this.$( '#thrive-ab-chart-title' ).html( this.model.get( 'title' ) );
this.$( '#thrive-ab-chart-total-value' ).html( this.model.get( 'total_over_time' ) + ' ' + this.model.get( 'test_type_txt' ) );
}
} );

View File

@@ -0,0 +1,25 @@
/**
* Created by PhpStorm.
* User: Ovidiu
* Date: 11/27/2017
* Time: 2:31 PM
*/
var base_view = require( '../base' );
module.exports = base_view.extend( {
template: TVE_Dash.tpl( 'report/report-item' ),
tagName: 'tr',
initialize: function () {
},
render: function () {
this.$el.html( this.template( {model: this.model} ) );
return this;
}
} );

View File

@@ -0,0 +1,61 @@
/**
* Created by PhpStorm.
* User: Ovidiu
* Date: 11/27/2017
* Time: 10:20 AM
*/
var base_view = require( '../base' ),
report_item_view = require( './report-item' ),
report_chart = require( './report-chart' ),
chart_model = require( './../../models/report-chart' ),
test_table_view = require( './../test/table' ),
winner_modal = require( './../../modals/winner' );
module.exports = base_view.extend( {
template: TVE_Dash.tpl( 'report/report' ),
initialize: function () {
base_view.prototype.initialize.apply( this, arguments );
},
render: function () {
this.$el.html( this.template( {
model: this.model,
edit_page_link: ThriveAB.page.edit_link
} ) );
this.$( 'select' ).select2();
var table_view = new test_table_view( {
el: this.$( '#thrive-ab-test' ),
model: this.model
} );
this.do_chart();
},
update_chart: function ( event, dom ) {
var type = this.$( '.tab-graph-type' ).val(),
interval = this.$( '.tab-graph-interval' ).val();
this.report_chart.interval_changed( type, interval );
},
do_chart: function () {
this.report_chart = new report_chart( {
el: this.$el,
model: new chart_model( ThriveAB.test_chart ),
render_to: 'tab-test-chart'
} );
},
stop_test: function () {
TVE_Dash.modal( winner_modal, {
model: this.model,
collection: this.collection,
'max-width': '80%',
width: '80%',
title: ThriveAB.t.choose_winner
} );
}
} );

View File

@@ -0,0 +1,13 @@
var base = require( '../base' );
module.exports = base.extend( {
initialize: function () {
this.template = TVE_Dash.tpl( 'test/item/goal/' + this.model.get( 'type' ) );
},
render: function () {
this.$el.html( this.template( {} ) );
return this;
}
} );

View File

@@ -0,0 +1,137 @@
var base = require( './../base' ),
stop_variation_modal = require( './../../modals/delete' ),
range = require( '../../controls/range' ),
variation_winner_modal = require( './../../modals/variation-winner' );
module.exports = base.extend( {
template: TVE_Dash.tpl( 'test/item/view' ),
className: '',
initialize: function ( attrs ) {
this.active_items = attrs.active_items;
this.stopped_items = attrs.stopped_items;
this.table_model = attrs.table_model;
},
render: function () {
this.$el.html( this.template( {
item: this.model,
table_model: this.table_model
} ) );
if ( this.className.length > 0 ) {
this.$el.attr( 'class', this.className );
}
if ( parseInt( this.model.get( 'active' ) ) !== 0 ) {
new range( {
el: this.$( '.thrive-ab-test-item-traffic' ),
/**
* because the active_items is a collection with active items too
* model.item is from whole collection of test items
*/
model: this.active_items.findWhere( {id: this.model.get( 'id' )} )
} );
}
return this;
},
set_as_winner: function ( model, callback ) {
if ( ! (model instanceof Backbone.Model) ) {
model = this.model;
}
TVE_Dash.showLoader( true );
ThriveAB.ajax.do( 'set_winner', 'post', model.toJSON() )
.done( _.bind( function () {
if ( typeof callback === 'function' ) {
callback( model );
} else {
this.table_model.trigger( 'winner_selected', this.table_model, model );
TVE_Dash.hideLoader();
}
}, this ) );
return false;
},
stop_variation: function () {
TVE_Dash.modal( stop_variation_modal, {
submit: _.bind( function () {
TVE_Dash.showLoader();
this.model.set( 'stop_test_item', true );
this.model.save( null, {
wait: true,
/**
* tell server to stop the item and return the item model to update the backbone model
*/
success: _.bind( function ( model ) {
/**
* split the removed traffic and save it
*/
this.active_items.split_traffic( model, model.previousAttributes().traffic );
this.active_items.save_distributed_traffic();
/**
* remove vew from active items list
*/
this.remove();
/**
* add to stopped items to be rendered
*/
this.stopped_items.add( model );
/**
* remove it from active collection items
* so splitting traffic will not take into consideration this item/model
*/
this.active_items.remove( model );
var index = ThriveAB.current_test.items.findIndex( function ( element ) {
return element.id == model.get( 'id' );
} );
if ( index >= 0 ) {
ThriveAB.current_test.items[index].active = 0;
}
if ( this.active_items.length === 1 ) {
this.set_as_winner( this.active_items.first(), function ( model ) {
TVE_Dash.hideLoader();
TVE_Dash.modal( variation_winner_modal, {
model: model,
title: '',
no_close: true,
dismissible: false
}
);
} );
}
}, this ),
error: _.bind( function () {
TVE_Dash.hideLoader();
TVE_Dash.err( ThriveAB.t.variation_status_not_changed );
}, this )
} );
}, this ),
title: '',
description: TVE_Dash.sprintf( ThriveAB.t.about_to_stop_variation, this.model.get( 'title' ) ),
btn_yes_txt: ThriveAB.t.stop,
btn_no_txt: ThriveAB.t.keep_it_running,
'max-width': '20%',
width: '20%'
} );
}
} );

View File

@@ -0,0 +1,144 @@
var base = require( '../base' ),
test_item = require( './item' ),
change_automatic_winner_settings = require( '../../modals/automatic-winner-settings' ),
test_items_collection = require( '../../collections/test-items' ),
test_model = require( '../../models/test' ),
goal = require( './goal' ),
modal_goal = require( '../../modals/goal' );
module.exports = base.extend( {
template: TVE_Dash.tpl( 'test/table' ),
initialize: function ( attr ) {
this.template = TVE_Dash.tpl( 'test/' + this.model.get( 'type' ) + '-table' );
if ( attr.item_template_name ) {
this.item_template_name = attr.item_template_name;
}
var raw_test = ThriveAB.current_test || ThriveAB.running_test;
this.active_items = new test_items_collection( _.filter( raw_test.items, {active: '1'} ) );
this.stopped_items = new test_items_collection( _.filter( raw_test.items, {active: '0'} ) );
this.listenTo( this.stopped_items, 'add', function ( model ) {
this.$stopped_item_list.append( this.render_item( model ).$el );
} );
this.listenTo( this.active_items, 'remove', function ( model ) {
this.render_active_items();
} );
this.listenTo( this.model, 'change:auto_win_enabled', this.toggle_auto_win_text );
base.prototype.initialize.apply( this, arguments );
},
render: function () {
this.$el.html( this.template( {item: this.model} ) );
this.toggle_auto_win_text( this.model );
if ( this.model.get( 'status' ) === 'completed' ) {
this.$( '.thrive-ab-test-footer' ).hide();
}
this.$item_list = this.$( '.thrive-ab-test-items' );
this.$stopped_item_list = this.$( '.thrive-ab-test-stopped-items' );
this.collection = this.model.get( 'items' );
this.render_variations();
this.render_goal_type();
return this;
},
toggle_auto_win_text: function ( model ) {
var text = model.get( 'auto_win_enabled' ) != 0 ? ThriveAB.t.auto_win_enabled : ThriveAB.t.auto_win_disabled;
this.$( '#thrive-ab-auto-win-text' ).text( text );
},
render_variations: function () {
this.render_active_items();
this.render_stopped_items();
},
render_active_items: function () {
this.$item_list.empty();
this.active_items.each( function ( item ) {
this.$item_list.append( this.render_item( item ).$el );
}, this );
return this;
},
render_stopped_items: function () {
this.$stopped_item_list.empty();
this.stopped_items.each( function ( item ) {
this.$stopped_item_list.append( this.render_item( item ).$el );
}, this );
return this;
},
render_item: function ( item ) {
var item_view = new test_item( {
model: item,
table_model: this.model,
active_items: this.active_items,
stopped_items: this.stopped_items
} );
if ( this.item_template_name ) {
item_view.template = TVE_Dash.tpl( this.item_template_name );
} else if ( item.get( 'is_control' ) ) {
item_view.template = TVE_Dash.tpl( 'test/item/control-view-' + this.model.get( 'type' ) );
item_view.className = 'tab-control-row';
} else if ( parseInt( item.get( 'active' ) ) === 0 ) {
item_view.template = TVE_Dash.tpl( 'test/item/view-stopped-' + this.model.get( 'type' ) );
} else {
item_view.template = TVE_Dash.tpl( 'test/item/view-' + this.model.get( 'type' ) );
}
return item_view.render();
},
render_goal_type: function () {
new goal( {
el: this.$( '#thrive-ab-conversion-goals' ),
model: this.model
} ).render();
},
/**
* Change Automatic Winner Settings
*/
change_automatic_winner_settings: function () {
TVE_Dash.modal( change_automatic_winner_settings, {
model: this.model,
title: ThriveAB.t.automatic_winner_settings
} );
return false;
},
view_conversion_goal_details: function () {
TVE_Dash.modal( modal_goal, {
collection: new Backbone.Collection( Object.values( this.model.get( 'goal_pages' ) ) ),
model: this.model,
title: ''
} );
return false;
}
} );

View File

@@ -0,0 +1,128 @@
var base = require( './base' ),
base_model = require( './../models/base' ),
range = require( '../controls/range' ),
delete_modal = require( '../modals/archive' ),
title_editor = require( './../controls/edit_title' );
module.exports = base.extend( {
className: 'tvd-col tvd-l3 tvd-m6',
template: TVE_Dash.tpl( 'html-variation-card' ),
initialize: function ( args ) {
base.prototype.initialize.apply( this, args );
this.archived_variations = args.archived_variations;
this.published_variations = args.published_variations;
},
archive: function () {
TVE_Dash.modal( delete_modal, {
submit: _.bind( function () {
this.remove();
this.model.set( 'action', 'archive' );
this.model.save();
this.published_variations.distribute_traffic( this.model.set( 'traffic', 0 ) );
this.published_variations.save_distributed_traffic();
this.archived_variations.add( this.model );
this.published_variations.remove( this.model );
}, this ),
model: this.model,
btn_yes_txt: ThriveAB.t.archive_title,
btn_no_txt: ThriveAB.t.cancel,
title: ThriveAB.t.archive_variation,
description: TVE_Dash.sprintf( ThriveAB.t.about_to_archive, this.model.get( 'post_title' ) )
} );
return false;
},
delete: function () {
TVE_Dash.modal( delete_modal, {
submit: _.bind( function () {
this.remove();
this.model.destroy();
this.published_variations.equalize_traffic();
this.published_variations.save_distributed_traffic();
}, this ),
model: this.model,
btn_yes_txt: ThriveAB.t.delete_title,
btn_no_txt: ThriveAB.t.cancel,
title: ThriveAB.t.delete_variation,
description: TVE_Dash.sprintf( ThriveAB.t.about_to_delete, this.model.get( 'post_title' ) )
} );
return false;
},
duplicate: function () {
var clone = this.model.clone(),
_new_traffic = parseInt( 100 / ( this.published_variations.length + 1 ) );
clone.set( {
ID: '',
post_title: 'Copy of ' + this.model.get( 'post_title' ),
source_id: this.model.get( 'ID' ),
traffic: _new_traffic,
is_control: false,
post_parent: ThriveAB.page.ID
} );
TVE_Dash.showLoader();
clone.save( null, {
success: _.bind( function ( model ) {
this.published_variations.add( model );
this.published_variations.equalize_traffic();
this.published_variations.save_distributed_traffic();
TVE_Dash.success( ThriveAB.t.variation_added, 1000 );
}, this ),
error: function () {
TVE_Dash.err( ThriveAB.t.add_variation_error );
},
complete: function () {
TVE_Dash.hideLoader();
}
} );
},
edit_title: function ( e ) {
var self = this,
$original_title = this.$el.find( '.thrive-ab-title-content' ),
editModel = new base_model( {post_title: this.model.get( 'post_title' )} );
editModel.on( 'thrive-ab-title-no-change', function () {
self.$( '.thrive-ab-title-editor' ).html( '' );
$original_title.show();
} );
editModel.on( 'change:post_title', function () {
self.model.save( {post_title: editModel.get( 'post_title' )}, {patch: true} );
self.$( '.thrive-ab-title-editor' ).html( '' );
$original_title.find( '.thrive-ab-card-title' ).html( editModel.get( 'post_title' ) );
$original_title.show();
} );
var titleEditor = new title_editor( {
el: this.$( '.thrive-ab-title-editor' ),
model: editModel
} );
$original_title.hide().after( titleEditor.render().$el );
titleEditor.focus();
return false;
},
render: function () {
this.$el.html( this.template( {item: this.model} ) );
new range( {
el: this.$( '.thrive-ab-card-footer' ),
model: this.model
} );
}
} );