Custom Contact Forms - Version 7.8.4

Version Description

  • Fix WP 4.7 conflict
Download this release

Release Info

Developer tlovett1
Plugin Icon 128x128 Custom Contact Forms
Version 7.8.4
Comparing to
See all releases

Code changes from version 7.8.3 to 7.8.4

assets/build/js/form-manager.js CHANGED
@@ -117,18 +117,22 @@
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
- format = 'HH:mm MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
- format = 'HH:mm DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
 
128
  }
129
 
130
  if ( value.date ) {
131
- dateString += ' ' + value.date;
 
 
 
132
  }
133
 
134
  if ( ! dateString ) {
@@ -449,7 +453,7 @@
449
  }
450
  );
451
 
452
- wp.ccf.models.Form = wp.ccf.models.Form || wp.api.models.Post.extend(
453
  {
454
 
455
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
@@ -494,7 +498,7 @@
494
  },
495
 
496
  decode: function() {
497
- var keys = _.keys( wp.api.models.Post.prototype.defaults );
498
  keys = _.without( keys, 'title' );
499
 
500
  return _modelDecode.call( this, keys );
@@ -703,7 +707,7 @@
703
  }
704
  );
705
 
706
- wp.ccf.models.Submission = wp.api.models.Submission || wp.api.models.Post.extend(
707
  {
708
  defaults: {
709
  id: null,
@@ -717,7 +721,7 @@
717
  }
718
  );
719
 
720
- wp.ccf.models.Field = wp.api.models.Field || wp.api.models.Post.extend(
721
  {
722
  idAttribute: 'id',
723
 
@@ -753,7 +757,7 @@
753
  },
754
 
755
  decode: function() {
756
- return _modelDecode.call( this, _.keys( wp.api.models.Post.prototype.defaults ) );
757
  },
758
 
759
  hasRequiredAttributes: function() {
@@ -1156,7 +1160,7 @@
1156
 
1157
  wp.ccf.collections = wp.ccf.collections || {};
1158
 
1159
- wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.api.collections.Posts.extend(
1160
  {
1161
  model: wp.ccf.models.Form,
1162
 
@@ -1192,7 +1196,7 @@
1192
  }
1193
  );
1194
 
1195
- wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.api.collections.Posts.extend(
1196
  {
1197
  model: wp.ccf.models.Field,
1198
 
@@ -1228,7 +1232,7 @@
1228
  }
1229
  );
1230
 
1231
- wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.api.collections.Posts.extend(
1232
  {
1233
  model: wp.ccf.models.Submission,
1234
 
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
+ format = 'MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
+ format = 'DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
128
+ format = 'HH:mm ' + format;
129
  }
130
 
131
  if ( value.date ) {
132
+ if ( dateString ) {
133
+ dateString += ' ';
134
+ }
135
+ dateString += value.date;
136
  }
137
 
138
  if ( ! dateString ) {
453
  }
454
  );
455
 
456
+ wp.ccf.models.Form = wp.ccf.models.Form || wp.ccf.api.models.Post.extend(
457
  {
458
 
459
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
498
  },
499
 
500
  decode: function() {
501
+ var keys = _.keys( wp.ccf.api.models.Post.prototype.defaults );
502
  keys = _.without( keys, 'title' );
503
 
504
  return _modelDecode.call( this, keys );
707
  }
708
  );
709
 
710
+ wp.ccf.models.Submission = wp.ccf.api.models.Submission || wp.ccf.api.models.Post.extend(
711
  {
712
  defaults: {
713
  id: null,
721
  }
722
  );
723
 
724
+ wp.ccf.models.Field = wp.ccf.api.models.Field || wp.ccf.api.models.Post.extend(
725
  {
726
  idAttribute: 'id',
727
 
757
  },
758
 
759
  decode: function() {
760
+ return _modelDecode.call( this, _.keys( wp.ccf.api.models.Post.prototype.defaults ) );
761
  },
762
 
763
  hasRequiredAttributes: function() {
1160
 
1161
  wp.ccf.collections = wp.ccf.collections || {};
1162
 
1163
+ wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.ccf.api.collections.Posts.extend(
1164
  {
1165
  model: wp.ccf.models.Form,
1166
 
1196
  }
1197
  );
1198
 
1199
+ wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.ccf.api.collections.Posts.extend(
1200
  {
1201
  model: wp.ccf.models.Field,
1202
 
1232
  }
1233
  );
1234
 
1235
+ wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.ccf.api.collections.Posts.extend(
1236
  {
1237
  model: wp.ccf.models.Submission,
1238
 
assets/build/js/form-manager.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (function(e,t,i,l){"use strict";window.wp=window.wp||{},wp.ccf=wp.ccf||{},wp.ccf.utils=wp.ccf.utils||{},wp.ccf.utils.cleanDateFields=function(e){delete e.date,delete e.date_gmt,delete e.modified,delete e.modified_gmt,delete e.date_tz,delete e.modified_tz},wp.ccf.utils.template=i.memoize(function(e){var t={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};return i.template(document.getElementById(e).innerHTML,null,t)}),wp.ccf.utils.insertFormShortcode=function(e){var t=wp.ccf.forms.findWhere({id:e.get("id")});t||wp.ccf.forms.add(e);var i=tinymce.get(wpActiveEditor),l='[ccf_form id="'+e.get("id")+'"]';i&&!i.isHidden()?tinymce.activeEditor.execCommand("mceInsertContent",!1,l):document.getElementById(wpActiveEditor).value+=l},wp.ccf.utils.getPrettyPostDate=function(e){return e=moment.utc(e),l.gmtOffset&&(e=e.utcOffset(60*parseInt(l.gmtOffset))),e.format("h:mm a M/D/YYYY")},wp.ccf.utils.wordChop=function(e,t){var i=e.substr(0,t);return i.substr(0,Math.min(i.length,i.lastIndexOf(" "))),i.length<e.length&&(i+="..."),i},wp.ccf.utils.isFieldDate=function(e){return e.date!==void 0||e.hour!==void 0&&e.minute!==void 0&&e["am-pm"]!==void 0?!0:!1},wp.ccf.utils.isFieldName=function(e){return e.name!==void 0||e.last!==void 0?!0:!1},wp.ccf.utils.isFieldEmailConfirm=function(e){return e.email!==void 0||e.confirm!==void 0?!0:!1},wp.ccf.utils.isFieldAddress=function(e){return e.street!==void 0&&e.city!==void 0&&e.zipcode!==void 0&&e.line_two!==void 0?!0:!1},wp.ccf.utils.isFieldFile=function(e){return e.id!==void 0&&e.url!==void 0&&e.file_name!==void 0?!0:!1},wp.ccf.utils.getPrettyFieldEmailConfirm=function(e){return e.email?e.email:e.confirm?e.confirm:"-"},wp.ccf.utils.getPrettyFieldDate=function(e,t){var i="",s="",o="HH:mm MM/DD/YY";if(t&&t.ccf_field_dateFormat&&"dd/mm/yyyy"===t.ccf_field_dateFormat&&(o="HH:mm DD/MM/YY"),e.hour&&e.minute&&e["am-pm"]&&(i+=e.hour+":"+e.minute+" "+e["am-pm"]),e.date&&(i+=" "+e.date),!i)return"-";var n=moment(i,o);return n.isValid()?(e.hour&&e.minute&&e["am-pm"]&&(s+=n.format("h:mm a")),e.date&&(s&&(s+=" "),s+=e.date),s):l.invalidDate},wp.ccf.utils.getPrettyFieldName=function(e){var t=e.first;return t.length>0&&(t+=" "),e.last&&(t+=e.last),t||(t="-"),t},wp.ccf.utils.getPrettyFieldAddress=function(e){if(!e.street||!e.city)return"-";var t=e.street;return e.line_two&&(t+=" "+e.line_two),t+=", "+e.city,e.state&&(t+=", "+e.state),e.zipcode&&(t+=" "+e.zipcode),e.country&&(t+=" "+e.country),t}})(jQuery,Backbone,_,ccfSettings),function(e,t,i){"use strict";wp.ccf.mixins=wp.ccf.mixins||{},wp.ccf.mixins.subViewable=wp.ccf.mixins.subViewable||{subViews:{},initRenderSubViews:function(e,t,l){this.renderedSubViews||(this.renderedSubViews={});for(var s in this.subViews){var o={el:this.$el.find(".ccf-"+s),parent:this};l&&i.extend(o,l),this.renderedSubViews[s]&&this.renderedSubViews[s].destroy&&this.renderedSubViews[s].destroy(),(t||!this.renderedSubViews[s])&&(this.renderedSubViews[s]=new this.subViews[s](o)),this.renderedSubViews[s].render(),e&&(this.renderedSubViews[s].el.style.display="block")}return this},showView:function(e,t,i){if(this.renderedSubViews!==void 0&&this.renderedSubViews[e]!==void 0){var l=this.renderedSubViews[e];i||l.render(t),l.el.style.display="block",this.currentView=e;for(var s in this.subViews)s!==e&&(this.renderedSubViews[s].el.style.display="none")}}}}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.models=wp.ccf.models||{},wp.ccf.models.Fields=wp.ccf.models.Fields||{};var s=function(e,i,l){return"object"!=typeof i&&""===i&&(i=""),t.Model.prototype.set.call(this,e,i,l)},o=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)},n=function(e){for(var t in this.attributes)if(-1===i.indexOf(e,t)){var l=this.get(t);"string"==typeof l&&""!==l&&(l=(l+"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#8220;/g,"”").replace(/&#8221;/g,"”").replace(/&#8216;/g,"‘").replace(/&#038;/g,"&").replace(/&#039;/g,"'"),this.set(t,l))}return this};wp.ccf.models.FieldConditional=wp.ccf.models.FieldConditional||t.Model.extend({defaults:{field:"",compare:"is",value:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FieldChoice=wp.ccf.models.FieldChoice||t.Model.extend({defaults:{label:"",value:"",selected:!1},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.PostFieldMapping=wp.ccf.models.PostFieldMapping||t.Model.extend({defaults:{formField:"",postField:"",customFieldKey:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotificationAddress=wp.ccf.models.FormNotificationAddress||t.Model.extend({defaults:{type:"custom",field:"",email:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotification=wp.ccf.models.FormNotification||t.Model.extend({defaults:function(){return{title:"",content:"[all_fields]",active:!0,includeUploads:!0,addresses:new wp.ccf.collections.FormNotificationAddresses,fromType:"default",fromAddress:"",fromField:"",subjectType:"default",subject:"",subjectField:"",fromNameType:"custom",fromName:"WordPress",fromNameField:"",replyToType:"default",replyToAddress:"",replyToField:"",replyToNameType:"custom",replyToName:"WordPress",replyToNameField:""}},initialize:function(e){if("object"==typeof e&&e.addresses){var t=[];i.each(e.addresses,function(e){var i=new wp.ccf.models.FormNotificationAddress(e);i.decode(),t.push(i)}),this.set("addresses",new wp.ccf.collections.FormNotificationAddresses(t))}},decode:function(){return n.call(this,[])},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.addresses&&(e.addresses=e.addresses.toJSON()),e},set:s}),wp.ccf.models.Form=wp.ccf.models.Form||wp.api.models.Post.extend({urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",set:s,sync:o,idAttribute:"id",initialize:function(){this.on("sync",this.decode,this)},defaults:function(){var e={fields:new wp.ccf.collections.Fields,type:"ccf_form",status:"publish",hideTitle:!1,description:"",buttonText:"Submit Form",buttonClass:"",completionActionType:"text",completionRedirectUrl:"",completionMessage:"",postCreation:!1,postCreationType:"post",postCreationStatus:"draft",postFieldMappings:new wp.ccf.collections.PostFieldMappings,notifications:new wp.ccf.collections.FormNotifications,pause:!1,requireLoggedIn:!1,pauseMessage:l.pauseMessage,theme:"none"};return e=i.defaults(e,this.constructor.__super__.defaults),wp.ccf.utils.cleanDateFields(e),e},decode:function(){var e=i.keys(wp.api.models.Post.prototype.defaults);return e=i.without(e,"title"),n.call(this,e)},getFieldSlugs:function(e){var t=wp.ccf.currentForm.get("fields"),i=[];return t.each(function(t){e&&t.isImmutable||i.push(t.get("slug"))}),i},parse:function(e){var t=this,l=0,s=0;if(e.fields){var o=t.get("fields");if(o&&o.length>0){for(l=0;e.fields.length>l;l++){var n=e.fields[l],c=o.findWhere({slug:n.slug});if(c){if(n.choices!==void 0){var r=t.get("choices");if(r&&r.length>0)for(s=0;n.choices>s;s++){var a=r.at(s);a.set(n.choices[s]),a.decode()}delete e.fields[l].choices}if(n.conditionals!==void 0){var d=t.get("conditionals");if(d&&d.length>0)for(s=0;n.conditionals>s;s++){var u=d.at(s);u.set(n.conditionals[s]),u.decode()}delete e.fields[l].conditionals}c.set(n),c.decode()}}delete e.fields}else{var f=[];i.each(e.fields,function(e){var t=new wp.ccf.models.Fields[e.type](e);t.decode(),f.push(t)}),e.fields=new wp.ccf.collections.Fields(f,{formId:e.id}),o?(o.add(f),delete e.fields):e.fields=new wp.ccf.collections.Fields(f,{formId:e.id})}}if(e.notifications){var p=t.get("notifications");if(p&&p.length>0){for(l=0;e.notifications.length>l;l++){var h=e.notifications[l],m=p.at(l);if(m){if(h.addresses!==void 0){var w=m.get("addresses");if(w&&w.length>0)for(s=0;h.addresses>s;s++){var v=w.at(s);v.set(h.addresses[s]),v.decode()}delete e.notifications[l].addresses}m.set(h),m.decode()}}delete e.notifications}else{var g=[];i.each(e.notifications,function(e){var t=new wp.ccf.models.FormNotification(e);t.decode(),g.push(t)}),p?(p.add(g),delete e.notifications):e.notifications=new wp.ccf.collections.FormNotifications(g)}}if(e.postFieldMappings){var y=t.get("postFieldMappings");if(y&&y.length>0){for(l=0;e.postFieldMappings.length>l;l++){var F=e.postFieldMappings[l],b=y.at(l);b&&(b.set(F),b.decode())}delete e.postFieldMappings}else{var S=[];i.each(e.postFieldMappings,function(e){var t=new wp.ccf.models.PostFieldMapping(e);t.decode(),S.push(t)}),y?(y.add(S),e.postFieldMappings=y):e.postFieldMappings=new wp.ccf.collections.PostFieldMappings(S)}}return this.constructor.__super__.parse.call(this,e)},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.fields&&(e.fields=e.fields.toJSON()),e.notifications&&(e.notifications=e.notifications.toJSON()),e.postFieldMappings&&(e.postFieldMappings=e.postFieldMappings.toJSON()),e.author&&(e.author=e.author.toJSON()),e}}),wp.ccf.models.Submission=wp.api.models.Submission||wp.api.models.Post.extend({defaults:{id:null,data:{},fields:{}},sync:o,urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/submissions"}),wp.ccf.models.Field=wp.api.models.Field||wp.api.models.Post.extend({idAttribute:"id",defaults:function(){return{id:null,conditionalsEnabled:!1,conditionalType:"show",conditionalFieldsRequired:"all",conditionals:new wp.ccf.collections.FieldConditionals}},set:s,initialize:function(e){if("object"==typeof e&&e.conditionals){var t=[];i.each(e.conditionals,function(e){var i=new wp.ccf.models.FieldConditional(e);i.decode(),t.push(i)}),this.set("conditionals",new wp.ccf.collections.FieldConditionals(t))}},required:function(){return["slug"]},decode:function(){return n.call(this,i.keys(wp.api.models.Post.prototype.defaults))},hasRequiredAttributes:function(){var e=this,t=!0;return i.each(this.required(),function(i){(e.get(i)===void 0||""===e.get(i))&&(t=!1)}),t},sync:o}),wp.ccf.models.StandardField=wp.ccf.models.StandardField||wp.ccf.models.Field.extend({idAttribute:"id",defaults:function(){var e={label:l.fieldLabel,value:"",placeholder:"",slug:"",type:"",required:!1,className:"",description:""};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return wp.ccf.models.StandardField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["single-line-text"]=wp.ccf.models.Fields["single-line-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"single-line-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.file=wp.ccf.models.Fields.file||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"file",fileExtensions:"",maxFileSize:l.maxFileSize};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["paragraph-text"]=wp.ccf.models.Fields["paragraph-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"paragraph-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.hidden=wp.ccf.models.Fields.hidden||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"hidden"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.email=wp.ccf.models.Fields.email||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"email",emailConfirmation:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.website=wp.ccf.models.Fields.website||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"website",placeholder:"http://"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.phone=wp.ccf.models.Fields.phone||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"phone",phoneFormat:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.date=wp.ccf.models.Fields.date||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"date",showDate:!0,showTime:!0,dateFormat:"mm/dd/yyyy"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.name=wp.ccf.models.Fields.name||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"name"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.recaptcha=wp.ccf.models.Fields.recaptcha||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"recaptcha",siteKey:"",secretKey:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return["siteKey","secretKey"]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["simple-captcha"]=wp.ccf.models.Fields["simple-captcha"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"simple-captcha",placeholder:l.defaultSimpleCaptchaPlaceholder};return i.defaults(e,this.constructor.__super__.defaults())},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.address=wp.ccf.models.Fields.address||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"address",addressType:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["section-header"]=wp.ccf.models.Fields["section-header"]||wp.ccf.models.Field.extend({defaults:function(){var e={type:"section-header",slug:"",heading:"",subheading:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.html=wp.ccf.models.Fields.html||wp.ccf.models.Field.extend({defaults:function(){var e={type:"html",slug:"",html:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.ChoiceableField=wp.ccf.models.ChoiceableField||wp.ccf.models.StandardField.extend({defaults:function(){var e={choices:new wp.ccf.collections.FieldChoices,useValues:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(e){if("object"==typeof e&&e.choices){var t=[];i.each(e.choices,function(e){var i=new wp.ccf.models.FieldChoice(e);i.decode(),t.push(i)}),this.set("choices",new wp.ccf.collections.FieldChoices(t))}return wp.ccf.models.ChoiceableField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.radio=wp.ccf.models.Fields.radio||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"radio"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.checkboxes=wp.ccf.models.Fields.checkboxes||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"checkboxes"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.dropdown=wp.ccf.models.Fields.dropdown||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"dropdown"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";var s=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)};wp.ccf.collections=wp.ccf.collections||{},wp.ccf.collections.Forms=wp.ccf.collections.Forms||wp.api.collections.Posts.extend({model:wp.ccf.models.Form,url:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",formsFetching:{},initialize:function(){this.constructor.__super__.initialize(),this.formsFetching={}},sync:s,remove:function(e,t){t=t||{};var l=this.constructor.__super__.remove.call(this,e,t);return t.destroy&&(e instanceof Array?i.each(e,function(e){e.destroy()}):e.destroy()),l}}),wp.ccf.collections.Fields=wp.ccf.collections.Fields||wp.api.collections.Posts.extend({model:wp.ccf.models.Field,url:function(){return l.apiRoot+"/ccf/forms/"+this.formId+"/fields"},initialize:function(e,t){t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.PostFieldMappings=wp.ccf.collections.PostFieldMappings||t.Collection.extend({model:wp.ccf.models.PostFieldMapping}),wp.ccf.collections.FormNotificationAddresses=wp.ccf.collections.FormNotificationAddresses||t.Collection.extend({model:wp.ccf.models.FormNotificationAddress}),wp.ccf.collections.FormNotifications=wp.ccf.collections.FormNotifications||t.Collection.extend({model:wp.ccf.models.FormNotification}),wp.ccf.collections.Submissions=wp.ccf.collections.Submissions||wp.api.collections.Posts.extend({model:wp.ccf.models.Submission,url:function(){return l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms/"+this.formId+"/submissions"},initialize:function(e,t){this.constructor.__super__.initialize.apply(this,arguments),t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.FieldChoices=wp.ccf.collections.FieldChoices||t.Collection.extend({model:wp.ccf.models.FieldChoice}),wp.ccf.collections.FieldConditionals=wp.ccf.collections.FieldConditionals||t.Collection.extend({model:wp.ccf.models.FieldConditional})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.views=wp.ccf.views||{},wp.ccf.views.Fields=wp.ccf.views.Fields||{},wp.ccf.views.FieldChoice=t.View.extend({template:wp.ccf.utils.template("ccf-field-choice-template"),className:"choice",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveChoice:"saveChoice",sorted:"triggerUpdateSort"},initialize:function(e){this.field=e.field},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveChoice),this.unbind()},triggerUpdateSort:function(e,t){this.field.get("choices").remove(this.model,{silent:!0}),this.field.get("choices").add(this.model,{at:t,silent:!0})},saveChoice:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".choice-label")[0].value,t=this.el.querySelectorAll(".choice-value"),i="";t.length&&(i=t[0].value),this.model.set("label",e),this.model.set("value",i),this.field.get("useValues")||this.model.set("value",this.model.get("label"));var l=this.el.querySelectorAll(".choice-selected")[0],s=l.checked?!0:!1;return this.model.set("selected",s),this}},render:function(){var e={showValue:this.field.get("useValues")};return this.model&&(e.choice=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveChoice,this),this},triggerAdd:function(){this.field.get("choices").add(new wp.ccf.models.FieldChoice)},triggerDelete:function(){var e=this.field.get("choices");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{for(var t=this.el.querySelectorAll(".choice-label, .choice-value"),i=this.el.querySelectorAll(".choice-selected"),l=0;t.length>l;l++)t[l].value="";i[0].checked=!1}}}),wp.ccf.views.FieldConditional=t.View.extend({template:wp.ccf.utils.template("ccf-field-conditional-template"),className:"conditional",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveConditional:"saveConditional"},initialize:function(e){this.field=e.field,this.fieldCollection=e.fieldCollection},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveConditional),this.unbind()},saveConditional:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".conditional-field")[0].value,t=this.el.querySelectorAll(".conditional-value")[0].value,i=this.el.querySelectorAll(".conditional-compare")[0].value;return this.model.set("field",e),this.model.set("value",t),this.model.set("compare",i),this}},updateFields:function(){var e=this.el.querySelectorAll(".conditional-field")[0];e.innerHTML="",e.disabled=!1;var t,i=0,s=this.model.get("field");this.fieldCollection.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),this.fieldCollection.each(function(l){if(this.field.get("slug")!==l.get("slug")){var o=l.get("type");"address"!==o&&"checkboxes"!==o&&"date"!==o&&"name"!==o&&"file"!==o&&"recaptcha"!==o&&"simple-captcha"!==o&&"section-header"!==o&&"html"!==o&&(t=document.createElement("option"),t.innerHTML=l.get("slug"),t.value=l.get("slug"),l.get("slug")===s&&(t.selected=!0),e.appendChild(t),i++)}},this)),0===i&&(e.innerHTML="",t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},render:function(){var e={};return this.model&&(e.conditional=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveConditional,this),this.listenTo(this.fieldCollection,"add",this.updateFields,this),this.listenTo(this.fieldCollection,"remove",this.updateFields,this),this.updateFields(),this},triggerAdd:function(){this.field.get("conditionals").add(new wp.ccf.models.FieldConditional)},triggerDelete:function(){var e=this.field.get("conditionals");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{var t=this.el.querySelectorAll(".conditional-value")[0],i=this.el.querySelectorAll(".conditional-field")[0];t.value="";for(var l=0;i.childNodes.length>l;l++)i.childNodes[l].selected=!1}}}),wp.ccf.views.EmptyFormNotificationTableRow=wp.ccf.views.EmptyFormNotificationTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-notification-row-template"),events:{"click .add":"triggerAdd"},initialize:function(e){this.form=e.form},destroy:function(){this.unbind()},render:function(){return this.$el.html(this.template()),this},triggerAdd:function(){var e=this.form.get("notifications");this.destroy(),e.add(new wp.ccf.models.FormNotification)}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.FormNotificationAddress=t.View.extend({template:wp.ccf.utils.template("ccf-form-notification-address-template"),className:"address",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.notification=e.notification,this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-notification-address-type")[0].value,t=this.el.querySelectorAll(".form-notification-address-email"),i=this.el.querySelectorAll(".form-notification-address-field"),l=this.model.get("type");return t.length&&this.model.set("email",t[0].value),i.length&&this.model.set("field",i[0].value),this.model.set("type",e),l!==e&&this.render(),this}},updateFromFieldField:function(){if("edit"===this.parent.context&&"field"===this.model.get("type")){var e=this.el.querySelectorAll(".form-notification-address-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("field");i.length>=1&&i.each(function(i){("email"===i.get("type")||"dropdown"===i.get("type")||"radio"===i.get("type")||"single-line-text"===i.get("type"))&&(t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++)}),0===s&&(t=document.createElement("option"),t.innerHTML=l.noApplicableFields,t.value="",e.appendChild(t),e.disabled=!0)}},render:function(){var e={};this.model&&(e.address=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFromFieldField,this),this.listenTo(t,"remove",this.updateFromFieldField,this),"field"===this.model.get("type")&&this.updateFromFieldField(),this},triggerAdd:function(){this.notification.get("addresses").add(new wp.ccf.models.FormNotificationAddress)},triggerDelete:function(){var e=this.notification.get("addresses");e.length>1?this.parent.deleteAddress(this):(this.model.clear().set(wp.ccf.models.FormNotificationAddress.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.ExistingFormNotificationRow=t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-notification-table-row-template"),tagName:"tr",events:{"change select.form-email-notification-from-type":"toggleNotificationFields","change select.form-email-notification-from-name-type":"toggleNotificationFields","change select.form-email-notification-reply-to-type":"toggleNotificationFields","change select.form-email-notification-reply-to-name-type":"toggleNotificationFields","change select.form-email-notification-subject-type":"toggleNotificationFields","click .close-notification":"changeContext","click .edit-notification":"changeContext","click .delete-notification":"triggerDelete","blur input":"save","change select":"save"},addressViews:[],initialize:function(e){this.form=e.form,this.addressViews=[],this.parent=e.parent,this.context=e.context!==void 0?e.context:"view";var t=this.model.get("addresses");this.listenTo(t,"add",this.addAddress)},deleteAddress:function(e){i.each(this.addressViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.addressViews,t);this.model.get("addresses").remove(e.model),this.addressViews[l].remove(),this.addressViews.splice(l,1)}},this)},addAddress:function(e){var t=this.el.querySelectorAll(".addresses")[0],i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form});this.addressViews.push(i),t.appendChild(i.render().el)},destroy:function(){this.unbind()},changeContext:function(e,t){"edit"===this.context&&this.save(),t?this.context=t:("view"===this.context&&this.parent.closeAllNotifications(),this.context="edit"===this.context?"view":"edit"),this.destroy(),this.render()},updateFieldVariables:function(){if("edit"===this.context){var e,t=this.el.querySelectorAll(".field-variables")[0],i="",l=this.form.get("fields");l.each(function(t){e=t.get("type"),"html"!==e&&"section-header"!==e&&"recaptcha"!==e&&"simple-captcha"!==e&&(i+="["+t.get("slug")+"] ")}),t.innerText=i}},updateFromFieldField:function(){if("edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-from-field")[0];e.innerHTML="",e.disabled=!1;var t=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0];t.innerHTML="",t.disabled=!1;var i=this.el.querySelectorAll(".form-email-notification-subject-field")[0];i.innerHTML="",i.disabled=!1;var s=this.el.querySelectorAll(".form-email-notification-from-name-field")[0];s.innerHTML="",s.disabled=!1;var o=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0];o.innerHTML="",o.disabled=!1;var n,c,r=this.form.get("fields"),a=0,d=0,u=0,f=this.model.get("fromField"),p=this.model.get("replyToField"),h=this.model.get("subjectField"),m=this.model.get("fromNameField"),w=this.model.get("replyToNameField");r.length>=1&&r.each(function(l){("email"===l.get("type")||"dropdown"===l.get("type")||"radio"===l.get("type")||"single-line-text"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===f&&(n.selected=!0),e.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===p&&(c.selected=!0),t.appendChild(c),a++),("name"===l.get("type")||"single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===m&&(n.selected=!0),s.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===w&&(c.selected=!0),o.appendChild(c),d++),("single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===h&&(n.selected=!0),i.appendChild(n),u++)}),0===a&&(n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",e.appendChild(n),e.disabled=!0,n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",t.appendChild(n),t.disabled=!0),0===d&&(n=document.createElement("option"),n.innerHTML=l.noNameFields,n.value="",s.appendChild(n),s.disabled=!0),0===u&&(n=document.createElement("option"),n.innerHTML=l.noApplicableFields,n.value="",i.appendChild(n),i.disabled=!0)}},toggleNotificationFields:function(){var e=this.el.querySelectorAll(".email-notification-from-address")[0],t=this.el.querySelectorAll(".email-notification-from-field")[0],i=this.el.querySelectorAll(".form-email-notification-from-type")[0],l=this.el.querySelectorAll(".email-notification-subject")[0],s=this.el.querySelectorAll(".email-notification-subject-field")[0],o=this.el.querySelectorAll(".form-email-notification-subject-type")[0],n=this.el.querySelectorAll(".email-notification-from-name")[0],c=this.el.querySelectorAll(".email-notification-from-name-field")[0],r=this.el.querySelectorAll(".form-email-notification-from-name-type")[0],a=this.el.querySelectorAll(".email-notification-reply-to-address")[0],d=this.el.querySelectorAll(".email-notification-reply-to-field")[0],u=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0],f=this.el.querySelectorAll(".email-notification-reply-to-name")[0],p=this.el.querySelectorAll(".email-notification-reply-to-name-field")[0],h=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0];e.style.display="none",t.style.display="none","custom"===i.value?e.style.display="block":"field"===i.value&&(t.style.display="block"),l.style.display="none",s.style.display="none","custom"===o.value?l.style.display="block":"field"===o.value&&(s.style.display="block"),n.style.display="none",c.style.display="none","custom"===r.value?n.style.display="block":"field"===r.value&&(c.style.display="block"),a.style.display="none",d.style.display="none","custom"===u.value?a.style.display="block":"field"===u.value&&(d.style.display="block"),f.style.display="none",p.style.display="none","custom"===h.value?f.style.display="block":"field"===h.value&&(p.style.display="block")},save:function(){if(""!==this.el.innerHTML&&"edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-title")[0].value;this.model.set("title",e);var t=this.el.querySelectorAll(".form-email-notification-content")[0].value;this.model.set("content",t);var i=this.el.querySelectorAll(".form-email-notification-active")[0].value;this.model.set("active","1"===i?!0:!1);var l=this.el.querySelectorAll(".form-email-notification-include-uploads")[0].value;this.model.set("includeUploads","1"===l?!0:!1);var s=this.el.querySelectorAll(".form-email-notification-from-type")[0].value;this.model.set("fromType",s);var o=this.el.querySelectorAll(".form-email-notification-from-address")[0].value;this.model.set("fromAddress",o);var n=this.el.querySelectorAll(".form-email-notification-from-field")[0].value;this.model.set("fromField",n);var c=this.el.querySelectorAll(".form-email-notification-from-name-type")[0].value;this.model.set("fromNameType",c);
2
- var r=this.el.querySelectorAll(".form-email-notification-from-name")[0].value;this.model.set("fromName",r);var a=this.el.querySelectorAll(".form-email-notification-from-name-field")[0].value;this.model.set("fromNameField",a);var d=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0].value;this.model.set("replyToType",d);var u=this.el.querySelectorAll(".form-email-notification-reply-to-address")[0].value;this.model.set("replyToAddress",u);var f=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0].value;this.model.set("replyToField",f);var p=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0].value;this.model.set("replyToNameType",p);var h=this.el.querySelectorAll(".form-email-notification-reply-to-name")[0].value;this.model.set("replyToName",h);var m=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0].value;this.model.set("replyToNameField",m);var w=this.el.querySelectorAll(".form-email-notification-subject-type")[0].value;this.model.set("subjectType",w);var v=this.el.querySelectorAll(".form-email-notification-subject")[0].value;this.model.set("subject",v);var g=this.el.querySelectorAll(".form-email-notification-subject-field")[0].value;this.model.set("subjectField",g);for(var y=0;this.addressViews.length>y;y++)this.addressViews[y].save();return this}},render:function(){var e={context:this.context,form:this.form.toJSON()};if(this.model&&(e.notification=this.model.toJSON()),this.el.innerHTML=this.template(e),"edit"===this.context){this.toggleNotificationFields(),this.updateFromFieldField(),this.updateFieldVariables();var t=this.el.querySelectorAll(".addresses")[0],i=this.model.get("addresses");if(i.length>=1)i.each(function(e){var i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form}).render();t.appendChild(i.el),this.addressViews.push(i)},this);else{var l=new wp.ccf.models.FormNotificationAddress;i.add(l)}}var s=this.form.get("fields");return this.listenTo(s,"add",this.updateFromFieldField,this),this.listenTo(s,"remove",this.updateFromFieldField,this),this.listenTo(s,"add",this.updateFieldVariables,this),this.listenTo(s,"remove",this.updateFieldVariables,this),this},triggerDelete:function(){this.parent.deleteNotification(this)}}),wp.ccf.views.FieldBase=wp.ccf.views.FieldBase||t.View.extend({events:{"blur input":"saveField","blur input.field-slug":"checkSlug","blur textarea":"saveField","change select":"saveField",'change input[type="checkbox"]':"saveField"},initialize:function(){var e=this.model.get("conditionals");this.listenTo(e,"add",this.addConditional)},addConditional:function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render(),i=this.el.querySelectorAll(".conditionals")[0];i.appendChild(t.el)},checkSlug:function(){var e=this.el.querySelectorAll(".field-slug");if(e.length>0){var t=e[0],i=!1;t.parentNode.className=t.value&&!t.value.match(/^[a-zA-Z0-9\-_]+$/)?t.parentNode.className.replace(/ field-error/i,"")+" field-error":t.parentNode.className.replace(/ field-error/i,""),this.collection.length>0&&""!==t.value?(this.collection.each(function(e){e!==this.model&&t.value===e.get("slug")&&(i=!0)},this),t.parentNode.className=i?t.parentNode.className.replace(/ field-duplicate-slug/i,"")+" field-duplicate-slug":t.parentNode.className.replace(/ field-duplicate-slug/i,"")):t.parentNode.className=t.parentNode.className.replace(/ field-duplicate-slug/i,"")}},destroy:function(){this.unbind()},saveField:function(){var t=this.el.querySelectorAll(".conditionals");if(t.length){var l=t[0].querySelectorAll(".conditional");i.each(l,function(t){e(t).trigger("saveConditional")}),this.model.set("conditionalType",this.el.querySelectorAll(".field-conditional-type")[0].value),this.model.set("conditionalFieldsRequired",this.el.querySelectorAll(".field-conditional-fields-required")[0].value);var s=this.model.get("conditionalsEnabled");this.model.set("conditionalsEnabled",1==this.el.querySelectorAll(".field-conditionals-enabled")[0].value?!0:!1),s!==this.model.get("conditionalsEnabled")&&this.render("advanced")}},render:function(e){e=e?e:"basic",this.el.innerHTML=this.template({field:this.model.toJSON(),startPanel:e}),this.checkSlug();var t=this.model.get("conditionals"),i=this.el.querySelectorAll(".conditionals");if(i.length)if(t.length>=1)t.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();i[0].appendChild(t.el)},this);else{var l=new wp.ccf.models.FieldConditional;t.add(l)}return this}}),wp.ccf.views.Fields["single-line-text"]=wp.ccf.views.Fields["single-line-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-single-line-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.file=wp.ccf.views.Fields.file||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-file-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.model.set("fileExtensions",this.el.querySelectorAll(".field-file-extensions")[0].value),this.model.set("maxFileSize",this.el.querySelectorAll(".field-max-file-size")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.recaptcha=wp.ccf.views.Fields.recaptcha||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-recaptcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("siteKey",this.el.querySelectorAll(".field-site-key")[0].value),this.model.set("secretKey",this.el.querySelectorAll(".field-secret-key")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["simple-captcha"]=wp.ccf.views.Fields["simple-captcha"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-simple-captcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["section-header"]=wp.ccf.views.Fields["section-header"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-section-header-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("heading",this.el.querySelectorAll(".field-heading")[0].value),this.model.set("subheading",this.el.querySelectorAll(".field-subheading")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.html=wp.ccf.views.Fields.html||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-html-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("html",this.el.querySelectorAll(".field-html")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["paragraph-text"]=wp.ccf.views.Fields["paragraph-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-paragraph-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.hidden=wp.ccf.views.Fields.hidden||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-hidden-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.date=wp.ccf.views.Fields.date||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-date-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length>0&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-date-format");t.length&&this.model.set("dateFormat",t[0].value);var i=this.model.get("showDate"),l=this.el.querySelectorAll(".field-show-date")[0].checked?!0:!1;this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("showDate",l);var s=this.model.get("showTime"),o=this.el.querySelectorAll(".field-show-time")[0].checked?!0:!1;return this.model.set("showTime",o),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),(o!=s||l!=i)&&this.render(),this}}}),wp.ccf.views.Fields.name=wp.ccf.views.Fields.name||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-name-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.website=wp.ccf.views.Fields.website||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-website-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.phone=wp.ccf.views.Fields.phone||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-phone-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("phoneFormat",this.el.querySelectorAll(".field-phone-format")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.address=wp.ccf.views.Fields.address||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-address-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value);var e=this.model.get("addressType");this.model.set("addressType",this.el.querySelectorAll(".field-address-type")[0].value);var t=this.el.querySelectorAll(".field-default-country");return t.length&&this.model.set("defaultCountry",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),e!==this.model.get("addressType")&&this.render(),this.constructor.__super__.saveField.apply(this,arguments),this}}}),wp.ccf.views.Fields.email=wp.ccf.views.Fields.email||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-email-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-placeholder");t.length&&this.model.set("placeholder",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1);var i=1==this.el.querySelectorAll(".field-email-confirmation")[0].value?!0:!1,l=this.model.get("emailConfirmation");return this.model.set("emailConfirmation",i),l!=i&&this.render(),this}}}),wp.ccf.views.ChoiceableField=wp.ccf.views.ChoiceableField||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),initialize:function(){var e=this.model.get("choices");this.listenTo(e,"add",this.addChoice)},addChoice:function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:this.model}).render(),i=this.el.querySelectorAll(".repeatable-choices")[0];i.appendChild(t.el)},saveField:function(t){if(""!==this.el.innerHTML&&(!t||"field-use-values"!==t.target.className||"focusout"!==t.type)){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),wp.ccf.views.ChoiceableField.__super__.saveField.apply(this,arguments);var l=this.el.querySelectorAll(".repeatable-choices")[0].querySelectorAll(".choice");i.each(l,function(t){e(t).trigger("saveChoice")});var s=this.model.get("useValues"),o=this.el.querySelectorAll(".field-use-values")[0].checked?!0:!1;return this.model.set("useValues",o),s!==o&&this.render(),this}},render:function(t){var i=this;t=t?t:"basic",this.model.get("useValues"),i.el.innerHTML=i.template({field:i.model.toJSON(),startPanel:t}),i.checkSlug();var l=i.model.get("choices"),s=this.el.querySelectorAll(".repeatable-choices")[0];if(l.length>=1)l.each(function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:i.model}).render();s.appendChild(t.el)});else{var o=new wp.ccf.models.FieldChoice;l.add(o)}s=this.el.querySelectorAll(".repeatable-choices")[0],e(s).sortable({handle:".move",axis:"y",stop:function(e,t){t.item.trigger("sorted",t.item.index())}});var n=this.model.get("conditionals"),c=this.el.querySelectorAll(".conditionals")[0];if(n.length>=1)n.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();c.appendChild(t.el)},this);else{var r=new wp.ccf.models.FieldConditional;n.add(r)}return i}}),wp.ccf.views.Fields.dropdown=wp.ccf.views.Fields.dropdown||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.radio=wp.ccf.views.Fields.radio||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-radio-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.checkboxes=wp.ccf.views.Fields.checkboxes||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-checkboxes-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.FieldSidebar=wp.ccf.views.FieldSidebar||t.View.extend({initialize:function(e){this.currentFieldView=null,this.form=e.form},save:function(e){this.currentFieldView&&""!==this.currentFieldView.el.innerHTML&&this.currentFieldView.saveField(),e&&e instanceof Object&&e.resolve()},fieldRemoved:function(){this.currentFieldView&&(this.form.get("fields").get(this.currentFieldView.model)||this.render())},destroy:function(){wp.ccf.dispatcher.off("saveField",this.save),wp.ccf.dispatcher.off("mainViewChange",this.save),this.unbind()},render:function(e){var t={};if(e){var i=e.get("type");this.currentFieldView&&(this.currentFieldView.saveField(),this.currentFieldView.destroy&&this.currentFieldView.destroy()),this.currentFieldView=new wp.ccf.views.Fields[i]({model:e,collection:this.form.get("fields")}),this.currentFieldView.render(),this.el.innerHTML="",this.el.appendChild(this.currentFieldView.el);var l=this.form.get("fields");this.listenTo(l,"remove",this.fieldRemoved)}else{var s=wp.ccf.utils.template("ccf-empty-field-template");this.el.innerHTML=s(t)}return wp.ccf.dispatcher.on("saveField",this.save,this),wp.ccf.dispatcher.on("mainViewChange",this.save,this),this}}),wp.ccf.views.FieldRowPlaceholder=wp.ccf.views.FieldRowPlaceholder||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",initialize:function(e){this.type=e.type},render:function(){return this.el.innerHTML=this.template({label:l.allLabels[this.type]}),this.el.setAttribute("data-field-type",this.type),this.el.className+=" "+this.type,this}}),wp.ccf.views.FieldRow=wp.ccf.views.FieldRow||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",events:{"click .delete":"triggerDelete","click h4":"triggerEdit",sorted:"triggerUpdateSort"},initialize:function(e){i.bindAll(this,"triggerDelete"),this.form=e.form,this.listenTo(this.model,"change",this.handleChange,this),this.listenTo(this.model,"requirementsNotMet",this.requirementsNotMet,this),this.listenTo(this.model,"requirementsMet",this.requirementsMet,this),this.listenTo(this.model,"duplicateSlug",this.duplicateSlug,this),this.model.attributes.choices&&this.listenTo(this.model.attributes.choices,"change",this.handleChange,this)},duplicateSlug:function(){this.requirementsMet(),this.el.className+=" field-duplicate-slug"},requirementsNotMet:function(){this.requirementsMet(),this.el.className+=" field-incomplete"},requirementsMet:function(){this.el.className=this.el.className.replace(/(field-incomplete|field-duplicate-slug)/i,"")},triggerUpdateSort:function(e,t){this.form.get("fields").remove(this.model),this.form.get("fields").add(this.model,{at:t})},handleChange:function(){this.render()},triggerDelete:function(e){e.stopPropagation(),this.form.get("fields").remove(this.model),this.undelegateEvents(),this.remove()},triggerEdit:function(){var e=this.el.parentNode.querySelectorAll(".ccf-editing");i.each(e,function(e){e.className=e.className.replace(/ccf-editing/i,"")}),this.el.className=this.el.className.replace(/ccf-editing/i,"")+" ccf-editing",wp.ccf.dispatcher.trigger("openEditField",this.model)},render:function(e){this.el.innerHTML=this.template({label:l.allLabels[this.model.get("type")]}),this.el.setAttribute("data-field-type",this.model.get("type"));var t=RegExp(" "+this.model.get("type"),"i");this.el.className=this.el.className.replace(t,"")+" "+this.model.get("type"),e&&(this.el.className=this.el.className.replace(/ instantiated/i,"")+" instantiated");var i=document.getElementById("ccf-"+this.model.get("type")+"-preview-template");if(i){var s=this.el.querySelectorAll(".preview")[0];s.style.display="block",s.innerHTML=wp.ccf.utils.template("ccf-"+this.model.get("type")+"-preview-template")({field:this.model.toJSON()})}return this}}),wp.ccf.views.PostFieldMapping=t.View.extend({template:wp.ccf.utils.template("ccf-post-field-mapping"),className:"field-mapping",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".field-form-field")[0].value,t=this.el.querySelectorAll(".field-post-field")[0].value,i=this.el.querySelectorAll(".field-custom-field-key"),l=this.model.get("postField");return this.model.set("formField",e),this.model.set("postField",t),i.length&&this.model.set("customFieldKey",i[0].value),l!==t&&this.render(),this}},updateFormFieldField:function(){var e=this.el.querySelectorAll(".field-form-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("formField");i.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),i.each(function(i){t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++})),0===s&&(t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},updatePostFields:function(){var e,t=this.el.querySelectorAll(".field-post-field")[0];e=document.createElement("option"),e.value="",e.innerText=l.choosePostField,t.appendChild(e);var s=this.form.get("postFieldMappings"),o=[];s.each(function(e){e!==this.model&&o.push(e.get("postField"))},this),i.each(l.postFields.single,function(i,l){-1===o.indexOf(l)&&(e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e))},this),i.each(l.postFields.repeatable,function(i,l){e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e)},this)},render:function(){var e={};this.model&&(e.mapping=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFormFieldField,this),this.listenTo(t,"remove",this.updateFormFieldField,this),this.updateFormFieldField(),this.updatePostFields(),this},triggerAdd:function(){this.form.get("postFieldMappings").add(new wp.ccf.models.PostFieldMapping)},triggerDelete:function(){var e=this.form.get("postFieldMappings");e.length>1?this.parent.deletePostFieldMapping(this):(this.model.clear().set(wp.ccf.models.PostFieldMapping.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.FormSettings=wp.ccf.views.FormSettings||t.View.extend({template:wp.ccf.utils.template("ccf-form-settings-template"),events:{"blur input":"save","change select":"save","change select.form-completion-action-type":"toggleCompletionFields","change select.form-pause":"togglePauseFields","change select.form-post-creation":"togglePostCreationFields","click .add-notification":"triggerAddNotification"},notificationViews:[],mappingViews:[],initialize:function(e){this.model=e.form,this.notificationViews=[],this.mappingViews=[];var t=this.model.get("notifications");this.listenTo(t,"add",this.addNotification);var i=this.model.get("postFieldMappings");this.listenTo(i,"add",this.addPostFieldMapping)},deletePostFieldMapping:function(e){i.each(this.mappingViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.mappingViews,t);this.model.get("postFieldMappings").remove(e.model),this.mappingViews[l].remove(),this.mappingViews.splice(l,1)}},this)},addPostFieldMapping:function(e){var t=this.el.querySelectorAll(".post-creation-mapping")[0],i=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model});this.mappingViews.push(i),t.appendChild(i.render().el)},triggerAddNotification:function(){var e=this.model.get("notifications");e.add(new wp.ccf.models.FormNotification)},closeAllNotifications:function(){i.each(this.notificationViews,function(e){e.changeContext(null,"view")})},addNotification:function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,context:"edit",parent:this}).render(),l=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];l.querySelectorAll(".no-notifications").length>0&&l.removeChild(l.firstChild),i.each(this.notificationViews,function(e){e.changeContext(null,"view")}),this.notificationViews.push(t),l.appendChild(t.el)},toggleCompletionFields:function(){var e=this.el.querySelectorAll(".form-completion-action-type")[0].value,t=this.el.querySelectorAll(".completion-message")[0],i=this.el.querySelectorAll(".completion-redirect-url")[0];"text"===e?(t.style.display="block",i.style.display="none"):(t.style.display="none",i.style.display="block")},togglePauseFields:function(){var e=this.el.querySelectorAll(".form-pause")[0].value,t=this.el.querySelectorAll(".pause-message")[0];t.style.display=parseInt(e)?"block":"none"},togglePostCreationFields:function(){var t=this.el.querySelectorAll(".form-post-creation")[0].value,i=e(this.el.querySelectorAll(".post-creation-mapping-field"));parseInt(t)?i.show():i.hide()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-title")[0].value;this.model.set("title",{raw:e});var t=this.el.querySelectorAll(".hide-title")[0].value;this.model.set("hideTitle",parseInt(t)?!0:!1);var i=this.el.querySelectorAll(".form-description")[0].value;this.model.set("description",i);var l=this.el.querySelectorAll(".form-button-text")[0].value;this.model.set("buttonText",l);var s=this.el.querySelectorAll(".form-button-class")[0].value;this.model.set("buttonClass",s);var o=this.el.querySelectorAll(".form-pause")[0].value;this.model.set("pause",parseInt(o)?!0:!1);var n=this.el.querySelectorAll(".form-require-logged-in")[0].value;this.model.set("requireLoggedIn",parseInt(n)?!0:!1);var c=this.el.querySelectorAll(".form-post-creation")[0].value;this.model.set("postCreation",parseInt(c)?!0:!1);var r=this.el.querySelectorAll(".form-post-creation-type")[0].value;this.model.set("postCreationType",r);var a=this.el.querySelectorAll(".form-post-creation-status")[0].value;this.model.set("postCreationStatus",a);var d=this.el.querySelectorAll(".form-pause-message")[0].value;this.model.set("pauseMessage",d);var u=this.el.querySelectorAll(".form-completion-message")[0].value;this.model.set("completionMessage",u);var f=this.el.querySelectorAll(".form-completion-redirect-url")[0].value;this.model.set("completionRedirectUrl",f);var p=this.el.querySelectorAll(".form-completion-action-type")[0].value;this.model.set("completionActionType",p);var h=this.el.querySelectorAll(".form-theme")[0].value;this.model.set("theme",h)}},fullSave:function(e){""!==this.el.innerHTML&&(this.save(),i.each(this.notificationViews,function(e){e.save()}),i.each(this.mappingViews,function(e){e.save()}),e!==void 0&&e.promise!==void 0&&e.resolve())},destroy:function(){wp.ccf.dispatcher.off("saveFormSettings",this.fullSave),wp.ccf.dispatcher.off("mainViewChange",this.fullSave)},deleteNotification:function(e){if(i.each(this.notificationViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.notificationViews,t);this.model.get("notifications").remove(e.model),this.notificationViews[l].remove(),this.notificationViews.splice(l,1)}},this),!this.notificationViews.length){var t=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];t.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el)}},render:function(){var e={form:this.model.toJSON()};this.model.get("fields");var t=this.model.get("notifications");this.el.innerHTML=this.template(e),this.toggleCompletionFields(),this.togglePostCreationFields(),this.togglePauseFields();var i=this.el.querySelectorAll(".ccf-form-notifications .rows")[0],l=document.createElement("tbody");l.className="rows",t.length>=1?t.each(function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,parent:this}).render();l.appendChild(t.el),this.notificationViews.push(t)},this):l.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el),i.parentNode.replaceChild(l,i);var s=this.el.querySelectorAll(".post-creation-mapping")[0],o=this.model.get("postFieldMappings");if(o.length>=1)o.each(function(e){var t=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model}).render();s.appendChild(t.el),this.mappingViews.push(t)},this);else{var n=new wp.ccf.models.PostFieldMapping;o.add(n)}return wp.ccf.dispatcher.on("mainViewChange",this.fullSave,this),wp.ccf.dispatcher.on("saveFormSettings",this.fullSave,this),this}}),wp.ccf.views.FormPane=wp.ccf.views.FormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-form-pane-template"),subViews:{"field-sidebar":wp.ccf.views.FieldSidebar,"form-settings":wp.ccf.views.FormSettings},events:{"click .save-button":"sync","click .signup-button":"signup","click .accordion-heading":"accordionClick","click .form-settings-heading":"accordionClick","click .insert-form-button":"insertForm"},initialize:function(){wp.ccf.dispatcher.on("openEditField",this.openEditField,this)},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},signup:function(){var t=this.el.querySelectorAll(".email-signup-field")[0].value,i=this.el.querySelectorAll(".bottom .left.signup")[0];i.className="left signup",t?e.ajax({url:"//taylorlovett.us8.list-manage.com/subscribe/post-json?u=66118f9a5b0ab0414e83f043a&amp;id=b4ed816a24&c=?",method:"post",dataType:"jsonp",data:{EMAIL:t}}).done(function(){i.className="left signup signup-success"}):i.className="left signup signup-error"},accordionClick:function(t){var l=e(t.currentTarget).parents(".accordion-container")[0],s=l.querySelectorAll(".accordion-section");t.currentTarget.parentNode.className.match(/expanded/i)?t.currentTarget.parentNode.className=t.currentTarget.parentNode.className.replace(/expanded/i,""):t.currentTarget.parentNode.className+=" expanded",i.each(s,function(e){e!=t.currentTarget.parentNode&&e.className.match(/expanded/i)&&(e.className=e.className.replace(/expanded/i,""))
3
  }),t.currentTarget.className.match(/form-settings-heading/i)?this.el.className.match(/show-form-settings/i)?this.el.className=this.el.className.replace(/show-form-settings/i,""):this.el.className+=" show-form-settings":this.el.className=this.el.className.replace(/show-form-settings/i,"")},openEditField:function(e){this.renderedSubViews["field-sidebar"].render(e).el.style.display="block"},disable:function(){this.el.querySelectorAll(".save-button")[0].setAttribute("disabled","disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="block"},enable:function(){this.el.querySelectorAll(".save-button")[0].removeAttribute("disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="none"},sync:function(){var t=this,i=e(this.el.querySelectorAll(".spinner")[0]);i.fadeIn(),t.disable();var s=e.Deferred(),o=e.Deferred();wp.ccf.dispatcher.trigger("saveFormSettings",s),wp.ccf.dispatcher.trigger("saveField",o),e.when(s,o).then(function(){var e=t.model.get("fields"),s=!0,o={};e.each(function(e){var t=e.get("slug");e.hasRequiredAttributes()?t&&!t.match(/^[a-zA-Z0-9\-_]+$/)?(s=!1,e.trigger("requirementsNotMet")):o[e.get("slug")]!==void 0?(s=!1,e.trigger("duplicateSlug"),o[e.get("slug")].trigger("duplicateSlug")):e.trigger("requirementsMet"):(s=!1,e.trigger("requirementsNotMet")),e.get("slug")&&(o[e.get("slug")]=e)}),s?t.model.save({},{context:"edit"}).error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}).done(function(){l.single&&!l.postId&&(window.location=l.adminUrl+"post.php?post="+t.model.get("id")+"&action=edit#ccf-form/"+t.model.get("id"))}).complete(function(){i.fadeOut(),t.enable(),wp.ccf.dispatcher.trigger("saveFormComplete",t.model)}):(t.enable(),i.fadeOut())})},enableDisableInsert:function(){var e=this.el.querySelectorAll(".insert-form-button")[0];this.model.get("id")?e.removeAttribute("disabled"):e.setAttribute("disabled","disabled")},getNextFieldOrd:function(){var e=this.model.get("fields"),t=e.length+1;return e.each(function(e){var i=e.get("slug"),l=/\-([0-9]+)$/g,s=l.exec(i);if(s&&s[1]){var o=parseInt(s[1]);o>=t&&(t=o+1)}}),t},render:function(t){var s=this;s.model=t?t:new wp.ccf.models.Form,this.listenTo(s.model,"change",this.enableDisableInsert,this);var o={labels:l.fieldLabels,form:s.model.toJSON()};window.form=s.model,s.el.innerHTML=this.template(o),s.el.className=s.el.className.replace(/show-form-settings/i,"");var n=s.el.querySelectorAll(".fields")[0];i.each(l.fieldLabels,function(e,t){n.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var c=s.el.querySelectorAll(".structure-fields")[0];i.each(l.structureFieldLabels,function(e,t){c.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var r=s.el.querySelectorAll(".special-fields")[0];i.each(l.specialFieldLabels,function(e,t){r.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var a=s.model.get("fields"),d=s.el.querySelectorAll(".form-content")[0],u=e(d);return e(s.el.querySelectorAll(".left-sidebar")[0].querySelectorAll(".field")).draggable({cursor:"move",distance:2,zIndex:160001,scroll:!1,containment:"document",appendTo:".ccf-main-modal",snap:!1,connectToSortable:".form-content",helper:function(t){var i=e(t.currentTarget),l=e('<div class="field" data-field-type="'+i.attr("data-field-type")+'"><h4>'+i.find(".label").html()+"</h4></div>");return l.css({width:u.width(),opacity:".75",height:i.height()})}}),a.length>=1&&(d.innerHTML="",a.each(function(e){var t=new wp.ccf.views.FieldRow({model:e,form:s.model}).render(!0).el;d.appendChild(t)})),e(d).sortable({axis:"y",distance:2,handle:"h4",placeholder:"field-placeholder",stop:function(e,t){if(!t.item.hasClass("instantiated")){var i=t.item.attr("data-field-type"),l={};wp.ccf.models.Fields[i].prototype.defaults().slug!==void 0&&(l.slug=i+"-"+s.getNextFieldOrd());var o=new wp.ccf.models.Fields[i](l),n=s.model.get("fields");n.add(o),new wp.ccf.views.FieldRow({model:o,el:t.item,form:s.model}).render(!0),t.item.attr("style","")}t.item.trigger("sorted",t.item.index())}}),s.initRenderSubViews(!1,!0,{form:s.model}),s.enableDisableInsert(),s}},wp.ccf.mixins.subViewable)),wp.ccf.views.ExistingFormTableRow=wp.ccf.views.ExistingFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-existing-form-table-row-template"),events:{"click .edit":"triggerMainViewChange","click .delete":"triggerDelete","click .duplicate":"triggerDuplicate","click .insert-form-button":"insertForm"},initialize:function(e){this.parent=e.parent},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},triggerMainViewChange:function(){wp.ccf.switchToForm(this.model)},triggerDelete:function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},triggerDuplicate:function(){var e=this,t=e.parent.collection.state.currentPage;e.model.clone().set("title",{raw:e.model.get("title").raw+" (Duplicate)"}).unset("id").save().done(function(){e.parent.showPage(t).done(function(){e.parent.renderPagination()})})},render:function(){return this.$el.html(this.template({form:this.model.toJSON(),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate}})),this}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.ExistingFormTable=wp.ccf.views.ExistingFormTable||t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-table-template"),initialize:function(){this.parent=arguments.parent,this.collection=new wp.ccf.collections.Forms,wp.ccf.dispatcher.on("changeFormTablePage",this.showPage,this),wp.ccf.dispatcher.on("saveFormComplete",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".rows")[0],i=document.createElement("tbody");i.className="rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.ExistingFormTableRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild((new wp.ccf.views.EmptyFormTableRow).render().el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(){var e=this;return this.el.innerHTML=this.template(),this.el.querySelectorAll(".ccf-pagination")[0],this.showPage(1).done(function(){e.renderPagination()}),this}}),wp.ccf.views.ExistingFormPane=wp.ccf.views.ExistingFormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-existing-form-pane-template"),subViews:{"existing-form-table":wp.ccf.views.ExistingFormTable},render:function(){return this.rendered?this:(this.rendered=!0,this.el.innerHTML=this.template(),this.initRenderSubViews(!0),this)}},wp.ccf.mixins.subViewable)),wp.ccf.views.MainModal=wp.ccf.views.MainModal||t.View.extend(i.defaults({tagName:"div",className:"ccf-main-modal",template:wp.ccf.utils.template("ccf-main-modal-template"),events:{"click .close-icon":"hide","click .main-menu a":"menuClick"},subViews:{"form-pane":wp.ccf.views.FormPane},initialize:function(){l.single||(this.subViews["existing-form-pane"]=wp.ccf.views.ExistingFormPane),wp.ccf.dispatcher.on("mainViewChange",this.toggleView,this)},toggleView:function(e){this.showView(e,wp.ccf.currentForm);var t=e;"form-pane"===e&&wp.ccf.currentForm&&(t="existing-form-pane");var l=this.el.querySelectorAll(".menu-item");i.each(l,function(e){var i=e.getAttribute("data-view");e.className=i===t?e.className.replace("selected","")+" selected":e.className.replace("selected","")})},menuClick:function(e){var t=e.currentTarget.getAttribute("data-view");"form-pane"===t&&(wp.ccf.currentForm=null),wp.ccf.dispatcher.trigger("mainViewChange",t),e.preventDefault()},render:function(e){return e=e||!1,this.overlay(),this.el.innerHTML=this.template({single:e}),this.initRenderSubViews(),this.showView("form-pane",wp.ccf.currentForm,!0),this},overlay:function(){return this.overlayEl===void 0&&(this.overlayEl=document.createElement("div"),this.overlayEl.className="ccf-main-modal-overlay",document.body.appendChild(this.overlayEl)),this.overlayEl},remove:function(){return document.body.removeChild(this.overlay()),this},show:function(){e(this.overlay()).show(),this.$el.show()},hide:function(){e(this.overlay()).hide(),this.$el.hide()}},wp.ccf.mixins.subViewable)),wp.ccf.views.SubmissionRow=wp.ccf.views.SubmissionRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-submission-row-template"),events:{"click .view":"view","click .delete":"delete"},initialize:function(e){this.parent=e.parent},"delete":function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},view:function(e){var t=e.currentTarget.getAttribute("data-submission-id"),i=e.currentTarget.getAttribute("data-submission-date");tb_show(l.thickboxTitle+" - "+wp.ccf.utils.getPrettyPostDate(i),"#TB_inline?height=500&amp;width=700&amp;inlineId=ccf-submission-content-"+parseInt(t),null)},render:function(){return this.$el.html(this.template({submission:this.model.toJSON(),currentColumns:this.parent.columns,columns:wp.ccf.currentForm.getFieldSlugs(!0),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate,wordChop:wp.ccf.utils.wordChop,isFieldDate:wp.ccf.utils.isFieldDate,isFieldName:wp.ccf.utils.isFieldName,isFieldFile:wp.ccf.utils.isFieldFile,isFieldAddress:wp.ccf.utils.isFieldAddress,isFieldEmailConfirm:wp.ccf.utils.isFieldEmailConfirm,getPrettyFieldDate:wp.ccf.utils.getPrettyFieldDate,getPrettyFieldAddress:wp.ccf.utils.getPrettyFieldAddress,getPrettyFieldName:wp.ccf.utils.getPrettyFieldName,getPrettyFieldEmailConfirm:wp.ccf.utils.getPrettyFieldEmailConfirm}})),this}}),wp.ccf.views.SubmissionsTable=wp.ccf.views.SubmissionsTable||t.View.extend({template:wp.ccf.utils.template("ccf-submission-table-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(){this.collection=new wp.ccf.collections.Submissions({},{formId:l.postId}),wp.ccf.dispatcher.on("submissionTableRebuild",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".submission-rows")[0],i=document.createElement("tbody");i.className="submission-rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.SubmissionRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild(new wp.ccf.views.EmptySubmissionTableRow({parent:t}).render(wp.ccf.currentForm.getFieldSlugs(!0).concat("date")).el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(e){var t=this;return t.columns=e?e:wp.ccf.currentForm.getFieldSlugs(!0).slice(0,4).concat("date"),1>t.columns.length?t.el.innerHTML="":(t.el.innerHTML=t.template({columns:t.columns}),t.el.querySelectorAll(".ccf-pagination")[0],t.showPage(1).done(function(){t.renderPagination()})),t}}),wp.ccf.views.ErrorModal=wp.ccf.views.ErrorModal||t.View.extend({template:wp.ccf.utils.template("ccf-error-modal-template"),tagName:"div",className:"ccf-error-modal",events:{"click .close":"hide"},hide:function(){this.el.className=this.el.className.replace(" show","")},show:function(){this.el.className=this.el.className.replace(" show","")+" show"},toggle:function(){this.el.className.match(" show")?this.hide():this.show()},render:function(e){var t={messageType:""};return e&&(t.messageType=e),this.el.innerHTML=this.template(t),this}}),wp.ccf.views.Pagination=wp.ccf.views.Pagination||t.View.extend({template:wp.ccf.utils.template("ccf-pagination-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(e){this.parent=e.parent},previousPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage-1).done(function(){e.render()})},nextPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage+1).done(function(){e.render()})},firstPage:function(){var e=this;e.parent.showPage(1).done(function(){e.render()})},lastPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.totalPages).done(function(){e.render()})},render:function(){return this.el.innerHTML=this.template({totalPages:this.parent.collection.state.totalPages,currentPage:this.parent.collection.state.currentPage,totalObjects:this.parent.collection.state.totalObjects}),this}}),wp.ccf.views.EmptySubmissionTableRow=wp.ccf.views.EmptySubmissionTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-no-submissions-row-template"),initialize:function(e){this.parent=e.parent},render:function(){return this.el.innerHTML=this.template({columns:this.parent.columns}),this}}),wp.ccf.views.SubmissionColumnController=wp.ccf.views.SubmissionColumnController||t.View.extend({template:wp.ccf.utils.template("ccf-submissions-controller-template"),events:{"click input[type=checkbox]":"triggerTableRebuild"},render:function(){this.el.innerHTML=this.template({columns:wp.ccf.currentForm.getFieldSlugs(!0).concat("date")})},triggerTableRebuild:function(){var e=[],t=document.querySelectorAll(".submission-column-checkbox");if(t.length>=1)for(var i=0;t.length>i;i++)t[i].checked&&e.push(t[i].value);wp.ccf.dispatcher.trigger("submissionTableRebuild",e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t){"use strict";wp.ccf.router=wp.ccf.router||t.Router.extend({routes:{"ccf-form":"open","ccf-form/:formId":"open"},open:function(e){wp.ccf.show(e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf=i.defaults(wp.ccf,{forms:new wp.ccf.collections.Forms,currentForm:null,errorModal:null,_currentFormDeferred:null,dispatcher:{},show:function(e){return this.switchToForm(e),this.instance.show(),this.instance},initErrorModal:function(){this.errorModal=(new wp.ccf.views.ErrorModal).render();var e=document.getElementsByTagName("body")[0];e.appendChild(this.errorModal.el)},switchToForm:function(e){var t=this;if(+e===parseInt(e)){var i=parseInt(e);if(e=t.forms.findWhere({id:parseInt(i)}),!e){var l;return t.forms.formsFetching[i]!==void 0?(l=t.forms.formsFetching[i],e=null):(e=new wp.ccf.models.Form({id:i}),l=e.fetch(),t.forms.formsFetching[i]=l),l.done(function(){e?(delete t.forms.formsFetching[i],t.forms.add(e)):e=t.forms.findWhere({id:i}),t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}),l}t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}else t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane");return!0},hide:function(){return this.instance.hide(),this.instance},toggle:function(e){return this.switchToForm(e),this.instance.$el.is(":visible")?this.instance.hide():this.instance.show(),this.instance},createSubmissionsTable:function(e){var t=document.querySelectorAll(".ccf-submission-column-controller"),i=new wp.ccf.views.SubmissionsTable({el:e});i.render(),t&&new wp.ccf.views.SubmissionColumnController({el:t}).render()},_setupMainModal:function(e){return this.instance=(new wp.ccf.views.MainModal).render(e),document.getElementsByTagName("body")[0].appendChild(this.instance.el),t.history.start(),this.instance},createManager:function(){var s=this,o=document.querySelectorAll(".ccf-open-form-manager")[0];if(!o)return!1;i.extend(this.dispatcher,t.Events),new wp.ccf.router,s.initErrorModal();var n=!1;if(l.single)if(n=!0,l.postId){var c=parseInt(l.postId);if(s.forms.formsFetching[c]===void 0){var r=new wp.ccf.models.Form({id:c}),a=r.fetch();s.forms.formsFetching[c]=a,s._currentFormDeferred=a,a.done(function(){delete s.forms.formsFetching[c],s.forms.add(r),s.currentForm=r})}else s._currentFormDeferred=s.forms.formsFetching[c],s._currentFormDeferred.done(function(){s.currentForm=s.forms.findWhere({id:c})});e.when(s._currentFormDeferred).then(function(){s._setupMainModal(!0),o.style.display="inline-block";var e=document.getElementById("ccf-submissions");if(e){var t=e.querySelectorAll(".inside")[0],i=document.createElement("div");i.className="ccf-submission-icon",i.setAttribute("data-icon","");var n=document.createElement("a");n.href="?action=edit&post="+parseInt(l.postId)+"&download_submissions=1&download_submissions_nonce="+l.downloadSubmissionsNonce,n.className="ccf-submission-icon",n.setAttribute("data-icon","");var c=document.getElementById("show-settings-link");i.onclick=function(){c.click()},e.insertBefore(i,e.firstChild.nextSibling.nextSibling),e.insertBefore(n,e.firstChild.nextSibling.nextSibling),wp.ccf.createSubmissionsTable(t);var r=document.querySelectorAll("#major-publishing-actions .duplicate")[0],a=function(e){e=e||window.event,e.preventDefault(),s.currentForm.clone().set("title",{raw:s.currentForm.get("title").raw+" (duplicate)"}).unset("id").save().done(function(e){document.location=l.adminUrl+"/post.php?action=edit&post="+e.id})};r.addEventListener?r.addEventListener("click",a,!1):r.attachEvent("onclick",a)}})}else s._setupMainModal(!0),o.style.display="inline-block";else s._setupMainModal();var d=function(e){e=e||window.event;var t=e.currentTarget?e.currentTarget:e.srcElement,i=t.getAttribute("data-form-id");wp.ccf.toggle(i)};o.addEventListener?o.addEventListener("click",d,!1):o.attachEvent("onclick",d)}}),wp.ccf.createManager()}(jQuery,Backbone,_,ccfSettings);
1
+ (function(e,t,i,l){"use strict";window.wp=window.wp||{},wp.ccf=wp.ccf||{},wp.ccf.utils=wp.ccf.utils||{},wp.ccf.utils.cleanDateFields=function(e){delete e.date,delete e.date_gmt,delete e.modified,delete e.modified_gmt,delete e.date_tz,delete e.modified_tz},wp.ccf.utils.template=i.memoize(function(e){var t={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};return i.template(document.getElementById(e).innerHTML,null,t)}),wp.ccf.utils.insertFormShortcode=function(e){var t=wp.ccf.forms.findWhere({id:e.get("id")});t||wp.ccf.forms.add(e);var i=tinymce.get(wpActiveEditor),l='[ccf_form id="'+e.get("id")+'"]';i&&!i.isHidden()?tinymce.activeEditor.execCommand("mceInsertContent",!1,l):document.getElementById(wpActiveEditor).value+=l},wp.ccf.utils.getPrettyPostDate=function(e){return e=moment.utc(e),l.gmtOffset&&(e=e.utcOffset(60*parseInt(l.gmtOffset))),e.format("h:mm a M/D/YYYY")},wp.ccf.utils.wordChop=function(e,t){var i=e.substr(0,t);return i.substr(0,Math.min(i.length,i.lastIndexOf(" "))),i.length<e.length&&(i+="..."),i},wp.ccf.utils.isFieldDate=function(e){return e.date!==void 0||e.hour!==void 0&&e.minute!==void 0&&e["am-pm"]!==void 0?!0:!1},wp.ccf.utils.isFieldName=function(e){return e.name!==void 0||e.last!==void 0?!0:!1},wp.ccf.utils.isFieldEmailConfirm=function(e){return e.email!==void 0||e.confirm!==void 0?!0:!1},wp.ccf.utils.isFieldAddress=function(e){return e.street!==void 0&&e.city!==void 0&&e.zipcode!==void 0&&e.line_two!==void 0?!0:!1},wp.ccf.utils.isFieldFile=function(e){return e.id!==void 0&&e.url!==void 0&&e.file_name!==void 0?!0:!1},wp.ccf.utils.getPrettyFieldEmailConfirm=function(e){return e.email?e.email:e.confirm?e.confirm:"-"},wp.ccf.utils.getPrettyFieldDate=function(e,t){var i="",s="",o="MM/DD/YY";if(t&&t.ccf_field_dateFormat&&"dd/mm/yyyy"===t.ccf_field_dateFormat&&(o="DD/MM/YY"),e.hour&&e.minute&&e["am-pm"]&&(i+=e.hour+":"+e.minute+" "+e["am-pm"],o="HH:mm "+o),e.date&&(i&&(i+=" "),i+=e.date),!i)return"-";var n=moment(i,o);return n.isValid()?(e.hour&&e.minute&&e["am-pm"]&&(s+=n.format("h:mm a")),e.date&&(s&&(s+=" "),s+=e.date),s):l.invalidDate},wp.ccf.utils.getPrettyFieldName=function(e){var t=e.first;return t.length>0&&(t+=" "),e.last&&(t+=e.last),t||(t="-"),t},wp.ccf.utils.getPrettyFieldAddress=function(e){if(!e.street||!e.city)return"-";var t=e.street;return e.line_two&&(t+=" "+e.line_two),t+=", "+e.city,e.state&&(t+=", "+e.state),e.zipcode&&(t+=" "+e.zipcode),e.country&&(t+=" "+e.country),t}})(jQuery,Backbone,_,ccfSettings),function(e,t,i){"use strict";wp.ccf.mixins=wp.ccf.mixins||{},wp.ccf.mixins.subViewable=wp.ccf.mixins.subViewable||{subViews:{},initRenderSubViews:function(e,t,l){this.renderedSubViews||(this.renderedSubViews={});for(var s in this.subViews){var o={el:this.$el.find(".ccf-"+s),parent:this};l&&i.extend(o,l),this.renderedSubViews[s]&&this.renderedSubViews[s].destroy&&this.renderedSubViews[s].destroy(),(t||!this.renderedSubViews[s])&&(this.renderedSubViews[s]=new this.subViews[s](o)),this.renderedSubViews[s].render(),e&&(this.renderedSubViews[s].el.style.display="block")}return this},showView:function(e,t,i){if(this.renderedSubViews!==void 0&&this.renderedSubViews[e]!==void 0){var l=this.renderedSubViews[e];i||l.render(t),l.el.style.display="block",this.currentView=e;for(var s in this.subViews)s!==e&&(this.renderedSubViews[s].el.style.display="none")}}}}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.models=wp.ccf.models||{},wp.ccf.models.Fields=wp.ccf.models.Fields||{};var s=function(e,i,l){return"object"!=typeof i&&""===i&&(i=""),t.Model.prototype.set.call(this,e,i,l)},o=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)},n=function(e){for(var t in this.attributes)if(-1===i.indexOf(e,t)){var l=this.get(t);"string"==typeof l&&""!==l&&(l=(l+"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#8220;/g,"”").replace(/&#8221;/g,"”").replace(/&#8216;/g,"‘").replace(/&#038;/g,"&").replace(/&#039;/g,"'"),this.set(t,l))}return this};wp.ccf.models.FieldConditional=wp.ccf.models.FieldConditional||t.Model.extend({defaults:{field:"",compare:"is",value:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FieldChoice=wp.ccf.models.FieldChoice||t.Model.extend({defaults:{label:"",value:"",selected:!1},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.PostFieldMapping=wp.ccf.models.PostFieldMapping||t.Model.extend({defaults:{formField:"",postField:"",customFieldKey:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotificationAddress=wp.ccf.models.FormNotificationAddress||t.Model.extend({defaults:{type:"custom",field:"",email:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotification=wp.ccf.models.FormNotification||t.Model.extend({defaults:function(){return{title:"",content:"[all_fields]",active:!0,includeUploads:!0,addresses:new wp.ccf.collections.FormNotificationAddresses,fromType:"default",fromAddress:"",fromField:"",subjectType:"default",subject:"",subjectField:"",fromNameType:"custom",fromName:"WordPress",fromNameField:"",replyToType:"default",replyToAddress:"",replyToField:"",replyToNameType:"custom",replyToName:"WordPress",replyToNameField:""}},initialize:function(e){if("object"==typeof e&&e.addresses){var t=[];i.each(e.addresses,function(e){var i=new wp.ccf.models.FormNotificationAddress(e);i.decode(),t.push(i)}),this.set("addresses",new wp.ccf.collections.FormNotificationAddresses(t))}},decode:function(){return n.call(this,[])},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.addresses&&(e.addresses=e.addresses.toJSON()),e},set:s}),wp.ccf.models.Form=wp.ccf.models.Form||wp.ccf.api.models.Post.extend({urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",set:s,sync:o,idAttribute:"id",initialize:function(){this.on("sync",this.decode,this)},defaults:function(){var e={fields:new wp.ccf.collections.Fields,type:"ccf_form",status:"publish",hideTitle:!1,description:"",buttonText:"Submit Form",buttonClass:"",completionActionType:"text",completionRedirectUrl:"",completionMessage:"",postCreation:!1,postCreationType:"post",postCreationStatus:"draft",postFieldMappings:new wp.ccf.collections.PostFieldMappings,notifications:new wp.ccf.collections.FormNotifications,pause:!1,requireLoggedIn:!1,pauseMessage:l.pauseMessage,theme:"none"};return e=i.defaults(e,this.constructor.__super__.defaults),wp.ccf.utils.cleanDateFields(e),e},decode:function(){var e=i.keys(wp.ccf.api.models.Post.prototype.defaults);return e=i.without(e,"title"),n.call(this,e)},getFieldSlugs:function(e){var t=wp.ccf.currentForm.get("fields"),i=[];return t.each(function(t){e&&t.isImmutable||i.push(t.get("slug"))}),i},parse:function(e){var t=this,l=0,s=0;if(e.fields){var o=t.get("fields");if(o&&o.length>0){for(l=0;e.fields.length>l;l++){var n=e.fields[l],c=o.findWhere({slug:n.slug});if(c){if(n.choices!==void 0){var r=t.get("choices");if(r&&r.length>0)for(s=0;n.choices>s;s++){var a=r.at(s);a.set(n.choices[s]),a.decode()}delete e.fields[l].choices}if(n.conditionals!==void 0){var d=t.get("conditionals");if(d&&d.length>0)for(s=0;n.conditionals>s;s++){var u=d.at(s);u.set(n.conditionals[s]),u.decode()}delete e.fields[l].conditionals}c.set(n),c.decode()}}delete e.fields}else{var f=[];i.each(e.fields,function(e){var t=new wp.ccf.models.Fields[e.type](e);t.decode(),f.push(t)}),e.fields=new wp.ccf.collections.Fields(f,{formId:e.id}),o?(o.add(f),delete e.fields):e.fields=new wp.ccf.collections.Fields(f,{formId:e.id})}}if(e.notifications){var p=t.get("notifications");if(p&&p.length>0){for(l=0;e.notifications.length>l;l++){var h=e.notifications[l],m=p.at(l);if(m){if(h.addresses!==void 0){var w=m.get("addresses");if(w&&w.length>0)for(s=0;h.addresses>s;s++){var v=w.at(s);v.set(h.addresses[s]),v.decode()}delete e.notifications[l].addresses}m.set(h),m.decode()}}delete e.notifications}else{var g=[];i.each(e.notifications,function(e){var t=new wp.ccf.models.FormNotification(e);t.decode(),g.push(t)}),p?(p.add(g),delete e.notifications):e.notifications=new wp.ccf.collections.FormNotifications(g)}}if(e.postFieldMappings){var y=t.get("postFieldMappings");if(y&&y.length>0){for(l=0;e.postFieldMappings.length>l;l++){var F=e.postFieldMappings[l],b=y.at(l);b&&(b.set(F),b.decode())}delete e.postFieldMappings}else{var S=[];i.each(e.postFieldMappings,function(e){var t=new wp.ccf.models.PostFieldMapping(e);t.decode(),S.push(t)}),y?(y.add(S),e.postFieldMappings=y):e.postFieldMappings=new wp.ccf.collections.PostFieldMappings(S)}}return this.constructor.__super__.parse.call(this,e)},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.fields&&(e.fields=e.fields.toJSON()),e.notifications&&(e.notifications=e.notifications.toJSON()),e.postFieldMappings&&(e.postFieldMappings=e.postFieldMappings.toJSON()),e.author&&(e.author=e.author.toJSON()),e}}),wp.ccf.models.Submission=wp.ccf.api.models.Submission||wp.ccf.api.models.Post.extend({defaults:{id:null,data:{},fields:{}},sync:o,urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/submissions"}),wp.ccf.models.Field=wp.ccf.api.models.Field||wp.ccf.api.models.Post.extend({idAttribute:"id",defaults:function(){return{id:null,conditionalsEnabled:!1,conditionalType:"show",conditionalFieldsRequired:"all",conditionals:new wp.ccf.collections.FieldConditionals}},set:s,initialize:function(e){if("object"==typeof e&&e.conditionals){var t=[];i.each(e.conditionals,function(e){var i=new wp.ccf.models.FieldConditional(e);i.decode(),t.push(i)}),this.set("conditionals",new wp.ccf.collections.FieldConditionals(t))}},required:function(){return["slug"]},decode:function(){return n.call(this,i.keys(wp.ccf.api.models.Post.prototype.defaults))},hasRequiredAttributes:function(){var e=this,t=!0;return i.each(this.required(),function(i){(e.get(i)===void 0||""===e.get(i))&&(t=!1)}),t},sync:o}),wp.ccf.models.StandardField=wp.ccf.models.StandardField||wp.ccf.models.Field.extend({idAttribute:"id",defaults:function(){var e={label:l.fieldLabel,value:"",placeholder:"",slug:"",type:"",required:!1,className:"",description:""};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return wp.ccf.models.StandardField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["single-line-text"]=wp.ccf.models.Fields["single-line-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"single-line-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.file=wp.ccf.models.Fields.file||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"file",fileExtensions:"",maxFileSize:l.maxFileSize};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["paragraph-text"]=wp.ccf.models.Fields["paragraph-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"paragraph-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.hidden=wp.ccf.models.Fields.hidden||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"hidden"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.email=wp.ccf.models.Fields.email||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"email",emailConfirmation:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.website=wp.ccf.models.Fields.website||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"website",placeholder:"http://"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.phone=wp.ccf.models.Fields.phone||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"phone",phoneFormat:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.date=wp.ccf.models.Fields.date||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"date",showDate:!0,showTime:!0,dateFormat:"mm/dd/yyyy"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.name=wp.ccf.models.Fields.name||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"name"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.recaptcha=wp.ccf.models.Fields.recaptcha||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"recaptcha",siteKey:"",secretKey:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return["siteKey","secretKey"]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["simple-captcha"]=wp.ccf.models.Fields["simple-captcha"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"simple-captcha",placeholder:l.defaultSimpleCaptchaPlaceholder};return i.defaults(e,this.constructor.__super__.defaults())},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.address=wp.ccf.models.Fields.address||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"address",addressType:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["section-header"]=wp.ccf.models.Fields["section-header"]||wp.ccf.models.Field.extend({defaults:function(){var e={type:"section-header",slug:"",heading:"",subheading:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.html=wp.ccf.models.Fields.html||wp.ccf.models.Field.extend({defaults:function(){var e={type:"html",slug:"",html:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.ChoiceableField=wp.ccf.models.ChoiceableField||wp.ccf.models.StandardField.extend({defaults:function(){var e={choices:new wp.ccf.collections.FieldChoices,useValues:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(e){if("object"==typeof e&&e.choices){var t=[];i.each(e.choices,function(e){var i=new wp.ccf.models.FieldChoice(e);i.decode(),t.push(i)}),this.set("choices",new wp.ccf.collections.FieldChoices(t))}return wp.ccf.models.ChoiceableField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.radio=wp.ccf.models.Fields.radio||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"radio"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.checkboxes=wp.ccf.models.Fields.checkboxes||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"checkboxes"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.dropdown=wp.ccf.models.Fields.dropdown||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"dropdown"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";var s=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)};wp.ccf.collections=wp.ccf.collections||{},wp.ccf.collections.Forms=wp.ccf.collections.Forms||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Form,url:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",formsFetching:{},initialize:function(){this.constructor.__super__.initialize(),this.formsFetching={}},sync:s,remove:function(e,t){t=t||{};var l=this.constructor.__super__.remove.call(this,e,t);return t.destroy&&(e instanceof Array?i.each(e,function(e){e.destroy()}):e.destroy()),l}}),wp.ccf.collections.Fields=wp.ccf.collections.Fields||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Field,url:function(){return l.apiRoot+"/ccf/forms/"+this.formId+"/fields"},initialize:function(e,t){t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.PostFieldMappings=wp.ccf.collections.PostFieldMappings||t.Collection.extend({model:wp.ccf.models.PostFieldMapping}),wp.ccf.collections.FormNotificationAddresses=wp.ccf.collections.FormNotificationAddresses||t.Collection.extend({model:wp.ccf.models.FormNotificationAddress}),wp.ccf.collections.FormNotifications=wp.ccf.collections.FormNotifications||t.Collection.extend({model:wp.ccf.models.FormNotification}),wp.ccf.collections.Submissions=wp.ccf.collections.Submissions||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Submission,url:function(){return l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms/"+this.formId+"/submissions"},initialize:function(e,t){this.constructor.__super__.initialize.apply(this,arguments),t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.FieldChoices=wp.ccf.collections.FieldChoices||t.Collection.extend({model:wp.ccf.models.FieldChoice}),wp.ccf.collections.FieldConditionals=wp.ccf.collections.FieldConditionals||t.Collection.extend({model:wp.ccf.models.FieldConditional})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.views=wp.ccf.views||{},wp.ccf.views.Fields=wp.ccf.views.Fields||{},wp.ccf.views.FieldChoice=t.View.extend({template:wp.ccf.utils.template("ccf-field-choice-template"),className:"choice",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveChoice:"saveChoice",sorted:"triggerUpdateSort"},initialize:function(e){this.field=e.field},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveChoice),this.unbind()},triggerUpdateSort:function(e,t){this.field.get("choices").remove(this.model,{silent:!0}),this.field.get("choices").add(this.model,{at:t,silent:!0})},saveChoice:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".choice-label")[0].value,t=this.el.querySelectorAll(".choice-value"),i="";t.length&&(i=t[0].value),this.model.set("label",e),this.model.set("value",i),this.field.get("useValues")||this.model.set("value",this.model.get("label"));var l=this.el.querySelectorAll(".choice-selected")[0],s=l.checked?!0:!1;return this.model.set("selected",s),this}},render:function(){var e={showValue:this.field.get("useValues")};return this.model&&(e.choice=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveChoice,this),this},triggerAdd:function(){this.field.get("choices").add(new wp.ccf.models.FieldChoice)},triggerDelete:function(){var e=this.field.get("choices");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{for(var t=this.el.querySelectorAll(".choice-label, .choice-value"),i=this.el.querySelectorAll(".choice-selected"),l=0;t.length>l;l++)t[l].value="";i[0].checked=!1}}}),wp.ccf.views.FieldConditional=t.View.extend({template:wp.ccf.utils.template("ccf-field-conditional-template"),className:"conditional",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveConditional:"saveConditional"},initialize:function(e){this.field=e.field,this.fieldCollection=e.fieldCollection},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveConditional),this.unbind()},saveConditional:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".conditional-field")[0].value,t=this.el.querySelectorAll(".conditional-value")[0].value,i=this.el.querySelectorAll(".conditional-compare")[0].value;return this.model.set("field",e),this.model.set("value",t),this.model.set("compare",i),this}},updateFields:function(){var e=this.el.querySelectorAll(".conditional-field")[0];e.innerHTML="",e.disabled=!1;var t,i=0,s=this.model.get("field");this.fieldCollection.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),this.fieldCollection.each(function(l){if(this.field.get("slug")!==l.get("slug")){var o=l.get("type");"address"!==o&&"checkboxes"!==o&&"date"!==o&&"name"!==o&&"file"!==o&&"recaptcha"!==o&&"simple-captcha"!==o&&"section-header"!==o&&"html"!==o&&(t=document.createElement("option"),t.innerHTML=l.get("slug"),t.value=l.get("slug"),l.get("slug")===s&&(t.selected=!0),e.appendChild(t),i++)}},this)),0===i&&(e.innerHTML="",t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},render:function(){var e={};return this.model&&(e.conditional=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveConditional,this),this.listenTo(this.fieldCollection,"add",this.updateFields,this),this.listenTo(this.fieldCollection,"remove",this.updateFields,this),this.updateFields(),this},triggerAdd:function(){this.field.get("conditionals").add(new wp.ccf.models.FieldConditional)},triggerDelete:function(){var e=this.field.get("conditionals");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{var t=this.el.querySelectorAll(".conditional-value")[0],i=this.el.querySelectorAll(".conditional-field")[0];t.value="";for(var l=0;i.childNodes.length>l;l++)i.childNodes[l].selected=!1}}}),wp.ccf.views.EmptyFormNotificationTableRow=wp.ccf.views.EmptyFormNotificationTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-notification-row-template"),events:{"click .add":"triggerAdd"},initialize:function(e){this.form=e.form},destroy:function(){this.unbind()},render:function(){return this.$el.html(this.template()),this},triggerAdd:function(){var e=this.form.get("notifications");this.destroy(),e.add(new wp.ccf.models.FormNotification)}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.FormNotificationAddress=t.View.extend({template:wp.ccf.utils.template("ccf-form-notification-address-template"),className:"address",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.notification=e.notification,this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-notification-address-type")[0].value,t=this.el.querySelectorAll(".form-notification-address-email"),i=this.el.querySelectorAll(".form-notification-address-field"),l=this.model.get("type");return t.length&&this.model.set("email",t[0].value),i.length&&this.model.set("field",i[0].value),this.model.set("type",e),l!==e&&this.render(),this}},updateFromFieldField:function(){if("edit"===this.parent.context&&"field"===this.model.get("type")){var e=this.el.querySelectorAll(".form-notification-address-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("field");i.length>=1&&i.each(function(i){("email"===i.get("type")||"dropdown"===i.get("type")||"radio"===i.get("type")||"single-line-text"===i.get("type"))&&(t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++)}),0===s&&(t=document.createElement("option"),t.innerHTML=l.noApplicableFields,t.value="",e.appendChild(t),e.disabled=!0)}},render:function(){var e={};this.model&&(e.address=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFromFieldField,this),this.listenTo(t,"remove",this.updateFromFieldField,this),"field"===this.model.get("type")&&this.updateFromFieldField(),this},triggerAdd:function(){this.notification.get("addresses").add(new wp.ccf.models.FormNotificationAddress)},triggerDelete:function(){var e=this.notification.get("addresses");e.length>1?this.parent.deleteAddress(this):(this.model.clear().set(wp.ccf.models.FormNotificationAddress.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.ExistingFormNotificationRow=t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-notification-table-row-template"),tagName:"tr",events:{"change select.form-email-notification-from-type":"toggleNotificationFields","change select.form-email-notification-from-name-type":"toggleNotificationFields","change select.form-email-notification-reply-to-type":"toggleNotificationFields","change select.form-email-notification-reply-to-name-type":"toggleNotificationFields","change select.form-email-notification-subject-type":"toggleNotificationFields","click .close-notification":"changeContext","click .edit-notification":"changeContext","click .delete-notification":"triggerDelete","blur input":"save","change select":"save"},addressViews:[],initialize:function(e){this.form=e.form,this.addressViews=[],this.parent=e.parent,this.context=e.context!==void 0?e.context:"view";var t=this.model.get("addresses");this.listenTo(t,"add",this.addAddress)},deleteAddress:function(e){i.each(this.addressViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.addressViews,t);this.model.get("addresses").remove(e.model),this.addressViews[l].remove(),this.addressViews.splice(l,1)}},this)},addAddress:function(e){var t=this.el.querySelectorAll(".addresses")[0],i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form});this.addressViews.push(i),t.appendChild(i.render().el)},destroy:function(){this.unbind()},changeContext:function(e,t){"edit"===this.context&&this.save(),t?this.context=t:("view"===this.context&&this.parent.closeAllNotifications(),this.context="edit"===this.context?"view":"edit"),this.destroy(),this.render()},updateFieldVariables:function(){if("edit"===this.context){var e,t=this.el.querySelectorAll(".field-variables")[0],i="",l=this.form.get("fields");l.each(function(t){e=t.get("type"),"html"!==e&&"section-header"!==e&&"recaptcha"!==e&&"simple-captcha"!==e&&(i+="["+t.get("slug")+"] ")}),t.innerText=i}},updateFromFieldField:function(){if("edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-from-field")[0];e.innerHTML="",e.disabled=!1;var t=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0];t.innerHTML="",t.disabled=!1;var i=this.el.querySelectorAll(".form-email-notification-subject-field")[0];i.innerHTML="",i.disabled=!1;var s=this.el.querySelectorAll(".form-email-notification-from-name-field")[0];s.innerHTML="",s.disabled=!1;var o=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0];o.innerHTML="",o.disabled=!1;var n,c,r=this.form.get("fields"),a=0,d=0,u=0,f=this.model.get("fromField"),p=this.model.get("replyToField"),h=this.model.get("subjectField"),m=this.model.get("fromNameField"),w=this.model.get("replyToNameField");r.length>=1&&r.each(function(l){("email"===l.get("type")||"dropdown"===l.get("type")||"radio"===l.get("type")||"single-line-text"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===f&&(n.selected=!0),e.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===p&&(c.selected=!0),t.appendChild(c),a++),("name"===l.get("type")||"single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===m&&(n.selected=!0),s.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===w&&(c.selected=!0),o.appendChild(c),d++),("single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===h&&(n.selected=!0),i.appendChild(n),u++)}),0===a&&(n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",e.appendChild(n),e.disabled=!0,n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",t.appendChild(n),t.disabled=!0),0===d&&(n=document.createElement("option"),n.innerHTML=l.noNameFields,n.value="",s.appendChild(n),s.disabled=!0),0===u&&(n=document.createElement("option"),n.innerHTML=l.noApplicableFields,n.value="",i.appendChild(n),i.disabled=!0)}},toggleNotificationFields:function(){var e=this.el.querySelectorAll(".email-notification-from-address")[0],t=this.el.querySelectorAll(".email-notification-from-field")[0],i=this.el.querySelectorAll(".form-email-notification-from-type")[0],l=this.el.querySelectorAll(".email-notification-subject")[0],s=this.el.querySelectorAll(".email-notification-subject-field")[0],o=this.el.querySelectorAll(".form-email-notification-subject-type")[0],n=this.el.querySelectorAll(".email-notification-from-name")[0],c=this.el.querySelectorAll(".email-notification-from-name-field")[0],r=this.el.querySelectorAll(".form-email-notification-from-name-type")[0],a=this.el.querySelectorAll(".email-notification-reply-to-address")[0],d=this.el.querySelectorAll(".email-notification-reply-to-field")[0],u=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0],f=this.el.querySelectorAll(".email-notification-reply-to-name")[0],p=this.el.querySelectorAll(".email-notification-reply-to-name-field")[0],h=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0];e.style.display="none",t.style.display="none","custom"===i.value?e.style.display="block":"field"===i.value&&(t.style.display="block"),l.style.display="none",s.style.display="none","custom"===o.value?l.style.display="block":"field"===o.value&&(s.style.display="block"),n.style.display="none",c.style.display="none","custom"===r.value?n.style.display="block":"field"===r.value&&(c.style.display="block"),a.style.display="none",d.style.display="none","custom"===u.value?a.style.display="block":"field"===u.value&&(d.style.display="block"),f.style.display="none",p.style.display="none","custom"===h.value?f.style.display="block":"field"===h.value&&(p.style.display="block")},save:function(){if(""!==this.el.innerHTML&&"edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-title")[0].value;this.model.set("title",e);var t=this.el.querySelectorAll(".form-email-notification-content")[0].value;this.model.set("content",t);var i=this.el.querySelectorAll(".form-email-notification-active")[0].value;this.model.set("active","1"===i?!0:!1);var l=this.el.querySelectorAll(".form-email-notification-include-uploads")[0].value;this.model.set("includeUploads","1"===l?!0:!1);var s=this.el.querySelectorAll(".form-email-notification-from-type")[0].value;this.model.set("fromType",s);var o=this.el.querySelectorAll(".form-email-notification-from-address")[0].value;this.model.set("fromAddress",o);var n=this.el.querySelectorAll(".form-email-notification-from-field")[0].value;this.model.set("fromField",n);var c=this.el.querySelectorAll(".form-email-notification-from-name-type")[0].value;
2
+ this.model.set("fromNameType",c);var r=this.el.querySelectorAll(".form-email-notification-from-name")[0].value;this.model.set("fromName",r);var a=this.el.querySelectorAll(".form-email-notification-from-name-field")[0].value;this.model.set("fromNameField",a);var d=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0].value;this.model.set("replyToType",d);var u=this.el.querySelectorAll(".form-email-notification-reply-to-address")[0].value;this.model.set("replyToAddress",u);var f=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0].value;this.model.set("replyToField",f);var p=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0].value;this.model.set("replyToNameType",p);var h=this.el.querySelectorAll(".form-email-notification-reply-to-name")[0].value;this.model.set("replyToName",h);var m=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0].value;this.model.set("replyToNameField",m);var w=this.el.querySelectorAll(".form-email-notification-subject-type")[0].value;this.model.set("subjectType",w);var v=this.el.querySelectorAll(".form-email-notification-subject")[0].value;this.model.set("subject",v);var g=this.el.querySelectorAll(".form-email-notification-subject-field")[0].value;this.model.set("subjectField",g);for(var y=0;this.addressViews.length>y;y++)this.addressViews[y].save();return this}},render:function(){var e={context:this.context,form:this.form.toJSON()};if(this.model&&(e.notification=this.model.toJSON()),this.el.innerHTML=this.template(e),"edit"===this.context){this.toggleNotificationFields(),this.updateFromFieldField(),this.updateFieldVariables();var t=this.el.querySelectorAll(".addresses")[0],i=this.model.get("addresses");if(i.length>=1)i.each(function(e){var i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form}).render();t.appendChild(i.el),this.addressViews.push(i)},this);else{var l=new wp.ccf.models.FormNotificationAddress;i.add(l)}}var s=this.form.get("fields");return this.listenTo(s,"add",this.updateFromFieldField,this),this.listenTo(s,"remove",this.updateFromFieldField,this),this.listenTo(s,"add",this.updateFieldVariables,this),this.listenTo(s,"remove",this.updateFieldVariables,this),this},triggerDelete:function(){this.parent.deleteNotification(this)}}),wp.ccf.views.FieldBase=wp.ccf.views.FieldBase||t.View.extend({events:{"blur input":"saveField","blur input.field-slug":"checkSlug","blur textarea":"saveField","change select":"saveField",'change input[type="checkbox"]':"saveField"},initialize:function(){var e=this.model.get("conditionals");this.listenTo(e,"add",this.addConditional)},addConditional:function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render(),i=this.el.querySelectorAll(".conditionals")[0];i.appendChild(t.el)},checkSlug:function(){var e=this.el.querySelectorAll(".field-slug");if(e.length>0){var t=e[0],i=!1;t.parentNode.className=t.value&&!t.value.match(/^[a-zA-Z0-9\-_]+$/)?t.parentNode.className.replace(/ field-error/i,"")+" field-error":t.parentNode.className.replace(/ field-error/i,""),this.collection.length>0&&""!==t.value?(this.collection.each(function(e){e!==this.model&&t.value===e.get("slug")&&(i=!0)},this),t.parentNode.className=i?t.parentNode.className.replace(/ field-duplicate-slug/i,"")+" field-duplicate-slug":t.parentNode.className.replace(/ field-duplicate-slug/i,"")):t.parentNode.className=t.parentNode.className.replace(/ field-duplicate-slug/i,"")}},destroy:function(){this.unbind()},saveField:function(){var t=this.el.querySelectorAll(".conditionals");if(t.length){var l=t[0].querySelectorAll(".conditional");i.each(l,function(t){e(t).trigger("saveConditional")}),this.model.set("conditionalType",this.el.querySelectorAll(".field-conditional-type")[0].value),this.model.set("conditionalFieldsRequired",this.el.querySelectorAll(".field-conditional-fields-required")[0].value);var s=this.model.get("conditionalsEnabled");this.model.set("conditionalsEnabled",1==this.el.querySelectorAll(".field-conditionals-enabled")[0].value?!0:!1),s!==this.model.get("conditionalsEnabled")&&this.render("advanced")}},render:function(e){e=e?e:"basic",this.el.innerHTML=this.template({field:this.model.toJSON(),startPanel:e}),this.checkSlug();var t=this.model.get("conditionals"),i=this.el.querySelectorAll(".conditionals");if(i.length)if(t.length>=1)t.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();i[0].appendChild(t.el)},this);else{var l=new wp.ccf.models.FieldConditional;t.add(l)}return this}}),wp.ccf.views.Fields["single-line-text"]=wp.ccf.views.Fields["single-line-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-single-line-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.file=wp.ccf.views.Fields.file||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-file-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.model.set("fileExtensions",this.el.querySelectorAll(".field-file-extensions")[0].value),this.model.set("maxFileSize",this.el.querySelectorAll(".field-max-file-size")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.recaptcha=wp.ccf.views.Fields.recaptcha||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-recaptcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("siteKey",this.el.querySelectorAll(".field-site-key")[0].value),this.model.set("secretKey",this.el.querySelectorAll(".field-secret-key")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["simple-captcha"]=wp.ccf.views.Fields["simple-captcha"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-simple-captcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["section-header"]=wp.ccf.views.Fields["section-header"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-section-header-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("heading",this.el.querySelectorAll(".field-heading")[0].value),this.model.set("subheading",this.el.querySelectorAll(".field-subheading")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.html=wp.ccf.views.Fields.html||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-html-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("html",this.el.querySelectorAll(".field-html")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["paragraph-text"]=wp.ccf.views.Fields["paragraph-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-paragraph-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.hidden=wp.ccf.views.Fields.hidden||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-hidden-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.date=wp.ccf.views.Fields.date||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-date-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length>0&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-date-format");t.length&&this.model.set("dateFormat",t[0].value);var i=this.model.get("showDate"),l=this.el.querySelectorAll(".field-show-date")[0].checked?!0:!1;this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("showDate",l);var s=this.model.get("showTime"),o=this.el.querySelectorAll(".field-show-time")[0].checked?!0:!1;return this.model.set("showTime",o),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),(o!=s||l!=i)&&this.render(),this}}}),wp.ccf.views.Fields.name=wp.ccf.views.Fields.name||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-name-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.website=wp.ccf.views.Fields.website||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-website-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.phone=wp.ccf.views.Fields.phone||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-phone-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("phoneFormat",this.el.querySelectorAll(".field-phone-format")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.address=wp.ccf.views.Fields.address||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-address-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value);var e=this.model.get("addressType");this.model.set("addressType",this.el.querySelectorAll(".field-address-type")[0].value);var t=this.el.querySelectorAll(".field-default-country");return t.length&&this.model.set("defaultCountry",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),e!==this.model.get("addressType")&&this.render(),this.constructor.__super__.saveField.apply(this,arguments),this}}}),wp.ccf.views.Fields.email=wp.ccf.views.Fields.email||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-email-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-placeholder");t.length&&this.model.set("placeholder",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1);var i=1==this.el.querySelectorAll(".field-email-confirmation")[0].value?!0:!1,l=this.model.get("emailConfirmation");return this.model.set("emailConfirmation",i),l!=i&&this.render(),this}}}),wp.ccf.views.ChoiceableField=wp.ccf.views.ChoiceableField||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),initialize:function(){var e=this.model.get("choices");this.listenTo(e,"add",this.addChoice)},addChoice:function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:this.model}).render(),i=this.el.querySelectorAll(".repeatable-choices")[0];i.appendChild(t.el)},saveField:function(t){if(""!==this.el.innerHTML&&(!t||"field-use-values"!==t.target.className||"focusout"!==t.type)){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),wp.ccf.views.ChoiceableField.__super__.saveField.apply(this,arguments);var l=this.el.querySelectorAll(".repeatable-choices")[0].querySelectorAll(".choice");i.each(l,function(t){e(t).trigger("saveChoice")});var s=this.model.get("useValues"),o=this.el.querySelectorAll(".field-use-values")[0].checked?!0:!1;return this.model.set("useValues",o),s!==o&&this.render(),this}},render:function(t){var i=this;t=t?t:"basic",this.model.get("useValues"),i.el.innerHTML=i.template({field:i.model.toJSON(),startPanel:t}),i.checkSlug();var l=i.model.get("choices"),s=this.el.querySelectorAll(".repeatable-choices")[0];if(l.length>=1)l.each(function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:i.model}).render();s.appendChild(t.el)});else{var o=new wp.ccf.models.FieldChoice;l.add(o)}s=this.el.querySelectorAll(".repeatable-choices")[0],e(s).sortable({handle:".move",axis:"y",stop:function(e,t){t.item.trigger("sorted",t.item.index())}});var n=this.model.get("conditionals"),c=this.el.querySelectorAll(".conditionals")[0];if(n.length>=1)n.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();c.appendChild(t.el)},this);else{var r=new wp.ccf.models.FieldConditional;n.add(r)}return i}}),wp.ccf.views.Fields.dropdown=wp.ccf.views.Fields.dropdown||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.radio=wp.ccf.views.Fields.radio||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-radio-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.checkboxes=wp.ccf.views.Fields.checkboxes||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-checkboxes-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.FieldSidebar=wp.ccf.views.FieldSidebar||t.View.extend({initialize:function(e){this.currentFieldView=null,this.form=e.form},save:function(e){this.currentFieldView&&""!==this.currentFieldView.el.innerHTML&&this.currentFieldView.saveField(),e&&e instanceof Object&&e.resolve()},fieldRemoved:function(){this.currentFieldView&&(this.form.get("fields").get(this.currentFieldView.model)||this.render())},destroy:function(){wp.ccf.dispatcher.off("saveField",this.save),wp.ccf.dispatcher.off("mainViewChange",this.save),this.unbind()},render:function(e){var t={};if(e){var i=e.get("type");this.currentFieldView&&(this.currentFieldView.saveField(),this.currentFieldView.destroy&&this.currentFieldView.destroy()),this.currentFieldView=new wp.ccf.views.Fields[i]({model:e,collection:this.form.get("fields")}),this.currentFieldView.render(),this.el.innerHTML="",this.el.appendChild(this.currentFieldView.el);var l=this.form.get("fields");this.listenTo(l,"remove",this.fieldRemoved)}else{var s=wp.ccf.utils.template("ccf-empty-field-template");this.el.innerHTML=s(t)}return wp.ccf.dispatcher.on("saveField",this.save,this),wp.ccf.dispatcher.on("mainViewChange",this.save,this),this}}),wp.ccf.views.FieldRowPlaceholder=wp.ccf.views.FieldRowPlaceholder||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",initialize:function(e){this.type=e.type},render:function(){return this.el.innerHTML=this.template({label:l.allLabels[this.type]}),this.el.setAttribute("data-field-type",this.type),this.el.className+=" "+this.type,this}}),wp.ccf.views.FieldRow=wp.ccf.views.FieldRow||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",events:{"click .delete":"triggerDelete","click h4":"triggerEdit",sorted:"triggerUpdateSort"},initialize:function(e){i.bindAll(this,"triggerDelete"),this.form=e.form,this.listenTo(this.model,"change",this.handleChange,this),this.listenTo(this.model,"requirementsNotMet",this.requirementsNotMet,this),this.listenTo(this.model,"requirementsMet",this.requirementsMet,this),this.listenTo(this.model,"duplicateSlug",this.duplicateSlug,this),this.model.attributes.choices&&this.listenTo(this.model.attributes.choices,"change",this.handleChange,this)},duplicateSlug:function(){this.requirementsMet(),this.el.className+=" field-duplicate-slug"},requirementsNotMet:function(){this.requirementsMet(),this.el.className+=" field-incomplete"},requirementsMet:function(){this.el.className=this.el.className.replace(/(field-incomplete|field-duplicate-slug)/i,"")},triggerUpdateSort:function(e,t){this.form.get("fields").remove(this.model),this.form.get("fields").add(this.model,{at:t})},handleChange:function(){this.render()},triggerDelete:function(e){e.stopPropagation(),this.form.get("fields").remove(this.model),this.undelegateEvents(),this.remove()},triggerEdit:function(){var e=this.el.parentNode.querySelectorAll(".ccf-editing");i.each(e,function(e){e.className=e.className.replace(/ccf-editing/i,"")}),this.el.className=this.el.className.replace(/ccf-editing/i,"")+" ccf-editing",wp.ccf.dispatcher.trigger("openEditField",this.model)},render:function(e){this.el.innerHTML=this.template({label:l.allLabels[this.model.get("type")]}),this.el.setAttribute("data-field-type",this.model.get("type"));var t=RegExp(" "+this.model.get("type"),"i");this.el.className=this.el.className.replace(t,"")+" "+this.model.get("type"),e&&(this.el.className=this.el.className.replace(/ instantiated/i,"")+" instantiated");var i=document.getElementById("ccf-"+this.model.get("type")+"-preview-template");if(i){var s=this.el.querySelectorAll(".preview")[0];s.style.display="block",s.innerHTML=wp.ccf.utils.template("ccf-"+this.model.get("type")+"-preview-template")({field:this.model.toJSON()})}return this}}),wp.ccf.views.PostFieldMapping=t.View.extend({template:wp.ccf.utils.template("ccf-post-field-mapping"),className:"field-mapping",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".field-form-field")[0].value,t=this.el.querySelectorAll(".field-post-field")[0].value,i=this.el.querySelectorAll(".field-custom-field-key"),l=this.model.get("postField");return this.model.set("formField",e),this.model.set("postField",t),i.length&&this.model.set("customFieldKey",i[0].value),l!==t&&this.render(),this}},updateFormFieldField:function(){var e=this.el.querySelectorAll(".field-form-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("formField");i.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),i.each(function(i){t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++})),0===s&&(t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},updatePostFields:function(){var e,t=this.el.querySelectorAll(".field-post-field")[0];e=document.createElement("option"),e.value="",e.innerText=l.choosePostField,t.appendChild(e);var s=this.form.get("postFieldMappings"),o=[];s.each(function(e){e!==this.model&&o.push(e.get("postField"))},this),i.each(l.postFields.single,function(i,l){-1===o.indexOf(l)&&(e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e))},this),i.each(l.postFields.repeatable,function(i,l){e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e)},this)},render:function(){var e={};this.model&&(e.mapping=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFormFieldField,this),this.listenTo(t,"remove",this.updateFormFieldField,this),this.updateFormFieldField(),this.updatePostFields(),this},triggerAdd:function(){this.form.get("postFieldMappings").add(new wp.ccf.models.PostFieldMapping)},triggerDelete:function(){var e=this.form.get("postFieldMappings");e.length>1?this.parent.deletePostFieldMapping(this):(this.model.clear().set(wp.ccf.models.PostFieldMapping.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.FormSettings=wp.ccf.views.FormSettings||t.View.extend({template:wp.ccf.utils.template("ccf-form-settings-template"),events:{"blur input":"save","change select":"save","change select.form-completion-action-type":"toggleCompletionFields","change select.form-pause":"togglePauseFields","change select.form-post-creation":"togglePostCreationFields","click .add-notification":"triggerAddNotification"},notificationViews:[],mappingViews:[],initialize:function(e){this.model=e.form,this.notificationViews=[],this.mappingViews=[];var t=this.model.get("notifications");this.listenTo(t,"add",this.addNotification);var i=this.model.get("postFieldMappings");this.listenTo(i,"add",this.addPostFieldMapping)},deletePostFieldMapping:function(e){i.each(this.mappingViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.mappingViews,t);this.model.get("postFieldMappings").remove(e.model),this.mappingViews[l].remove(),this.mappingViews.splice(l,1)}},this)},addPostFieldMapping:function(e){var t=this.el.querySelectorAll(".post-creation-mapping")[0],i=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model});this.mappingViews.push(i),t.appendChild(i.render().el)},triggerAddNotification:function(){var e=this.model.get("notifications");e.add(new wp.ccf.models.FormNotification)},closeAllNotifications:function(){i.each(this.notificationViews,function(e){e.changeContext(null,"view")})},addNotification:function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,context:"edit",parent:this}).render(),l=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];l.querySelectorAll(".no-notifications").length>0&&l.removeChild(l.firstChild),i.each(this.notificationViews,function(e){e.changeContext(null,"view")}),this.notificationViews.push(t),l.appendChild(t.el)},toggleCompletionFields:function(){var e=this.el.querySelectorAll(".form-completion-action-type")[0].value,t=this.el.querySelectorAll(".completion-message")[0],i=this.el.querySelectorAll(".completion-redirect-url")[0];"text"===e?(t.style.display="block",i.style.display="none"):(t.style.display="none",i.style.display="block")},togglePauseFields:function(){var e=this.el.querySelectorAll(".form-pause")[0].value,t=this.el.querySelectorAll(".pause-message")[0];t.style.display=parseInt(e)?"block":"none"},togglePostCreationFields:function(){var t=this.el.querySelectorAll(".form-post-creation")[0].value,i=e(this.el.querySelectorAll(".post-creation-mapping-field"));parseInt(t)?i.show():i.hide()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-title")[0].value;this.model.set("title",{raw:e});var t=this.el.querySelectorAll(".hide-title")[0].value;this.model.set("hideTitle",parseInt(t)?!0:!1);var i=this.el.querySelectorAll(".form-description")[0].value;this.model.set("description",i);var l=this.el.querySelectorAll(".form-button-text")[0].value;this.model.set("buttonText",l);var s=this.el.querySelectorAll(".form-button-class")[0].value;this.model.set("buttonClass",s);var o=this.el.querySelectorAll(".form-pause")[0].value;this.model.set("pause",parseInt(o)?!0:!1);var n=this.el.querySelectorAll(".form-require-logged-in")[0].value;this.model.set("requireLoggedIn",parseInt(n)?!0:!1);var c=this.el.querySelectorAll(".form-post-creation")[0].value;this.model.set("postCreation",parseInt(c)?!0:!1);var r=this.el.querySelectorAll(".form-post-creation-type")[0].value;this.model.set("postCreationType",r);var a=this.el.querySelectorAll(".form-post-creation-status")[0].value;this.model.set("postCreationStatus",a);var d=this.el.querySelectorAll(".form-pause-message")[0].value;this.model.set("pauseMessage",d);var u=this.el.querySelectorAll(".form-completion-message")[0].value;this.model.set("completionMessage",u);var f=this.el.querySelectorAll(".form-completion-redirect-url")[0].value;this.model.set("completionRedirectUrl",f);var p=this.el.querySelectorAll(".form-completion-action-type")[0].value;this.model.set("completionActionType",p);var h=this.el.querySelectorAll(".form-theme")[0].value;this.model.set("theme",h)}},fullSave:function(e){""!==this.el.innerHTML&&(this.save(),i.each(this.notificationViews,function(e){e.save()}),i.each(this.mappingViews,function(e){e.save()}),e!==void 0&&e.promise!==void 0&&e.resolve())},destroy:function(){wp.ccf.dispatcher.off("saveFormSettings",this.fullSave),wp.ccf.dispatcher.off("mainViewChange",this.fullSave)},deleteNotification:function(e){if(i.each(this.notificationViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.notificationViews,t);this.model.get("notifications").remove(e.model),this.notificationViews[l].remove(),this.notificationViews.splice(l,1)}},this),!this.notificationViews.length){var t=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];t.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el)}},render:function(){var e={form:this.model.toJSON()};this.model.get("fields");var t=this.model.get("notifications");this.el.innerHTML=this.template(e),this.toggleCompletionFields(),this.togglePostCreationFields(),this.togglePauseFields();var i=this.el.querySelectorAll(".ccf-form-notifications .rows")[0],l=document.createElement("tbody");l.className="rows",t.length>=1?t.each(function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,parent:this}).render();l.appendChild(t.el),this.notificationViews.push(t)},this):l.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el),i.parentNode.replaceChild(l,i);var s=this.el.querySelectorAll(".post-creation-mapping")[0],o=this.model.get("postFieldMappings");if(o.length>=1)o.each(function(e){var t=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model}).render();s.appendChild(t.el),this.mappingViews.push(t)},this);else{var n=new wp.ccf.models.PostFieldMapping;o.add(n)}return wp.ccf.dispatcher.on("mainViewChange",this.fullSave,this),wp.ccf.dispatcher.on("saveFormSettings",this.fullSave,this),this}}),wp.ccf.views.FormPane=wp.ccf.views.FormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-form-pane-template"),subViews:{"field-sidebar":wp.ccf.views.FieldSidebar,"form-settings":wp.ccf.views.FormSettings},events:{"click .save-button":"sync","click .signup-button":"signup","click .accordion-heading":"accordionClick","click .form-settings-heading":"accordionClick","click .insert-form-button":"insertForm"},initialize:function(){wp.ccf.dispatcher.on("openEditField",this.openEditField,this)},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},signup:function(){var t=this.el.querySelectorAll(".email-signup-field")[0].value,i=this.el.querySelectorAll(".bottom .left.signup")[0];i.className="left signup",t?e.ajax({url:"//taylorlovett.us8.list-manage.com/subscribe/post-json?u=66118f9a5b0ab0414e83f043a&amp;id=b4ed816a24&c=?",method:"post",dataType:"jsonp",data:{EMAIL:t}}).done(function(){i.className="left signup signup-success"}):i.className="left signup signup-error"},accordionClick:function(t){var l=e(t.currentTarget).parents(".accordion-container")[0],s=l.querySelectorAll(".accordion-section");t.currentTarget.parentNode.className.match(/expanded/i)?t.currentTarget.parentNode.className=t.currentTarget.parentNode.className.replace(/expanded/i,""):t.currentTarget.parentNode.className+=" expanded",i.each(s,function(e){e!=t.currentTarget.parentNode&&e.className.match(/expanded/i)&&(e.className=e.className.replace(/expanded/i,""))
3
  }),t.currentTarget.className.match(/form-settings-heading/i)?this.el.className.match(/show-form-settings/i)?this.el.className=this.el.className.replace(/show-form-settings/i,""):this.el.className+=" show-form-settings":this.el.className=this.el.className.replace(/show-form-settings/i,"")},openEditField:function(e){this.renderedSubViews["field-sidebar"].render(e).el.style.display="block"},disable:function(){this.el.querySelectorAll(".save-button")[0].setAttribute("disabled","disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="block"},enable:function(){this.el.querySelectorAll(".save-button")[0].removeAttribute("disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="none"},sync:function(){var t=this,i=e(this.el.querySelectorAll(".spinner")[0]);i.fadeIn(),t.disable();var s=e.Deferred(),o=e.Deferred();wp.ccf.dispatcher.trigger("saveFormSettings",s),wp.ccf.dispatcher.trigger("saveField",o),e.when(s,o).then(function(){var e=t.model.get("fields"),s=!0,o={};e.each(function(e){var t=e.get("slug");e.hasRequiredAttributes()?t&&!t.match(/^[a-zA-Z0-9\-_]+$/)?(s=!1,e.trigger("requirementsNotMet")):o[e.get("slug")]!==void 0?(s=!1,e.trigger("duplicateSlug"),o[e.get("slug")].trigger("duplicateSlug")):e.trigger("requirementsMet"):(s=!1,e.trigger("requirementsNotMet")),e.get("slug")&&(o[e.get("slug")]=e)}),s?t.model.save({},{context:"edit"}).error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}).done(function(){l.single&&!l.postId&&(window.location=l.adminUrl+"post.php?post="+t.model.get("id")+"&action=edit#ccf-form/"+t.model.get("id"))}).complete(function(){i.fadeOut(),t.enable(),wp.ccf.dispatcher.trigger("saveFormComplete",t.model)}):(t.enable(),i.fadeOut())})},enableDisableInsert:function(){var e=this.el.querySelectorAll(".insert-form-button")[0];this.model.get("id")?e.removeAttribute("disabled"):e.setAttribute("disabled","disabled")},getNextFieldOrd:function(){var e=this.model.get("fields"),t=e.length+1;return e.each(function(e){var i=e.get("slug"),l=/\-([0-9]+)$/g,s=l.exec(i);if(s&&s[1]){var o=parseInt(s[1]);o>=t&&(t=o+1)}}),t},render:function(t){var s=this;s.model=t?t:new wp.ccf.models.Form,this.listenTo(s.model,"change",this.enableDisableInsert,this);var o={labels:l.fieldLabels,form:s.model.toJSON()};window.form=s.model,s.el.innerHTML=this.template(o),s.el.className=s.el.className.replace(/show-form-settings/i,"");var n=s.el.querySelectorAll(".fields")[0];i.each(l.fieldLabels,function(e,t){n.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var c=s.el.querySelectorAll(".structure-fields")[0];i.each(l.structureFieldLabels,function(e,t){c.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var r=s.el.querySelectorAll(".special-fields")[0];i.each(l.specialFieldLabels,function(e,t){r.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var a=s.model.get("fields"),d=s.el.querySelectorAll(".form-content")[0],u=e(d);return e(s.el.querySelectorAll(".left-sidebar")[0].querySelectorAll(".field")).draggable({cursor:"move",distance:2,zIndex:160001,scroll:!1,containment:"document",appendTo:".ccf-main-modal",snap:!1,connectToSortable:".form-content",helper:function(t){var i=e(t.currentTarget),l=e('<div class="field" data-field-type="'+i.attr("data-field-type")+'"><h4>'+i.find(".label").html()+"</h4></div>");return l.css({width:u.width(),opacity:".75",height:i.height()})}}),a.length>=1&&(d.innerHTML="",a.each(function(e){var t=new wp.ccf.views.FieldRow({model:e,form:s.model}).render(!0).el;d.appendChild(t)})),e(d).sortable({axis:"y",distance:2,handle:"h4",placeholder:"field-placeholder",stop:function(e,t){if(!t.item.hasClass("instantiated")){var i=t.item.attr("data-field-type"),l={};wp.ccf.models.Fields[i].prototype.defaults().slug!==void 0&&(l.slug=i+"-"+s.getNextFieldOrd());var o=new wp.ccf.models.Fields[i](l),n=s.model.get("fields");n.add(o),new wp.ccf.views.FieldRow({model:o,el:t.item,form:s.model}).render(!0),t.item.attr("style","")}t.item.trigger("sorted",t.item.index())}}),s.initRenderSubViews(!1,!0,{form:s.model}),s.enableDisableInsert(),s}},wp.ccf.mixins.subViewable)),wp.ccf.views.ExistingFormTableRow=wp.ccf.views.ExistingFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-existing-form-table-row-template"),events:{"click .edit":"triggerMainViewChange","click .delete":"triggerDelete","click .duplicate":"triggerDuplicate","click .insert-form-button":"insertForm"},initialize:function(e){this.parent=e.parent},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},triggerMainViewChange:function(){wp.ccf.switchToForm(this.model)},triggerDelete:function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},triggerDuplicate:function(){var e=this,t=e.parent.collection.state.currentPage;e.model.clone().set("title",{raw:e.model.get("title").raw+" (Duplicate)"}).unset("id").save().done(function(){e.parent.showPage(t).done(function(){e.parent.renderPagination()})})},render:function(){return this.$el.html(this.template({form:this.model.toJSON(),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate}})),this}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.ExistingFormTable=wp.ccf.views.ExistingFormTable||t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-table-template"),initialize:function(){this.parent=arguments.parent,this.collection=new wp.ccf.collections.Forms,wp.ccf.dispatcher.on("changeFormTablePage",this.showPage,this),wp.ccf.dispatcher.on("saveFormComplete",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".rows")[0],i=document.createElement("tbody");i.className="rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.ExistingFormTableRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild((new wp.ccf.views.EmptyFormTableRow).render().el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(){var e=this;return this.el.innerHTML=this.template(),this.el.querySelectorAll(".ccf-pagination")[0],this.showPage(1).done(function(){e.renderPagination()}),this}}),wp.ccf.views.ExistingFormPane=wp.ccf.views.ExistingFormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-existing-form-pane-template"),subViews:{"existing-form-table":wp.ccf.views.ExistingFormTable},render:function(){return this.rendered?this:(this.rendered=!0,this.el.innerHTML=this.template(),this.initRenderSubViews(!0),this)}},wp.ccf.mixins.subViewable)),wp.ccf.views.MainModal=wp.ccf.views.MainModal||t.View.extend(i.defaults({tagName:"div",className:"ccf-main-modal",template:wp.ccf.utils.template("ccf-main-modal-template"),events:{"click .close-icon":"hide","click .main-menu a":"menuClick"},subViews:{"form-pane":wp.ccf.views.FormPane},initialize:function(){l.single||(this.subViews["existing-form-pane"]=wp.ccf.views.ExistingFormPane),wp.ccf.dispatcher.on("mainViewChange",this.toggleView,this)},toggleView:function(e){this.showView(e,wp.ccf.currentForm);var t=e;"form-pane"===e&&wp.ccf.currentForm&&(t="existing-form-pane");var l=this.el.querySelectorAll(".menu-item");i.each(l,function(e){var i=e.getAttribute("data-view");e.className=i===t?e.className.replace("selected","")+" selected":e.className.replace("selected","")})},menuClick:function(e){var t=e.currentTarget.getAttribute("data-view");"form-pane"===t&&(wp.ccf.currentForm=null),wp.ccf.dispatcher.trigger("mainViewChange",t),e.preventDefault()},render:function(e){return e=e||!1,this.overlay(),this.el.innerHTML=this.template({single:e}),this.initRenderSubViews(),this.showView("form-pane",wp.ccf.currentForm,!0),this},overlay:function(){return this.overlayEl===void 0&&(this.overlayEl=document.createElement("div"),this.overlayEl.className="ccf-main-modal-overlay",document.body.appendChild(this.overlayEl)),this.overlayEl},remove:function(){return document.body.removeChild(this.overlay()),this},show:function(){e(this.overlay()).show(),this.$el.show()},hide:function(){e(this.overlay()).hide(),this.$el.hide()}},wp.ccf.mixins.subViewable)),wp.ccf.views.SubmissionRow=wp.ccf.views.SubmissionRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-submission-row-template"),events:{"click .view":"view","click .delete":"delete"},initialize:function(e){this.parent=e.parent},"delete":function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},view:function(e){var t=e.currentTarget.getAttribute("data-submission-id"),i=e.currentTarget.getAttribute("data-submission-date");tb_show(l.thickboxTitle+" - "+wp.ccf.utils.getPrettyPostDate(i),"#TB_inline?height=500&amp;width=700&amp;inlineId=ccf-submission-content-"+parseInt(t),null)},render:function(){return this.$el.html(this.template({submission:this.model.toJSON(),currentColumns:this.parent.columns,columns:wp.ccf.currentForm.getFieldSlugs(!0),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate,wordChop:wp.ccf.utils.wordChop,isFieldDate:wp.ccf.utils.isFieldDate,isFieldName:wp.ccf.utils.isFieldName,isFieldFile:wp.ccf.utils.isFieldFile,isFieldAddress:wp.ccf.utils.isFieldAddress,isFieldEmailConfirm:wp.ccf.utils.isFieldEmailConfirm,getPrettyFieldDate:wp.ccf.utils.getPrettyFieldDate,getPrettyFieldAddress:wp.ccf.utils.getPrettyFieldAddress,getPrettyFieldName:wp.ccf.utils.getPrettyFieldName,getPrettyFieldEmailConfirm:wp.ccf.utils.getPrettyFieldEmailConfirm}})),this}}),wp.ccf.views.SubmissionsTable=wp.ccf.views.SubmissionsTable||t.View.extend({template:wp.ccf.utils.template("ccf-submission-table-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(){this.collection=new wp.ccf.collections.Submissions({},{formId:l.postId}),wp.ccf.dispatcher.on("submissionTableRebuild",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".submission-rows")[0],i=document.createElement("tbody");i.className="submission-rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.SubmissionRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild(new wp.ccf.views.EmptySubmissionTableRow({parent:t}).render(wp.ccf.currentForm.getFieldSlugs(!0).concat("date")).el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(e){var t=this;return t.columns=e?e:wp.ccf.currentForm.getFieldSlugs(!0).slice(0,4).concat("date"),1>t.columns.length?t.el.innerHTML="":(t.el.innerHTML=t.template({columns:t.columns}),t.el.querySelectorAll(".ccf-pagination")[0],t.showPage(1).done(function(){t.renderPagination()})),t}}),wp.ccf.views.ErrorModal=wp.ccf.views.ErrorModal||t.View.extend({template:wp.ccf.utils.template("ccf-error-modal-template"),tagName:"div",className:"ccf-error-modal",events:{"click .close":"hide"},hide:function(){this.el.className=this.el.className.replace(" show","")},show:function(){this.el.className=this.el.className.replace(" show","")+" show"},toggle:function(){this.el.className.match(" show")?this.hide():this.show()},render:function(e){var t={messageType:""};return e&&(t.messageType=e),this.el.innerHTML=this.template(t),this}}),wp.ccf.views.Pagination=wp.ccf.views.Pagination||t.View.extend({template:wp.ccf.utils.template("ccf-pagination-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(e){this.parent=e.parent},previousPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage-1).done(function(){e.render()})},nextPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage+1).done(function(){e.render()})},firstPage:function(){var e=this;e.parent.showPage(1).done(function(){e.render()})},lastPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.totalPages).done(function(){e.render()})},render:function(){return this.el.innerHTML=this.template({totalPages:this.parent.collection.state.totalPages,currentPage:this.parent.collection.state.currentPage,totalObjects:this.parent.collection.state.totalObjects}),this}}),wp.ccf.views.EmptySubmissionTableRow=wp.ccf.views.EmptySubmissionTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-no-submissions-row-template"),initialize:function(e){this.parent=e.parent},render:function(){return this.el.innerHTML=this.template({columns:this.parent.columns}),this}}),wp.ccf.views.SubmissionColumnController=wp.ccf.views.SubmissionColumnController||t.View.extend({template:wp.ccf.utils.template("ccf-submissions-controller-template"),events:{"click input[type=checkbox]":"triggerTableRebuild"},render:function(){this.el.innerHTML=this.template({columns:wp.ccf.currentForm.getFieldSlugs(!0).concat("date")})},triggerTableRebuild:function(){var e=[],t=document.querySelectorAll(".submission-column-checkbox");if(t.length>=1)for(var i=0;t.length>i;i++)t[i].checked&&e.push(t[i].value);wp.ccf.dispatcher.trigger("submissionTableRebuild",e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t){"use strict";wp.ccf.router=wp.ccf.router||t.Router.extend({routes:{"ccf-form":"open","ccf-form/:formId":"open"},open:function(e){wp.ccf.show(e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf=i.defaults(wp.ccf,{forms:new wp.ccf.collections.Forms,currentForm:null,errorModal:null,_currentFormDeferred:null,dispatcher:{},show:function(e){return this.switchToForm(e),this.instance.show(),this.instance},initErrorModal:function(){this.errorModal=(new wp.ccf.views.ErrorModal).render();var e=document.getElementsByTagName("body")[0];e.appendChild(this.errorModal.el)},switchToForm:function(e){var t=this;if(+e===parseInt(e)){var i=parseInt(e);if(e=t.forms.findWhere({id:parseInt(i)}),!e){var l;return t.forms.formsFetching[i]!==void 0?(l=t.forms.formsFetching[i],e=null):(e=new wp.ccf.models.Form({id:i}),l=e.fetch(),t.forms.formsFetching[i]=l),l.done(function(){e?(delete t.forms.formsFetching[i],t.forms.add(e)):e=t.forms.findWhere({id:i}),t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}),l}t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}else t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane");return!0},hide:function(){return this.instance.hide(),this.instance},toggle:function(e){return this.switchToForm(e),this.instance.$el.is(":visible")?this.instance.hide():this.instance.show(),this.instance},createSubmissionsTable:function(e){var t=document.querySelectorAll(".ccf-submission-column-controller"),i=new wp.ccf.views.SubmissionsTable({el:e});i.render(),t&&new wp.ccf.views.SubmissionColumnController({el:t}).render()},_setupMainModal:function(e){return this.instance=(new wp.ccf.views.MainModal).render(e),document.getElementsByTagName("body")[0].appendChild(this.instance.el),t.history.start(),this.instance},createManager:function(){var s=this,o=document.querySelectorAll(".ccf-open-form-manager")[0];if(!o)return!1;i.extend(this.dispatcher,t.Events),new wp.ccf.router,s.initErrorModal();var n=!1;if(l.single)if(n=!0,l.postId){var c=parseInt(l.postId);if(s.forms.formsFetching[c]===void 0){var r=new wp.ccf.models.Form({id:c}),a=r.fetch();s.forms.formsFetching[c]=a,s._currentFormDeferred=a,a.done(function(){delete s.forms.formsFetching[c],s.forms.add(r),s.currentForm=r})}else s._currentFormDeferred=s.forms.formsFetching[c],s._currentFormDeferred.done(function(){s.currentForm=s.forms.findWhere({id:c})});e.when(s._currentFormDeferred).then(function(){s._setupMainModal(!0),o.style.display="inline-block";var e=document.getElementById("ccf-submissions");if(e){var t=e.querySelectorAll(".inside")[0],i=document.createElement("div");i.className="ccf-submission-icon",i.setAttribute("data-icon","");var n=document.createElement("a");n.href="?action=edit&post="+parseInt(l.postId)+"&download_submissions=1&download_submissions_nonce="+l.downloadSubmissionsNonce,n.className="ccf-submission-icon",n.setAttribute("data-icon","");var c=document.getElementById("show-settings-link");i.onclick=function(){c.click()},e.insertBefore(i,e.firstChild.nextSibling.nextSibling),e.insertBefore(n,e.firstChild.nextSibling.nextSibling),wp.ccf.createSubmissionsTable(t);var r=document.querySelectorAll("#major-publishing-actions .duplicate")[0],a=function(e){e=e||window.event,e.preventDefault(),s.currentForm.clone().set("title",{raw:s.currentForm.get("title").raw+" (duplicate)"}).unset("id").save().done(function(e){document.location=l.adminUrl+"/post.php?action=edit&post="+e.id})};r.addEventListener?r.addEventListener("click",a,!1):r.attachEvent("onclick",a)}})}else s._setupMainModal(!0),o.style.display="inline-block";else s._setupMainModal();var d=function(e){e=e||window.event;var t=e.currentTarget?e.currentTarget:e.srcElement,i=t.getAttribute("data-form-id");wp.ccf.toggle(i)};o.addEventListener?o.addEventListener("click",d,!1):o.attachEvent("onclick",d)}}),wp.ccf.createManager()}(jQuery,Backbone,_,ccfSettings);
assets/js/manager/collections.js CHANGED
@@ -14,7 +14,7 @@
14
 
15
  wp.ccf.collections = wp.ccf.collections || {};
16
 
17
- wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.api.collections.Posts.extend(
18
  {
19
  model: wp.ccf.models.Form,
20
 
@@ -50,7 +50,7 @@
50
  }
51
  );
52
 
53
- wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.api.collections.Posts.extend(
54
  {
55
  model: wp.ccf.models.Field,
56
 
@@ -86,7 +86,7 @@
86
  }
87
  );
88
 
89
- wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.api.collections.Posts.extend(
90
  {
91
  model: wp.ccf.models.Submission,
92
 
14
 
15
  wp.ccf.collections = wp.ccf.collections || {};
16
 
17
+ wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.ccf.api.collections.Posts.extend(
18
  {
19
  model: wp.ccf.models.Form,
20
 
50
  }
51
  );
52
 
53
+ wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.ccf.api.collections.Posts.extend(
54
  {
55
  model: wp.ccf.models.Field,
56
 
86
  }
87
  );
88
 
89
+ wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.ccf.api.collections.Posts.extend(
90
  {
91
  model: wp.ccf.models.Submission,
92
 
assets/js/manager/models.js CHANGED
@@ -184,7 +184,7 @@
184
  }
185
  );
186
 
187
- wp.ccf.models.Form = wp.ccf.models.Form || wp.api.models.Post.extend(
188
  {
189
 
190
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
@@ -229,7 +229,7 @@
229
  },
230
 
231
  decode: function() {
232
- var keys = _.keys( wp.api.models.Post.prototype.defaults );
233
  keys = _.without( keys, 'title' );
234
 
235
  return _modelDecode.call( this, keys );
@@ -438,7 +438,7 @@
438
  }
439
  );
440
 
441
- wp.ccf.models.Submission = wp.api.models.Submission || wp.api.models.Post.extend(
442
  {
443
  defaults: {
444
  id: null,
@@ -452,7 +452,7 @@
452
  }
453
  );
454
 
455
- wp.ccf.models.Field = wp.api.models.Field || wp.api.models.Post.extend(
456
  {
457
  idAttribute: 'id',
458
 
@@ -488,7 +488,7 @@
488
  },
489
 
490
  decode: function() {
491
- return _modelDecode.call( this, _.keys( wp.api.models.Post.prototype.defaults ) );
492
  },
493
 
494
  hasRequiredAttributes: function() {
184
  }
185
  );
186
 
187
+ wp.ccf.models.Form = wp.ccf.models.Form || wp.ccf.api.models.Post.extend(
188
  {
189
 
190
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
229
  },
230
 
231
  decode: function() {
232
+ var keys = _.keys( wp.ccf.api.models.Post.prototype.defaults );
233
  keys = _.without( keys, 'title' );
234
 
235
  return _modelDecode.call( this, keys );
438
  }
439
  );
440
 
441
+ wp.ccf.models.Submission = wp.ccf.api.models.Submission || wp.ccf.api.models.Post.extend(
442
  {
443
  defaults: {
444
  id: null,
452
  }
453
  );
454
 
455
+ wp.ccf.models.Field = wp.ccf.api.models.Field || wp.ccf.api.models.Post.extend(
456
  {
457
  idAttribute: 'id',
458
 
488
  },
489
 
490
  decode: function() {
491
+ return _modelDecode.call( this, _.keys( wp.ccf.api.models.Post.prototype.defaults ) );
492
  },
493
 
494
  hasRequiredAttributes: function() {
assets/js/manager/utils.js CHANGED
@@ -117,18 +117,22 @@
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
- format = 'HH:mm MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
- format = 'HH:mm DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
 
128
  }
129
 
130
  if ( value.date ) {
131
- dateString += ' ' + value.date;
 
 
 
132
  }
133
 
134
  if ( ! dateString ) {
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
+ format = 'MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
+ format = 'DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
128
+ format = 'HH:mm ' + format;
129
  }
130
 
131
  if ( value.date ) {
132
+ if ( dateString ) {
133
+ dateString += ' ';
134
+ }
135
+ dateString += value.date;
136
  }
137
 
138
  if ( ! dateString ) {
bin/production-ready.sh DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- echo "Are you sure you want to do this? Uncommitted work could be lost. [y/n]"
4
- read input_variable
5
-
6
- if [ "$input_variable" == "y" ]; then
7
- DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
8
-
9
- cd "$DIR/../"
10
-
11
- rm bin/install-wp-tests.sh > /dev/null 2>&1
12
-
13
- rm -rf bower_components > /dev/null 2>&1
14
- rm -rf node_modules > /dev/null 2>&1
15
- rm -rf scss > /dev/null 2>&1
16
- rm -rf tests > /dev/null 2>&1
17
- rm -rf .sass-cache > /dev/null 2>&1
18
-
19
- rm .travis.yml > /dev/null 2>&1
20
- rm codeception.yml > /dev/null 2>&1
21
- rm Gruntfile.js > /dev/null 2>&1
22
- rm Dockunit.json > /dev/null 2>&1
23
- rm composer.json > /dev/null 2>&1
24
- rm Dockunit.json > /dev/null 2>&1
25
- rm composer.lock > /dev/null 2>&1
26
- rm phpunit.xml > /dev/null 2>&1
27
- rm .jshintrc > /dev/null 2>&1
28
-
29
- bower install --production > /dev/null 2>&1
30
-
31
- echo "Done! Custom Contact Forms is cleaned up and production ready."
32
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/js/form-manager.js CHANGED
@@ -117,18 +117,22 @@
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
- format = 'HH:mm MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
- format = 'HH:mm DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
 
128
  }
129
 
130
  if ( value.date ) {
131
- dateString += ' ' + value.date;
 
 
 
132
  }
133
 
134
  if ( ! dateString ) {
@@ -392,7 +396,8 @@
392
  return {
393
  title: '',
394
  content: '[all_fields]',
395
- active: false,
 
396
  addresses: new wp.ccf.collections.FormNotificationAddresses(),
397
  fromType: 'default',
398
  fromAddress: '',
@@ -402,7 +407,16 @@
402
  subjectField: '',
403
  fromNameType: 'custom',
404
  fromName: 'WordPress',
405
- fromNameField: ''
 
 
 
 
 
 
 
 
 
406
  };
407
  },
408
 
@@ -439,7 +453,7 @@
439
  }
440
  );
441
 
442
- wp.ccf.models.Form = wp.ccf.models.Form || wp.api.models.Post.extend(
443
  {
444
 
445
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
@@ -459,6 +473,7 @@
459
  fields: new wp.ccf.collections.Fields(),
460
  type: 'ccf_form',
461
  status: 'publish',
 
462
  description: '',
463
  buttonText: 'Submit Form',
464
  buttonClass: '',
@@ -471,6 +486,7 @@
471
  postFieldMappings: new wp.ccf.collections.PostFieldMappings(),
472
  notifications: new wp.ccf.collections.FormNotifications(),
473
  pause: false,
 
474
  pauseMessage: ccfSettings.pauseMessage,
475
  theme: 'none'
476
  };
@@ -482,7 +498,7 @@
482
  },
483
 
484
  decode: function() {
485
- var keys = _.keys( wp.api.models.Post.prototype.defaults );
486
  keys = _.without( keys, 'title' );
487
 
488
  return _modelDecode.call( this, keys );
@@ -691,7 +707,7 @@
691
  }
692
  );
693
 
694
- wp.ccf.models.Submission = wp.api.models.Submission || wp.api.models.Post.extend(
695
  {
696
  defaults: {
697
  id: null,
@@ -705,7 +721,7 @@
705
  }
706
  );
707
 
708
- wp.ccf.models.Field = wp.api.models.Field || wp.api.models.Post.extend(
709
  {
710
  idAttribute: 'id',
711
 
@@ -741,7 +757,7 @@
741
  },
742
 
743
  decode: function() {
744
- return _modelDecode.call( this, _.keys( wp.api.models.Post.prototype.defaults ) );
745
  },
746
 
747
  hasRequiredAttributes: function() {
@@ -962,6 +978,25 @@
962
  }
963
  );
964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
  wp.ccf.models.Fields.address = wp.ccf.models.Fields.address || wp.ccf.models.StandardField.extend(
966
  {
967
  defaults: function() {
@@ -1034,7 +1069,8 @@
1034
  {
1035
  defaults: function() {
1036
  var defaults = {
1037
- choices: new wp.ccf.collections.FieldChoices()
 
1038
  };
1039
 
1040
  return _.defaults( defaults, this.constructor.__super__.defaults() );
@@ -1124,7 +1160,7 @@
1124
 
1125
  wp.ccf.collections = wp.ccf.collections || {};
1126
 
1127
- wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.api.collections.Posts.extend(
1128
  {
1129
  model: wp.ccf.models.Form,
1130
 
@@ -1160,7 +1196,7 @@
1160
  }
1161
  );
1162
 
1163
- wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.api.collections.Posts.extend(
1164
  {
1165
  model: wp.ccf.models.Field,
1166
 
@@ -1196,7 +1232,7 @@
1196
  }
1197
  );
1198
 
1199
- wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.api.collections.Posts.extend(
1200
  {
1201
  model: wp.ccf.models.Submission,
1202
 
@@ -1270,11 +1306,20 @@
1270
  }
1271
 
1272
  var label = this.el.querySelectorAll( '.choice-label' )[0].value;
1273
- var value = this.el.querySelectorAll( '.choice-value' )[0].value;
 
 
 
 
 
1274
 
1275
  this.model.set( 'label', label );
1276
  this.model.set( 'value', value );
1277
 
 
 
 
 
1278
  var selectedElement = this.el.querySelectorAll( '.choice-selected' )[0];
1279
  var selected = ( selectedElement.checked ) ? true : false;
1280
 
@@ -1285,7 +1330,9 @@
1285
  },
1286
 
1287
  render: function() {
1288
- var context = {};
 
 
1289
  if ( this.model ) {
1290
  context.choice = this.model.toJSON();
1291
  }
@@ -1381,7 +1428,7 @@
1381
  if ( this.field.get( 'slug' ) !== field.get( 'slug' ) ) {
1382
  var type = field.get( 'type' );
1383
 
1384
- if ( 'address' !== type && 'date' !== type && 'name' !== type && 'file' !== type && 'recaptcha' !== type && 'section-header' !== type && 'html' !== type ) {
1385
  option = document.createElement( 'option' );
1386
  option.innerHTML = field.get( 'slug' );
1387
  option.value = field.get( 'slug' );
@@ -1633,6 +1680,8 @@
1633
  events: {
1634
  'change select.form-email-notification-from-type': 'toggleNotificationFields',
1635
  'change select.form-email-notification-from-name-type': 'toggleNotificationFields',
 
 
1636
  'change select.form-email-notification-subject-type': 'toggleNotificationFields',
1637
  'click .close-notification': 'changeContext',
1638
  'click .edit-notification': 'changeContext',
@@ -1707,7 +1756,7 @@
1707
  fields.each( function( field ) {
1708
  type = field.get( 'type' );
1709
 
1710
- if ( 'html' !== type && 'section-header' !== type && 'recaptcha' !== type ) {
1711
  variablesText += '[' + field.get( 'slug' ) + '] ';
1712
  }
1713
  } );
@@ -1724,6 +1773,10 @@
1724
  emailNotificationFromField.innerHTML = '';
1725
  emailNotificationFromField.disabled = false;
1726
 
 
 
 
 
1727
  var emailNotificationSubjectField = this.el.querySelectorAll( '.form-email-notification-subject-field' )[0];
1728
  emailNotificationSubjectField.innerHTML = '';
1729
  emailNotificationSubjectField.disabled = false;
@@ -1732,15 +1785,22 @@
1732
  emailNotificationFromNameField.innerHTML = '';
1733
  emailNotificationFromNameField.disabled = false;
1734
 
 
 
 
 
1735
  var fields = this.form.get( 'fields' ),
1736
  addressFieldsAdded = 0,
1737
  nameFieldsAdded = 0,
1738
  subjectFieldsAdded = 0;
1739
 
1740
- var addressField = this.model.get( 'emailNotificationFromField' );
1741
- var subjectField = this.model.get( 'emailNotificationSubjectField' );
1742
- var nameField = this.model.get( 'emailNotificationFromNameField' ),
1743
- option;
 
 
 
1744
 
1745
  if ( fields.length >= 1 ) {
1746
  fields.each( function( field ) {
@@ -1755,6 +1815,16 @@
1755
 
1756
  emailNotificationFromField.appendChild( option );
1757
 
 
 
 
 
 
 
 
 
 
 
1758
  addressFieldsAdded++;
1759
  } if ( 'name' === field.get( 'type' ) || 'single-line-text' === field.get( 'type' ) || 'radio' === field.get( 'type' ) || 'dropdown' === field.get( 'type' ) ) {
1760
  option = document.createElement( 'option' );
@@ -1767,6 +1837,16 @@
1767
 
1768
  emailNotificationFromNameField.appendChild( option );
1769
 
 
 
 
 
 
 
 
 
 
 
1770
  nameFieldsAdded++;
1771
  } if ( 'single-line-text' === field.get( 'type' ) || 'radio' === field.get( 'type' ) || 'dropdown' === field.get( 'type' ) ) {
1772
  // @Todo: add more applicable fields
@@ -1792,6 +1872,12 @@
1792
  option.value = '';
1793
  emailNotificationFromField.appendChild( option );
1794
  emailNotificationFromField.disabled = true;
 
 
 
 
 
 
1795
  }
1796
 
1797
  if ( 0 === nameFieldsAdded ) {
@@ -1832,6 +1918,24 @@
1832
 
1833
  var emailNotificationFromNameType = this.el.querySelectorAll( '.form-email-notification-from-name-type' )[0];
1834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1835
  emailNotificationFromAddress.style.display = 'none';
1836
  emailNotificationFromField.style.display = 'none';
1837
 
@@ -1858,6 +1962,24 @@
1858
  } else if ( 'field' === emailNotificationFromNameType.value ) {
1859
  emailNotificationFromNameField.style.display = 'block';
1860
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1861
  },
1862
 
1863
  save: function() {
@@ -1879,6 +2001,9 @@
1879
  var emailNotificationActive = this.el.querySelectorAll( '.form-email-notification-active' )[0].value;
1880
  this.model.set( 'active', ( '1' === emailNotificationActive ) ? true : false );
1881
 
 
 
 
1882
  var emailNotificationFromType = this.el.querySelectorAll( '.form-email-notification-from-type' )[0].value;
1883
  this.model.set( 'fromType', emailNotificationFromType );
1884
 
@@ -1897,6 +2022,24 @@
1897
  var emailNotificationFromNameField = this.el.querySelectorAll( '.form-email-notification-from-name-field' )[0].value;
1898
  this.model.set( 'fromNameField', emailNotificationFromNameField );
1899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1900
  var emailNotificationSubjectType = this.el.querySelectorAll( '.form-email-notification-subject-type' )[0].value;
1901
  this.model.set( 'subjectType', emailNotificationSubjectType );
1902
 
@@ -2021,20 +2164,24 @@
2021
  },
2022
 
2023
  saveField: function() {
2024
- var conditionals = this.el.querySelectorAll( '.conditionals' )[0].querySelectorAll( '.conditional' );
2025
 
2026
- _.each( conditionals, function( conditional ) {
2027
- $( conditional ).trigger( 'saveConditional' );
2028
- });
2029
 
2030
- this.model.set( 'conditionalType', this.el.querySelectorAll( '.field-conditional-type' )[0].value );
2031
- this.model.set( 'conditionalFieldsRequired', this.el.querySelectorAll( '.field-conditional-fields-required' )[0].value );
 
 
 
 
2032
 
2033
- var oldConditionals = this.model.get( 'conditionalsEnabled' );
2034
- this.model.set( 'conditionalsEnabled', ( this.el.querySelectorAll( '.field-conditionals-enabled' )[0].value == 1 ) ? true : false );
2035
 
2036
- if ( oldConditionals !== this.model.get( 'conditionalsEnabled' ) ) {
2037
- this.render( 'advanced' );
 
2038
  }
2039
  },
2040
 
@@ -2047,17 +2194,20 @@
2047
 
2048
  var conditionalsCollection = this.model.get( 'conditionals' );
2049
 
2050
- var conditionals = this.el.querySelectorAll( '.conditionals' )[0];
2051
 
2052
- if ( conditionalsCollection.length >= 1 ) {
2053
 
2054
- conditionalsCollection.each( function( model ) {
2055
- var view = new wp.ccf.views.FieldConditional( { model: model, field: this.model, fieldCollection: this.collection } ).render();
2056
- conditionals.appendChild( view.el );
2057
- }, this );
2058
- } else {
2059
- var conditional = new wp.ccf.models.FieldConditional();
2060
- conditionalsCollection.add( conditional );
 
 
 
2061
  }
2062
 
2063
  return this;
@@ -2138,6 +2288,28 @@
2138
  }
2139
  );
2140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2141
  wp.ccf.views.Fields['section-header'] = wp.ccf.views.Fields['section-header'] || wp.ccf.views.FieldBase.extend(
2142
  {
2143
  template: wp.ccf.utils.template( 'ccf-section-header-template' ),
@@ -2358,10 +2530,23 @@
2358
  this.model.set( 'slug', this.el.querySelectorAll( '.field-slug' )[0].value );
2359
  this.model.set( 'label', this.el.querySelectorAll( '.field-label' )[0].value );
2360
  this.model.set( 'description', this.el.querySelectorAll( '.field-description' )[0].value );
 
 
 
2361
  this.model.set( 'addressType', this.el.querySelectorAll( '.field-address-type' )[0].value );
 
 
 
 
 
 
2362
  this.model.set( 'className', this.el.querySelectorAll( '.field-class-name' )[0].value );
2363
  this.model.set( 'required', ( this.el.querySelectorAll( '.field-required' )[0].value == 1 ) ? true : false );
2364
 
 
 
 
 
2365
  this.constructor.__super__.saveField.apply( this, arguments );
2366
 
2367
  return this;
@@ -2428,12 +2613,17 @@
2428
  choices.appendChild( view.el );
2429
  },
2430
 
2431
- saveField: function() {
2432
  // @todo: fix this ie8 hack
2433
  if ( this.el.innerHTML === '' ) {
2434
  return;
2435
  }
2436
 
 
 
 
 
 
2437
  this.model.set( 'slug', this.el.querySelectorAll( '.field-slug' )[0].value );
2438
  this.model.set( 'label', this.el.querySelectorAll( '.field-label' )[0].value );
2439
  this.model.set( 'description', this.el.querySelectorAll( '.field-description' )[0].value );
@@ -2448,6 +2638,15 @@
2448
  $( choice ).trigger( 'saveChoice' );
2449
  });
2450
 
 
 
 
 
 
 
 
 
 
2451
  return this;
2452
 
2453
  },
@@ -2457,6 +2656,8 @@
2457
 
2458
  startPanel = ( startPanel ) ? startPanel : 'basic';
2459
 
 
 
2460
  SELF.el.innerHTML = SELF.template( { field: SELF.model.toJSON(), startPanel: startPanel } );
2461
 
2462
  SELF.checkSlug();
@@ -3017,6 +3218,9 @@
3017
  var title = this.el.querySelectorAll( '.form-title' )[0].value;
3018
  this.model.set( 'title', { raw: title } );
3019
 
 
 
 
3020
  var description = this.el.querySelectorAll( '.form-description' )[0].value;
3021
  this.model.set( 'description', description );
3022
 
@@ -3029,6 +3233,9 @@
3029
  var pause = this.el.querySelectorAll( '.form-pause' )[0].value;
3030
  this.model.set( 'pause', ( parseInt( pause ) ) ? true : false );
3031
 
 
 
 
3032
  var postCreation = this.el.querySelectorAll( '.form-post-creation' )[0].value;
3033
  this.model.set( 'postCreation', ( parseInt( postCreation ) ) ? true : false );
3034
 
@@ -3448,6 +3655,7 @@
3448
  events: {
3449
  'click .edit': 'triggerMainViewChange',
3450
  'click .delete': 'triggerDelete',
 
3451
  'click .insert-form-button': 'insertForm'
3452
  },
3453
 
@@ -3483,6 +3691,22 @@
3483
  });
3484
  },
3485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3486
  render: function() {
3487
  this.$el.html( this.template( { form: this.model.toJSON(), utils: { getPrettyPostDate: wp.ccf.utils.getPrettyPostDate } } ) );
3488
  return this;
@@ -3641,7 +3865,7 @@
3641
  },
3642
 
3643
  menuClick: function( event ) {
3644
- var view = event.target.getAttribute( 'data-view' );
3645
 
3646
  if ( 'form-pane' === view ) {
3647
  wp.ccf.currentForm = null;
@@ -4188,6 +4412,27 @@
4188
  metabox.insertBefore( download, metabox.firstChild.nextSibling.nextSibling );
4189
 
4190
  wp.ccf.createSubmissionsTable( container );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4191
  }
4192
  });
4193
  } else {
117
  wp.ccf.utils.getPrettyFieldDate = function( value, field ) {
118
  var dateString = '',
119
  output = '',
120
+ format = 'MM/DD/YY';
121
 
122
  if ( field && field.ccf_field_dateFormat && 'dd/mm/yyyy' === field.ccf_field_dateFormat ) {
123
+ format = 'DD/MM/YY';
124
  }
125
 
126
  if ( value.hour && value.minute && value['am-pm'] ) {
127
  dateString += value.hour + ':' + value.minute + ' ' + value['am-pm'];
128
+ format = 'HH:mm ' + format;
129
  }
130
 
131
  if ( value.date ) {
132
+ if ( dateString ) {
133
+ dateString += ' ';
134
+ }
135
+ dateString += value.date;
136
  }
137
 
138
  if ( ! dateString ) {
396
  return {
397
  title: '',
398
  content: '[all_fields]',
399
+ active: true,
400
+ includeUploads: true,
401
  addresses: new wp.ccf.collections.FormNotificationAddresses(),
402
  fromType: 'default',
403
  fromAddress: '',
407
  subjectField: '',
408
  fromNameType: 'custom',
409
  fromName: 'WordPress',
410
+ fromNameField: '',
411
+
412
+ replyToType: 'default',
413
+ replyToAddress: '',
414
+ replyToField: '',
415
+
416
+
417
+ replyToNameType: 'custom',
418
+ replyToName: 'WordPress',
419
+ replyToNameField: ''
420
  };
421
  },
422
 
453
  }
454
  );
455
 
456
+ wp.ccf.models.Form = wp.ccf.models.Form || wp.ccf.api.models.Post.extend(
457
  {
458
 
459
  urlRoot: ccfSettings.apiRoot.replace( /\/$/, '' ) + '/ccf/v1/forms',
473
  fields: new wp.ccf.collections.Fields(),
474
  type: 'ccf_form',
475
  status: 'publish',
476
+ hideTitle: false,
477
  description: '',
478
  buttonText: 'Submit Form',
479
  buttonClass: '',
486
  postFieldMappings: new wp.ccf.collections.PostFieldMappings(),
487
  notifications: new wp.ccf.collections.FormNotifications(),
488
  pause: false,
489
+ requireLoggedIn: false,
490
  pauseMessage: ccfSettings.pauseMessage,
491
  theme: 'none'
492
  };
498
  },
499
 
500
  decode: function() {
501
+ var keys = _.keys( wp.ccf.api.models.Post.prototype.defaults );
502
  keys = _.without( keys, 'title' );
503
 
504
  return _modelDecode.call( this, keys );
707
  }
708
  );
709
 
710
+ wp.ccf.models.Submission = wp.ccf.api.models.Submission || wp.ccf.api.models.Post.extend(
711
  {
712
  defaults: {
713
  id: null,
721
  }
722
  );
723
 
724
+ wp.ccf.models.Field = wp.ccf.api.models.Field || wp.ccf.api.models.Post.extend(
725
  {
726
  idAttribute: 'id',
727
 
757
  },
758
 
759
  decode: function() {
760
+ return _modelDecode.call( this, _.keys( wp.ccf.api.models.Post.prototype.defaults ) );
761
  },
762
 
763
  hasRequiredAttributes: function() {
978
  }
979
  );
980
 
981
+ wp.ccf.models.Fields['simple-captcha'] = wp.ccf.models.Fields['simple-captcha'] || wp.ccf.models.StandardField.extend(
982
+ {
983
+ defaults: function() {
984
+ var defaults = {
985
+ type: 'simple-captcha',
986
+ placeholder: ccfSettings.defaultSimpleCaptchaPlaceholder
987
+ };
988
+
989
+ return _.defaults( defaults, this.constructor.__super__.defaults() );
990
+ },
991
+
992
+ isImmutable: true,
993
+
994
+ initialize: function() {
995
+ return this.constructor.__super__.initialize.apply( this, arguments );
996
+ }
997
+ }
998
+ );
999
+
1000
  wp.ccf.models.Fields.address = wp.ccf.models.Fields.address || wp.ccf.models.StandardField.extend(
1001
  {
1002
  defaults: function() {
1069
  {
1070
  defaults: function() {
1071
  var defaults = {
1072
+ choices: new wp.ccf.collections.FieldChoices(),
1073
+ useValues: false
1074
  };
1075
 
1076
  return _.defaults( defaults, this.constructor.__super__.defaults() );
1160
 
1161
  wp.ccf.collections = wp.ccf.collections || {};
1162
 
1163
+ wp.ccf.collections.Forms = wp.ccf.collections.Forms || wp.ccf.api.collections.Posts.extend(
1164
  {
1165
  model: wp.ccf.models.Form,
1166
 
1196
  }
1197
  );
1198
 
1199
+ wp.ccf.collections.Fields = wp.ccf.collections.Fields || wp.ccf.api.collections.Posts.extend(
1200
  {
1201
  model: wp.ccf.models.Field,
1202
 
1232
  }
1233
  );
1234
 
1235
+ wp.ccf.collections.Submissions = wp.ccf.collections.Submissions || wp.ccf.api.collections.Posts.extend(
1236
  {
1237
  model: wp.ccf.models.Submission,
1238
 
1306
  }
1307
 
1308
  var label = this.el.querySelectorAll( '.choice-label' )[0].value;
1309
+
1310
+ var valueSelector = this.el.querySelectorAll( '.choice-value' ),
1311
+ value = '';
1312
+ if ( valueSelector.length ) {
1313
+ value = valueSelector[0].value;
1314
+ }
1315
 
1316
  this.model.set( 'label', label );
1317
  this.model.set( 'value', value );
1318
 
1319
+ if ( ! this.field.get( 'useValues' ) ) {
1320
+ this.model.set( 'value', this.model.get( 'label' ) );
1321
+ }
1322
+
1323
  var selectedElement = this.el.querySelectorAll( '.choice-selected' )[0];
1324
  var selected = ( selectedElement.checked ) ? true : false;
1325
 
1330
  },
1331
 
1332
  render: function() {
1333
+ var context = {
1334
+ showValue: this.field.get( 'useValues' )
1335
+ };
1336
  if ( this.model ) {
1337
  context.choice = this.model.toJSON();
1338
  }
1428
  if ( this.field.get( 'slug' ) !== field.get( 'slug' ) ) {
1429
  var type = field.get( 'type' );
1430
 
1431
+ if ( 'address' !== type && 'checkboxes' !== type && 'date' !== type && 'name' !== type && 'file' !== type && 'recaptcha' !== type && 'simple-captcha' !== type && 'section-header' !== type && 'html' !== type ) {
1432
  option = document.createElement( 'option' );
1433
  option.innerHTML = field.get( 'slug' );
1434
  option.value = field.get( 'slug' );
1680
  events: {
1681
  'change select.form-email-notification-from-type': 'toggleNotificationFields',
1682
  'change select.form-email-notification-from-name-type': 'toggleNotificationFields',
1683
+ 'change select.form-email-notification-reply-to-type': 'toggleNotificationFields',
1684
+ 'change select.form-email-notification-reply-to-name-type': 'toggleNotificationFields',
1685
  'change select.form-email-notification-subject-type': 'toggleNotificationFields',
1686
  'click .close-notification': 'changeContext',
1687
  'click .edit-notification': 'changeContext',
1756
  fields.each( function( field ) {
1757
  type = field.get( 'type' );
1758
 
1759
+ if ( 'html' !== type && 'section-header' !== type && 'recaptcha' !== type && 'simple-captcha' !== type ) {
1760
  variablesText += '[' + field.get( 'slug' ) + '] ';
1761
  }
1762
  } );
1773
  emailNotificationFromField.innerHTML = '';
1774
  emailNotificationFromField.disabled = false;
1775
 
1776
+ var emailNotificationReplyToField = this.el.querySelectorAll( '.form-email-notification-reply-to-field' )[0];
1777
+ emailNotificationReplyToField.innerHTML = '';
1778
+ emailNotificationReplyToField.disabled = false;
1779
+
1780
  var emailNotificationSubjectField = this.el.querySelectorAll( '.form-email-notification-subject-field' )[0];
1781
  emailNotificationSubjectField.innerHTML = '';
1782
  emailNotificationSubjectField.disabled = false;
1785
  emailNotificationFromNameField.innerHTML = '';
1786
  emailNotificationFromNameField.disabled = false;
1787
 
1788
+ var emailNotificationReplyToNameField = this.el.querySelectorAll( '.form-email-notification-reply-to-name-field' )[0];
1789
+ emailNotificationReplyToNameField.innerHTML = '';
1790
+ emailNotificationReplyToNameField.disabled = false;
1791
+
1792
  var fields = this.form.get( 'fields' ),
1793
  addressFieldsAdded = 0,
1794
  nameFieldsAdded = 0,
1795
  subjectFieldsAdded = 0;
1796
 
1797
+ var addressField = this.model.get( 'fromField' );
1798
+ var replyToAddressField = this.model.get( 'replyToField' );
1799
+ var subjectField = this.model.get( 'subjectField' );
1800
+ var nameField = this.model.get( 'fromNameField' ),
1801
+ replyToNameField = this.model.get( 'replyToNameField' ),
1802
+ option,
1803
+ replyToOption;
1804
 
1805
  if ( fields.length >= 1 ) {
1806
  fields.each( function( field ) {
1815
 
1816
  emailNotificationFromField.appendChild( option );
1817
 
1818
+ replyToOption = document.createElement( 'option' );
1819
+ replyToOption.innerHTML = field.get( 'slug' );
1820
+ replyToOption.value = field.get( 'slug' );
1821
+
1822
+ if ( field.get( 'slug' ) === replyToAddressField ) {
1823
+ replyToOption.selected = true;
1824
+ }
1825
+
1826
+ emailNotificationReplyToField.appendChild( replyToOption );
1827
+
1828
  addressFieldsAdded++;
1829
  } if ( 'name' === field.get( 'type' ) || 'single-line-text' === field.get( 'type' ) || 'radio' === field.get( 'type' ) || 'dropdown' === field.get( 'type' ) ) {
1830
  option = document.createElement( 'option' );
1837
 
1838
  emailNotificationFromNameField.appendChild( option );
1839
 
1840
+ replyToOption = document.createElement( 'option' );
1841
+ replyToOption.innerHTML = field.get( 'slug' );
1842
+ replyToOption.value = field.get( 'slug' );
1843
+
1844
+ if ( field.get( 'slug' ) === replyToNameField ) {
1845
+ replyToOption.selected = true;
1846
+ }
1847
+
1848
+ emailNotificationReplyToNameField.appendChild( replyToOption );
1849
+
1850
  nameFieldsAdded++;
1851
  } if ( 'single-line-text' === field.get( 'type' ) || 'radio' === field.get( 'type' ) || 'dropdown' === field.get( 'type' ) ) {
1852
  // @Todo: add more applicable fields
1872
  option.value = '';
1873
  emailNotificationFromField.appendChild( option );
1874
  emailNotificationFromField.disabled = true;
1875
+
1876
+ option = document.createElement( 'option' );
1877
+ option.innerHTML = ccfSettings.noEmailFields;
1878
+ option.value = '';
1879
+ emailNotificationReplyToField.appendChild( option );
1880
+ emailNotificationReplyToField.disabled = true;
1881
  }
1882
 
1883
  if ( 0 === nameFieldsAdded ) {
1918
 
1919
  var emailNotificationFromNameType = this.el.querySelectorAll( '.form-email-notification-from-name-type' )[0];
1920
 
1921
+
1922
+
1923
+ var emailNotificationReplyToAddress = this.el.querySelectorAll( '.email-notification-reply-to-address' )[0];
1924
+
1925
+ var emailNotificationReplyToField = this.el.querySelectorAll( '.email-notification-reply-to-field' )[0];
1926
+
1927
+ var emailNotificationReplyToType = this.el.querySelectorAll( '.form-email-notification-reply-to-type' )[0];
1928
+
1929
+ var emailNotificationReplyToName = this.el.querySelectorAll( '.email-notification-reply-to-name' )[0];
1930
+
1931
+ var emailNotificationReplyToNameField = this.el.querySelectorAll( '.email-notification-reply-to-name-field' )[0];
1932
+
1933
+ var emailNotificationReplyToNameType = this.el.querySelectorAll( '.form-email-notification-reply-to-name-type' )[0];
1934
+
1935
+
1936
+
1937
+
1938
+
1939
  emailNotificationFromAddress.style.display = 'none';
1940
  emailNotificationFromField.style.display = 'none';
1941
 
1962
  } else if ( 'field' === emailNotificationFromNameType.value ) {
1963
  emailNotificationFromNameField.style.display = 'block';
1964
  }
1965
+
1966
+ emailNotificationReplyToAddress.style.display = 'none';
1967
+ emailNotificationReplyToField.style.display = 'none';
1968
+
1969
+ if ( 'custom' === emailNotificationReplyToType.value ) {
1970
+ emailNotificationReplyToAddress.style.display = 'block';
1971
+ } else if ( 'field' === emailNotificationReplyToType.value ) {
1972
+ emailNotificationReplyToField.style.display = 'block';
1973
+ }
1974
+
1975
+ emailNotificationReplyToName.style.display = 'none';
1976
+ emailNotificationReplyToNameField.style.display = 'none';
1977
+
1978
+ if ( 'custom' === emailNotificationReplyToNameType.value ) {
1979
+ emailNotificationReplyToName.style.display = 'block';
1980
+ } else if ( 'field' === emailNotificationReplyToNameType.value ) {
1981
+ emailNotificationReplyToNameField.style.display = 'block';
1982
+ }
1983
  },
1984
 
1985
  save: function() {
2001
  var emailNotificationActive = this.el.querySelectorAll( '.form-email-notification-active' )[0].value;
2002
  this.model.set( 'active', ( '1' === emailNotificationActive ) ? true : false );
2003
 
2004
+ var emailNotificationIncludeUploads = this.el.querySelectorAll( '.form-email-notification-include-uploads' )[0].value;
2005
+ this.model.set( 'includeUploads', ( '1' === emailNotificationIncludeUploads ) ? true : false );
2006
+
2007
  var emailNotificationFromType = this.el.querySelectorAll( '.form-email-notification-from-type' )[0].value;
2008
  this.model.set( 'fromType', emailNotificationFromType );
2009
 
2022
  var emailNotificationFromNameField = this.el.querySelectorAll( '.form-email-notification-from-name-field' )[0].value;
2023
  this.model.set( 'fromNameField', emailNotificationFromNameField );
2024
 
2025
+ var emailNotificationReplyToType = this.el.querySelectorAll( '.form-email-notification-reply-to-type' )[0].value;
2026
+ this.model.set( 'replyToType', emailNotificationReplyToType );
2027
+
2028
+ var emailNotificationReplyToAddress = this.el.querySelectorAll( '.form-email-notification-reply-to-address' )[0].value;
2029
+ this.model.set( 'replyToAddress', emailNotificationReplyToAddress );
2030
+
2031
+ var emailNotificationReplyToField = this.el.querySelectorAll( '.form-email-notification-reply-to-field' )[0].value;
2032
+ this.model.set( 'replyToField', emailNotificationReplyToField );
2033
+
2034
+ var emailNotificationReplyToNameType = this.el.querySelectorAll( '.form-email-notification-reply-to-name-type' )[0].value;
2035
+ this.model.set( 'replyToNameType', emailNotificationReplyToNameType );
2036
+
2037
+ var emailNotificationReplyToName = this.el.querySelectorAll( '.form-email-notification-reply-to-name' )[0].value;
2038
+ this.model.set( 'replyToName', emailNotificationReplyToName );
2039
+
2040
+ var emailNotificationReplyToNameField = this.el.querySelectorAll( '.form-email-notification-reply-to-name-field' )[0].value;
2041
+ this.model.set( 'replyToNameField', emailNotificationReplyToNameField );
2042
+
2043
  var emailNotificationSubjectType = this.el.querySelectorAll( '.form-email-notification-subject-type' )[0].value;
2044
  this.model.set( 'subjectType', emailNotificationSubjectType );
2045
 
2164
  },
2165
 
2166
  saveField: function() {
2167
+ var conditionalsWrapper = this.el.querySelectorAll( '.conditionals' );
2168
 
2169
+ if ( conditionalsWrapper.length ) {
2170
+ var conditionals = conditionalsWrapper[0].querySelectorAll( '.conditional' );
 
2171
 
2172
+ _.each( conditionals, function( conditional ) {
2173
+ $( conditional ).trigger( 'saveConditional' );
2174
+ });
2175
+
2176
+ this.model.set( 'conditionalType', this.el.querySelectorAll( '.field-conditional-type' )[0].value );
2177
+ this.model.set( 'conditionalFieldsRequired', this.el.querySelectorAll( '.field-conditional-fields-required' )[0].value );
2178
 
2179
+ var oldConditionals = this.model.get( 'conditionalsEnabled' );
2180
+ this.model.set( 'conditionalsEnabled', ( this.el.querySelectorAll( '.field-conditionals-enabled' )[0].value == 1 ) ? true : false );
2181
 
2182
+ if ( oldConditionals !== this.model.get( 'conditionalsEnabled' ) ) {
2183
+ this.render( 'advanced' );
2184
+ }
2185
  }
2186
  },
2187
 
2194
 
2195
  var conditionalsCollection = this.model.get( 'conditionals' );
2196
 
2197
+ var conditionalsWrapper = this.el.querySelectorAll( '.conditionals' );
2198
 
2199
+ if ( conditionalsWrapper.length ) {
2200
 
2201
+ if ( conditionalsCollection.length >= 1 ) {
2202
+
2203
+ conditionalsCollection.each( function( model ) {
2204
+ var view = new wp.ccf.views.FieldConditional( { model: model, field: this.model, fieldCollection: this.collection } ).render();
2205
+ conditionalsWrapper[0].appendChild( view.el );
2206
+ }, this );
2207
+ } else {
2208
+ var conditional = new wp.ccf.models.FieldConditional();
2209
+ conditionalsCollection.add( conditional );
2210
+ }
2211
  }
2212
 
2213
  return this;
2288
  }
2289
  );
2290
 
2291
+ wp.ccf.views.Fields['simple-captcha'] = wp.ccf.views.Fields['simple-captcha'] || wp.ccf.views.FieldBase.extend(
2292
+ {
2293
+ template: wp.ccf.utils.template( 'ccf-simple-captcha-template' ),
2294
+
2295
+ saveField: function() {
2296
+ // @todo: fix this ie8 hack
2297
+ if ( this.el.innerHTML === '' ) {
2298
+ return;
2299
+ }
2300
+
2301
+ this.model.set( 'label', this.el.querySelectorAll( '.field-label' )[0].value );
2302
+ this.model.set( 'description', this.el.querySelectorAll( '.field-description' )[0].value );
2303
+ this.model.set( 'placeholder', this.el.querySelectorAll( '.field-placeholder' )[0].value );
2304
+ this.model.set( 'className', this.el.querySelectorAll( '.field-class-name' )[0].value );
2305
+
2306
+ this.constructor.__super__.saveField.apply( this, arguments );
2307
+
2308
+ return this;
2309
+ }
2310
+ }
2311
+ );
2312
+
2313
  wp.ccf.views.Fields['section-header'] = wp.ccf.views.Fields['section-header'] || wp.ccf.views.FieldBase.extend(
2314
  {
2315
  template: wp.ccf.utils.template( 'ccf-section-header-template' ),
2530
  this.model.set( 'slug', this.el.querySelectorAll( '.field-slug' )[0].value );
2531
  this.model.set( 'label', this.el.querySelectorAll( '.field-label' )[0].value );
2532
  this.model.set( 'description', this.el.querySelectorAll( '.field-description' )[0].value );
2533
+
2534
+ var oldType = this.model.get( 'addressType' );
2535
+
2536
  this.model.set( 'addressType', this.el.querySelectorAll( '.field-address-type' )[0].value );
2537
+
2538
+ var defaultCountry = this.el.querySelectorAll( '.field-default-country' );
2539
+ if ( defaultCountry.length ) {
2540
+ this.model.set( 'defaultCountry', defaultCountry[0].value );
2541
+ }
2542
+
2543
  this.model.set( 'className', this.el.querySelectorAll( '.field-class-name' )[0].value );
2544
  this.model.set( 'required', ( this.el.querySelectorAll( '.field-required' )[0].value == 1 ) ? true : false );
2545
 
2546
+ if ( oldType !== this.model.get( 'addressType' ) ) {
2547
+ this.render();
2548
+ }
2549
+
2550
  this.constructor.__super__.saveField.apply( this, arguments );
2551
 
2552
  return this;
2613
  choices.appendChild( view.el );
2614
  },
2615
 
2616
+ saveField: function( event ) {
2617
  // @todo: fix this ie8 hack
2618
  if ( this.el.innerHTML === '' ) {
2619
  return;
2620
  }
2621
 
2622
+ if ( event && 'field-use-values' === event.target.className && 'focusout' === event.type ) {
2623
+ // Make sure we don't double save
2624
+ return;
2625
+ }
2626
+
2627
  this.model.set( 'slug', this.el.querySelectorAll( '.field-slug' )[0].value );
2628
  this.model.set( 'label', this.el.querySelectorAll( '.field-label' )[0].value );
2629
  this.model.set( 'description', this.el.querySelectorAll( '.field-description' )[0].value );
2638
  $( choice ).trigger( 'saveChoice' );
2639
  });
2640
 
2641
+ var oldUseValues = this.model.get( 'useValues' ),
2642
+ useValues = ( this.el.querySelectorAll( '.field-use-values' )[0].checked ) ? true : false;
2643
+
2644
+ this.model.set( 'useValues', useValues );
2645
+
2646
+ if ( oldUseValues !== useValues ) {
2647
+ this.render();
2648
+ }
2649
+
2650
  return this;
2651
 
2652
  },
2656
 
2657
  startPanel = ( startPanel ) ? startPanel : 'basic';
2658
 
2659
+ var useValues = this.model.get( 'useValues' );
2660
+
2661
  SELF.el.innerHTML = SELF.template( { field: SELF.model.toJSON(), startPanel: startPanel } );
2662
 
2663
  SELF.checkSlug();
3218
  var title = this.el.querySelectorAll( '.form-title' )[0].value;
3219
  this.model.set( 'title', { raw: title } );
3220
 
3221
+ var hideTitle = this.el.querySelectorAll( '.hide-title' )[0].value;
3222
+ this.model.set( 'hideTitle', ( parseInt( hideTitle ) ) ? true : false );
3223
+
3224
  var description = this.el.querySelectorAll( '.form-description' )[0].value;
3225
  this.model.set( 'description', description );
3226
 
3233
  var pause = this.el.querySelectorAll( '.form-pause' )[0].value;
3234
  this.model.set( 'pause', ( parseInt( pause ) ) ? true : false );
3235
 
3236
+ var requireLoggedIn = this.el.querySelectorAll( '.form-require-logged-in' )[0].value;
3237
+ this.model.set( 'requireLoggedIn', ( parseInt( requireLoggedIn ) ) ? true : false );
3238
+
3239
  var postCreation = this.el.querySelectorAll( '.form-post-creation' )[0].value;
3240
  this.model.set( 'postCreation', ( parseInt( postCreation ) ) ? true : false );
3241
 
3655
  events: {
3656
  'click .edit': 'triggerMainViewChange',
3657
  'click .delete': 'triggerDelete',
3658
+ 'click .duplicate': 'triggerDuplicate',
3659
  'click .insert-form-button': 'insertForm'
3660
  },
3661
 
3691
  });
3692
  },
3693
 
3694
+ triggerDuplicate: function() {
3695
+ var SELF = this,
3696
+ currentPage = SELF.parent.collection.state.currentPage;
3697
+
3698
+ SELF.model
3699
+ .clone()
3700
+ .set( 'title', { raw: SELF.model.get( 'title' ).raw + ' (Duplicate)' } )
3701
+ .unset( 'id' )
3702
+ .save()
3703
+ .done( function() {
3704
+ SELF.parent.showPage( currentPage ).done( function() {
3705
+ SELF.parent.renderPagination();
3706
+ });
3707
+ });
3708
+ },
3709
+
3710
  render: function() {
3711
  this.$el.html( this.template( { form: this.model.toJSON(), utils: { getPrettyPostDate: wp.ccf.utils.getPrettyPostDate } } ) );
3712
  return this;
3865
  },
3866
 
3867
  menuClick: function( event ) {
3868
+ var view = event.currentTarget.getAttribute( 'data-view' );
3869
 
3870
  if ( 'form-pane' === view ) {
3871
  wp.ccf.currentForm = null;
4412
  metabox.insertBefore( download, metabox.firstChild.nextSibling.nextSibling );
4413
 
4414
  wp.ccf.createSubmissionsTable( container );
4415
+
4416
+ var duplicateButton = document.querySelectorAll( '#major-publishing-actions .duplicate')[0];
4417
+
4418
+ var duplicateClick = function( evnt ) {
4419
+ evnt = evnt || window.event;
4420
+ evnt.preventDefault();
4421
+
4422
+ SELF.currentForm.clone()
4423
+ .set( 'title', { raw: SELF.currentForm.get( 'title' ).raw + ' (duplicate)' } )
4424
+ .unset( 'id' )
4425
+ .save()
4426
+ .done( function( newForm ) {
4427
+ document.location = ccfSettings.adminUrl + '/post.php?action=edit&post=' + newForm.id;
4428
+ });
4429
+ };
4430
+
4431
+ if ( duplicateButton.addEventListener ) {
4432
+ duplicateButton.addEventListener( 'click', duplicateClick, false );
4433
+ } else {
4434
+ duplicateButton.attachEvent( 'onclick', duplicateClick );
4435
+ }
4436
  }
4437
  });
4438
  } else {
build/js/form-manager.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (function(e,t,i,l){"use strict";window.wp=window.wp||{},wp.ccf=wp.ccf||{},wp.ccf.utils=wp.ccf.utils||{},wp.ccf.utils.cleanDateFields=function(e){delete e.date,delete e.date_gmt,delete e.modified,delete e.modified_gmt,delete e.date_tz,delete e.modified_tz},wp.ccf.utils.template=i.memoize(function(e){var t={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};return i.template(document.getElementById(e).innerHTML,null,t)}),wp.ccf.utils.insertFormShortcode=function(e){var t=wp.ccf.forms.findWhere({id:e.get("id")});t||wp.ccf.forms.add(e);var i=tinymce.get(wpActiveEditor),l='[ccf_form id="'+e.get("id")+'"]';i&&!i.isHidden()?tinymce.activeEditor.execCommand("mceInsertContent",!1,l):document.getElementById(wpActiveEditor).value+=l},wp.ccf.utils.getPrettyPostDate=function(e){return e=moment.utc(e),l.gmtOffset&&(e=e.utcOffset(60*parseInt(l.gmtOffset))),e.format("h:mm a M/D/YYYY")},wp.ccf.utils.wordChop=function(e,t){var i=e.substr(0,t);return i.substr(0,Math.min(i.length,i.lastIndexOf(" "))),i.length<e.length&&(i+="..."),i},wp.ccf.utils.isFieldDate=function(e){return e.date!==void 0||e.hour!==void 0&&e.minute!==void 0&&e["am-pm"]!==void 0?!0:!1},wp.ccf.utils.isFieldName=function(e){return e.name!==void 0||e.last!==void 0?!0:!1},wp.ccf.utils.isFieldEmailConfirm=function(e){return e.email!==void 0||e.confirm!==void 0?!0:!1},wp.ccf.utils.isFieldAddress=function(e){return e.street!==void 0&&e.city!==void 0&&e.zipcode!==void 0&&e.line_two!==void 0?!0:!1},wp.ccf.utils.isFieldFile=function(e){return e.id!==void 0&&e.url!==void 0&&e.file_name!==void 0?!0:!1},wp.ccf.utils.getPrettyFieldEmailConfirm=function(e){return e.email?e.email:e.confirm?e.confirm:"-"},wp.ccf.utils.getPrettyFieldDate=function(e,t){var i="",s="",o="HH:mm MM/DD/YY";if(t&&t.ccf_field_dateFormat&&"dd/mm/yyyy"===t.ccf_field_dateFormat&&(o="HH:mm DD/MM/YY"),e.hour&&e.minute&&e["am-pm"]&&(i+=e.hour+":"+e.minute+" "+e["am-pm"]),e.date&&(i+=" "+e.date),!i)return"-";var n=moment(i,o);return n.isValid()?(e.hour&&e.minute&&e["am-pm"]&&(s+=n.format("h:mm a")),e.date&&(s&&(s+=" "),s+=e.date),s):l.invalidDate},wp.ccf.utils.getPrettyFieldName=function(e){var t=e.first;return t.length>0&&(t+=" "),e.last&&(t+=e.last),t||(t="-"),t},wp.ccf.utils.getPrettyFieldAddress=function(e){if(!e.street||!e.city)return"-";var t=e.street;return e.line_two&&(t+=" "+e.line_two),t+=", "+e.city,e.state&&(t+=", "+e.state),e.zipcode&&(t+=" "+e.zipcode),e.country&&(t+=" "+e.country),t}})(jQuery,Backbone,_,ccfSettings),function(e,t,i){"use strict";wp.ccf.mixins=wp.ccf.mixins||{},wp.ccf.mixins.subViewable=wp.ccf.mixins.subViewable||{subViews:{},initRenderSubViews:function(e,t,l){this.renderedSubViews||(this.renderedSubViews={});for(var s in this.subViews){var o={el:this.$el.find(".ccf-"+s),parent:this};l&&i.extend(o,l),this.renderedSubViews[s]&&this.renderedSubViews[s].destroy&&this.renderedSubViews[s].destroy(),(t||!this.renderedSubViews[s])&&(this.renderedSubViews[s]=new this.subViews[s](o)),this.renderedSubViews[s].render(),e&&(this.renderedSubViews[s].el.style.display="block")}return this},showView:function(e,t,i){if(this.renderedSubViews!==void 0&&this.renderedSubViews[e]!==void 0){var l=this.renderedSubViews[e];i||l.render(t),l.el.style.display="block",this.currentView=e;for(var s in this.subViews)s!==e&&(this.renderedSubViews[s].el.style.display="none")}}}}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.models=wp.ccf.models||{},wp.ccf.models.Fields=wp.ccf.models.Fields||{};var s=function(e,i,l){return"object"!=typeof i&&""===i&&(i=""),t.Model.prototype.set.call(this,e,i,l)},o=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)},n=function(e){for(var t in this.attributes)if(-1===i.indexOf(e,t)){var l=this.get(t);"string"==typeof l&&""!==l&&(l=(l+"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#8220;/g,"”").replace(/&#8221;/g,"”").replace(/&#8216;/g,"‘").replace(/&#038;/g,"&").replace(/&#039;/g,"'"),this.set(t,l))}return this};wp.ccf.models.FieldConditional=wp.ccf.models.FieldConditional||t.Model.extend({defaults:{field:"",compare:"is",value:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FieldChoice=wp.ccf.models.FieldChoice||t.Model.extend({defaults:{label:"",value:"",selected:!1},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.PostFieldMapping=wp.ccf.models.PostFieldMapping||t.Model.extend({defaults:{formField:"",postField:"",customFieldKey:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotificationAddress=wp.ccf.models.FormNotificationAddress||t.Model.extend({defaults:{type:"custom",field:"",email:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotification=wp.ccf.models.FormNotification||t.Model.extend({defaults:function(){return{title:"",content:"[all_fields]",active:!1,addresses:new wp.ccf.collections.FormNotificationAddresses,fromType:"default",fromAddress:"",fromField:"",subjectType:"default",subject:"",subjectField:"",fromNameType:"custom",fromName:"WordPress",fromNameField:""}},initialize:function(e){if("object"==typeof e&&e.addresses){var t=[];i.each(e.addresses,function(e){var i=new wp.ccf.models.FormNotificationAddress(e);i.decode(),t.push(i)}),this.set("addresses",new wp.ccf.collections.FormNotificationAddresses(t))}},decode:function(){return n.call(this,[])},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.addresses&&(e.addresses=e.addresses.toJSON()),e},set:s}),wp.ccf.models.Form=wp.ccf.models.Form||wp.api.models.Post.extend({urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",set:s,sync:o,idAttribute:"id",initialize:function(){this.on("sync",this.decode,this)},defaults:function(){var e={fields:new wp.ccf.collections.Fields,type:"ccf_form",status:"publish",description:"",buttonText:"Submit Form",completionActionType:"text",completionRedirectUrl:"",completionMessage:"",postCreation:!1,postCreationType:"post",postCreationStatus:"draft",postFieldMappings:new wp.ccf.collections.PostFieldMappings,notifications:new wp.ccf.collections.FormNotifications,pause:!1,pauseMessage:l.pauseMessage,theme:"none"};return e=i.defaults(e,this.constructor.__super__.defaults),wp.ccf.utils.cleanDateFields(e),e},decode:function(){var e=i.keys(wp.api.models.Post.prototype.defaults);return e=i.without(e,"title"),n.call(this,e)},getFieldSlugs:function(e){var t=wp.ccf.currentForm.get("fields"),i=[];return t.each(function(t){e&&t.isImmutable||i.push(t.get("slug"))}),i},parse:function(e){var t=this,l=0,s=0;if(e.fields){var o=t.get("fields");if(o&&o.length>0){for(l=0;e.fields.length>l;l++){var n=e.fields[l],c=o.findWhere({slug:n.slug});if(c){if(n.choices!==void 0){var r=t.get("choices");if(r&&r.length>0)for(s=0;n.choices>s;s++){var a=r.at(s);a.set(n.choices[s]),a.decode()}delete e.fields[l].choices}if(n.conditionals!==void 0){var d=t.get("conditionals");if(d&&d.length>0)for(s=0;n.conditionals>s;s++){var u=d.at(s);u.set(n.conditionals[s]),u.decode()}delete e.fields[l].conditionals}c.set(n),c.decode()}}delete e.fields}else{var f=[];i.each(e.fields,function(e){var t=new wp.ccf.models.Fields[e.type](e);t.decode(),f.push(t)}),e.fields=new wp.ccf.collections.Fields(f,{formId:e.id}),o?(o.add(f),delete e.fields):e.fields=new wp.ccf.collections.Fields(f,{formId:e.id})}}if(e.notifications){var p=t.get("notifications");if(p&&p.length>0){for(l=0;e.notifications.length>l;l++){var h=e.notifications[l],m=p.at(l);if(m){if(h.addresses!==void 0){var w=m.get("addresses");if(w&&w.length>0)for(s=0;h.addresses>s;s++){var g=w.at(s);g.set(h.addresses[s]),g.decode()}delete e.notifications[l].addresses}m.set(h),m.decode()}}delete e.notifications}else{var v=[];i.each(e.notifications,function(e){var t=new wp.ccf.models.FormNotification(e);t.decode(),v.push(t)}),p?(p.add(v),delete e.notifications):e.notifications=new wp.ccf.collections.FormNotifications(v)}}if(e.postFieldMappings){var y=t.get("postFieldMappings");if(y&&y.length>0){for(l=0;e.postFieldMappings.length>l;l++){var F=e.postFieldMappings[l],b=y.at(l);b&&(b.set(F),b.decode())}delete e.postFieldMappings}else{var S=[];i.each(e.postFieldMappings,function(e){var t=new wp.ccf.models.PostFieldMapping(e);t.decode(),S.push(t)}),y?(y.add(S),e.postFieldMappings=y):e.postFieldMappings=new wp.ccf.collections.PostFieldMappings(S)}}return this.constructor.__super__.parse.call(this,e)},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.fields&&(e.fields=e.fields.toJSON()),e.notifications&&(e.notifications=e.notifications.toJSON()),e.postFieldMappings&&(e.postFieldMappings=e.postFieldMappings.toJSON()),e.author&&(e.author=e.author.toJSON()),e}}),wp.ccf.models.Submission=wp.api.models.Submission||wp.api.models.Post.extend({defaults:{id:null,data:{},fields:{}},sync:o,urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/submissions"}),wp.ccf.models.Field=wp.api.models.Field||wp.api.models.Post.extend({idAttribute:"id",defaults:function(){return{id:null,conditionalsEnabled:!1,conditionalType:"show",conditionalFieldsRequired:"all",conditionals:new wp.ccf.collections.FieldConditionals}},set:s,initialize:function(e){if("object"==typeof e&&e.conditionals){var t=[];i.each(e.conditionals,function(e){var i=new wp.ccf.models.FieldConditional(e);i.decode(),t.push(i)}),this.set("conditionals",new wp.ccf.collections.FieldConditionals(t))}},required:function(){return["slug"]},decode:function(){return n.call(this,i.keys(wp.api.models.Post.prototype.defaults))},hasRequiredAttributes:function(){var e=this,t=!0;return i.each(this.required(),function(i){(e.get(i)===void 0||""===e.get(i))&&(t=!1)}),t},sync:o}),wp.ccf.models.StandardField=wp.ccf.models.StandardField||wp.ccf.models.Field.extend({idAttribute:"id",defaults:function(){var e={label:l.fieldLabel,value:"",placeholder:"",slug:"",type:"",required:!1,className:"",description:""};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return wp.ccf.models.StandardField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["single-line-text"]=wp.ccf.models.Fields["single-line-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"single-line-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.file=wp.ccf.models.Fields.file||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"file",fileExtensions:"",maxFileSize:l.maxFileSize};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["paragraph-text"]=wp.ccf.models.Fields["paragraph-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"paragraph-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.hidden=wp.ccf.models.Fields.hidden||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"hidden"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.email=wp.ccf.models.Fields.email||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"email",emailConfirmation:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.website=wp.ccf.models.Fields.website||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"website",placeholder:"http://"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.phone=wp.ccf.models.Fields.phone||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"phone",phoneFormat:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.date=wp.ccf.models.Fields.date||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"date",showDate:!0,showTime:!0,dateFormat:"mm/dd/yyyy"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.name=wp.ccf.models.Fields.name||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"name"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.recaptcha=wp.ccf.models.Fields.recaptcha||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"recaptcha",siteKey:"",secretKey:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return["siteKey","secretKey"]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.address=wp.ccf.models.Fields.address||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"address",addressType:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["section-header"]=wp.ccf.models.Fields["section-header"]||wp.ccf.models.Field.extend({defaults:function(){var e={type:"section-header",slug:"",heading:"",subheading:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.html=wp.ccf.models.Fields.html||wp.ccf.models.Field.extend({defaults:function(){var e={type:"html",slug:"",html:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.ChoiceableField=wp.ccf.models.ChoiceableField||wp.ccf.models.StandardField.extend({defaults:function(){var e={choices:new wp.ccf.collections.FieldChoices};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(e){if("object"==typeof e&&e.choices){var t=[];i.each(e.choices,function(e){var i=new wp.ccf.models.FieldChoice(e);i.decode(),t.push(i)}),this.set("choices",new wp.ccf.collections.FieldChoices(t))}return wp.ccf.models.ChoiceableField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.radio=wp.ccf.models.Fields.radio||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"radio"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.checkboxes=wp.ccf.models.Fields.checkboxes||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"checkboxes"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.dropdown=wp.ccf.models.Fields.dropdown||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"dropdown"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";var s=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)};wp.ccf.collections=wp.ccf.collections||{},wp.ccf.collections.Forms=wp.ccf.collections.Forms||wp.api.collections.Posts.extend({model:wp.ccf.models.Form,url:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",formsFetching:{},initialize:function(){this.constructor.__super__.initialize(),this.formsFetching={}},sync:s,remove:function(e,t){t=t||{};var l=this.constructor.__super__.remove.call(this,e,t);return t.destroy&&(e instanceof Array?i.each(e,function(e){e.destroy()}):e.destroy()),l}}),wp.ccf.collections.Fields=wp.ccf.collections.Fields||wp.api.collections.Posts.extend({model:wp.ccf.models.Field,url:function(){return l.apiRoot+"/ccf/forms/"+this.formId+"/fields"},initialize:function(e,t){t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.PostFieldMappings=wp.ccf.collections.PostFieldMappings||t.Collection.extend({model:wp.ccf.models.PostFieldMapping}),wp.ccf.collections.FormNotificationAddresses=wp.ccf.collections.FormNotificationAddresses||t.Collection.extend({model:wp.ccf.models.FormNotificationAddress}),wp.ccf.collections.FormNotifications=wp.ccf.collections.FormNotifications||t.Collection.extend({model:wp.ccf.models.FormNotification}),wp.ccf.collections.Submissions=wp.ccf.collections.Submissions||wp.api.collections.Posts.extend({model:wp.ccf.models.Submission,url:function(){return l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms/"+this.formId+"/submissions"},initialize:function(e,t){this.constructor.__super__.initialize.apply(this,arguments),t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.FieldChoices=wp.ccf.collections.FieldChoices||t.Collection.extend({model:wp.ccf.models.FieldChoice}),wp.ccf.collections.FieldConditionals=wp.ccf.collections.FieldConditionals||t.Collection.extend({model:wp.ccf.models.FieldConditional})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.views=wp.ccf.views||{},wp.ccf.views.Fields=wp.ccf.views.Fields||{},wp.ccf.views.FieldChoice=t.View.extend({template:wp.ccf.utils.template("ccf-field-choice-template"),className:"choice",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveChoice:"saveChoice",sorted:"triggerUpdateSort"},initialize:function(e){this.field=e.field},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveChoice),this.unbind()},triggerUpdateSort:function(e,t){this.field.get("choices").remove(this.model,{silent:!0}),this.field.get("choices").add(this.model,{at:t,silent:!0})},saveChoice:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".choice-label")[0].value,t=this.el.querySelectorAll(".choice-value")[0].value;this.model.set("label",e),this.model.set("value",t);var i=this.el.querySelectorAll(".choice-selected")[0],l=i.checked?!0:!1;return this.model.set("selected",l),this}},render:function(){var e={};return this.model&&(e.choice=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveChoice,this),this},triggerAdd:function(){this.field.get("choices").add(new wp.ccf.models.FieldChoice)},triggerDelete:function(){var e=this.field.get("choices");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{for(var t=this.el.querySelectorAll(".choice-label, .choice-value"),i=this.el.querySelectorAll(".choice-selected"),l=0;t.length>l;l++)t[l].value="";i[0].checked=!1}}}),wp.ccf.views.FieldConditional=t.View.extend({template:wp.ccf.utils.template("ccf-field-conditional-template"),className:"conditional",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveConditional:"saveConditional"},initialize:function(e){this.field=e.field,this.fieldCollection=e.fieldCollection},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveConditional),this.unbind()},saveConditional:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".conditional-field")[0].value,t=this.el.querySelectorAll(".conditional-value")[0].value,i=this.el.querySelectorAll(".conditional-compare")[0].value;return this.model.set("field",e),this.model.set("value",t),this.model.set("compare",i),this}},updateFields:function(){var e=this.el.querySelectorAll(".conditional-field")[0];e.innerHTML="",e.disabled=!1;var t,i=0,s=this.model.get("field");this.fieldCollection.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),this.fieldCollection.each(function(l){if(this.field.get("slug")!==l.get("slug")){var o=l.get("type");"address"!==o&&"date"!==o&&"name"!==o&&"file"!==o&&"recaptcha"!==o&&"section-header"!==o&&"html"!==o&&(t=document.createElement("option"),t.innerHTML=l.get("slug"),t.value=l.get("slug"),l.get("slug")===s&&(t.selected=!0),e.appendChild(t),i++)}},this)),0===i&&(e.innerHTML="",t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},render:function(){var e={};return this.model&&(e.conditional=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveConditional,this),this.listenTo(this.fieldCollection,"add",this.updateFields,this),this.listenTo(this.fieldCollection,"remove",this.updateFields,this),this.updateFields(),this},triggerAdd:function(){this.field.get("conditionals").add(new wp.ccf.models.FieldConditional)},triggerDelete:function(){var e=this.field.get("conditionals");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{var t=this.el.querySelectorAll(".conditional-value")[0],i=this.el.querySelectorAll(".conditional-field")[0];t.value="";for(var l=0;i.childNodes.length>l;l++)i.childNodes[l].selected=!1}}}),wp.ccf.views.EmptyFormNotificationTableRow=wp.ccf.views.EmptyFormNotificationTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-notification-row-template"),events:{"click .add":"triggerAdd"},initialize:function(e){this.form=e.form},destroy:function(){this.unbind()},render:function(){return this.$el.html(this.template()),this},triggerAdd:function(){var e=this.form.get("notifications");this.destroy(),e.add(new wp.ccf.models.FormNotification)}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.FormNotificationAddress=t.View.extend({template:wp.ccf.utils.template("ccf-form-notification-address-template"),className:"address",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.notification=e.notification,this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-notification-address-type")[0].value,t=this.el.querySelectorAll(".form-notification-address-email"),i=this.el.querySelectorAll(".form-notification-address-field"),l=this.model.get("type");return t.length&&this.model.set("email",t[0].value),i.length&&this.model.set("field",i[0].value),this.model.set("type",e),l!==e&&this.render(),this}},updateFromFieldField:function(){if("edit"===this.parent.context&&"field"===this.model.get("type")){var e=this.el.querySelectorAll(".form-notification-address-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("field");i.length>=1&&i.each(function(i){("email"===i.get("type")||"dropdown"===i.get("type")||"radio"===i.get("type")||"single-line-text"===i.get("type"))&&(t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++)}),0===s&&(t=document.createElement("option"),t.innerHTML=l.noApplicableFields,t.value="",e.appendChild(t),e.disabled=!0)}},render:function(){var e={};this.model&&(e.address=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFromFieldField,this),this.listenTo(t,"remove",this.updateFromFieldField,this),"field"===this.model.get("type")&&this.updateFromFieldField(),this},triggerAdd:function(){this.notification.get("addresses").add(new wp.ccf.models.FormNotificationAddress)},triggerDelete:function(){var e=this.notification.get("addresses");e.length>1?this.parent.deleteAddress(this):(this.model.clear().set(wp.ccf.models.FormNotificationAddress.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.ExistingFormNotificationRow=t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-notification-table-row-template"),tagName:"tr",events:{"change select.form-email-notification-from-type":"toggleNotificationFields","change select.form-email-notification-from-name-type":"toggleNotificationFields","change select.form-email-notification-subject-type":"toggleNotificationFields","click .close-notification":"changeContext","click .edit-notification":"changeContext","click .delete-notification":"triggerDelete","blur input":"save","change select":"save"},addressViews:[],initialize:function(e){this.form=e.form,this.addressViews=[],this.parent=e.parent,this.context=e.context!==void 0?e.context:"view";var t=this.model.get("addresses");this.listenTo(t,"add",this.addAddress)},deleteAddress:function(e){i.each(this.addressViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.addressViews,t);this.model.get("addresses").remove(e.model),this.addressViews[l].remove(),this.addressViews.splice(l,1)}},this)},addAddress:function(e){var t=this.el.querySelectorAll(".addresses")[0],i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form});this.addressViews.push(i),t.appendChild(i.render().el)},destroy:function(){this.unbind()},changeContext:function(e,t){"edit"===this.context&&this.save(),t?this.context=t:("view"===this.context&&this.parent.closeAllNotifications(),this.context="edit"===this.context?"view":"edit"),this.destroy(),this.render()},updateFieldVariables:function(){if("edit"===this.context){var e,t=this.el.querySelectorAll(".field-variables")[0],i="",l=this.form.get("fields");l.each(function(t){e=t.get("type"),"html"!==e&&"section-header"!==e&&"recaptcha"!==e&&(i+="["+t.get("slug")+"] ")}),t.innerText=i}},updateFromFieldField:function(){if("edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-from-field")[0];e.innerHTML="",e.disabled=!1;var t=this.el.querySelectorAll(".form-email-notification-subject-field")[0];t.innerHTML="",t.disabled=!1;var i=this.el.querySelectorAll(".form-email-notification-from-name-field")[0];i.innerHTML="",i.disabled=!1;var s,o=this.form.get("fields"),n=0,c=0,r=0,a=this.model.get("emailNotificationFromField"),d=this.model.get("emailNotificationSubjectField"),u=this.model.get("emailNotificationFromNameField");o.length>=1&&o.each(function(l){("email"===l.get("type")||"dropdown"===l.get("type")||"radio"===l.get("type")||"single-line-text"===l.get("type"))&&(s=document.createElement("option"),s.innerHTML=l.get("slug"),s.value=l.get("slug"),l.get("slug")===a&&(s.selected=!0),e.appendChild(s),n++),("name"===l.get("type")||"single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(s=document.createElement("option"),s.innerHTML=l.get("slug"),s.value=l.get("slug"),l.get("slug")===u&&(s.selected=!0),i.appendChild(s),c++),("single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(s=document.createElement("option"),s.innerHTML=l.get("slug"),s.value=l.get("slug"),l.get("slug")===d&&(s.selected=!0),t.appendChild(s),r++)}),0===n&&(s=document.createElement("option"),s.innerHTML=l.noEmailFields,s.value="",e.appendChild(s),e.disabled=!0),0===c&&(s=document.createElement("option"),s.innerHTML=l.noNameFields,s.value="",i.appendChild(s),i.disabled=!0),0===r&&(s=document.createElement("option"),s.innerHTML=l.noApplicableFields,s.value="",t.appendChild(s),t.disabled=!0)}},toggleNotificationFields:function(){var e=this.el.querySelectorAll(".email-notification-from-address")[0],t=this.el.querySelectorAll(".email-notification-from-field")[0],i=this.el.querySelectorAll(".form-email-notification-from-type")[0],l=this.el.querySelectorAll(".email-notification-subject")[0],s=this.el.querySelectorAll(".email-notification-subject-field")[0],o=this.el.querySelectorAll(".form-email-notification-subject-type")[0],n=this.el.querySelectorAll(".email-notification-from-name")[0],c=this.el.querySelectorAll(".email-notification-from-name-field")[0],r=this.el.querySelectorAll(".form-email-notification-from-name-type")[0];e.style.display="none",t.style.display="none","custom"===i.value?e.style.display="block":"field"===i.value&&(t.style.display="block"),l.style.display="none",s.style.display="none","custom"===o.value?l.style.display="block":"field"===o.value&&(s.style.display="block"),n.style.display="none",c.style.display="none","custom"===r.value?n.style.display="block":"field"===r.value&&(c.style.display="block")},save:function(){if(""!==this.el.innerHTML&&"edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-title")[0].value;this.model.set("title",e);var t=this.el.querySelectorAll(".form-email-notification-content")[0].value;this.model.set("content",t);var i=this.el.querySelectorAll(".form-email-notification-active")[0].value;this.model.set("active","1"===i?!0:!1);var l=this.el.querySelectorAll(".form-email-notification-from-type")[0].value;this.model.set("fromType",l);var s=this.el.querySelectorAll(".form-email-notification-from-address")[0].value;this.model.set("fromAddress",s);var o=this.el.querySelectorAll(".form-email-notification-from-field")[0].value;this.model.set("fromField",o);var n=this.el.querySelectorAll(".form-email-notification-from-name-type")[0].value;this.model.set("fromNameType",n);var c=this.el.querySelectorAll(".form-email-notification-from-name")[0].value;this.model.set("fromName",c);var r=this.el.querySelectorAll(".form-email-notification-from-name-field")[0].value;this.model.set("fromNameField",r);var a=this.el.querySelectorAll(".form-email-notification-subject-type")[0].value;this.model.set("subjectType",a);var d=this.el.querySelectorAll(".form-email-notification-subject")[0].value;this.model.set("subject",d);var u=this.el.querySelectorAll(".form-email-notification-subject-field")[0].value;this.model.set("subjectField",u);for(var f=0;this.addressViews.length>f;f++)this.addressViews[f].save();return this}},render:function(){var e={context:this.context,form:this.form.toJSON()};if(this.model&&(e.notification=this.model.toJSON()),this.el.innerHTML=this.template(e),"edit"===this.context){this.toggleNotificationFields(),this.updateFromFieldField(),this.updateFieldVariables();var t=this.el.querySelectorAll(".addresses")[0],i=this.model.get("addresses");if(i.length>=1)i.each(function(e){var i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form}).render();t.appendChild(i.el),this.addressViews.push(i)},this);else{var l=new wp.ccf.models.FormNotificationAddress;i.add(l)}}var s=this.form.get("fields");return this.listenTo(s,"add",this.updateFromFieldField,this),this.listenTo(s,"remove",this.updateFromFieldField,this),this.listenTo(s,"add",this.updateFieldVariables,this),this.listenTo(s,"remove",this.updateFieldVariables,this),this},triggerDelete:function(){this.parent.deleteNotification(this)}}),wp.ccf.views.FieldBase=wp.ccf.views.FieldBase||t.View.extend({events:{"blur input":"saveField","blur input.field-slug":"checkSlug","blur textarea":"saveField","change select":"saveField",'change input[type="checkbox"]':"saveField"},initialize:function(){var e=this.model.get("conditionals");this.listenTo(e,"add",this.addConditional)},addConditional:function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render(),i=this.el.querySelectorAll(".conditionals")[0];i.appendChild(t.el)},checkSlug:function(){var e=this.el.querySelectorAll(".field-slug");if(e.length>0){var t=e[0],i=!1;t.parentNode.className=t.value&&!t.value.match(/^[a-zA-Z0-9\-_]+$/)?t.parentNode.className.replace(/ field-error/i,"")+" field-error":t.parentNode.className.replace(/ field-error/i,""),this.collection.length>0&&""!==t.value?(this.collection.each(function(e){e!==this.model&&t.value===e.get("slug")&&(i=!0)
2
- },this),t.parentNode.className=i?t.parentNode.className.replace(/ field-duplicate-slug/i,"")+" field-duplicate-slug":t.parentNode.className.replace(/ field-duplicate-slug/i,"")):t.parentNode.className=t.parentNode.className.replace(/ field-duplicate-slug/i,"")}},destroy:function(){this.unbind()},saveField:function(){var t=this.el.querySelectorAll(".conditionals")[0].querySelectorAll(".conditional");i.each(t,function(t){e(t).trigger("saveConditional")}),this.model.set("conditionalType",this.el.querySelectorAll(".field-conditional-type")[0].value),this.model.set("conditionalFieldsRequired",this.el.querySelectorAll(".field-conditional-fields-required")[0].value);var l=this.model.get("conditionalsEnabled");this.model.set("conditionalsEnabled",1==this.el.querySelectorAll(".field-conditionals-enabled")[0].value?!0:!1),l!==this.model.get("conditionalsEnabled")&&this.render("advanced")},render:function(e){e=e?e:"basic",this.el.innerHTML=this.template({field:this.model.toJSON(),startPanel:e}),this.checkSlug();var t=this.model.get("conditionals"),i=this.el.querySelectorAll(".conditionals")[0];if(t.length>=1)t.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();i.appendChild(t.el)},this);else{var l=new wp.ccf.models.FieldConditional;t.add(l)}return this}}),wp.ccf.views.Fields["single-line-text"]=wp.ccf.views.Fields["single-line-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-single-line-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.file=wp.ccf.views.Fields.file||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-file-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.model.set("fileExtensions",this.el.querySelectorAll(".field-file-extensions")[0].value),this.model.set("maxFileSize",this.el.querySelectorAll(".field-max-file-size")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.recaptcha=wp.ccf.views.Fields.recaptcha||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-recaptcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("siteKey",this.el.querySelectorAll(".field-site-key")[0].value),this.model.set("secretKey",this.el.querySelectorAll(".field-secret-key")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["section-header"]=wp.ccf.views.Fields["section-header"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-section-header-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("heading",this.el.querySelectorAll(".field-heading")[0].value),this.model.set("subheading",this.el.querySelectorAll(".field-subheading")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.html=wp.ccf.views.Fields.html||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-html-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("html",this.el.querySelectorAll(".field-html")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["paragraph-text"]=wp.ccf.views.Fields["paragraph-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-paragraph-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.hidden=wp.ccf.views.Fields.hidden||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-hidden-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.date=wp.ccf.views.Fields.date||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-date-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length>0&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-date-format");t.length&&this.model.set("dateFormat",t[0].value);var i=this.model.get("showDate"),l=this.el.querySelectorAll(".field-show-date")[0].checked?!0:!1;this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("showDate",l);var s=this.model.get("showTime"),o=this.el.querySelectorAll(".field-show-time")[0].checked?!0:!1;return this.model.set("showTime",o),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),(o!=s||l!=i)&&this.render(),this}}}),wp.ccf.views.Fields.name=wp.ccf.views.Fields.name||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-name-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.website=wp.ccf.views.Fields.website||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-website-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.phone=wp.ccf.views.Fields.phone||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-phone-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("phoneFormat",this.el.querySelectorAll(".field-phone-format")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.address=wp.ccf.views.Fields.address||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-address-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("addressType",this.el.querySelectorAll(".field-address-type")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.email=wp.ccf.views.Fields.email||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-email-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-placeholder");t.length&&this.model.set("placeholder",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1);var i=1==this.el.querySelectorAll(".field-email-confirmation")[0].value?!0:!1,l=this.model.get("emailConfirmation");return this.model.set("emailConfirmation",i),l!=i&&this.render(),this}}}),wp.ccf.views.ChoiceableField=wp.ccf.views.ChoiceableField||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),initialize:function(){var e=this.model.get("choices");this.listenTo(e,"add",this.addChoice)},addChoice:function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:this.model}).render(),i=this.el.querySelectorAll(".repeatable-choices")[0];i.appendChild(t.el)},saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),wp.ccf.views.ChoiceableField.__super__.saveField.apply(this,arguments);var t=this.el.querySelectorAll(".repeatable-choices")[0].querySelectorAll(".choice");return i.each(t,function(t){e(t).trigger("saveChoice")}),this}},render:function(t){var i=this;t=t?t:"basic",i.el.innerHTML=i.template({field:i.model.toJSON(),startPanel:t}),i.checkSlug();var l=i.model.get("choices"),s=this.el.querySelectorAll(".repeatable-choices")[0];if(l.length>=1)l.each(function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:i.model}).render();s.appendChild(t.el)});else{var o=new wp.ccf.models.FieldChoice;l.add(o)}s=this.el.querySelectorAll(".repeatable-choices")[0],e(s).sortable({handle:".move",axis:"y",stop:function(e,t){t.item.trigger("sorted",t.item.index())}});var n=this.model.get("conditionals"),c=this.el.querySelectorAll(".conditionals")[0];if(n.length>=1)n.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();c.appendChild(t.el)},this);else{var r=new wp.ccf.models.FieldConditional;n.add(r)}return i}}),wp.ccf.views.Fields.dropdown=wp.ccf.views.Fields.dropdown||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.radio=wp.ccf.views.Fields.radio||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-radio-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.checkboxes=wp.ccf.views.Fields.checkboxes||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-checkboxes-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.FieldSidebar=wp.ccf.views.FieldSidebar||t.View.extend({initialize:function(e){this.currentFieldView=null,this.form=e.form},save:function(e){this.currentFieldView&&""!==this.currentFieldView.el.innerHTML&&this.currentFieldView.saveField(),e&&e instanceof Object&&e.resolve()},fieldRemoved:function(){this.currentFieldView&&(this.form.get("fields").get(this.currentFieldView.model)||this.render())},destroy:function(){wp.ccf.dispatcher.off("saveField",this.save),wp.ccf.dispatcher.off("mainViewChange",this.save),this.unbind()},render:function(e){var t={};if(e){var i=e.get("type");this.currentFieldView&&(this.currentFieldView.saveField(),this.currentFieldView.destroy&&this.currentFieldView.destroy()),this.currentFieldView=new wp.ccf.views.Fields[i]({model:e,collection:this.form.get("fields")}),this.currentFieldView.render(),this.el.innerHTML="",this.el.appendChild(this.currentFieldView.el);var l=this.form.get("fields");this.listenTo(l,"remove",this.fieldRemoved)}else{var s=wp.ccf.utils.template("ccf-empty-field-template");this.el.innerHTML=s(t)}return wp.ccf.dispatcher.on("saveField",this.save,this),wp.ccf.dispatcher.on("mainViewChange",this.save,this),this}}),wp.ccf.views.FieldRowPlaceholder=wp.ccf.views.FieldRowPlaceholder||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",initialize:function(e){this.type=e.type},render:function(){return this.el.innerHTML=this.template({label:l.allLabels[this.type]}),this.el.setAttribute("data-field-type",this.type),this.el.className+=" "+this.type,this}}),wp.ccf.views.FieldRow=wp.ccf.views.FieldRow||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",events:{"click .delete":"triggerDelete","click h4":"triggerEdit",sorted:"triggerUpdateSort"},initialize:function(e){i.bindAll(this,"triggerDelete"),this.form=e.form,this.listenTo(this.model,"change",this.handleChange,this),this.listenTo(this.model,"requirementsNotMet",this.requirementsNotMet,this),this.listenTo(this.model,"requirementsMet",this.requirementsMet,this),this.listenTo(this.model,"duplicateSlug",this.duplicateSlug,this),this.model.attributes.choices&&this.listenTo(this.model.attributes.choices,"change",this.handleChange,this)},duplicateSlug:function(){this.requirementsMet(),this.el.className+=" field-duplicate-slug"},requirementsNotMet:function(){this.requirementsMet(),this.el.className+=" field-incomplete"},requirementsMet:function(){this.el.className=this.el.className.replace(/(field-incomplete|field-duplicate-slug)/i,"")},triggerUpdateSort:function(e,t){this.form.get("fields").remove(this.model),this.form.get("fields").add(this.model,{at:t})},handleChange:function(){this.render()},triggerDelete:function(e){e.stopPropagation(),this.form.get("fields").remove(this.model),this.undelegateEvents(),this.remove()},triggerEdit:function(){var e=this.el.parentNode.querySelectorAll(".ccf-editing");i.each(e,function(e){e.className=e.className.replace(/ccf-editing/i,"")}),this.el.className=this.el.className.replace(/ccf-editing/i,"")+" ccf-editing",wp.ccf.dispatcher.trigger("openEditField",this.model)},render:function(e){this.el.innerHTML=this.template({label:l.allLabels[this.model.get("type")]}),this.el.setAttribute("data-field-type",this.model.get("type"));var t=RegExp(" "+this.model.get("type"),"i");this.el.className=this.el.className.replace(t,"")+" "+this.model.get("type"),e&&(this.el.className=this.el.className.replace(/ instantiated/i,"")+" instantiated");var i=document.getElementById("ccf-"+this.model.get("type")+"-preview-template");if(i){var s=this.el.querySelectorAll(".preview")[0];s.style.display="block",s.innerHTML=wp.ccf.utils.template("ccf-"+this.model.get("type")+"-preview-template")({field:this.model.toJSON()})}return this}}),wp.ccf.views.PostFieldMapping=t.View.extend({template:wp.ccf.utils.template("ccf-post-field-mapping"),className:"field-mapping",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".field-form-field")[0].value,t=this.el.querySelectorAll(".field-post-field")[0].value,i=this.el.querySelectorAll(".field-custom-field-key"),l=this.model.get("postField");return this.model.set("formField",e),this.model.set("postField",t),i.length&&this.model.set("customFieldKey",i[0].value),l!==t&&this.render(),this}},updateFormFieldField:function(){var e=this.el.querySelectorAll(".field-form-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("formField");i.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),i.each(function(i){t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++})),0===s&&(t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},updatePostFields:function(){var e,t=this.el.querySelectorAll(".field-post-field")[0];e=document.createElement("option"),e.value="",e.innerText=l.choosePostField,t.appendChild(e);var s=this.form.get("postFieldMappings"),o=[];s.each(function(e){e!==this.model&&o.push(e.get("postField"))},this),i.each(l.postFields.single,function(i,l){-1===o.indexOf(l)&&(e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e))},this),i.each(l.postFields.repeatable,function(i,l){e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e)},this)},render:function(){var e={};this.model&&(e.mapping=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFormFieldField,this),this.listenTo(t,"remove",this.updateFormFieldField,this),this.updateFormFieldField(),this.updatePostFields(),this},triggerAdd:function(){this.form.get("postFieldMappings").add(new wp.ccf.models.PostFieldMapping)},triggerDelete:function(){var e=this.form.get("postFieldMappings");e.length>1?this.parent.deletePostFieldMapping(this):(this.model.clear().set(wp.ccf.models.PostFieldMapping.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.FormSettings=wp.ccf.views.FormSettings||t.View.extend({template:wp.ccf.utils.template("ccf-form-settings-template"),events:{"blur input":"save","change select":"save","change select.form-completion-action-type":"toggleCompletionFields","change select.form-pause":"togglePauseFields","change select.form-post-creation":"togglePostCreationFields","click .add-notification":"triggerAddNotification"},notificationViews:[],mappingViews:[],initialize:function(e){this.model=e.form,this.notificationViews=[],this.mappingViews=[];var t=this.model.get("notifications");this.listenTo(t,"add",this.addNotification);var i=this.model.get("postFieldMappings");this.listenTo(i,"add",this.addPostFieldMapping)},deletePostFieldMapping:function(e){i.each(this.mappingViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.mappingViews,t);this.model.get("postFieldMappings").remove(e.model),this.mappingViews[l].remove(),this.mappingViews.splice(l,1)}},this)},addPostFieldMapping:function(e){var t=this.el.querySelectorAll(".post-creation-mapping")[0],i=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model});this.mappingViews.push(i),t.appendChild(i.render().el)},triggerAddNotification:function(){var e=this.model.get("notifications");e.add(new wp.ccf.models.FormNotification)},closeAllNotifications:function(){i.each(this.notificationViews,function(e){e.changeContext(null,"view")})},addNotification:function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,context:"edit",parent:this}).render(),l=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];l.querySelectorAll(".no-notifications").length>0&&l.removeChild(l.firstChild),i.each(this.notificationViews,function(e){e.changeContext(null,"view")}),this.notificationViews.push(t),l.appendChild(t.el)},toggleCompletionFields:function(){var e=this.el.querySelectorAll(".form-completion-action-type")[0].value,t=this.el.querySelectorAll(".completion-message")[0],i=this.el.querySelectorAll(".completion-redirect-url")[0];"text"===e?(t.style.display="block",i.style.display="none"):(t.style.display="none",i.style.display="block")},togglePauseFields:function(){var e=this.el.querySelectorAll(".form-pause")[0].value,t=this.el.querySelectorAll(".pause-message")[0];t.style.display=parseInt(e)?"block":"none"},togglePostCreationFields:function(){var t=this.el.querySelectorAll(".form-post-creation")[0].value,i=e(this.el.querySelectorAll(".post-creation-mapping-field"));parseInt(t)?i.show():i.hide()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-title")[0].value;this.model.set("title",{raw:e});var t=this.el.querySelectorAll(".form-description")[0].value;this.model.set("description",t);var i=this.el.querySelectorAll(".form-button-text")[0].value;this.model.set("buttonText",i);var l=this.el.querySelectorAll(".form-pause")[0].value;this.model.set("pause",parseInt(l)?!0:!1);var s=this.el.querySelectorAll(".form-post-creation")[0].value;this.model.set("postCreation",parseInt(s)?!0:!1);var o=this.el.querySelectorAll(".form-post-creation-type")[0].value;this.model.set("postCreationType",o);var n=this.el.querySelectorAll(".form-post-creation-status")[0].value;this.model.set("postCreationStatus",n);var c=this.el.querySelectorAll(".form-pause-message")[0].value;this.model.set("pauseMessage",c);var r=this.el.querySelectorAll(".form-completion-message")[0].value;this.model.set("completionMessage",r);var a=this.el.querySelectorAll(".form-completion-redirect-url")[0].value;this.model.set("completionRedirectUrl",a);var d=this.el.querySelectorAll(".form-completion-action-type")[0].value;this.model.set("completionActionType",d);var u=this.el.querySelectorAll(".form-theme")[0].value;this.model.set("theme",u)}},fullSave:function(e){""!==this.el.innerHTML&&(this.save(),i.each(this.notificationViews,function(e){e.save()}),i.each(this.mappingViews,function(e){e.save()}),e!==void 0&&e.promise!==void 0&&e.resolve())},destroy:function(){wp.ccf.dispatcher.off("saveFormSettings",this.fullSave),wp.ccf.dispatcher.off("mainViewChange",this.fullSave)},deleteNotification:function(e){if(i.each(this.notificationViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.notificationViews,t);this.model.get("notifications").remove(e.model),this.notificationViews[l].remove(),this.notificationViews.splice(l,1)}},this),!this.notificationViews.length){var t=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];t.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el)}},render:function(){var e={form:this.model.toJSON()};this.model.get("fields");var t=this.model.get("notifications");this.el.innerHTML=this.template(e),this.toggleCompletionFields(),this.togglePostCreationFields(),this.togglePauseFields();var i=this.el.querySelectorAll(".ccf-form-notifications .rows")[0],l=document.createElement("tbody");l.className="rows",t.length>=1?t.each(function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,parent:this}).render();l.appendChild(t.el),this.notificationViews.push(t)},this):l.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el),i.parentNode.replaceChild(l,i);var s=this.el.querySelectorAll(".post-creation-mapping")[0],o=this.model.get("postFieldMappings");if(o.length>=1)o.each(function(e){var t=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model}).render();s.appendChild(t.el),this.mappingViews.push(t)},this);else{var n=new wp.ccf.models.PostFieldMapping;o.add(n)}return wp.ccf.dispatcher.on("mainViewChange",this.fullSave,this),wp.ccf.dispatcher.on("saveFormSettings",this.fullSave,this),this}}),wp.ccf.views.FormPane=wp.ccf.views.FormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-form-pane-template"),subViews:{"field-sidebar":wp.ccf.views.FieldSidebar,"form-settings":wp.ccf.views.FormSettings},events:{"click .save-button":"sync","click .signup-button":"signup","click .accordion-heading":"accordionClick","click .form-settings-heading":"accordionClick","click .insert-form-button":"insertForm"},initialize:function(){wp.ccf.dispatcher.on("openEditField",this.openEditField,this)},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},signup:function(){var t=this.el.querySelectorAll(".email-signup-field")[0].value,i=this.el.querySelectorAll(".bottom .left.signup")[0];i.className="left signup",t?e.ajax({url:"//taylorlovett.us8.list-manage.com/subscribe/post-json?u=66118f9a5b0ab0414e83f043a&amp;id=b4ed816a24&c=?",method:"post",dataType:"jsonp",data:{EMAIL:t}}).done(function(){i.className="left signup signup-success"}):i.className="left signup signup-error"},accordionClick:function(t){var l=e(t.currentTarget).parents(".accordion-container")[0],s=l.querySelectorAll(".accordion-section");t.currentTarget.parentNode.className.match(/expanded/i)?t.currentTarget.parentNode.className=t.currentTarget.parentNode.className.replace(/expanded/i,""):t.currentTarget.parentNode.className+=" expanded",i.each(s,function(e){e!=t.currentTarget.parentNode&&e.className.match(/expanded/i)&&(e.className=e.className.replace(/expanded/i,""))}),t.currentTarget.className.match(/form-settings-heading/i)?this.el.className.match(/show-form-settings/i)?this.el.className=this.el.className.replace(/show-form-settings/i,""):this.el.className+=" show-form-settings":this.el.className=this.el.className.replace(/show-form-settings/i,"")},openEditField:function(e){this.renderedSubViews["field-sidebar"].render(e).el.style.display="block"},disable:function(){this.el.querySelectorAll(".save-button")[0].setAttribute("disabled","disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="block"},enable:function(){this.el.querySelectorAll(".save-button")[0].removeAttribute("disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="none"},sync:function(){var t=this,i=e(this.el.querySelectorAll(".spinner")[0]);i.fadeIn(),t.disable();var s=e.Deferred(),o=e.Deferred();wp.ccf.dispatcher.trigger("saveFormSettings",s),wp.ccf.dispatcher.trigger("saveField",o),e.when(s,o).then(function(){var e=t.model.get("fields"),s=!0,o={};e.each(function(e){var t=e.get("slug");e.hasRequiredAttributes()?t&&!t.match(/^[a-zA-Z0-9\-_]+$/)?(s=!1,e.trigger("requirementsNotMet")):o[e.get("slug")]!==void 0?(s=!1,e.trigger("duplicateSlug"),o[e.get("slug")].trigger("duplicateSlug")):e.trigger("requirementsMet"):(s=!1,e.trigger("requirementsNotMet")),e.get("slug")&&(o[e.get("slug")]=e)}),s?t.model.save({},{context:"edit"}).error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}).done(function(){l.single&&!l.postId&&(window.location=l.adminUrl+"post.php?post="+t.model.get("id")+"&action=edit#ccf-form/"+t.model.get("id"))}).complete(function(){i.fadeOut(),t.enable(),wp.ccf.dispatcher.trigger("saveFormComplete",t.model)}):(t.enable(),i.fadeOut())})},enableDisableInsert:function(){var e=this.el.querySelectorAll(".insert-form-button")[0];this.model.get("id")?e.removeAttribute("disabled"):e.setAttribute("disabled","disabled")},getNextFieldOrd:function(){var e=this.model.get("fields"),t=e.length+1;return e.each(function(e){var i=e.get("slug"),l=/\-([0-9]+)$/g,s=l.exec(i);if(s&&s[1]){var o=parseInt(s[1]);o>=t&&(t=o+1)}}),t},render:function(t){var s=this;s.model=t?t:new wp.ccf.models.Form,this.listenTo(s.model,"change",this.enableDisableInsert,this);var o={labels:l.fieldLabels,form:s.model.toJSON()};window.form=s.model,s.el.innerHTML=this.template(o),s.el.className=s.el.className.replace(/show-form-settings/i,"");var n=s.el.querySelectorAll(".fields")[0];i.each(l.fieldLabels,function(e,t){n.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var c=s.el.querySelectorAll(".structure-fields")[0];i.each(l.structureFieldLabels,function(e,t){c.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var r=s.el.querySelectorAll(".special-fields")[0];i.each(l.specialFieldLabels,function(e,t){r.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var a=s.model.get("fields"),d=s.el.querySelectorAll(".form-content")[0],u=e(d);return e(s.el.querySelectorAll(".left-sidebar")[0].querySelectorAll(".field")).draggable({cursor:"move",distance:2,zIndex:160001,scroll:!1,containment:"document",appendTo:".ccf-main-modal",snap:!1,connectToSortable:".form-content",helper:function(t){var i=e(t.currentTarget),l=e('<div class="field" data-field-type="'+i.attr("data-field-type")+'"><h4>'+i.find(".label").html()+"</h4></div>");return l.css({width:u.width(),opacity:".75",height:i.height()})}}),a.length>=1&&(d.innerHTML="",a.each(function(e){var t=new wp.ccf.views.FieldRow({model:e,form:s.model}).render(!0).el;d.appendChild(t)})),e(d).sortable({axis:"y",distance:2,handle:"h4",placeholder:"field-placeholder",stop:function(e,t){if(!t.item.hasClass("instantiated")){var i=t.item.attr("data-field-type"),l={};wp.ccf.models.Fields[i].prototype.defaults().slug!==void 0&&(l.slug=i+"-"+s.getNextFieldOrd());var o=new wp.ccf.models.Fields[i](l),n=s.model.get("fields");n.add(o),new wp.ccf.views.FieldRow({model:o,el:t.item,form:s.model}).render(!0),t.item.attr("style","")}t.item.trigger("sorted",t.item.index())}}),s.initRenderSubViews(!1,!0,{form:s.model}),s.enableDisableInsert(),s}},wp.ccf.mixins.subViewable)),wp.ccf.views.ExistingFormTableRow=wp.ccf.views.ExistingFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-existing-form-table-row-template"),events:{"click .edit":"triggerMainViewChange","click .delete":"triggerDelete","click .insert-form-button":"insertForm"},initialize:function(e){this.parent=e.parent
3
- },insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},triggerMainViewChange:function(){wp.ccf.switchToForm(this.model)},triggerDelete:function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},render:function(){return this.$el.html(this.template({form:this.model.toJSON(),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate}})),this}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.ExistingFormTable=wp.ccf.views.ExistingFormTable||t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-table-template"),initialize:function(){this.parent=arguments.parent,this.collection=new wp.ccf.collections.Forms,wp.ccf.dispatcher.on("changeFormTablePage",this.showPage,this),wp.ccf.dispatcher.on("saveFormComplete",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".rows")[0],i=document.createElement("tbody");i.className="rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.ExistingFormTableRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild((new wp.ccf.views.EmptyFormTableRow).render().el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(){var e=this;return this.el.innerHTML=this.template(),this.el.querySelectorAll(".ccf-pagination")[0],this.showPage(1).done(function(){e.renderPagination()}),this}}),wp.ccf.views.ExistingFormPane=wp.ccf.views.ExistingFormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-existing-form-pane-template"),subViews:{"existing-form-table":wp.ccf.views.ExistingFormTable},render:function(){return this.rendered?this:(this.rendered=!0,this.el.innerHTML=this.template(),this.initRenderSubViews(!0),this)}},wp.ccf.mixins.subViewable)),wp.ccf.views.MainModal=wp.ccf.views.MainModal||t.View.extend(i.defaults({tagName:"div",className:"ccf-main-modal",template:wp.ccf.utils.template("ccf-main-modal-template"),events:{"click .close-icon":"hide","click .main-menu a":"menuClick"},subViews:{"form-pane":wp.ccf.views.FormPane},initialize:function(){l.single||(this.subViews["existing-form-pane"]=wp.ccf.views.ExistingFormPane),wp.ccf.dispatcher.on("mainViewChange",this.toggleView,this)},toggleView:function(e){this.showView(e,wp.ccf.currentForm);var t=e;"form-pane"===e&&wp.ccf.currentForm&&(t="existing-form-pane");var l=this.el.querySelectorAll(".menu-item");i.each(l,function(e){var i=e.getAttribute("data-view");e.className=i===t?e.className.replace("selected","")+" selected":e.className.replace("selected","")})},menuClick:function(e){var t=e.target.getAttribute("data-view");"form-pane"===t&&(wp.ccf.currentForm=null),wp.ccf.dispatcher.trigger("mainViewChange",t),e.preventDefault()},render:function(e){return e=e||!1,this.overlay(),this.el.innerHTML=this.template({single:e}),this.initRenderSubViews(),this.showView("form-pane",wp.ccf.currentForm,!0),this},overlay:function(){return this.overlayEl===void 0&&(this.overlayEl=document.createElement("div"),this.overlayEl.className="ccf-main-modal-overlay",document.body.appendChild(this.overlayEl)),this.overlayEl},remove:function(){return document.body.removeChild(this.overlay()),this},show:function(){e(this.overlay()).show(),this.$el.show()},hide:function(){e(this.overlay()).hide(),this.$el.hide()}},wp.ccf.mixins.subViewable)),wp.ccf.views.SubmissionRow=wp.ccf.views.SubmissionRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-submission-row-template"),events:{"click .view":"view","click .delete":"delete"},initialize:function(e){this.parent=e.parent},"delete":function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},view:function(e){var t=e.currentTarget.getAttribute("data-submission-id"),i=e.currentTarget.getAttribute("data-submission-date");tb_show(l.thickboxTitle+" - "+wp.ccf.utils.getPrettyPostDate(i),"#TB_inline?height=500&amp;width=700&amp;inlineId=ccf-submission-content-"+parseInt(t),null)},render:function(){return this.$el.html(this.template({submission:this.model.toJSON(),currentColumns:this.parent.columns,columns:wp.ccf.currentForm.getFieldSlugs(!0),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate,wordChop:wp.ccf.utils.wordChop,isFieldDate:wp.ccf.utils.isFieldDate,isFieldName:wp.ccf.utils.isFieldName,isFieldFile:wp.ccf.utils.isFieldFile,isFieldAddress:wp.ccf.utils.isFieldAddress,isFieldEmailConfirm:wp.ccf.utils.isFieldEmailConfirm,getPrettyFieldDate:wp.ccf.utils.getPrettyFieldDate,getPrettyFieldAddress:wp.ccf.utils.getPrettyFieldAddress,getPrettyFieldName:wp.ccf.utils.getPrettyFieldName,getPrettyFieldEmailConfirm:wp.ccf.utils.getPrettyFieldEmailConfirm}})),this}}),wp.ccf.views.SubmissionsTable=wp.ccf.views.SubmissionsTable||t.View.extend({template:wp.ccf.utils.template("ccf-submission-table-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(){this.collection=new wp.ccf.collections.Submissions({},{formId:l.postId}),wp.ccf.dispatcher.on("submissionTableRebuild",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".submission-rows")[0],i=document.createElement("tbody");i.className="submission-rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.SubmissionRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild(new wp.ccf.views.EmptySubmissionTableRow({parent:t}).render(wp.ccf.currentForm.getFieldSlugs(!0).concat("date")).el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(e){var t=this;return t.columns=e?e:wp.ccf.currentForm.getFieldSlugs(!0).slice(0,4).concat("date"),1>t.columns.length?t.el.innerHTML="":(t.el.innerHTML=t.template({columns:t.columns}),t.el.querySelectorAll(".ccf-pagination")[0],t.showPage(1).done(function(){t.renderPagination()})),t}}),wp.ccf.views.ErrorModal=wp.ccf.views.ErrorModal||t.View.extend({template:wp.ccf.utils.template("ccf-error-modal-template"),tagName:"div",className:"ccf-error-modal",events:{"click .close":"hide"},hide:function(){this.el.className=this.el.className.replace(" show","")},show:function(){this.el.className=this.el.className.replace(" show","")+" show"},toggle:function(){this.el.className.match(" show")?this.hide():this.show()},render:function(e){var t={messageType:""};return e&&(t.messageType=e),this.el.innerHTML=this.template(t),this}}),wp.ccf.views.Pagination=wp.ccf.views.Pagination||t.View.extend({template:wp.ccf.utils.template("ccf-pagination-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(e){this.parent=e.parent},previousPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage-1).done(function(){e.render()})},nextPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage+1).done(function(){e.render()})},firstPage:function(){var e=this;e.parent.showPage(1).done(function(){e.render()})},lastPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.totalPages).done(function(){e.render()})},render:function(){return this.el.innerHTML=this.template({totalPages:this.parent.collection.state.totalPages,currentPage:this.parent.collection.state.currentPage,totalObjects:this.parent.collection.state.totalObjects}),this}}),wp.ccf.views.EmptySubmissionTableRow=wp.ccf.views.EmptySubmissionTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-no-submissions-row-template"),initialize:function(e){this.parent=e.parent},render:function(){return this.el.innerHTML=this.template({columns:this.parent.columns}),this}}),wp.ccf.views.SubmissionColumnController=wp.ccf.views.SubmissionColumnController||t.View.extend({template:wp.ccf.utils.template("ccf-submissions-controller-template"),events:{"click input[type=checkbox]":"triggerTableRebuild"},render:function(){this.el.innerHTML=this.template({columns:wp.ccf.currentForm.getFieldSlugs(!0).concat("date")})},triggerTableRebuild:function(){var e=[],t=document.querySelectorAll(".submission-column-checkbox");if(t.length>=1)for(var i=0;t.length>i;i++)t[i].checked&&e.push(t[i].value);wp.ccf.dispatcher.trigger("submissionTableRebuild",e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t){"use strict";wp.ccf.router=wp.ccf.router||t.Router.extend({routes:{"ccf-form":"open","ccf-form/:formId":"open"},open:function(e){wp.ccf.show(e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf=i.defaults(wp.ccf,{forms:new wp.ccf.collections.Forms,currentForm:null,errorModal:null,_currentFormDeferred:null,dispatcher:{},show:function(e){return this.switchToForm(e),this.instance.show(),this.instance},initErrorModal:function(){this.errorModal=(new wp.ccf.views.ErrorModal).render();var e=document.getElementsByTagName("body")[0];e.appendChild(this.errorModal.el)},switchToForm:function(e){var t=this;if(+e===parseInt(e)){var i=parseInt(e);if(e=t.forms.findWhere({id:parseInt(i)}),!e){var l;return t.forms.formsFetching[i]!==void 0?(l=t.forms.formsFetching[i],e=null):(e=new wp.ccf.models.Form({id:i}),l=e.fetch(),t.forms.formsFetching[i]=l),l.done(function(){e?(delete t.forms.formsFetching[i],t.forms.add(e)):e=t.forms.findWhere({id:i}),t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}),l}t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}else t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane");return!0},hide:function(){return this.instance.hide(),this.instance},toggle:function(e){return this.switchToForm(e),this.instance.$el.is(":visible")?this.instance.hide():this.instance.show(),this.instance},createSubmissionsTable:function(e){var t=document.querySelectorAll(".ccf-submission-column-controller"),i=new wp.ccf.views.SubmissionsTable({el:e});i.render(),t&&new wp.ccf.views.SubmissionColumnController({el:t}).render()},_setupMainModal:function(e){return this.instance=(new wp.ccf.views.MainModal).render(e),document.getElementsByTagName("body")[0].appendChild(this.instance.el),t.history.start(),this.instance},createManager:function(){var s=this,o=document.querySelectorAll(".ccf-open-form-manager")[0];if(!o)return!1;i.extend(this.dispatcher,t.Events),new wp.ccf.router,s.initErrorModal();var n=!1;if(l.single)if(n=!0,l.postId){var c=parseInt(l.postId);if(s.forms.formsFetching[c]===void 0){var r=new wp.ccf.models.Form({id:c}),a=r.fetch();s.forms.formsFetching[c]=a,s._currentFormDeferred=a,a.done(function(){delete s.forms.formsFetching[c],s.forms.add(r),s.currentForm=r})}else s._currentFormDeferred=s.forms.formsFetching[c],s._currentFormDeferred.done(function(){s.currentForm=s.forms.findWhere({id:c})});e.when(s._currentFormDeferred).then(function(){s._setupMainModal(!0),o.style.display="inline-block";var e=document.getElementById("ccf-submissions");if(e){var t=e.querySelectorAll(".inside")[0],i=document.createElement("div");i.className="ccf-submission-icon",i.setAttribute("data-icon","");var n=document.createElement("a");n.href="?action=edit&post="+parseInt(l.postId)+"&download_submissions=1&download_submissions_nonce="+l.downloadSubmissionsNonce,n.className="ccf-submission-icon",n.setAttribute("data-icon","");var c=document.getElementById("show-settings-link");i.onclick=function(){c.click()},e.insertBefore(i,e.firstChild.nextSibling.nextSibling),e.insertBefore(n,e.firstChild.nextSibling.nextSibling),wp.ccf.createSubmissionsTable(t)}})}else s._setupMainModal(!0),o.style.display="inline-block";else s._setupMainModal();var d=function(e){e=e||window.event;var t=e.currentTarget?e.currentTarget:e.srcElement,i=t.getAttribute("data-form-id");wp.ccf.toggle(i)};o.addEventListener?o.addEventListener("click",d,!1):o.attachEvent("onclick",d)}}),wp.ccf.createManager()}(jQuery,Backbone,_,ccfSettings);
1
+ (function(e,t,i,l){"use strict";window.wp=window.wp||{},wp.ccf=wp.ccf||{},wp.ccf.utils=wp.ccf.utils||{},wp.ccf.utils.cleanDateFields=function(e){delete e.date,delete e.date_gmt,delete e.modified,delete e.modified_gmt,delete e.date_tz,delete e.modified_tz},wp.ccf.utils.template=i.memoize(function(e){var t={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};return i.template(document.getElementById(e).innerHTML,null,t)}),wp.ccf.utils.insertFormShortcode=function(e){var t=wp.ccf.forms.findWhere({id:e.get("id")});t||wp.ccf.forms.add(e);var i=tinymce.get(wpActiveEditor),l='[ccf_form id="'+e.get("id")+'"]';i&&!i.isHidden()?tinymce.activeEditor.execCommand("mceInsertContent",!1,l):document.getElementById(wpActiveEditor).value+=l},wp.ccf.utils.getPrettyPostDate=function(e){return e=moment.utc(e),l.gmtOffset&&(e=e.utcOffset(60*parseInt(l.gmtOffset))),e.format("h:mm a M/D/YYYY")},wp.ccf.utils.wordChop=function(e,t){var i=e.substr(0,t);return i.substr(0,Math.min(i.length,i.lastIndexOf(" "))),i.length<e.length&&(i+="..."),i},wp.ccf.utils.isFieldDate=function(e){return e.date!==void 0||e.hour!==void 0&&e.minute!==void 0&&e["am-pm"]!==void 0?!0:!1},wp.ccf.utils.isFieldName=function(e){return e.name!==void 0||e.last!==void 0?!0:!1},wp.ccf.utils.isFieldEmailConfirm=function(e){return e.email!==void 0||e.confirm!==void 0?!0:!1},wp.ccf.utils.isFieldAddress=function(e){return e.street!==void 0&&e.city!==void 0&&e.zipcode!==void 0&&e.line_two!==void 0?!0:!1},wp.ccf.utils.isFieldFile=function(e){return e.id!==void 0&&e.url!==void 0&&e.file_name!==void 0?!0:!1},wp.ccf.utils.getPrettyFieldEmailConfirm=function(e){return e.email?e.email:e.confirm?e.confirm:"-"},wp.ccf.utils.getPrettyFieldDate=function(e,t){var i="",s="",o="MM/DD/YY";if(t&&t.ccf_field_dateFormat&&"dd/mm/yyyy"===t.ccf_field_dateFormat&&(o="DD/MM/YY"),e.hour&&e.minute&&e["am-pm"]&&(i+=e.hour+":"+e.minute+" "+e["am-pm"],o="HH:mm "+o),e.date&&(i&&(i+=" "),i+=e.date),!i)return"-";var n=moment(i,o);return n.isValid()?(e.hour&&e.minute&&e["am-pm"]&&(s+=n.format("h:mm a")),e.date&&(s&&(s+=" "),s+=e.date),s):l.invalidDate},wp.ccf.utils.getPrettyFieldName=function(e){var t=e.first;return t.length>0&&(t+=" "),e.last&&(t+=e.last),t||(t="-"),t},wp.ccf.utils.getPrettyFieldAddress=function(e){if(!e.street||!e.city)return"-";var t=e.street;return e.line_two&&(t+=" "+e.line_two),t+=", "+e.city,e.state&&(t+=", "+e.state),e.zipcode&&(t+=" "+e.zipcode),e.country&&(t+=" "+e.country),t}})(jQuery,Backbone,_,ccfSettings),function(e,t,i){"use strict";wp.ccf.mixins=wp.ccf.mixins||{},wp.ccf.mixins.subViewable=wp.ccf.mixins.subViewable||{subViews:{},initRenderSubViews:function(e,t,l){this.renderedSubViews||(this.renderedSubViews={});for(var s in this.subViews){var o={el:this.$el.find(".ccf-"+s),parent:this};l&&i.extend(o,l),this.renderedSubViews[s]&&this.renderedSubViews[s].destroy&&this.renderedSubViews[s].destroy(),(t||!this.renderedSubViews[s])&&(this.renderedSubViews[s]=new this.subViews[s](o)),this.renderedSubViews[s].render(),e&&(this.renderedSubViews[s].el.style.display="block")}return this},showView:function(e,t,i){if(this.renderedSubViews!==void 0&&this.renderedSubViews[e]!==void 0){var l=this.renderedSubViews[e];i||l.render(t),l.el.style.display="block",this.currentView=e;for(var s in this.subViews)s!==e&&(this.renderedSubViews[s].el.style.display="none")}}}}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.models=wp.ccf.models||{},wp.ccf.models.Fields=wp.ccf.models.Fields||{};var s=function(e,i,l){return"object"!=typeof i&&""===i&&(i=""),t.Model.prototype.set.call(this,e,i,l)},o=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)},n=function(e){for(var t in this.attributes)if(-1===i.indexOf(e,t)){var l=this.get(t);"string"==typeof l&&""!==l&&(l=(l+"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#8220;/g,"”").replace(/&#8221;/g,"”").replace(/&#8216;/g,"‘").replace(/&#038;/g,"&").replace(/&#039;/g,"'"),this.set(t,l))}return this};wp.ccf.models.FieldConditional=wp.ccf.models.FieldConditional||t.Model.extend({defaults:{field:"",compare:"is",value:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FieldChoice=wp.ccf.models.FieldChoice||t.Model.extend({defaults:{label:"",value:"",selected:!1},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.PostFieldMapping=wp.ccf.models.PostFieldMapping||t.Model.extend({defaults:{formField:"",postField:"",customFieldKey:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotificationAddress=wp.ccf.models.FormNotificationAddress||t.Model.extend({defaults:{type:"custom",field:"",email:""},decode:function(){return n.call(this,[])},set:s}),wp.ccf.models.FormNotification=wp.ccf.models.FormNotification||t.Model.extend({defaults:function(){return{title:"",content:"[all_fields]",active:!0,includeUploads:!0,addresses:new wp.ccf.collections.FormNotificationAddresses,fromType:"default",fromAddress:"",fromField:"",subjectType:"default",subject:"",subjectField:"",fromNameType:"custom",fromName:"WordPress",fromNameField:"",replyToType:"default",replyToAddress:"",replyToField:"",replyToNameType:"custom",replyToName:"WordPress",replyToNameField:""}},initialize:function(e){if("object"==typeof e&&e.addresses){var t=[];i.each(e.addresses,function(e){var i=new wp.ccf.models.FormNotificationAddress(e);i.decode(),t.push(i)}),this.set("addresses",new wp.ccf.collections.FormNotificationAddresses(t))}},decode:function(){return n.call(this,[])},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.addresses&&(e.addresses=e.addresses.toJSON()),e},set:s}),wp.ccf.models.Form=wp.ccf.models.Form||wp.ccf.api.models.Post.extend({urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",set:s,sync:o,idAttribute:"id",initialize:function(){this.on("sync",this.decode,this)},defaults:function(){var e={fields:new wp.ccf.collections.Fields,type:"ccf_form",status:"publish",hideTitle:!1,description:"",buttonText:"Submit Form",buttonClass:"",completionActionType:"text",completionRedirectUrl:"",completionMessage:"",postCreation:!1,postCreationType:"post",postCreationStatus:"draft",postFieldMappings:new wp.ccf.collections.PostFieldMappings,notifications:new wp.ccf.collections.FormNotifications,pause:!1,requireLoggedIn:!1,pauseMessage:l.pauseMessage,theme:"none"};return e=i.defaults(e,this.constructor.__super__.defaults),wp.ccf.utils.cleanDateFields(e),e},decode:function(){var e=i.keys(wp.ccf.api.models.Post.prototype.defaults);return e=i.without(e,"title"),n.call(this,e)},getFieldSlugs:function(e){var t=wp.ccf.currentForm.get("fields"),i=[];return t.each(function(t){e&&t.isImmutable||i.push(t.get("slug"))}),i},parse:function(e){var t=this,l=0,s=0;if(e.fields){var o=t.get("fields");if(o&&o.length>0){for(l=0;e.fields.length>l;l++){var n=e.fields[l],c=o.findWhere({slug:n.slug});if(c){if(n.choices!==void 0){var r=t.get("choices");if(r&&r.length>0)for(s=0;n.choices>s;s++){var a=r.at(s);a.set(n.choices[s]),a.decode()}delete e.fields[l].choices}if(n.conditionals!==void 0){var d=t.get("conditionals");if(d&&d.length>0)for(s=0;n.conditionals>s;s++){var u=d.at(s);u.set(n.conditionals[s]),u.decode()}delete e.fields[l].conditionals}c.set(n),c.decode()}}delete e.fields}else{var f=[];i.each(e.fields,function(e){var t=new wp.ccf.models.Fields[e.type](e);t.decode(),f.push(t)}),e.fields=new wp.ccf.collections.Fields(f,{formId:e.id}),o?(o.add(f),delete e.fields):e.fields=new wp.ccf.collections.Fields(f,{formId:e.id})}}if(e.notifications){var p=t.get("notifications");if(p&&p.length>0){for(l=0;e.notifications.length>l;l++){var h=e.notifications[l],m=p.at(l);if(m){if(h.addresses!==void 0){var w=m.get("addresses");if(w&&w.length>0)for(s=0;h.addresses>s;s++){var v=w.at(s);v.set(h.addresses[s]),v.decode()}delete e.notifications[l].addresses}m.set(h),m.decode()}}delete e.notifications}else{var g=[];i.each(e.notifications,function(e){var t=new wp.ccf.models.FormNotification(e);t.decode(),g.push(t)}),p?(p.add(g),delete e.notifications):e.notifications=new wp.ccf.collections.FormNotifications(g)}}if(e.postFieldMappings){var y=t.get("postFieldMappings");if(y&&y.length>0){for(l=0;e.postFieldMappings.length>l;l++){var F=e.postFieldMappings[l],b=y.at(l);b&&(b.set(F),b.decode())}delete e.postFieldMappings}else{var S=[];i.each(e.postFieldMappings,function(e){var t=new wp.ccf.models.PostFieldMapping(e);t.decode(),S.push(t)}),y?(y.add(S),e.postFieldMappings=y):e.postFieldMappings=new wp.ccf.collections.PostFieldMappings(S)}}return this.constructor.__super__.parse.call(this,e)},toJSON:function(){var e=this.constructor.__super__.toJSON.call(this);return e.fields&&(e.fields=e.fields.toJSON()),e.notifications&&(e.notifications=e.notifications.toJSON()),e.postFieldMappings&&(e.postFieldMappings=e.postFieldMappings.toJSON()),e.author&&(e.author=e.author.toJSON()),e}}),wp.ccf.models.Submission=wp.ccf.api.models.Submission||wp.ccf.api.models.Post.extend({defaults:{id:null,data:{},fields:{}},sync:o,urlRoot:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/submissions"}),wp.ccf.models.Field=wp.ccf.api.models.Field||wp.ccf.api.models.Post.extend({idAttribute:"id",defaults:function(){return{id:null,conditionalsEnabled:!1,conditionalType:"show",conditionalFieldsRequired:"all",conditionals:new wp.ccf.collections.FieldConditionals}},set:s,initialize:function(e){if("object"==typeof e&&e.conditionals){var t=[];i.each(e.conditionals,function(e){var i=new wp.ccf.models.FieldConditional(e);i.decode(),t.push(i)}),this.set("conditionals",new wp.ccf.collections.FieldConditionals(t))}},required:function(){return["slug"]},decode:function(){return n.call(this,i.keys(wp.ccf.api.models.Post.prototype.defaults))},hasRequiredAttributes:function(){var e=this,t=!0;return i.each(this.required(),function(i){(e.get(i)===void 0||""===e.get(i))&&(t=!1)}),t},sync:o}),wp.ccf.models.StandardField=wp.ccf.models.StandardField||wp.ccf.models.Field.extend({idAttribute:"id",defaults:function(){var e={label:l.fieldLabel,value:"",placeholder:"",slug:"",type:"",required:!1,className:"",description:""};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return wp.ccf.models.StandardField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["single-line-text"]=wp.ccf.models.Fields["single-line-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"single-line-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.file=wp.ccf.models.Fields.file||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"file",fileExtensions:"",maxFileSize:l.maxFileSize};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["paragraph-text"]=wp.ccf.models.Fields["paragraph-text"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"paragraph-text"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.hidden=wp.ccf.models.Fields.hidden||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"hidden"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.email=wp.ccf.models.Fields.email||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"email",emailConfirmation:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.website=wp.ccf.models.Fields.website||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"website",placeholder:"http://"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.phone=wp.ccf.models.Fields.phone||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"phone",phoneFormat:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.date=wp.ccf.models.Fields.date||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"date",showDate:!0,showTime:!0,dateFormat:"mm/dd/yyyy"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.name=wp.ccf.models.Fields.name||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"name"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.recaptcha=wp.ccf.models.Fields.recaptcha||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"recaptcha",siteKey:"",secretKey:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return["siteKey","secretKey"]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["simple-captcha"]=wp.ccf.models.Fields["simple-captcha"]||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"simple-captcha",placeholder:l.defaultSimpleCaptchaPlaceholder};return i.defaults(e,this.constructor.__super__.defaults())},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.address=wp.ccf.models.Fields.address||wp.ccf.models.StandardField.extend({defaults:function(){var e={type:"address",addressType:"us"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields["section-header"]=wp.ccf.models.Fields["section-header"]||wp.ccf.models.Field.extend({defaults:function(){var e={type:"section-header",slug:"",heading:"",subheading:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.html=wp.ccf.models.Fields.html||wp.ccf.models.Field.extend({defaults:function(){var e={type:"html",slug:"",html:"",className:""};return i.defaults(e,this.constructor.__super__.defaults())},required:function(){return[]},isImmutable:!0,initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.ChoiceableField=wp.ccf.models.ChoiceableField||wp.ccf.models.StandardField.extend({defaults:function(){var e={choices:new wp.ccf.collections.FieldChoices,useValues:!1};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(e){if("object"==typeof e&&e.choices){var t=[];i.each(e.choices,function(e){var i=new wp.ccf.models.FieldChoice(e);i.decode(),t.push(i)}),this.set("choices",new wp.ccf.collections.FieldChoices(t))}return wp.ccf.models.ChoiceableField.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.radio=wp.ccf.models.Fields.radio||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"radio"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.checkboxes=wp.ccf.models.Fields.checkboxes||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"checkboxes"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}}),wp.ccf.models.Fields.dropdown=wp.ccf.models.Fields.dropdown||wp.ccf.models.ChoiceableField.extend({defaults:function(){var e={type:"dropdown"};return i.defaults(e,this.constructor.__super__.defaults())},initialize:function(){return this.constructor.__super__.initialize.apply(this,arguments)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";var s=function(e,t,i){return i=i||{},i.emulateHTTP=!0,this.constructor.__super__.sync.call(this,e,t,i)};wp.ccf.collections=wp.ccf.collections||{},wp.ccf.collections.Forms=wp.ccf.collections.Forms||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Form,url:l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms",formsFetching:{},initialize:function(){this.constructor.__super__.initialize(),this.formsFetching={}},sync:s,remove:function(e,t){t=t||{};var l=this.constructor.__super__.remove.call(this,e,t);return t.destroy&&(e instanceof Array?i.each(e,function(e){e.destroy()}):e.destroy()),l}}),wp.ccf.collections.Fields=wp.ccf.collections.Fields||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Field,url:function(){return l.apiRoot+"/ccf/forms/"+this.formId+"/fields"},initialize:function(e,t){t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.PostFieldMappings=wp.ccf.collections.PostFieldMappings||t.Collection.extend({model:wp.ccf.models.PostFieldMapping}),wp.ccf.collections.FormNotificationAddresses=wp.ccf.collections.FormNotificationAddresses||t.Collection.extend({model:wp.ccf.models.FormNotificationAddress}),wp.ccf.collections.FormNotifications=wp.ccf.collections.FormNotifications||t.Collection.extend({model:wp.ccf.models.FormNotification}),wp.ccf.collections.Submissions=wp.ccf.collections.Submissions||wp.ccf.api.collections.Posts.extend({model:wp.ccf.models.Submission,url:function(){return l.apiRoot.replace(/\/$/,"")+"/ccf/v1/forms/"+this.formId+"/submissions"},initialize:function(e,t){this.constructor.__super__.initialize.apply(this,arguments),t&&t.formId&&(this.formId=t.formId)},sync:s}),wp.ccf.collections.FieldChoices=wp.ccf.collections.FieldChoices||t.Collection.extend({model:wp.ccf.models.FieldChoice}),wp.ccf.collections.FieldConditionals=wp.ccf.collections.FieldConditionals||t.Collection.extend({model:wp.ccf.models.FieldConditional})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf.views=wp.ccf.views||{},wp.ccf.views.Fields=wp.ccf.views.Fields||{},wp.ccf.views.FieldChoice=t.View.extend({template:wp.ccf.utils.template("ccf-field-choice-template"),className:"choice",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveChoice:"saveChoice",sorted:"triggerUpdateSort"},initialize:function(e){this.field=e.field},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveChoice),this.unbind()},triggerUpdateSort:function(e,t){this.field.get("choices").remove(this.model,{silent:!0}),this.field.get("choices").add(this.model,{at:t,silent:!0})},saveChoice:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".choice-label")[0].value,t=this.el.querySelectorAll(".choice-value"),i="";t.length&&(i=t[0].value),this.model.set("label",e),this.model.set("value",i),this.field.get("useValues")||this.model.set("value",this.model.get("label"));var l=this.el.querySelectorAll(".choice-selected")[0],s=l.checked?!0:!1;return this.model.set("selected",s),this}},render:function(){var e={showValue:this.field.get("useValues")};return this.model&&(e.choice=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveChoice,this),this},triggerAdd:function(){this.field.get("choices").add(new wp.ccf.models.FieldChoice)},triggerDelete:function(){var e=this.field.get("choices");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{for(var t=this.el.querySelectorAll(".choice-label, .choice-value"),i=this.el.querySelectorAll(".choice-selected"),l=0;t.length>l;l++)t[l].value="";i[0].checked=!1}}}),wp.ccf.views.FieldConditional=t.View.extend({template:wp.ccf.utils.template("ccf-field-conditional-template"),className:"conditional",events:{"click .add":"triggerAdd","click .delete":"triggerDelete",saveConditional:"saveConditional"},initialize:function(e){this.field=e.field,this.fieldCollection=e.fieldCollection},destroy:function(){wp.ccf.dispatcher.off("mainViewChange",this.saveConditional),this.unbind()},saveConditional:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".conditional-field")[0].value,t=this.el.querySelectorAll(".conditional-value")[0].value,i=this.el.querySelectorAll(".conditional-compare")[0].value;return this.model.set("field",e),this.model.set("value",t),this.model.set("compare",i),this}},updateFields:function(){var e=this.el.querySelectorAll(".conditional-field")[0];e.innerHTML="",e.disabled=!1;var t,i=0,s=this.model.get("field");this.fieldCollection.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),this.fieldCollection.each(function(l){if(this.field.get("slug")!==l.get("slug")){var o=l.get("type");"address"!==o&&"checkboxes"!==o&&"date"!==o&&"name"!==o&&"file"!==o&&"recaptcha"!==o&&"simple-captcha"!==o&&"section-header"!==o&&"html"!==o&&(t=document.createElement("option"),t.innerHTML=l.get("slug"),t.value=l.get("slug"),l.get("slug")===s&&(t.selected=!0),e.appendChild(t),i++)}},this)),0===i&&(e.innerHTML="",t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},render:function(){var e={};return this.model&&(e.conditional=this.model.toJSON()),this.el.innerHTML=this.template(e),wp.ccf.dispatcher.on("mainViewChange",this.saveConditional,this),this.listenTo(this.fieldCollection,"add",this.updateFields,this),this.listenTo(this.fieldCollection,"remove",this.updateFields,this),this.updateFields(),this},triggerAdd:function(){this.field.get("conditionals").add(new wp.ccf.models.FieldConditional)},triggerDelete:function(){var e=this.field.get("conditionals");if(e.length>1)e.remove(this.model),this.destroy(),this.remove();else{var t=this.el.querySelectorAll(".conditional-value")[0],i=this.el.querySelectorAll(".conditional-field")[0];t.value="";for(var l=0;i.childNodes.length>l;l++)i.childNodes[l].selected=!1}}}),wp.ccf.views.EmptyFormNotificationTableRow=wp.ccf.views.EmptyFormNotificationTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-notification-row-template"),events:{"click .add":"triggerAdd"},initialize:function(e){this.form=e.form},destroy:function(){this.unbind()},render:function(){return this.$el.html(this.template()),this},triggerAdd:function(){var e=this.form.get("notifications");this.destroy(),e.add(new wp.ccf.models.FormNotification)}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.FormNotificationAddress=t.View.extend({template:wp.ccf.utils.template("ccf-form-notification-address-template"),className:"address",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.notification=e.notification,this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-notification-address-type")[0].value,t=this.el.querySelectorAll(".form-notification-address-email"),i=this.el.querySelectorAll(".form-notification-address-field"),l=this.model.get("type");return t.length&&this.model.set("email",t[0].value),i.length&&this.model.set("field",i[0].value),this.model.set("type",e),l!==e&&this.render(),this}},updateFromFieldField:function(){if("edit"===this.parent.context&&"field"===this.model.get("type")){var e=this.el.querySelectorAll(".form-notification-address-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("field");i.length>=1&&i.each(function(i){("email"===i.get("type")||"dropdown"===i.get("type")||"radio"===i.get("type")||"single-line-text"===i.get("type"))&&(t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++)}),0===s&&(t=document.createElement("option"),t.innerHTML=l.noApplicableFields,t.value="",e.appendChild(t),e.disabled=!0)}},render:function(){var e={};this.model&&(e.address=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFromFieldField,this),this.listenTo(t,"remove",this.updateFromFieldField,this),"field"===this.model.get("type")&&this.updateFromFieldField(),this},triggerAdd:function(){this.notification.get("addresses").add(new wp.ccf.models.FormNotificationAddress)},triggerDelete:function(){var e=this.notification.get("addresses");e.length>1?this.parent.deleteAddress(this):(this.model.clear().set(wp.ccf.models.FormNotificationAddress.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.ExistingFormNotificationRow=t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-notification-table-row-template"),tagName:"tr",events:{"change select.form-email-notification-from-type":"toggleNotificationFields","change select.form-email-notification-from-name-type":"toggleNotificationFields","change select.form-email-notification-reply-to-type":"toggleNotificationFields","change select.form-email-notification-reply-to-name-type":"toggleNotificationFields","change select.form-email-notification-subject-type":"toggleNotificationFields","click .close-notification":"changeContext","click .edit-notification":"changeContext","click .delete-notification":"triggerDelete","blur input":"save","change select":"save"},addressViews:[],initialize:function(e){this.form=e.form,this.addressViews=[],this.parent=e.parent,this.context=e.context!==void 0?e.context:"view";var t=this.model.get("addresses");this.listenTo(t,"add",this.addAddress)},deleteAddress:function(e){i.each(this.addressViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.addressViews,t);this.model.get("addresses").remove(e.model),this.addressViews[l].remove(),this.addressViews.splice(l,1)}},this)},addAddress:function(e){var t=this.el.querySelectorAll(".addresses")[0],i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form});this.addressViews.push(i),t.appendChild(i.render().el)},destroy:function(){this.unbind()},changeContext:function(e,t){"edit"===this.context&&this.save(),t?this.context=t:("view"===this.context&&this.parent.closeAllNotifications(),this.context="edit"===this.context?"view":"edit"),this.destroy(),this.render()},updateFieldVariables:function(){if("edit"===this.context){var e,t=this.el.querySelectorAll(".field-variables")[0],i="",l=this.form.get("fields");l.each(function(t){e=t.get("type"),"html"!==e&&"section-header"!==e&&"recaptcha"!==e&&"simple-captcha"!==e&&(i+="["+t.get("slug")+"] ")}),t.innerText=i}},updateFromFieldField:function(){if("edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-from-field")[0];e.innerHTML="",e.disabled=!1;var t=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0];t.innerHTML="",t.disabled=!1;var i=this.el.querySelectorAll(".form-email-notification-subject-field")[0];i.innerHTML="",i.disabled=!1;var s=this.el.querySelectorAll(".form-email-notification-from-name-field")[0];s.innerHTML="",s.disabled=!1;var o=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0];o.innerHTML="",o.disabled=!1;var n,c,r=this.form.get("fields"),a=0,d=0,u=0,f=this.model.get("fromField"),p=this.model.get("replyToField"),h=this.model.get("subjectField"),m=this.model.get("fromNameField"),w=this.model.get("replyToNameField");r.length>=1&&r.each(function(l){("email"===l.get("type")||"dropdown"===l.get("type")||"radio"===l.get("type")||"single-line-text"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===f&&(n.selected=!0),e.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===p&&(c.selected=!0),t.appendChild(c),a++),("name"===l.get("type")||"single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===m&&(n.selected=!0),s.appendChild(n),c=document.createElement("option"),c.innerHTML=l.get("slug"),c.value=l.get("slug"),l.get("slug")===w&&(c.selected=!0),o.appendChild(c),d++),("single-line-text"===l.get("type")||"radio"===l.get("type")||"dropdown"===l.get("type"))&&(n=document.createElement("option"),n.innerHTML=l.get("slug"),n.value=l.get("slug"),l.get("slug")===h&&(n.selected=!0),i.appendChild(n),u++)}),0===a&&(n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",e.appendChild(n),e.disabled=!0,n=document.createElement("option"),n.innerHTML=l.noEmailFields,n.value="",t.appendChild(n),t.disabled=!0),0===d&&(n=document.createElement("option"),n.innerHTML=l.noNameFields,n.value="",s.appendChild(n),s.disabled=!0),0===u&&(n=document.createElement("option"),n.innerHTML=l.noApplicableFields,n.value="",i.appendChild(n),i.disabled=!0)}},toggleNotificationFields:function(){var e=this.el.querySelectorAll(".email-notification-from-address")[0],t=this.el.querySelectorAll(".email-notification-from-field")[0],i=this.el.querySelectorAll(".form-email-notification-from-type")[0],l=this.el.querySelectorAll(".email-notification-subject")[0],s=this.el.querySelectorAll(".email-notification-subject-field")[0],o=this.el.querySelectorAll(".form-email-notification-subject-type")[0],n=this.el.querySelectorAll(".email-notification-from-name")[0],c=this.el.querySelectorAll(".email-notification-from-name-field")[0],r=this.el.querySelectorAll(".form-email-notification-from-name-type")[0],a=this.el.querySelectorAll(".email-notification-reply-to-address")[0],d=this.el.querySelectorAll(".email-notification-reply-to-field")[0],u=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0],f=this.el.querySelectorAll(".email-notification-reply-to-name")[0],p=this.el.querySelectorAll(".email-notification-reply-to-name-field")[0],h=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0];e.style.display="none",t.style.display="none","custom"===i.value?e.style.display="block":"field"===i.value&&(t.style.display="block"),l.style.display="none",s.style.display="none","custom"===o.value?l.style.display="block":"field"===o.value&&(s.style.display="block"),n.style.display="none",c.style.display="none","custom"===r.value?n.style.display="block":"field"===r.value&&(c.style.display="block"),a.style.display="none",d.style.display="none","custom"===u.value?a.style.display="block":"field"===u.value&&(d.style.display="block"),f.style.display="none",p.style.display="none","custom"===h.value?f.style.display="block":"field"===h.value&&(p.style.display="block")},save:function(){if(""!==this.el.innerHTML&&"edit"===this.context){var e=this.el.querySelectorAll(".form-email-notification-title")[0].value;this.model.set("title",e);var t=this.el.querySelectorAll(".form-email-notification-content")[0].value;this.model.set("content",t);var i=this.el.querySelectorAll(".form-email-notification-active")[0].value;this.model.set("active","1"===i?!0:!1);var l=this.el.querySelectorAll(".form-email-notification-include-uploads")[0].value;this.model.set("includeUploads","1"===l?!0:!1);var s=this.el.querySelectorAll(".form-email-notification-from-type")[0].value;this.model.set("fromType",s);var o=this.el.querySelectorAll(".form-email-notification-from-address")[0].value;this.model.set("fromAddress",o);var n=this.el.querySelectorAll(".form-email-notification-from-field")[0].value;this.model.set("fromField",n);var c=this.el.querySelectorAll(".form-email-notification-from-name-type")[0].value;
2
+ this.model.set("fromNameType",c);var r=this.el.querySelectorAll(".form-email-notification-from-name")[0].value;this.model.set("fromName",r);var a=this.el.querySelectorAll(".form-email-notification-from-name-field")[0].value;this.model.set("fromNameField",a);var d=this.el.querySelectorAll(".form-email-notification-reply-to-type")[0].value;this.model.set("replyToType",d);var u=this.el.querySelectorAll(".form-email-notification-reply-to-address")[0].value;this.model.set("replyToAddress",u);var f=this.el.querySelectorAll(".form-email-notification-reply-to-field")[0].value;this.model.set("replyToField",f);var p=this.el.querySelectorAll(".form-email-notification-reply-to-name-type")[0].value;this.model.set("replyToNameType",p);var h=this.el.querySelectorAll(".form-email-notification-reply-to-name")[0].value;this.model.set("replyToName",h);var m=this.el.querySelectorAll(".form-email-notification-reply-to-name-field")[0].value;this.model.set("replyToNameField",m);var w=this.el.querySelectorAll(".form-email-notification-subject-type")[0].value;this.model.set("subjectType",w);var v=this.el.querySelectorAll(".form-email-notification-subject")[0].value;this.model.set("subject",v);var g=this.el.querySelectorAll(".form-email-notification-subject-field")[0].value;this.model.set("subjectField",g);for(var y=0;this.addressViews.length>y;y++)this.addressViews[y].save();return this}},render:function(){var e={context:this.context,form:this.form.toJSON()};if(this.model&&(e.notification=this.model.toJSON()),this.el.innerHTML=this.template(e),"edit"===this.context){this.toggleNotificationFields(),this.updateFromFieldField(),this.updateFieldVariables();var t=this.el.querySelectorAll(".addresses")[0],i=this.model.get("addresses");if(i.length>=1)i.each(function(e){var i=new wp.ccf.views.FormNotificationAddress({model:e,parent:this,notification:this.model,form:this.form}).render();t.appendChild(i.el),this.addressViews.push(i)},this);else{var l=new wp.ccf.models.FormNotificationAddress;i.add(l)}}var s=this.form.get("fields");return this.listenTo(s,"add",this.updateFromFieldField,this),this.listenTo(s,"remove",this.updateFromFieldField,this),this.listenTo(s,"add",this.updateFieldVariables,this),this.listenTo(s,"remove",this.updateFieldVariables,this),this},triggerDelete:function(){this.parent.deleteNotification(this)}}),wp.ccf.views.FieldBase=wp.ccf.views.FieldBase||t.View.extend({events:{"blur input":"saveField","blur input.field-slug":"checkSlug","blur textarea":"saveField","change select":"saveField",'change input[type="checkbox"]':"saveField"},initialize:function(){var e=this.model.get("conditionals");this.listenTo(e,"add",this.addConditional)},addConditional:function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render(),i=this.el.querySelectorAll(".conditionals")[0];i.appendChild(t.el)},checkSlug:function(){var e=this.el.querySelectorAll(".field-slug");if(e.length>0){var t=e[0],i=!1;t.parentNode.className=t.value&&!t.value.match(/^[a-zA-Z0-9\-_]+$/)?t.parentNode.className.replace(/ field-error/i,"")+" field-error":t.parentNode.className.replace(/ field-error/i,""),this.collection.length>0&&""!==t.value?(this.collection.each(function(e){e!==this.model&&t.value===e.get("slug")&&(i=!0)},this),t.parentNode.className=i?t.parentNode.className.replace(/ field-duplicate-slug/i,"")+" field-duplicate-slug":t.parentNode.className.replace(/ field-duplicate-slug/i,"")):t.parentNode.className=t.parentNode.className.replace(/ field-duplicate-slug/i,"")}},destroy:function(){this.unbind()},saveField:function(){var t=this.el.querySelectorAll(".conditionals");if(t.length){var l=t[0].querySelectorAll(".conditional");i.each(l,function(t){e(t).trigger("saveConditional")}),this.model.set("conditionalType",this.el.querySelectorAll(".field-conditional-type")[0].value),this.model.set("conditionalFieldsRequired",this.el.querySelectorAll(".field-conditional-fields-required")[0].value);var s=this.model.get("conditionalsEnabled");this.model.set("conditionalsEnabled",1==this.el.querySelectorAll(".field-conditionals-enabled")[0].value?!0:!1),s!==this.model.get("conditionalsEnabled")&&this.render("advanced")}},render:function(e){e=e?e:"basic",this.el.innerHTML=this.template({field:this.model.toJSON(),startPanel:e}),this.checkSlug();var t=this.model.get("conditionals"),i=this.el.querySelectorAll(".conditionals");if(i.length)if(t.length>=1)t.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();i[0].appendChild(t.el)},this);else{var l=new wp.ccf.models.FieldConditional;t.add(l)}return this}}),wp.ccf.views.Fields["single-line-text"]=wp.ccf.views.Fields["single-line-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-single-line-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.file=wp.ccf.views.Fields.file||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-file-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.model.set("fileExtensions",this.el.querySelectorAll(".field-file-extensions")[0].value),this.model.set("maxFileSize",this.el.querySelectorAll(".field-max-file-size")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.recaptcha=wp.ccf.views.Fields.recaptcha||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-recaptcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("siteKey",this.el.querySelectorAll(".field-site-key")[0].value),this.model.set("secretKey",this.el.querySelectorAll(".field-secret-key")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["simple-captcha"]=wp.ccf.views.Fields["simple-captcha"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-simple-captcha-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["section-header"]=wp.ccf.views.Fields["section-header"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-section-header-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("heading",this.el.querySelectorAll(".field-heading")[0].value),this.model.set("subheading",this.el.querySelectorAll(".field-subheading")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.html=wp.ccf.views.Fields.html||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-html-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("html",this.el.querySelectorAll(".field-html")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields["paragraph-text"]=wp.ccf.views.Fields["paragraph-text"]||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-paragraph-text-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.hidden=wp.ccf.views.Fields.hidden||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-hidden-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.date=wp.ccf.views.Fields.date||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-date-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length>0&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-date-format");t.length&&this.model.set("dateFormat",t[0].value);var i=this.model.get("showDate"),l=this.el.querySelectorAll(".field-show-date")[0].checked?!0:!1;this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("showDate",l);var s=this.model.get("showTime"),o=this.el.querySelectorAll(".field-show-time")[0].checked?!0:!1;return this.model.set("showTime",o),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),(o!=s||l!=i)&&this.render(),this}}}),wp.ccf.views.Fields.name=wp.ccf.views.Fields.name||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-name-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.website=wp.ccf.views.Fields.website||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-website-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.phone=wp.ccf.views.Fields.phone||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-phone-template"),saveField:function(){return""!==this.el.innerHTML?(this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("value",this.el.querySelectorAll(".field-value")[0].value),this.model.set("placeholder",this.el.querySelectorAll(".field-placeholder")[0].value),this.model.set("phoneFormat",this.el.querySelectorAll(".field-phone-format")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),this.constructor.__super__.saveField.apply(this,arguments),this):void 0}}),wp.ccf.views.Fields.address=wp.ccf.views.Fields.address||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-address-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value);var e=this.model.get("addressType");this.model.set("addressType",this.el.querySelectorAll(".field-address-type")[0].value);var t=this.el.querySelectorAll(".field-default-country");return t.length&&this.model.set("defaultCountry",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),e!==this.model.get("addressType")&&this.render(),this.constructor.__super__.saveField.apply(this,arguments),this}}}),wp.ccf.views.Fields.email=wp.ccf.views.Fields.email||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-email-template"),saveField:function(){if(""!==this.el.innerHTML){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.constructor.__super__.saveField.apply(this,arguments);var e=this.el.querySelectorAll(".field-value");e.length&&this.model.set("value",e[0].value);var t=this.el.querySelectorAll(".field-placeholder");t.length&&this.model.set("placeholder",t[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1);var i=1==this.el.querySelectorAll(".field-email-confirmation")[0].value?!0:!1,l=this.model.get("emailConfirmation");return this.model.set("emailConfirmation",i),l!=i&&this.render(),this}}}),wp.ccf.views.ChoiceableField=wp.ccf.views.ChoiceableField||wp.ccf.views.FieldBase.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),initialize:function(){var e=this.model.get("choices");this.listenTo(e,"add",this.addChoice)},addChoice:function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:this.model}).render(),i=this.el.querySelectorAll(".repeatable-choices")[0];i.appendChild(t.el)},saveField:function(t){if(""!==this.el.innerHTML&&(!t||"field-use-values"!==t.target.className||"focusout"!==t.type)){this.model.set("slug",this.el.querySelectorAll(".field-slug")[0].value),this.model.set("label",this.el.querySelectorAll(".field-label")[0].value),this.model.set("description",this.el.querySelectorAll(".field-description")[0].value),this.model.set("className",this.el.querySelectorAll(".field-class-name")[0].value),this.model.set("required",1==this.el.querySelectorAll(".field-required")[0].value?!0:!1),wp.ccf.views.ChoiceableField.__super__.saveField.apply(this,arguments);var l=this.el.querySelectorAll(".repeatable-choices")[0].querySelectorAll(".choice");i.each(l,function(t){e(t).trigger("saveChoice")});var s=this.model.get("useValues"),o=this.el.querySelectorAll(".field-use-values")[0].checked?!0:!1;return this.model.set("useValues",o),s!==o&&this.render(),this}},render:function(t){var i=this;t=t?t:"basic",this.model.get("useValues"),i.el.innerHTML=i.template({field:i.model.toJSON(),startPanel:t}),i.checkSlug();var l=i.model.get("choices"),s=this.el.querySelectorAll(".repeatable-choices")[0];if(l.length>=1)l.each(function(e){var t=new wp.ccf.views.FieldChoice({model:e,field:i.model}).render();s.appendChild(t.el)});else{var o=new wp.ccf.models.FieldChoice;l.add(o)}s=this.el.querySelectorAll(".repeatable-choices")[0],e(s).sortable({handle:".move",axis:"y",stop:function(e,t){t.item.trigger("sorted",t.item.index())}});var n=this.model.get("conditionals"),c=this.el.querySelectorAll(".conditionals")[0];if(n.length>=1)n.each(function(e){var t=new wp.ccf.views.FieldConditional({model:e,field:this.model,fieldCollection:this.collection}).render();c.appendChild(t.el)},this);else{var r=new wp.ccf.models.FieldConditional;n.add(r)}return i}}),wp.ccf.views.Fields.dropdown=wp.ccf.views.Fields.dropdown||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-dropdown-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.radio=wp.ccf.views.Fields.radio||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-radio-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.Fields.checkboxes=wp.ccf.views.Fields.checkboxes||wp.ccf.views.ChoiceableField.extend({template:wp.ccf.utils.template("ccf-checkboxes-template"),events:function(){return this.constructor.__super__.events}}),wp.ccf.views.FieldSidebar=wp.ccf.views.FieldSidebar||t.View.extend({initialize:function(e){this.currentFieldView=null,this.form=e.form},save:function(e){this.currentFieldView&&""!==this.currentFieldView.el.innerHTML&&this.currentFieldView.saveField(),e&&e instanceof Object&&e.resolve()},fieldRemoved:function(){this.currentFieldView&&(this.form.get("fields").get(this.currentFieldView.model)||this.render())},destroy:function(){wp.ccf.dispatcher.off("saveField",this.save),wp.ccf.dispatcher.off("mainViewChange",this.save),this.unbind()},render:function(e){var t={};if(e){var i=e.get("type");this.currentFieldView&&(this.currentFieldView.saveField(),this.currentFieldView.destroy&&this.currentFieldView.destroy()),this.currentFieldView=new wp.ccf.views.Fields[i]({model:e,collection:this.form.get("fields")}),this.currentFieldView.render(),this.el.innerHTML="",this.el.appendChild(this.currentFieldView.el);var l=this.form.get("fields");this.listenTo(l,"remove",this.fieldRemoved)}else{var s=wp.ccf.utils.template("ccf-empty-field-template");this.el.innerHTML=s(t)}return wp.ccf.dispatcher.on("saveField",this.save,this),wp.ccf.dispatcher.on("mainViewChange",this.save,this),this}}),wp.ccf.views.FieldRowPlaceholder=wp.ccf.views.FieldRowPlaceholder||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",initialize:function(e){this.type=e.type},render:function(){return this.el.innerHTML=this.template({label:l.allLabels[this.type]}),this.el.setAttribute("data-field-type",this.type),this.el.className+=" "+this.type,this}}),wp.ccf.views.FieldRow=wp.ccf.views.FieldRow||t.View.extend({template:wp.ccf.utils.template("ccf-field-row-template"),tagName:"div",className:"field",events:{"click .delete":"triggerDelete","click h4":"triggerEdit",sorted:"triggerUpdateSort"},initialize:function(e){i.bindAll(this,"triggerDelete"),this.form=e.form,this.listenTo(this.model,"change",this.handleChange,this),this.listenTo(this.model,"requirementsNotMet",this.requirementsNotMet,this),this.listenTo(this.model,"requirementsMet",this.requirementsMet,this),this.listenTo(this.model,"duplicateSlug",this.duplicateSlug,this),this.model.attributes.choices&&this.listenTo(this.model.attributes.choices,"change",this.handleChange,this)},duplicateSlug:function(){this.requirementsMet(),this.el.className+=" field-duplicate-slug"},requirementsNotMet:function(){this.requirementsMet(),this.el.className+=" field-incomplete"},requirementsMet:function(){this.el.className=this.el.className.replace(/(field-incomplete|field-duplicate-slug)/i,"")},triggerUpdateSort:function(e,t){this.form.get("fields").remove(this.model),this.form.get("fields").add(this.model,{at:t})},handleChange:function(){this.render()},triggerDelete:function(e){e.stopPropagation(),this.form.get("fields").remove(this.model),this.undelegateEvents(),this.remove()},triggerEdit:function(){var e=this.el.parentNode.querySelectorAll(".ccf-editing");i.each(e,function(e){e.className=e.className.replace(/ccf-editing/i,"")}),this.el.className=this.el.className.replace(/ccf-editing/i,"")+" ccf-editing",wp.ccf.dispatcher.trigger("openEditField",this.model)},render:function(e){this.el.innerHTML=this.template({label:l.allLabels[this.model.get("type")]}),this.el.setAttribute("data-field-type",this.model.get("type"));var t=RegExp(" "+this.model.get("type"),"i");this.el.className=this.el.className.replace(t,"")+" "+this.model.get("type"),e&&(this.el.className=this.el.className.replace(/ instantiated/i,"")+" instantiated");var i=document.getElementById("ccf-"+this.model.get("type")+"-preview-template");if(i){var s=this.el.querySelectorAll(".preview")[0];s.style.display="block",s.innerHTML=wp.ccf.utils.template("ccf-"+this.model.get("type")+"-preview-template")({field:this.model.toJSON()})}return this}}),wp.ccf.views.PostFieldMapping=t.View.extend({template:wp.ccf.utils.template("ccf-post-field-mapping"),className:"field-mapping",events:{"click .add":"triggerAdd","click .delete":"triggerDelete","blur input":"save","change select":"save"},initialize:function(e){this.parent=e.parent,this.form=e.form},destroy:function(){this.unbind()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".field-form-field")[0].value,t=this.el.querySelectorAll(".field-post-field")[0].value,i=this.el.querySelectorAll(".field-custom-field-key"),l=this.model.get("postField");return this.model.set("formField",e),this.model.set("postField",t),i.length&&this.model.set("customFieldKey",i[0].value),l!==t&&this.render(),this}},updateFormFieldField:function(){var e=this.el.querySelectorAll(".field-form-field")[0];e.innerHTML="",e.disabled=!1;var t,i=this.form.get("fields"),s=0,o=this.model.get("formField");i.length>=1&&(t=document.createElement("option"),t.innerHTML=l.chooseFormField,t.value="",e.appendChild(t),i.each(function(i){t=document.createElement("option"),t.innerHTML=i.get("slug"),t.value=i.get("slug"),i.get("slug")===o&&(t.selected=!0),e.appendChild(t),s++})),0===s&&(t=document.createElement("option"),t.innerHTML=l.noAvailableFields,t.value="",e.appendChild(t),e.disabled=!0)},updatePostFields:function(){var e,t=this.el.querySelectorAll(".field-post-field")[0];e=document.createElement("option"),e.value="",e.innerText=l.choosePostField,t.appendChild(e);var s=this.form.get("postFieldMappings"),o=[];s.each(function(e){e!==this.model&&o.push(e.get("postField"))},this),i.each(l.postFields.single,function(i,l){-1===o.indexOf(l)&&(e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e))},this),i.each(l.postFields.repeatable,function(i,l){e=document.createElement("option"),e.value=l,e.innerText=i,this.model.get("postField")===l&&(e.selected=!0),t.appendChild(e)},this)},render:function(){var e={};this.model&&(e.mapping=this.model.toJSON()),this.el.innerHTML=this.template(e);var t=this.form.get("fields");return this.listenTo(t,"add",this.updateFormFieldField,this),this.listenTo(t,"remove",this.updateFormFieldField,this),this.updateFormFieldField(),this.updatePostFields(),this},triggerAdd:function(){this.form.get("postFieldMappings").add(new wp.ccf.models.PostFieldMapping)},triggerDelete:function(){var e=this.form.get("postFieldMappings");e.length>1?this.parent.deletePostFieldMapping(this):(this.model.clear().set(wp.ccf.models.PostFieldMapping.prototype.defaults),this.destroy(),this.render())}}),wp.ccf.views.FormSettings=wp.ccf.views.FormSettings||t.View.extend({template:wp.ccf.utils.template("ccf-form-settings-template"),events:{"blur input":"save","change select":"save","change select.form-completion-action-type":"toggleCompletionFields","change select.form-pause":"togglePauseFields","change select.form-post-creation":"togglePostCreationFields","click .add-notification":"triggerAddNotification"},notificationViews:[],mappingViews:[],initialize:function(e){this.model=e.form,this.notificationViews=[],this.mappingViews=[];var t=this.model.get("notifications");this.listenTo(t,"add",this.addNotification);var i=this.model.get("postFieldMappings");this.listenTo(i,"add",this.addPostFieldMapping)},deletePostFieldMapping:function(e){i.each(this.mappingViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.mappingViews,t);this.model.get("postFieldMappings").remove(e.model),this.mappingViews[l].remove(),this.mappingViews.splice(l,1)}},this)},addPostFieldMapping:function(e){var t=this.el.querySelectorAll(".post-creation-mapping")[0],i=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model});this.mappingViews.push(i),t.appendChild(i.render().el)},triggerAddNotification:function(){var e=this.model.get("notifications");e.add(new wp.ccf.models.FormNotification)},closeAllNotifications:function(){i.each(this.notificationViews,function(e){e.changeContext(null,"view")})},addNotification:function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,context:"edit",parent:this}).render(),l=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];l.querySelectorAll(".no-notifications").length>0&&l.removeChild(l.firstChild),i.each(this.notificationViews,function(e){e.changeContext(null,"view")}),this.notificationViews.push(t),l.appendChild(t.el)},toggleCompletionFields:function(){var e=this.el.querySelectorAll(".form-completion-action-type")[0].value,t=this.el.querySelectorAll(".completion-message")[0],i=this.el.querySelectorAll(".completion-redirect-url")[0];"text"===e?(t.style.display="block",i.style.display="none"):(t.style.display="none",i.style.display="block")},togglePauseFields:function(){var e=this.el.querySelectorAll(".form-pause")[0].value,t=this.el.querySelectorAll(".pause-message")[0];t.style.display=parseInt(e)?"block":"none"},togglePostCreationFields:function(){var t=this.el.querySelectorAll(".form-post-creation")[0].value,i=e(this.el.querySelectorAll(".post-creation-mapping-field"));parseInt(t)?i.show():i.hide()},save:function(){if(""!==this.el.innerHTML){var e=this.el.querySelectorAll(".form-title")[0].value;this.model.set("title",{raw:e});var t=this.el.querySelectorAll(".hide-title")[0].value;this.model.set("hideTitle",parseInt(t)?!0:!1);var i=this.el.querySelectorAll(".form-description")[0].value;this.model.set("description",i);var l=this.el.querySelectorAll(".form-button-text")[0].value;this.model.set("buttonText",l);var s=this.el.querySelectorAll(".form-button-class")[0].value;this.model.set("buttonClass",s);var o=this.el.querySelectorAll(".form-pause")[0].value;this.model.set("pause",parseInt(o)?!0:!1);var n=this.el.querySelectorAll(".form-require-logged-in")[0].value;this.model.set("requireLoggedIn",parseInt(n)?!0:!1);var c=this.el.querySelectorAll(".form-post-creation")[0].value;this.model.set("postCreation",parseInt(c)?!0:!1);var r=this.el.querySelectorAll(".form-post-creation-type")[0].value;this.model.set("postCreationType",r);var a=this.el.querySelectorAll(".form-post-creation-status")[0].value;this.model.set("postCreationStatus",a);var d=this.el.querySelectorAll(".form-pause-message")[0].value;this.model.set("pauseMessage",d);var u=this.el.querySelectorAll(".form-completion-message")[0].value;this.model.set("completionMessage",u);var f=this.el.querySelectorAll(".form-completion-redirect-url")[0].value;this.model.set("completionRedirectUrl",f);var p=this.el.querySelectorAll(".form-completion-action-type")[0].value;this.model.set("completionActionType",p);var h=this.el.querySelectorAll(".form-theme")[0].value;this.model.set("theme",h)}},fullSave:function(e){""!==this.el.innerHTML&&(this.save(),i.each(this.notificationViews,function(e){e.save()}),i.each(this.mappingViews,function(e){e.save()}),e!==void 0&&e.promise!==void 0&&e.resolve())},destroy:function(){wp.ccf.dispatcher.off("saveFormSettings",this.fullSave),wp.ccf.dispatcher.off("mainViewChange",this.fullSave)},deleteNotification:function(e){if(i.each(this.notificationViews,function(t){if(e.cid===t.cid){var l=i.indexOf(this.notificationViews,t);this.model.get("notifications").remove(e.model),this.notificationViews[l].remove(),this.notificationViews.splice(l,1)}},this),!this.notificationViews.length){var t=this.el.querySelectorAll(".ccf-form-notifications .rows")[0];t.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el)}},render:function(){var e={form:this.model.toJSON()};this.model.get("fields");var t=this.model.get("notifications");this.el.innerHTML=this.template(e),this.toggleCompletionFields(),this.togglePostCreationFields(),this.togglePauseFields();var i=this.el.querySelectorAll(".ccf-form-notifications .rows")[0],l=document.createElement("tbody");l.className="rows",t.length>=1?t.each(function(e){var t=new wp.ccf.views.ExistingFormNotificationRow({model:e,form:this.model,parent:this}).render();l.appendChild(t.el),this.notificationViews.push(t)},this):l.appendChild(new wp.ccf.views.EmptyFormNotificationTableRow({form:this.model}).render().el),i.parentNode.replaceChild(l,i);var s=this.el.querySelectorAll(".post-creation-mapping")[0],o=this.model.get("postFieldMappings");if(o.length>=1)o.each(function(e){var t=new wp.ccf.views.PostFieldMapping({model:e,parent:this,form:this.model}).render();s.appendChild(t.el),this.mappingViews.push(t)},this);else{var n=new wp.ccf.models.PostFieldMapping;o.add(n)}return wp.ccf.dispatcher.on("mainViewChange",this.fullSave,this),wp.ccf.dispatcher.on("saveFormSettings",this.fullSave,this),this}}),wp.ccf.views.FormPane=wp.ccf.views.FormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-form-pane-template"),subViews:{"field-sidebar":wp.ccf.views.FieldSidebar,"form-settings":wp.ccf.views.FormSettings},events:{"click .save-button":"sync","click .signup-button":"signup","click .accordion-heading":"accordionClick","click .form-settings-heading":"accordionClick","click .insert-form-button":"insertForm"},initialize:function(){wp.ccf.dispatcher.on("openEditField",this.openEditField,this)},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},signup:function(){var t=this.el.querySelectorAll(".email-signup-field")[0].value,i=this.el.querySelectorAll(".bottom .left.signup")[0];i.className="left signup",t?e.ajax({url:"//taylorlovett.us8.list-manage.com/subscribe/post-json?u=66118f9a5b0ab0414e83f043a&amp;id=b4ed816a24&c=?",method:"post",dataType:"jsonp",data:{EMAIL:t}}).done(function(){i.className="left signup signup-success"}):i.className="left signup signup-error"},accordionClick:function(t){var l=e(t.currentTarget).parents(".accordion-container")[0],s=l.querySelectorAll(".accordion-section");t.currentTarget.parentNode.className.match(/expanded/i)?t.currentTarget.parentNode.className=t.currentTarget.parentNode.className.replace(/expanded/i,""):t.currentTarget.parentNode.className+=" expanded",i.each(s,function(e){e!=t.currentTarget.parentNode&&e.className.match(/expanded/i)&&(e.className=e.className.replace(/expanded/i,""))
3
+ }),t.currentTarget.className.match(/form-settings-heading/i)?this.el.className.match(/show-form-settings/i)?this.el.className=this.el.className.replace(/show-form-settings/i,""):this.el.className+=" show-form-settings":this.el.className=this.el.className.replace(/show-form-settings/i,"")},openEditField:function(e){this.renderedSubViews["field-sidebar"].render(e).el.style.display="block"},disable:function(){this.el.querySelectorAll(".save-button")[0].setAttribute("disabled","disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="block"},enable:function(){this.el.querySelectorAll(".save-button")[0].removeAttribute("disabled"),this.el.querySelectorAll(".disabled-overlay")[0].style.display="none"},sync:function(){var t=this,i=e(this.el.querySelectorAll(".spinner")[0]);i.fadeIn(),t.disable();var s=e.Deferred(),o=e.Deferred();wp.ccf.dispatcher.trigger("saveFormSettings",s),wp.ccf.dispatcher.trigger("saveField",o),e.when(s,o).then(function(){var e=t.model.get("fields"),s=!0,o={};e.each(function(e){var t=e.get("slug");e.hasRequiredAttributes()?t&&!t.match(/^[a-zA-Z0-9\-_]+$/)?(s=!1,e.trigger("requirementsNotMet")):o[e.get("slug")]!==void 0?(s=!1,e.trigger("duplicateSlug"),o[e.get("slug")].trigger("duplicateSlug")):e.trigger("requirementsMet"):(s=!1,e.trigger("requirementsNotMet")),e.get("slug")&&(o[e.get("slug")]=e)}),s?t.model.save({},{context:"edit"}).error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}).done(function(){l.single&&!l.postId&&(window.location=l.adminUrl+"post.php?post="+t.model.get("id")+"&action=edit#ccf-form/"+t.model.get("id"))}).complete(function(){i.fadeOut(),t.enable(),wp.ccf.dispatcher.trigger("saveFormComplete",t.model)}):(t.enable(),i.fadeOut())})},enableDisableInsert:function(){var e=this.el.querySelectorAll(".insert-form-button")[0];this.model.get("id")?e.removeAttribute("disabled"):e.setAttribute("disabled","disabled")},getNextFieldOrd:function(){var e=this.model.get("fields"),t=e.length+1;return e.each(function(e){var i=e.get("slug"),l=/\-([0-9]+)$/g,s=l.exec(i);if(s&&s[1]){var o=parseInt(s[1]);o>=t&&(t=o+1)}}),t},render:function(t){var s=this;s.model=t?t:new wp.ccf.models.Form,this.listenTo(s.model,"change",this.enableDisableInsert,this);var o={labels:l.fieldLabels,form:s.model.toJSON()};window.form=s.model,s.el.innerHTML=this.template(o),s.el.className=s.el.className.replace(/show-form-settings/i,"");var n=s.el.querySelectorAll(".fields")[0];i.each(l.fieldLabels,function(e,t){n.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var c=s.el.querySelectorAll(".structure-fields")[0];i.each(l.structureFieldLabels,function(e,t){c.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var r=s.el.querySelectorAll(".special-fields")[0];i.each(l.specialFieldLabels,function(e,t){r.appendChild(new wp.ccf.views.FieldRowPlaceholder({type:t}).render().el)});var a=s.model.get("fields"),d=s.el.querySelectorAll(".form-content")[0],u=e(d);return e(s.el.querySelectorAll(".left-sidebar")[0].querySelectorAll(".field")).draggable({cursor:"move",distance:2,zIndex:160001,scroll:!1,containment:"document",appendTo:".ccf-main-modal",snap:!1,connectToSortable:".form-content",helper:function(t){var i=e(t.currentTarget),l=e('<div class="field" data-field-type="'+i.attr("data-field-type")+'"><h4>'+i.find(".label").html()+"</h4></div>");return l.css({width:u.width(),opacity:".75",height:i.height()})}}),a.length>=1&&(d.innerHTML="",a.each(function(e){var t=new wp.ccf.views.FieldRow({model:e,form:s.model}).render(!0).el;d.appendChild(t)})),e(d).sortable({axis:"y",distance:2,handle:"h4",placeholder:"field-placeholder",stop:function(e,t){if(!t.item.hasClass("instantiated")){var i=t.item.attr("data-field-type"),l={};wp.ccf.models.Fields[i].prototype.defaults().slug!==void 0&&(l.slug=i+"-"+s.getNextFieldOrd());var o=new wp.ccf.models.Fields[i](l),n=s.model.get("fields");n.add(o),new wp.ccf.views.FieldRow({model:o,el:t.item,form:s.model}).render(!0),t.item.attr("style","")}t.item.trigger("sorted",t.item.index())}}),s.initRenderSubViews(!1,!0,{form:s.model}),s.enableDisableInsert(),s}},wp.ccf.mixins.subViewable)),wp.ccf.views.ExistingFormTableRow=wp.ccf.views.ExistingFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-existing-form-table-row-template"),events:{"click .edit":"triggerMainViewChange","click .delete":"triggerDelete","click .duplicate":"triggerDuplicate","click .insert-form-button":"insertForm"},initialize:function(e){this.parent=e.parent},insertForm:function(){wp.ccf.utils.insertFormShortcode(this.model),wp.ccf.toggle()},triggerMainViewChange:function(){wp.ccf.switchToForm(this.model)},triggerDelete:function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},triggerDuplicate:function(){var e=this,t=e.parent.collection.state.currentPage;e.model.clone().set("title",{raw:e.model.get("title").raw+" (Duplicate)"}).unset("id").save().done(function(){e.parent.showPage(t).done(function(){e.parent.renderPagination()})})},render:function(){return this.$el.html(this.template({form:this.model.toJSON(),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate}})),this}}),wp.ccf.views.EmptyFormTableRow=wp.ccf.views.EmptyFormTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-empty-form-table-row-template"),render:function(){return this.$el.html(this.template()),this}}),wp.ccf.views.ExistingFormTable=wp.ccf.views.ExistingFormTable||t.View.extend({template:wp.ccf.utils.template("ccf-existing-form-table-template"),initialize:function(){this.parent=arguments.parent,this.collection=new wp.ccf.collections.Forms,wp.ccf.dispatcher.on("changeFormTablePage",this.showPage,this),wp.ccf.dispatcher.on("saveFormComplete",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".rows")[0],i=document.createElement("tbody");i.className="rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.ExistingFormTableRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild((new wp.ccf.views.EmptyFormTableRow).render().el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(){var e=this;return this.el.innerHTML=this.template(),this.el.querySelectorAll(".ccf-pagination")[0],this.showPage(1).done(function(){e.renderPagination()}),this}}),wp.ccf.views.ExistingFormPane=wp.ccf.views.ExistingFormPane||t.View.extend(i.defaults({template:wp.ccf.utils.template("ccf-existing-form-pane-template"),subViews:{"existing-form-table":wp.ccf.views.ExistingFormTable},render:function(){return this.rendered?this:(this.rendered=!0,this.el.innerHTML=this.template(),this.initRenderSubViews(!0),this)}},wp.ccf.mixins.subViewable)),wp.ccf.views.MainModal=wp.ccf.views.MainModal||t.View.extend(i.defaults({tagName:"div",className:"ccf-main-modal",template:wp.ccf.utils.template("ccf-main-modal-template"),events:{"click .close-icon":"hide","click .main-menu a":"menuClick"},subViews:{"form-pane":wp.ccf.views.FormPane},initialize:function(){l.single||(this.subViews["existing-form-pane"]=wp.ccf.views.ExistingFormPane),wp.ccf.dispatcher.on("mainViewChange",this.toggleView,this)},toggleView:function(e){this.showView(e,wp.ccf.currentForm);var t=e;"form-pane"===e&&wp.ccf.currentForm&&(t="existing-form-pane");var l=this.el.querySelectorAll(".menu-item");i.each(l,function(e){var i=e.getAttribute("data-view");e.className=i===t?e.className.replace("selected","")+" selected":e.className.replace("selected","")})},menuClick:function(e){var t=e.currentTarget.getAttribute("data-view");"form-pane"===t&&(wp.ccf.currentForm=null),wp.ccf.dispatcher.trigger("mainViewChange",t),e.preventDefault()},render:function(e){return e=e||!1,this.overlay(),this.el.innerHTML=this.template({single:e}),this.initRenderSubViews(),this.showView("form-pane",wp.ccf.currentForm,!0),this},overlay:function(){return this.overlayEl===void 0&&(this.overlayEl=document.createElement("div"),this.overlayEl.className="ccf-main-modal-overlay",document.body.appendChild(this.overlayEl)),this.overlayEl},remove:function(){return document.body.removeChild(this.overlay()),this},show:function(){e(this.overlay()).show(),this.$el.show()},hide:function(){e(this.overlay()).hide(),this.$el.hide()}},wp.ccf.mixins.subViewable)),wp.ccf.views.SubmissionRow=wp.ccf.views.SubmissionRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-submission-row-template"),events:{"click .view":"view","click .delete":"delete"},initialize:function(e){this.parent=e.parent},"delete":function(){var e,t=this,i=t.parent.collection.state.currentPage;t.model.destroy().done(function(){e=i,e===t.parent.collection.state.totalPages&&e-1===(t.parent.collection.state.totalObjects-1)/l.postsPerPage&&e--,t.parent.showPage(e).done(function(){t.parent.renderPagination()})})},view:function(e){var t=e.currentTarget.getAttribute("data-submission-id"),i=e.currentTarget.getAttribute("data-submission-date");tb_show(l.thickboxTitle+" - "+wp.ccf.utils.getPrettyPostDate(i),"#TB_inline?height=500&amp;width=700&amp;inlineId=ccf-submission-content-"+parseInt(t),null)},render:function(){return this.$el.html(this.template({submission:this.model.toJSON(),currentColumns:this.parent.columns,columns:wp.ccf.currentForm.getFieldSlugs(!0),utils:{getPrettyPostDate:wp.ccf.utils.getPrettyPostDate,wordChop:wp.ccf.utils.wordChop,isFieldDate:wp.ccf.utils.isFieldDate,isFieldName:wp.ccf.utils.isFieldName,isFieldFile:wp.ccf.utils.isFieldFile,isFieldAddress:wp.ccf.utils.isFieldAddress,isFieldEmailConfirm:wp.ccf.utils.isFieldEmailConfirm,getPrettyFieldDate:wp.ccf.utils.getPrettyFieldDate,getPrettyFieldAddress:wp.ccf.utils.getPrettyFieldAddress,getPrettyFieldName:wp.ccf.utils.getPrettyFieldName,getPrettyFieldEmailConfirm:wp.ccf.utils.getPrettyFieldEmailConfirm}})),this}}),wp.ccf.views.SubmissionsTable=wp.ccf.views.SubmissionsTable||t.View.extend({template:wp.ccf.utils.template("ccf-submission-table-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(){this.collection=new wp.ccf.collections.Submissions({},{formId:l.postId}),wp.ccf.dispatcher.on("submissionTableRebuild",this.render,this)},showPage:function(e){var t=this,i=this.collection.fetch({data:{page:e}});return i.error(function(){var e="sync";wp.ccf.errorModal.render(e).show()}),i.done(function(){var e=t.el.querySelectorAll(".submission-rows")[0],i=document.createElement("tbody");i.className="submission-rows",t.collection.length>=1?t.collection.each(function(e){var l=new wp.ccf.views.SubmissionRow({model:e,parent:t}).render();i.appendChild(l.el)},t):i.appendChild(new wp.ccf.views.EmptySubmissionTableRow({parent:t}).render(wp.ccf.currentForm.getFieldSlugs(!0).concat("date")).el),e.parentNode.replaceChild(i,e)}),i},renderPagination:function(){var e=this.el.querySelectorAll(".ccf-pagination")[0];e.innerHTML="",this.collection.state.totalPages>1&&e.appendChild(new wp.ccf.views.Pagination({parent:this}).render(this.collection.state.totalPages,this.collection.state.currentPage).el)},render:function(e){var t=this;return t.columns=e?e:wp.ccf.currentForm.getFieldSlugs(!0).slice(0,4).concat("date"),1>t.columns.length?t.el.innerHTML="":(t.el.innerHTML=t.template({columns:t.columns}),t.el.querySelectorAll(".ccf-pagination")[0],t.showPage(1).done(function(){t.renderPagination()})),t}}),wp.ccf.views.ErrorModal=wp.ccf.views.ErrorModal||t.View.extend({template:wp.ccf.utils.template("ccf-error-modal-template"),tagName:"div",className:"ccf-error-modal",events:{"click .close":"hide"},hide:function(){this.el.className=this.el.className.replace(" show","")},show:function(){this.el.className=this.el.className.replace(" show","")+" show"},toggle:function(){this.el.className.match(" show")?this.hide():this.show()},render:function(e){var t={messageType:""};return e&&(t.messageType=e),this.el.innerHTML=this.template(t),this}}),wp.ccf.views.Pagination=wp.ccf.views.Pagination||t.View.extend({template:wp.ccf.utils.template("ccf-pagination-template"),events:{"click .prev:not(.disabled)":"previousPage","click .next:not(.disabled)":"nextPage","click .first:not(.disabled)":"firstPage","click .last:not(.disabled)":"lastPage"},initialize:function(e){this.parent=e.parent},previousPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage-1).done(function(){e.render()})},nextPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.currentPage+1).done(function(){e.render()})},firstPage:function(){var e=this;e.parent.showPage(1).done(function(){e.render()})},lastPage:function(){var e=this;e.parent.showPage(e.parent.collection.state.totalPages).done(function(){e.render()})},render:function(){return this.el.innerHTML=this.template({totalPages:this.parent.collection.state.totalPages,currentPage:this.parent.collection.state.currentPage,totalObjects:this.parent.collection.state.totalObjects}),this}}),wp.ccf.views.EmptySubmissionTableRow=wp.ccf.views.EmptySubmissionTableRow||t.View.extend({tagName:"tr",template:wp.ccf.utils.template("ccf-no-submissions-row-template"),initialize:function(e){this.parent=e.parent},render:function(){return this.el.innerHTML=this.template({columns:this.parent.columns}),this}}),wp.ccf.views.SubmissionColumnController=wp.ccf.views.SubmissionColumnController||t.View.extend({template:wp.ccf.utils.template("ccf-submissions-controller-template"),events:{"click input[type=checkbox]":"triggerTableRebuild"},render:function(){this.el.innerHTML=this.template({columns:wp.ccf.currentForm.getFieldSlugs(!0).concat("date")})},triggerTableRebuild:function(){var e=[],t=document.querySelectorAll(".submission-column-checkbox");if(t.length>=1)for(var i=0;t.length>i;i++)t[i].checked&&e.push(t[i].value);wp.ccf.dispatcher.trigger("submissionTableRebuild",e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t){"use strict";wp.ccf.router=wp.ccf.router||t.Router.extend({routes:{"ccf-form":"open","ccf-form/:formId":"open"},open:function(e){wp.ccf.show(e)}})}(jQuery,Backbone,_,ccfSettings),function(e,t,i,l){"use strict";wp.ccf=i.defaults(wp.ccf,{forms:new wp.ccf.collections.Forms,currentForm:null,errorModal:null,_currentFormDeferred:null,dispatcher:{},show:function(e){return this.switchToForm(e),this.instance.show(),this.instance},initErrorModal:function(){this.errorModal=(new wp.ccf.views.ErrorModal).render();var e=document.getElementsByTagName("body")[0];e.appendChild(this.errorModal.el)},switchToForm:function(e){var t=this;if(+e===parseInt(e)){var i=parseInt(e);if(e=t.forms.findWhere({id:parseInt(i)}),!e){var l;return t.forms.formsFetching[i]!==void 0?(l=t.forms.formsFetching[i],e=null):(e=new wp.ccf.models.Form({id:i}),l=e.fetch(),t.forms.formsFetching[i]=l),l.done(function(){e?(delete t.forms.formsFetching[i],t.forms.add(e)):e=t.forms.findWhere({id:i}),t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}),l}t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane")}else t.currentForm=e,wp.ccf.dispatcher.trigger("mainViewChange","form-pane");return!0},hide:function(){return this.instance.hide(),this.instance},toggle:function(e){return this.switchToForm(e),this.instance.$el.is(":visible")?this.instance.hide():this.instance.show(),this.instance},createSubmissionsTable:function(e){var t=document.querySelectorAll(".ccf-submission-column-controller"),i=new wp.ccf.views.SubmissionsTable({el:e});i.render(),t&&new wp.ccf.views.SubmissionColumnController({el:t}).render()},_setupMainModal:function(e){return this.instance=(new wp.ccf.views.MainModal).render(e),document.getElementsByTagName("body")[0].appendChild(this.instance.el),t.history.start(),this.instance},createManager:function(){var s=this,o=document.querySelectorAll(".ccf-open-form-manager")[0];if(!o)return!1;i.extend(this.dispatcher,t.Events),new wp.ccf.router,s.initErrorModal();var n=!1;if(l.single)if(n=!0,l.postId){var c=parseInt(l.postId);if(s.forms.formsFetching[c]===void 0){var r=new wp.ccf.models.Form({id:c}),a=r.fetch();s.forms.formsFetching[c]=a,s._currentFormDeferred=a,a.done(function(){delete s.forms.formsFetching[c],s.forms.add(r),s.currentForm=r})}else s._currentFormDeferred=s.forms.formsFetching[c],s._currentFormDeferred.done(function(){s.currentForm=s.forms.findWhere({id:c})});e.when(s._currentFormDeferred).then(function(){s._setupMainModal(!0),o.style.display="inline-block";var e=document.getElementById("ccf-submissions");if(e){var t=e.querySelectorAll(".inside")[0],i=document.createElement("div");i.className="ccf-submission-icon",i.setAttribute("data-icon","");var n=document.createElement("a");n.href="?action=edit&post="+parseInt(l.postId)+"&download_submissions=1&download_submissions_nonce="+l.downloadSubmissionsNonce,n.className="ccf-submission-icon",n.setAttribute("data-icon","");var c=document.getElementById("show-settings-link");i.onclick=function(){c.click()},e.insertBefore(i,e.firstChild.nextSibling.nextSibling),e.insertBefore(n,e.firstChild.nextSibling.nextSibling),wp.ccf.createSubmissionsTable(t);var r=document.querySelectorAll("#major-publishing-actions .duplicate")[0],a=function(e){e=e||window.event,e.preventDefault(),s.currentForm.clone().set("title",{raw:s.currentForm.get("title").raw+" (duplicate)"}).unset("id").save().done(function(e){document.location=l.adminUrl+"/post.php?action=edit&post="+e.id})};r.addEventListener?r.addEventListener("click",a,!1):r.attachEvent("onclick",a)}})}else s._setupMainModal(!0),o.style.display="inline-block";else s._setupMainModal();var d=function(e){e=e||window.event;var t=e.currentTarget?e.currentTarget:e.srcElement,i=t.getAttribute("data-form-id");wp.ccf.toggle(i)};o.addEventListener?o.addEventListener("click",d,!1):o.attachEvent("onclick",d)}}),wp.ccf.createManager()}(jQuery,Backbone,_,ccfSettings);
classes/class-ccf-custom-contact-forms.php CHANGED
@@ -107,10 +107,10 @@ class CCF_Custom_Contact_Forms {
107
  * @since 7.8.3
108
  */
109
  public function rest_register_scripts_manual() {
110
- wp_register_script( 'wp-api', plugins_url( 'wp-api.js', __FILE__ ), array( 'jquery', 'backbone', 'underscore' ), '1.1', true );
111
 
112
  $settings = array( 'root' => esc_url_raw( get_rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ) );
113
- wp_localize_script( 'wp-api', 'WP_API_Settings', $settings );
114
  }
115
 
116
  /**
107
  * @since 7.8.3
108
  */
109
  public function rest_register_scripts_manual() {
110
+ wp_enqueue_script( 'wp-api-ccf', plugins_url( 'wp-api/wp-api.js', dirname( __FILE__ ) . '../' ), array( 'jquery', 'backbone', 'underscore' ), '1.2', true );
111
 
112
  $settings = array( 'root' => esc_url_raw( get_rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ) );
113
+ wp_localize_script( 'wp-api-ccf', 'WP_API_Settings', $settings );
114
  }
115
 
116
  /**
classes/class-ccf-form-handler.php CHANGED
@@ -1108,7 +1108,7 @@ class CCF_Form_Handler {
1108
  $notification_content = ' '; // Hack to send email with empty body via PHPMailer
1109
  }
1110
 
1111
- $subject = apply_filters( 'ccf_email_subject', $subject, $form_id, $email, $form_page, $notification );
1112
  $notification_content = apply_filters( 'ccf_email_content', $message, $form_id, $email, $form_page, $notification );
1113
  $notification_headers = apply_filters( 'ccf_email_headers', $headers, $form_id, $email, $form_page, $notification );
1114
 
1108
  $notification_content = ' '; // Hack to send email with empty body via PHPMailer
1109
  }
1110
 
1111
+ $subject = apply_filters( 'ccf_email_subject', $subject, $form_id, $email, $form_page, $notification, $submission );
1112
  $notification_content = apply_filters( 'ccf_email_content', $message, $form_id, $email, $form_page, $notification );
1113
  $notification_headers = apply_filters( 'ccf_email_headers', $headers, $form_id, $email, $form_page, $notification );
1114
 
classes/class-ccf-form-manager.php CHANGED
@@ -2329,8 +2329,8 @@ class CCF_Form_Manager {
2329
 
2330
  wp_register_script( 'moment', plugins_url( '/bower_components/moment/moment.js', dirname( __FILE__ ) ), array(), CCF_VERSION );
2331
 
2332
- if ( ! wp_script_is( 'wp-api', 'registered' ) ) {
2333
- wp_register_script( 'wp-api', plugins_url( '/wp-api/wp-api.js', dirname( __FILE__ ) ), array(), CCF_VERSION );
2334
  }
2335
 
2336
  $site_url_parsed = parse_url( site_url() );
@@ -2342,7 +2342,7 @@ class CCF_Form_Manager {
2342
  $api_root = site_url( 'wp-json' );
2343
  }
2344
 
2345
- wp_enqueue_script( 'ccf-form-manager', plugins_url( $js_manager_path, dirname( __FILE__ ) ), array( 'json2', 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'underscore', 'backbone', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-api', 'moment' ), CCF_VERSION, true );
2346
  wp_localize_script( 'ccf-form-manager', 'ccfSettings', array(
2347
  'apiRoot' => $api_root,
2348
  'nonce' => wp_create_nonce( 'ccf_nonce' ),
2329
 
2330
  wp_register_script( 'moment', plugins_url( '/bower_components/moment/moment.js', dirname( __FILE__ ) ), array(), CCF_VERSION );
2331
 
2332
+ if ( ! wp_script_is( 'wp-api-ccf', 'registered' ) ) {
2333
+ wp_register_script( 'wp-api-ccf', plugins_url( '/wp-api/wp-api.js', dirname( __FILE__ ) ), array(), CCF_VERSION );
2334
  }
2335
 
2336
  $site_url_parsed = parse_url( site_url() );
2342
  $api_root = site_url( 'wp-json' );
2343
  }
2344
 
2345
+ wp_enqueue_script( 'ccf-form-manager', plugins_url( $js_manager_path, dirname( __FILE__ ) ), array( 'json2', 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'underscore', 'backbone', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-api-ccf', 'moment' ), CCF_VERSION, true );
2346
  wp_localize_script( 'ccf-form-manager', 'ccfSettings', array(
2347
  'apiRoot' => $api_root,
2348
  'nonce' => wp_create_nonce( 'ccf_nonce' ),
custom-contact-forms.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://www.taylorlovett.com
5
  * Description: Build beautiful custom forms and manage submissions the WordPress way. View live previews of your forms while you build them. Contact forms, subscription forms, payment forms, etc.
6
  * Author: Taylor Lovett
7
- * Version: 7.8.3
8
  * Text Domain: custom-contact-forms
9
  * Domain Path: /languages
10
  * Author URI: http://www.taylorlovett.com
@@ -15,7 +15,7 @@
15
  */
16
 
17
 
18
- define( 'CCF_VERSION', '7.8.3' );
19
 
20
  require_once( dirname( __FILE__ ) . '/classes/class-ccf-constants.php' );
21
  require_once( dirname( __FILE__ ) . '/classes/class-ccf-custom-contact-forms.php' );
4
  * Plugin URI: http://www.taylorlovett.com
5
  * Description: Build beautiful custom forms and manage submissions the WordPress way. View live previews of your forms while you build them. Contact forms, subscription forms, payment forms, etc.
6
  * Author: Taylor Lovett
7
+ * Version: 7.8.4
8
  * Text Domain: custom-contact-forms
9
  * Domain Path: /languages
10
  * Author URI: http://www.taylorlovett.com
15
  */
16
 
17
 
18
+ define( 'CCF_VERSION', '7.8.4' );
19
 
20
  require_once( dirname( __FILE__ ) . '/classes/class-ccf-constants.php' );
21
  require_once( dirname( __FILE__ ) . '/classes/class-ccf-custom-contact-forms.php' );
languages/custom-contact-forms-fr_FR.po CHANGED
@@ -167,11 +167,11 @@ msgstr "Pays"
167
  #: ../classes/class-ccf-field-renderer.php:803 ../classes/class-ccf-form-manager.php:1215
168
  #: ../classes/class-ccf-form-manager.php:1516
169
  msgid "Email"
170
- msgstr "Mél"
171
 
172
  #: ../classes/class-ccf-field-renderer.php:810 ../classes/class-ccf-form-manager.php:1219
173
  msgid "Confirm Email"
174
- msgstr "Confirmez l’adresse mél"
175
 
176
  #: ../classes/class-ccf-field-renderer.php:876 ../classes/class-ccf-form-manager.php:1087
177
  msgid "First"
@@ -379,11 +379,11 @@ msgstr "Ce n’est pas un numéro de téléphone à 10 chiffres"
379
 
380
  #: ../classes/class-ccf-form-handler.php:368 ../classes/class-ccf-form-handler.php:384
381
  msgid "This is not a valid email"
382
- msgstr "Ce n’est pas une adresse mél valide"
383
 
384
  #: ../classes/class-ccf-form-handler.php:376 ../classes/class-ccf-form-renderer.php:54
385
  msgid "Emails do not match."
386
- msgstr "Les adresses mél ne correspondent pas."
387
 
388
  #: ../classes/class-ccf-form-handler.php:409
389
  msgid "First name is required."
@@ -575,15 +575,15 @@ msgstr "Notifications du formulaire"
575
 
576
  #: ../classes/class-ccf-form-manager.php:192
577
  msgid "Send Email Notifications:"
578
- msgstr "Envoyer un mél de notification :"
579
 
580
  #: ../classes/class-ccf-form-manager.php:201
581
  msgid "\"To\" Email Addresses (comma separated):"
582
- msgstr "Adresses mél de destination (séparée par une virgule) :"
583
 
584
  #: ../classes/class-ccf-form-manager.php:206
585
  msgid "\"From\" Email Address Type:"
586
- msgstr "Type d’adresse mél d’origine"
587
 
588
  #: ../classes/class-ccf-form-manager.php:208
589
  msgid "WordPress Default"
@@ -591,7 +591,7 @@ msgstr "Wordpress par défaut"
591
 
592
  #: ../classes/class-ccf-form-manager.php:209
593
  msgid "Custom Email"
594
- msgstr "Mél personnalisé"
595
 
596
  #: ../classes/class-ccf-form-manager.php:210 ../classes/class-ccf-form-manager.php:231
597
  msgid "Form Field"
@@ -958,7 +958,7 @@ msgstr ""
958
 
959
  #: ../classes/class-ccf-form-manager.php:1541
960
  msgid "You have no email fields"
961
- msgstr "Vous n’avez pas de champ mél"
962
 
963
  #: ../classes/class-ccf-form-manager.php:1542
964
  msgid "You have no name fields"
@@ -978,7 +978,7 @@ msgstr "Ce formulaire est bloqué. Ressayer plus tard !"
978
 
979
  #: ../classes/class-ccf-form-renderer.php:55
980
  msgid "This is not a valid email address."
981
- msgstr "Ce n’est pas une adresse mél valide."
982
 
983
  #: ../classes/class-ccf-form-renderer.php:58
984
  msgid "This is not a valid phone number."
167
  #: ../classes/class-ccf-field-renderer.php:803 ../classes/class-ccf-form-manager.php:1215
168
  #: ../classes/class-ccf-form-manager.php:1516
169
  msgid "Email"
170
+ msgstr "Mail"
171
 
172
  #: ../classes/class-ccf-field-renderer.php:810 ../classes/class-ccf-form-manager.php:1219
173
  msgid "Confirm Email"
174
+ msgstr "Confirmez l’adresse mail"
175
 
176
  #: ../classes/class-ccf-field-renderer.php:876 ../classes/class-ccf-form-manager.php:1087
177
  msgid "First"
379
 
380
  #: ../classes/class-ccf-form-handler.php:368 ../classes/class-ccf-form-handler.php:384
381
  msgid "This is not a valid email"
382
+ msgstr "Ce n’est pas une adresse mail valide"
383
 
384
  #: ../classes/class-ccf-form-handler.php:376 ../classes/class-ccf-form-renderer.php:54
385
  msgid "Emails do not match."
386
+ msgstr "Les adresses mail ne correspondent pas."
387
 
388
  #: ../classes/class-ccf-form-handler.php:409
389
  msgid "First name is required."
575
 
576
  #: ../classes/class-ccf-form-manager.php:192
577
  msgid "Send Email Notifications:"
578
+ msgstr "Envoyer un mail de notification :"
579
 
580
  #: ../classes/class-ccf-form-manager.php:201
581
  msgid "\"To\" Email Addresses (comma separated):"
582
+ msgstr "Adresses mail de destination (séparée par une virgule) :"
583
 
584
  #: ../classes/class-ccf-form-manager.php:206
585
  msgid "\"From\" Email Address Type:"
586
+ msgstr "Type d’adresse mail d’origine"
587
 
588
  #: ../classes/class-ccf-form-manager.php:208
589
  msgid "WordPress Default"
591
 
592
  #: ../classes/class-ccf-form-manager.php:209
593
  msgid "Custom Email"
594
+ msgstr "Mail personnalisé"
595
 
596
  #: ../classes/class-ccf-form-manager.php:210 ../classes/class-ccf-form-manager.php:231
597
  msgid "Form Field"
958
 
959
  #: ../classes/class-ccf-form-manager.php:1541
960
  msgid "You have no email fields"
961
+ msgstr "Vous n’avez pas de champ mail"
962
 
963
  #: ../classes/class-ccf-form-manager.php:1542
964
  msgid "You have no name fields"
978
 
979
  #: ../classes/class-ccf-form-renderer.php:55
980
  msgid "This is not a valid email address."
981
+ msgstr "Ce n’est pas une adresse mail valide."
982
 
983
  #: ../classes/class-ccf-form-renderer.php:58
984
  msgid "This is not a valid phone number."
package.json CHANGED
@@ -4,10 +4,10 @@
4
  "grunt": "~0.4.2",
5
  "grunt-contrib-concat": "^0.5.0",
6
  "grunt-contrib-cssmin": "~0.7.0",
7
- "grunt-contrib-jshint": "^0.10.0",
8
  "grunt-contrib-sass": "~0.6.0",
9
  "grunt-contrib-uglify": "0.2.0",
10
  "grunt-contrib-watch": "0.5.3",
11
- "grunt-contrib-qunit": "~0.4.0"
 
12
  }
13
  }
4
  "grunt": "~0.4.2",
5
  "grunt-contrib-concat": "^0.5.0",
6
  "grunt-contrib-cssmin": "~0.7.0",
 
7
  "grunt-contrib-sass": "~0.6.0",
8
  "grunt-contrib-uglify": "0.2.0",
9
  "grunt-contrib-watch": "0.5.3",
10
+ "grunt-contrib-qunit": "~0.4.0",
11
+ "grunt-contrib-jshint": "^1.1.0"
12
  }
13
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: tlovett1
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HR34W94MM53RQ
4
  Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers, forms
5
  Requires at least: 3.9
6
- Tested up to: 4.6
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -60,6 +60,9 @@ For full documentation, questions, feature requests, and support concerning the
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 7.8.3 =
64
  * Fix WooCommerce conflict
65
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HR34W94MM53RQ
4
  Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers, forms
5
  Requires at least: 3.9
6
+ Tested up to: 4.8
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
60
 
61
  == Changelog ==
62
 
63
+ = 7.8.4 =
64
+ * Fix WP 4.7 conflict
65
+
66
  = 7.8.3 =
67
  * Fix WooCommerce conflict
68
 
wp-api/wp-api.js CHANGED
@@ -2,8 +2,9 @@
2
  'use strict';
3
 
4
  window.wp = window.wp || {};
 
5
 
6
- wp.api = {
7
  models: {},
8
  collections: {},
9
  utils: {}
@@ -40,7 +41,7 @@
40
  *
41
  * @param {Date} date.
42
  */
43
- wp.api.utils.parseISO8601 = function( date ) {
44
  var timestamp, struct, i, k,
45
  minutesOffset = 0,
46
  numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ];
@@ -120,13 +121,13 @@
120
  return;
121
  }
122
 
123
- var timestamp = wp.api.utils.parseISO8601( response[key] );
124
  response[key] = new Date( timestamp );
125
  });
126
 
127
  // Parse the author into a User object.
128
  if ( 'undefined' !== typeof response.author ) {
129
- response.author = new wp.api.models.User( response.author );
130
  }
131
 
132
  return response;
@@ -218,7 +219,7 @@
218
  /**
219
  * Backbone model for single users.
220
  */
221
- wp.api.models.User = BaseModel.extend(
222
  /** @lends User.prototype */
223
  {
224
  idAttribute: 'id',
@@ -250,7 +251,7 @@
250
  /**
251
  * Model for Taxonomy.
252
  */
253
- wp.api.models.Taxonomy = BaseModel.extend(
254
  /** @lends Taxonomy.prototype */
255
  {
256
  idAttribute: 'slug',
@@ -272,7 +273,7 @@
272
  /**
273
  * Backbone model for term.
274
  */
275
- wp.api.models.Term = BaseModel.extend(
276
  /** @lends Term.prototype */
277
  {
278
  idAttribute: 'id',
@@ -307,7 +308,7 @@
307
  /**
308
  * Backbone model for single posts.
309
  */
310
- wp.api.models.Post = BaseModel.extend( _.extend(
311
  /** @lends Post.prototype */
312
  {
313
  idAttribute: 'id',
@@ -343,7 +344,7 @@
343
  /**
344
  * Backbone model for pages.
345
  */
346
- wp.api.models.Page = BaseModel.extend( _.extend(
347
  /** @lends Page.prototype */
348
  {
349
  idAttribute: 'id',
@@ -379,7 +380,7 @@
379
  /**
380
  * Backbone model for revisions.
381
  */
382
- wp.api.models.Revision = BaseModel.extend( _.extend(
383
  /** @lends Revision.prototype */
384
  {
385
  idAttribute: 'id',
@@ -417,7 +418,7 @@
417
  /**
418
  * Backbone model for media items.
419
  */
420
- wp.api.models.Media = BaseModel.extend( _.extend(
421
  /** @lends Media.prototype */
422
  {
423
  idAttribute: 'id',
@@ -458,7 +459,7 @@
458
  initialize: function() {
459
 
460
  // Todo: what of the parent model is a page?
461
- this.parentModel = wp.api.models.Post;
462
  }
463
  }, TimeStampedMixin, HierarchicalMixin )
464
  );
@@ -466,7 +467,7 @@
466
  /**
467
  * Backbone model for comments.
468
  */
469
- wp.api.models.Comment = BaseModel.extend( _.extend(
470
  /** @lends Comment.prototype */
471
  {
472
  idAttribute: 'id',
@@ -511,7 +512,7 @@
511
  /**
512
  * Backbone model for single post types.
513
  */
514
- wp.api.models.PostType = BaseModel.extend(
515
  /** @lends PostType.prototype */
516
  {
517
  idAttribute: 'slug',
@@ -549,7 +550,7 @@
549
  /**
550
  * Backbone model for a post status.
551
  */
552
- wp.api.models.PostStatus = BaseModel.extend(
553
  /** @lends PostStatus.prototype */
554
  {
555
  idAttribute: 'slug',
@@ -715,48 +716,48 @@
715
  /**
716
  * Backbone collection for posts.
717
  */
718
- wp.api.collections.Posts = BaseCollection.extend(
719
  /** @lends Posts.prototype */
720
  {
721
  url: WP_API_Settings.root + 'wp/v2/posts',
722
 
723
- model: wp.api.models.Post
724
  }
725
  );
726
 
727
  /**
728
  * Backbone collection for pages.
729
  */
730
- wp.api.collections.Pages = BaseCollection.extend(
731
  /** @lends Pages.prototype */
732
  {
733
  url: WP_API_Settings.root + 'wp/v2/pages',
734
 
735
- model: wp.api.models.Page
736
  }
737
  );
738
 
739
  /**
740
  * Backbone users collection.
741
  */
742
- wp.api.collections.Users = BaseCollection.extend(
743
  /** @lends Users.prototype */
744
  {
745
  url: WP_API_Settings.root + 'wp/v2/users',
746
 
747
- model: wp.api.models.User
748
  }
749
  );
750
 
751
  /**
752
  * Backbone post statuses collection.
753
  */
754
- wp.api.collections.PostStatuses = BaseCollection.extend(
755
  /** @lends PostStatuses.prototype */
756
  {
757
  url: WP_API_Settings.root + 'wp/v2/statuses',
758
 
759
- model: wp.api.models.PostStatus,
760
 
761
  parse: function( response ) {
762
  var responseArray = [];
@@ -775,22 +776,22 @@
775
  /**
776
  * Backbone media library collection.
777
  */
778
- wp.api.collections.MediaLibrary = BaseCollection.extend(
779
  /** @lends MediaLibrary.prototype */
780
  {
781
  url: WP_API_Settings.root + 'wp/v2/media',
782
 
783
- model: wp.api.models.Media
784
  }
785
  );
786
 
787
  /**
788
  * Backbone taxonomy collection.
789
  */
790
- wp.api.collections.Taxonomies = BaseCollection.extend(
791
  /** @lends Taxonomies.prototype */
792
  {
793
- model: wp.api.models.Taxonomy,
794
 
795
  url: WP_API_Settings.root + 'wp/v2/taxonomies'
796
  }
@@ -799,10 +800,10 @@
799
  /**
800
  * Backbone comment collection.
801
  */
802
- wp.api.collections.Comments = BaseCollection.extend(
803
  /** @lends Comments.prototype */
804
  {
805
- model: wp.api.models.Comment,
806
 
807
  /**
808
  * Return URL for collection.
@@ -816,10 +817,10 @@
816
  /**
817
  * Backbone post type collection.
818
  */
819
- wp.api.collections.PostTypes = BaseCollection.extend(
820
  /** @lends PostTypes.prototype */
821
  {
822
- model: wp.api.models.PostType,
823
 
824
  url: WP_API_Settings.root + 'wp/v2/types',
825
 
@@ -840,12 +841,12 @@
840
  /**
841
  * Backbone terms collection.
842
  *
843
- * Usage: new wp.api.collections.Terms( {}, { taxonomy: 'taxonomy-slug' } )
844
  */
845
- wp.api.collections.Terms = BaseCollection.extend(
846
  /** @lends Terms.prototype */
847
  {
848
- model: wp.api.models.Term,
849
 
850
  taxonomy: 'category',
851
 
@@ -876,12 +877,12 @@
876
  /**
877
  * Backbone revisions collection.
878
  *
879
- * Usage: new wp.api.collections.Revisions( {}, { parent: POST_ID } ).
880
  */
881
- wp.api.collections.Revisions = BaseCollection.extend(
882
  /** @lends Revisions.prototype */
883
  {
884
- model: wp.api.models.Revision,
885
 
886
  parent: null,
887
 
2
  'use strict';
3
 
4
  window.wp = window.wp || {};
5
+ wp.ccf = wp.ccf || {};
6
 
7
+ wp.ccf.api = {
8
  models: {},
9
  collections: {},
10
  utils: {}
41
  *
42
  * @param {Date} date.
43
  */
44
+ wp.ccf.api.utils.parseISO8601 = function( date ) {
45
  var timestamp, struct, i, k,
46
  minutesOffset = 0,
47
  numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ];
121
  return;
122
  }
123
 
124
+ var timestamp = wp.ccf.api.utils.parseISO8601( response[key] );
125
  response[key] = new Date( timestamp );
126
  });
127
 
128
  // Parse the author into a User object.
129
  if ( 'undefined' !== typeof response.author ) {
130
+ response.author = new wp.ccf.api.models.User( response.author );
131
  }
132
 
133
  return response;
219
  /**
220
  * Backbone model for single users.
221
  */
222
+ wp.ccf.api.models.User = BaseModel.extend(
223
  /** @lends User.prototype */
224
  {
225
  idAttribute: 'id',
251
  /**
252
  * Model for Taxonomy.
253
  */
254
+ wp.ccf.api.models.Taxonomy = BaseModel.extend(
255
  /** @lends Taxonomy.prototype */
256
  {
257
  idAttribute: 'slug',
273
  /**
274
  * Backbone model for term.
275
  */
276
+ wp.ccf.api.models.Term = BaseModel.extend(
277
  /** @lends Term.prototype */
278
  {
279
  idAttribute: 'id',
308
  /**
309
  * Backbone model for single posts.
310
  */
311
+ wp.ccf.api.models.Post = BaseModel.extend( _.extend(
312
  /** @lends Post.prototype */
313
  {
314
  idAttribute: 'id',
344
  /**
345
  * Backbone model for pages.
346
  */
347
+ wp.ccf.api.models.Page = BaseModel.extend( _.extend(
348
  /** @lends Page.prototype */
349
  {
350
  idAttribute: 'id',
380
  /**
381
  * Backbone model for revisions.
382
  */
383
+ wp.ccf.api.models.Revision = BaseModel.extend( _.extend(
384
  /** @lends Revision.prototype */
385
  {
386
  idAttribute: 'id',
418
  /**
419
  * Backbone model for media items.
420
  */
421
+ wp.ccf.api.models.Media = BaseModel.extend( _.extend(
422
  /** @lends Media.prototype */
423
  {
424
  idAttribute: 'id',
459
  initialize: function() {
460
 
461
  // Todo: what of the parent model is a page?
462
+ this.parentModel = wp.ccf.api.models.Post;
463
  }
464
  }, TimeStampedMixin, HierarchicalMixin )
465
  );
467
  /**
468
  * Backbone model for comments.
469
  */
470
+ wp.ccf.api.models.Comment = BaseModel.extend( _.extend(
471
  /** @lends Comment.prototype */
472
  {
473
  idAttribute: 'id',
512
  /**
513
  * Backbone model for single post types.
514
  */
515
+ wp.ccf.api.models.PostType = BaseModel.extend(
516
  /** @lends PostType.prototype */
517
  {
518
  idAttribute: 'slug',
550
  /**
551
  * Backbone model for a post status.
552
  */
553
+ wp.ccf.api.models.PostStatus = BaseModel.extend(
554
  /** @lends PostStatus.prototype */
555
  {
556
  idAttribute: 'slug',
716
  /**
717
  * Backbone collection for posts.
718
  */
719
+ wp.ccf.api.collections.Posts = BaseCollection.extend(
720
  /** @lends Posts.prototype */
721
  {
722
  url: WP_API_Settings.root + 'wp/v2/posts',
723
 
724
+ model: wp.ccf.api.models.Post
725
  }
726
  );
727
 
728
  /**
729
  * Backbone collection for pages.
730
  */
731
+ wp.ccf.api.collections.Pages = BaseCollection.extend(
732
  /** @lends Pages.prototype */
733
  {
734
  url: WP_API_Settings.root + 'wp/v2/pages',
735
 
736
+ model: wp.ccf.api.models.Page
737
  }
738
  );
739
 
740
  /**
741
  * Backbone users collection.
742
  */
743
+ wp.ccf.api.collections.Users = BaseCollection.extend(
744
  /** @lends Users.prototype */
745
  {
746
  url: WP_API_Settings.root + 'wp/v2/users',
747
 
748
+ model: wp.ccf.api.models.User
749
  }
750
  );
751
 
752
  /**
753
  * Backbone post statuses collection.
754
  */
755
+ wp.ccf.api.collections.PostStatuses = BaseCollection.extend(
756
  /** @lends PostStatuses.prototype */
757
  {
758
  url: WP_API_Settings.root + 'wp/v2/statuses',
759
 
760
+ model: wp.ccf.api.models.PostStatus,
761
 
762
  parse: function( response ) {
763
  var responseArray = [];
776
  /**
777
  * Backbone media library collection.
778
  */
779
+ wp.ccf.api.collections.MediaLibrary = BaseCollection.extend(
780
  /** @lends MediaLibrary.prototype */
781
  {
782
  url: WP_API_Settings.root + 'wp/v2/media',
783
 
784
+ model: wp.ccf.api.models.Media
785
  }
786
  );
787
 
788
  /**
789
  * Backbone taxonomy collection.
790
  */
791
+ wp.ccf.api.collections.Taxonomies = BaseCollection.extend(
792
  /** @lends Taxonomies.prototype */
793
  {
794
+ model: wp.ccf.api.models.Taxonomy,
795
 
796
  url: WP_API_Settings.root + 'wp/v2/taxonomies'
797
  }
800
  /**
801
  * Backbone comment collection.
802
  */
803
+ wp.ccf.api.collections.Comments = BaseCollection.extend(
804
  /** @lends Comments.prototype */
805
  {
806
+ model: wp.ccf.api.models.Comment,
807
 
808
  /**
809
  * Return URL for collection.
817
  /**
818
  * Backbone post type collection.
819
  */
820
+ wp.ccf.api.collections.PostTypes = BaseCollection.extend(
821
  /** @lends PostTypes.prototype */
822
  {
823
+ model: wp.ccf.api.models.PostType,
824
 
825
  url: WP_API_Settings.root + 'wp/v2/types',
826
 
841
  /**
842
  * Backbone terms collection.
843
  *
844
+ * Usage: new wp.ccf.api.collections.Terms( {}, { taxonomy: 'taxonomy-slug' } )
845
  */
846
+ wp.ccf.api.collections.Terms = BaseCollection.extend(
847
  /** @lends Terms.prototype */
848
  {
849
+ model: wp.ccf.api.models.Term,
850
 
851
  taxonomy: 'category',
852
 
877
  /**
878
  * Backbone revisions collection.
879
  *
880
+ * Usage: new wp.ccf.api.collections.Revisions( {}, { parent: POST_ID } ).
881
  */
882
+ wp.ccf.api.collections.Revisions = BaseCollection.extend(
883
  /** @lends Revisions.prototype */
884
  {
885
+ model: wp.ccf.api.models.Revision,
886
 
887
  parent: null,
888