forked from graphpaperpress/Sell-Media
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsell-media-price-listings.js
107 lines (99 loc) · 3.19 KB
/
sell-media-price-listings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(function( $ ) {
"use strict";
var sell_media_price_listing = {
options : {
blank_data : {},
after_delete : function( e ){
}
},
init : function( options ){
var $this = this;
this.options = $.extend( {}, this.options, options );
this.fetch_data()
this.add_new()
this.delete_data();
},
fetch_data : function() {
var $this = this;
var obj = $this.options.data;
if( obj.length > 0 ){
$this.append( obj );
}
else{
this.add_new_row();
}
},
add_new : function() {
var $this = this;
$( document ).on( 'click', this.options.add_button, function(){
$this.add_new_row();
});
},
add_new_row : function() {
var index = $( this.options.wrapper_element ).children().last().data('index');
var data = {
index : (typeof index == 'undefined' ) ? 0 : index + 1,
}
data = [$.extend({},data,this.options.blank_data)];
this.append( data );
},
delete_data : function() {
var $this = this;
$( document ).on( 'click', this.options.delete_button, function(){
if( ! confirm( $(this).data( 'message' ) ) )
return false;
var index = $(this).data( 'index' );
$( $this.options.wrapper_element ).find( '#_row-data-' + index ).remove();
$this.options.after_delete( $(this) );
return false;
} );
},
append: function( input ) {
var $this = this;
var post_template = wp.template( $this.options.wp_template );
$( $this.options.wrapper_element ).append( post_template( input ) );
},
}
var defualt_listing_args = {
add_button : '#sell-media-add-button',
delete_button: '.sell-media-price-group-delete-term',
wp_template : 'sm-download-group-post',
after_delete : function( e ){
var old_value = $('[name=deleted_term_ids]').val();
var new_value = ( '' !== old_value ) ? old_value +',' + e.data( 'termid' ) : e.data( 'termid' );
$('[name=deleted_term_ids]').val( new_value )
}
}
if( 'undefined' !== typeof( sell_media_price_listings['price-group'] ) ){
var defualt_listing_args = $.extend( {}, defualt_listing_args, {
wrapper_element : 'table#sell-media-price-table.tax-price-group tbody',
data: sell_media_price_listings['price-group'],
} );
sell_media_price_listing.init( defualt_listing_args );
}
if( 'undefined' !== typeof( sell_media_price_listings['reprints-price-group'] ) ){
var defualt_listing_args = $.extend( {}, defualt_listing_args, {
wrapper_element : 'table#sell-media-price-table.tax-reprints-price-group tbody',
data: sell_media_price_listings['reprints-price-group'],
} );
sell_media_price_listing.init( defualt_listing_args );
}
$( '.tab-price-lists select' ).change( function(){
var link = $(this).val();
window.location = link;
});
$( '.tab-title a' ).click( function(){
$(this).next().toggle();
});
$('#sell-media-pricelist-form, #sell-media-new-pricelist-form').parsley();
// Delete Pricelist.
$(document).on( 'click', '.tab-price-lists .deletion', function(e){
var href = $(this).data('href');
var message = $(this).data('message');
if(!confirm( message ) ){
return false;
}
window.location = href;
return false;
});
})(jQuery);