Commit e2d78274 by shz

tospur

parent ef304d65
<?php <?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php'); require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Dao/InsertDao.php'); require_once(PLUGIN_DIR . 'Dao/InsertDao.php');
require_once(PLUGIN_DIR . 'Tools/Image.php'); require_once(PLUGIN_DIR . 'Tools/Image.php');
require_once(PLUGIN_DIR . 'Tools/Core.php'); require_once(PLUGIN_DIR . 'Tools/Core.php');
require_once(PLUGIN_DIR . 'Admin/Tospur_House.php'); require_once(PLUGIN_DIR . 'Admin/Tospur_House.php');
class House extends Tospur_House{ class House extends Tospur_House{
public static function init_view(){ public static function init_view(){
wp_enqueue_script('jquery-ui'); wp_enqueue_script('jquery-ui');
wp_enqueue_script('bootstrapjs'); wp_enqueue_script('bootstrapjs');
wp_enqueue_style('jquery-ui_css'); wp_enqueue_script('validate');
wp_enqueue_style('bootstrapcss'); wp_enqueue_style('jquery-ui_css');
wp_enqueue_style('bootstrapcss');
global $wpdb; wp_enqueue_style('bootstrapMinCss');
$type = $_POST["type"];
$context = array(); global $wpdb;
$context['siteUrl'] = get_site_url(); $type = $_POST["type"];
if($type==1){ $context = array();
$insert_tospur_house_array = array( $context['siteUrl'] = get_site_url();
'name' => $_POST['housename'], if($type==1){
'average_price' => $_POST['average_price'], $insert_tospur_house_array = array(
'latest_news' => $_POST['latest_news'], 'name' => $_POST['housename'],
'address' => $_POST['address'], 'average_price' => $_POST['average_price'],
'traffic' => $_POST['traffic'], 'latest_news' => $_POST['latest_news'],
'periphery' => $_POST['periphery'], 'address' => $_POST['address'],
'developer' => $_POST['developers'], 'traffic' => $_POST['traffic'],
'check_in_time' => $_POST['check_in_time'], 'periphery' => $_POST['periphery'],
'property_age' => $_POST['property_age'], 'developer' => $_POST['developers'],
'decoration' => $_POST['decoration'], 'check_in_time' => $_POST['check_in_time'],
'covered_area' => $_POST['covered_area'], 'property_age' => $_POST['property_age'],
'volume_rate' => $_POST['volume_rate'], 'decoration' => $_POST['decoration'],
'greening_rate' => $_POST['greening_rate'], 'covered_area' => $_POST['covered_area'],
'households' => $_POST['households'], 'volume_rate' => $_POST['volume_rate'],
'parking_spaces' => $_POST['parking_spaces'], 'greening_rate' => $_POST['greening_rate'],
'property_management' => $_POST['property_management'], 'households' => $_POST['households'],
'overview' => $_POST['overview'], 'parking_spaces' => $_POST['parking_spaces'],
'city_id' => $_POST['baseCity'], 'property_management' => $_POST['property_management'],
'district_id' => $_POST['baseAreaId'], 'overview' => $_POST['overview'],
'plate_id' => $_POST["basePlateId"], 'city_id' => $_POST['baseCity'],
'room_id' => $_POST['baseRoom'], 'district_id' => $_POST['baseAreaId'],
"location" => $_POST["location"], 'plate_id' => $_POST["basePlateId"],
'status' =>$_POST['status'], 'room_id' => $_POST['baseRoom'],
"property_money" => $_POST["property_money"], "location" => $_POST["location"],
'community_name' => $_POST["community_name"], 'status' =>$_POST['status'],
); "property_money" => $_POST["property_money"],
$wpdb->query("START TRANSACTION"); 'community_name' => $_POST["community_name"],
if(isset($_POST['houseId'])){ );
$result = House::data_update($_POST['houseId'],$insert_tospur_house_array); $wpdb->query("START TRANSACTION");
if($result != 203){ if(isset($_POST['houseId'])){
$wpdb->query("ROLLBACK"); $result = House::data_update($_POST['houseId'],$insert_tospur_house_array);
print_r($result); if($result != 203){
echo "新房房源修改失败"; $wpdb->query("ROLLBACK");
}else{ print_r($result);
$wpdb->query("COMMIT"); echo "新房房源修改失败";
echo "新房房源修改成功"; }else{
} $wpdb->query("COMMIT");
}else{ echo "新房房源修改成功";
$result = House::data_insert($insert_tospur_house_array); }
print_r($result); }else{
if($result != 200){ $result = House::data_insert($insert_tospur_house_array);
$wpdb->query("ROLLBACK"); if($result != 200){
print_r($result);; $wpdb->query("ROLLBACK");
echo "新增房源失败"; print_r($result);;
}else{ echo "新增房源失败";
$wpdb->query("COMMIT"); }else{
echo "新增房源成功"; $wpdb->query("COMMIT");
} echo "新增房源成功";
} }
exit; }
}else if(isset($_GET['edit'])){ exit;
$context['houseId'] = $_GET['id']; }else if(isset($_GET['edit'])){
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id'],"edit")); $context['houseId'] = $_GET['id'];
$context["district"] = SearchDao::searchCity($context['result']->city_id); $context = array_merge($context,SearchDao::getDetailInfo($_GET['id'],"edit"));
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id); $context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["mark"] = SearchDao::searchHouseTag($_GET['id']); $context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
} $context["mark"] = SearchDao::searchHouseTag($_GET['id']);
$context['role'] = SecHandHouse::getCurrentRole(); }
$context["city"] = SearchDao::searchCity(); $context['role'] = SecHandHouse::getCurrentRole();
$context["buildProperty"] = SearchDao::searchBuildProperty(); $context["city"] = SearchDao::searchCity();
$context["room"] = SearchDao::searchRoom(); $context["buildProperty"] = SearchDao::searchBuildProperty();
$context["photoType"] = SearchDao::searchPhotoType(); $context["room"] = SearchDao::searchRoom();
$context["status"] = searchDao::searchStatusType(1); $context["photoType"] = SearchDao::searchPhotoType();
Timber::render("newhouse.html",$context); $context["status"] = searchDao::searchStatusType(1);
} Timber::render("newhouse.html",$context);
}
public static function data_update($houseId,$insert_tospur_house_array){
global $wpdb; public static function data_update($houseId,$insert_tospur_house_array){
$data = $_POST["data"]; global $wpdb;
$wpdb->update(Config::TOSPUR_HOUSE_TABLE,$insert_tospur_house_array,array("id" => $houseId)); $data = $_POST["data"];
$result = 203; $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$insert_tospur_house_array,array("id" => $houseId));
$exist_ids = array(); $result = 203;
if(isset($_POST['exists'])){ $exist_ids = array();
foreach($_POST['exists'] as $id => $item){ if(isset($_POST['exists'])){
$wpdb->update(Config::A_DISTRICT_AREA_TABLE,array( foreach($_POST['exists'] as $id => $item){
"buildproperty_id" => $item['buildProperty'], $wpdb->update(Config::A_DISTRICT_AREA_TABLE,array(
"house_area" => $item['housearea'] "buildproperty_id" => $item['buildProperty'],
),array("image_id" => $id)); "house_area" => $item['housearea']
$exist_ids[] = $id; ),array("image_id" => $id));
} $exist_ids[] = $id;
$old_exists_ids = explode(",",$_POST['exists_ids']); }
$delete_ids = array(); $old_exists_ids = explode(",",$_POST['exists_ids']);
foreach(array_diff($old_exists_ids,$exist_ids) as $key => $id){ $delete_ids = array();
$delete_ids[] = $id; foreach(array_diff($old_exists_ids,$exist_ids) as $key => $id){
} $delete_ids[] = $id;
$delete_ids = implode(",",$delete_ids); }
$wpdb->query("delete from ".Config::A_DISTRICT_AREA_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});"); $delete_ids = implode(",",$delete_ids);
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});"); $wpdb->query("delete from ".Config::A_DISTRICT_AREA_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});");
} $wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});");
InsertDao::addMainImage($houseId,$data); }
InsertDao::addMainImage($houseId,$data);
$exists_photo_ids = array();
if(isset($_POST['exists_photo'])){ $exists_photo_ids = array();
foreach($_POST['exists_photo'] as $id => $item){ if(isset($_POST['exists_photo'])){
$wpdb->update(Config::TOSPUR_IMAGE_TABLE,array( foreach($_POST['exists_photo'] as $id => $item){
"image_type" => $item['type'], $wpdb->update(Config::TOSPUR_IMAGE_TABLE,array(
),array("id" => $id)); "image_type" => $item['type'],
$exists_photo_ids[] = $id; ),array("id" => $id));
} $exists_photo_ids[] = $id;
} }
$old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']); }
$delete_photo_ids = array(); $old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']);
foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){ $delete_photo_ids = array();
$delete_photo_ids[] = $id; foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){
} $delete_photo_ids[] = $id;
$delete_photo_ids = implode(",",$delete_photo_ids); }
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});"); $delete_photo_ids = implode(",",$delete_photo_ids);
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});");
$wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
$res = InsertDao::addRecommend($houseId,$data); $wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
if($res == 504){ $res = InsertDao::addRecommend($houseId,$data);
$result = $res; if($res == 504){
echo "推荐房源修改失败"; $result = $res;
} echo "推荐房源修改失败";
}
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
$res = InsertDao::addRecConsultant($houseId,$data); $wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
if($res == 505){ $res = InsertDao::addRecConsultant($houseId,$data);
$result = $res; if($res == 505){
echo "推荐置业顾问修改失败"; $result = $res;
} echo "推荐置业顾问修改失败";
InsertDao::addHouseTag($_POST['mark'],$houseId); }
return $result; InsertDao::addHouseTag($_POST['mark'],$houseId);
} return $result;
}
public static function data_insert($params){
global $wpdb; public static function data_insert($params){
//房源与类型以及面积信息 global $wpdb;
$data = $_POST["data"]; //房源与类型以及面积信息
//获取新房信息,存入tospur_house表 $data = $_POST["data"];
$params['user_id'] = get_current_user_id(); //获取新房信息,存入tospur_house表
$params['creattime'] = date("Y-m-d H:i:s"); $params['user_id'] = get_current_user_id();
$params['house_type'] = 0; $params['creattime'] = date("Y-m-d H:i:s");
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['housename'] . '" and address="' . $_POST['address'] . '" and house_type=0', OBJECT); $params['house_type'] = 0;
if (!$res) { $res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['housename'] . '" and address="' . $_POST['address'] . '" and house_type=0', OBJECT);
$houseId = InsertDao::insert_tospur_house($params); if (!$res) {
$houseId = InsertDao::insert_tospur_house($params);
InsertDao::addMainImage($houseId,$data);
InsertDao::addMainImage($houseId,$data);
InsertDao::addRecommend($houseId,$data);
InsertDao::addRecommend($houseId,$data);
InsertDao::addRecConsultant($houseId,$data);
InsertDao::addRecConsultant($houseId,$data);
InsertDao::addHouseTag($_POST['mark'],$houseId);
InsertDao::addHouseTag($_POST['mark'],$houseId);
}else{
return 506; }else{
} return 506;
return 200; }
} return 200;
}
} }
\ No newline at end of file
<?php <?php
class Tospur_House{ class Tospur_House{
public static function getCurrentRole(){ public static function getCurrentRole(){
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) ) if ( !($current_user instanceof WP_User) )
return; return;
$roles = $current_user->roles; $roles = $current_user->roles;
return $roles[0]; return $roles[0];
} }
} }
\ No newline at end of file
...@@ -46,4 +46,6 @@ class introduction ...@@ -46,4 +46,6 @@ class introduction
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
return $current_user->ID; return $current_user->ID;
} }
} }
\ No newline at end of file
?>
\ No newline at end of file
...@@ -7,6 +7,7 @@ class SecHandHouse extends Tospur_House{ ...@@ -7,6 +7,7 @@ class SecHandHouse extends Tospur_House{
public static function secHandHouse_html(){ public static function secHandHouse_html(){
wp_enqueue_script('bootstrapjs'); wp_enqueue_script('bootstrapjs');
wp_enqueue_style('bootstrapcss'); wp_enqueue_style('bootstrapcss');
wp_enqueue_style('bootstrapMinCss');
global $wpdb; global $wpdb;
$type = $_POST["type"]; $type = $_POST["type"];
$context = array(); $context = array();
...@@ -69,6 +70,7 @@ class SecHandHouse extends Tospur_House{ ...@@ -69,6 +70,7 @@ class SecHandHouse extends Tospur_House{
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id); $context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
$context["mark"] = SearchDao::searchHouseTag($_GET['id']); $context["mark"] = SearchDao::searchHouseTag($_GET['id']);
$context["featureOld"] = SearchDao::searchFeatureByHouse($_GET['id']); $context["featureOld"] = SearchDao::searchFeatureByHouse($_GET['id']);
} }
$context['role'] = SecHandHouse::getCurrentRole(); $context['role'] = SecHandHouse::getCurrentRole();
$context["city"] = SearchDao::searchCity(); $context["city"] = SearchDao::searchCity();
...@@ -144,7 +146,6 @@ class SecHandHouse extends Tospur_House{ ...@@ -144,7 +146,6 @@ class SecHandHouse extends Tospur_House{
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId)); $wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
InsertDao::addRecConsultant($houseId,$data); InsertDao::addRecConsultant($houseId,$data);
// $wpdb->delete(Config::A_HOUSE_TAG_TABLE,array("house_id" => $houseId));
$wpdb->query( $wpdb->query(
$wpdb->prepare( $wpdb->prepare(
"DELETE FROM a_house_tag "DELETE FROM a_house_tag
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/*!
* jQuery Validation Plugin v1.14.0
*
* http://jqueryvalidation.org/
*
* Copyright (c) 2015 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
define( ["jquery"], factory );
} else {
factory( jQuery );
}
}(function( $ ) {
$.extend($.fn, {
// http://jqueryvalidation.org/validate/
validate: function( options ) {
// if nothing is selected, return nothing; can't chain anyway
if ( !this.length ) {
if ( options && options.debug && window.console ) {
console.warn( "Nothing selected, can't validate, returning nothing." );
}
return;
}
// check if a validator for this form was already created
var validator = $.data( this[ 0 ], "validator" );
if ( validator ) {
return validator;
}
// Add novalidate tag if HTML5.
this.attr( "novalidate", "novalidate" );
validator = new $.validator( options, this[ 0 ] );
$.data( this[ 0 ], "validator", validator );
if ( validator.settings.onsubmit ) {
this.on( "click.validate", ":submit", function( event ) {
if ( validator.settings.submitHandler ) {
validator.submitButton = event.target;
}
// allow suppressing validation by adding a cancel class to the submit button
if ( $( this ).hasClass( "cancel" ) ) {
validator.cancelSubmit = true;
}
// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if ( $( this ).attr( "formnovalidate" ) !== undefined ) {
validator.cancelSubmit = true;
}
});
// validate the form on submit
this.on( "submit.validate", function( event ) {
if ( validator.settings.debug ) {
// prevent form submit to be able to see console output
event.preventDefault();
}
function handle() {
var hidden, result;
if ( validator.settings.submitHandler ) {
if ( validator.submitButton ) {
// insert a hidden input as a replacement for the missing submit button
hidden = $( "<input type='hidden'/>" )
.attr( "name", validator.submitButton.name )
.val( $( validator.submitButton ).val() )
.appendTo( validator.currentForm );
}
result = validator.settings.submitHandler.call( validator, validator.currentForm, event );
if ( validator.submitButton ) {
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden.remove();
}
if ( result !== undefined ) {
return result;
}
return false;
}
return true;
}
// prevent submit for invalid forms or custom submit handlers
if ( validator.cancelSubmit ) {
validator.cancelSubmit = false;
return handle();
}
if ( validator.form() ) {
if ( validator.pendingRequest ) {
validator.formSubmitted = true;
return false;
}
return handle();
} else {
validator.focusInvalid();
return false;
}
});
}
return validator;
},
// http://jqueryvalidation.org/valid/
valid: function() {
var valid, validator, errorList;
if ( $( this[ 0 ] ).is( "form" ) ) {
valid = this.validate().form();
} else {
errorList = [];
valid = true;
validator = $( this[ 0 ].form ).validate();
this.each( function() {
valid = validator.element( this ) && valid;
errorList = errorList.concat( validator.errorList );
});
validator.errorList = errorList;
}
return valid;
},
// http://jqueryvalidation.org/rules/
rules: function( command, argument ) {
var element = this[ 0 ],
settings, staticRules, existingRules, data, param, filtered;
if ( command ) {
settings = $.data( element.form, "validator" ).settings;
staticRules = settings.rules;
existingRules = $.validator.staticRules( element );
switch ( command ) {
case "add":
$.extend( existingRules, $.validator.normalizeRule( argument ) );
// remove messages from rules, but allow them to be set separately
delete existingRules.messages;
staticRules[ element.name ] = existingRules;
if ( argument.messages ) {
settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages );
}
break;
case "remove":
if ( !argument ) {
delete staticRules[ element.name ];
return existingRules;
}
filtered = {};
$.each( argument.split( /\s/ ), function( index, method ) {
filtered[ method ] = existingRules[ method ];
delete existingRules[ method ];
if ( method === "required" ) {
$( element ).removeAttr( "aria-required" );
}
});
return filtered;
}
}
data = $.validator.normalizeRules(
$.extend(
{},
$.validator.classRules( element ),
$.validator.attributeRules( element ),
$.validator.dataRules( element ),
$.validator.staticRules( element )
), element );
// make sure required is at front
if ( data.required ) {
param = data.required;
delete data.required;
data = $.extend( { required: param }, data );
$( element ).attr( "aria-required", "true" );
}
// make sure remote is at back
if ( data.remote ) {
param = data.remote;
delete data.remote;
data = $.extend( data, { remote: param });
}
return data;
}
});
// Custom selectors
$.extend( $.expr[ ":" ], {
// http://jqueryvalidation.org/blank-selector/
blank: function( a ) {
return !$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/filled-selector/
filled: function( a ) {
return !!$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/unchecked-selector/
unchecked: function( a ) {
return !$( a ).prop( "checked" );
}
});
// constructor for validator
$.validator = function( options, form ) {
this.settings = $.extend( true, {}, $.validator.defaults, options );
this.currentForm = form;
this.init();
};
// http://jqueryvalidation.org/jQuery.validator.format/
$.validator.format = function( source, params ) {
if ( arguments.length === 1 ) {
return function() {
var args = $.makeArray( arguments );
args.unshift( source );
return $.validator.format.apply( this, args );
};
}
if ( arguments.length > 2 && params.constructor !== Array ) {
params = $.makeArray( arguments ).slice( 1 );
}
if ( params.constructor !== Array ) {
params = [ params ];
}
$.each( params, function( i, n ) {
source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() {
return n;
});
});
return source;
};
$.extend( $.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusCleanup: false,
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function( element ) {
this.lastActive = element;
// Hide error label and remove error class on focus if enabled
if ( this.settings.focusCleanup ) {
if ( this.settings.unhighlight ) {
this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
}
this.hideThese( this.errorsFor( element ) );
}
},
onfocusout: function( element ) {
if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) {
this.element( element );
}
},
onkeyup: function( element, event ) {
// Avoid revalidate the field when pressing one of the following keys
// Shift => 16
// Ctrl => 17
// Alt => 18
// Caps lock => 20
// End => 35
// Home => 36
// Left arrow => 37
// Up arrow => 38
// Right arrow => 39
// Down arrow => 40
// Insert => 45
// Num lock => 144
// AltGr key => 225
var excludedKeys = [
16, 17, 18, 20, 35, 36, 37,
38, 39, 40, 45, 144, 225
];
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return;
} else if ( element.name in this.submitted || element === this.lastElement ) {
this.element( element );
}
},
onclick: function( element ) {
// click on selects, radiobuttons and checkboxes
if ( element.name in this.submitted ) {
this.element( element );
// or option elements, check parent select in that case
} else if ( element.parentNode.name in this.submitted ) {
this.element( element.parentNode );
}
},
highlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).addClass( errorClass ).removeClass( validClass );
} else {
$( element ).addClass( errorClass ).removeClass( validClass );
}
},
unhighlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).removeClass( errorClass ).addClass( validClass );
} else {
$( element ).removeClass( errorClass ).addClass( validClass );
}
}
},
// http://jqueryvalidation.org/jQuery.validator.setDefaults/
setDefaults: function( settings ) {
$.extend( $.validator.defaults, settings );
},
messages: {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date ( ISO ).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
maxlength: $.validator.format( "Please enter no more than {0} characters." ),
minlength: $.validator.format( "Please enter at least {0} characters." ),
rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
range: $.validator.format( "Please enter a value between {0} and {1}." ),
max: $.validator.format( "Please enter a value less than or equal to {0}." ),
min: $.validator.format( "Please enter a value greater than or equal to {0}." )
},
autoCreateRanges: false,
prototype: {
init: function() {
this.labelContainer = $( this.settings.errorLabelContainer );
this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm );
this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
var groups = ( this.groups = {} ),
rules;
$.each( this.settings.groups, function( key, value ) {
if ( typeof value === "string" ) {
value = value.split( /\s/ );
}
$.each( value, function( index, name ) {
groups[ name ] = key;
});
});
rules = this.settings.rules;
$.each( rules, function( key, value ) {
rules[ key ] = $.validator.normalizeRule( value );
});
function delegate( event ) {
var validator = $.data( this.form, "validator" ),
eventType = "on" + event.type.replace( /^validate/, "" ),
settings = validator.settings;
if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
settings[ eventType ].call( validator, this, event );
}
}
$( this.currentForm )
.on( "focusin.validate focusout.validate keyup.validate",
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
"[type='radio'], [type='checkbox']", delegate)
// Support: Chrome, oldIE
// "select" is provided as event.target when clicking a option
.on("click.validate", "select, option, [type='radio'], [type='checkbox']", delegate);
if ( this.settings.invalidHandler ) {
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
}
// Add aria-required to any Static/Data/Class required fields before first validation
// Screen readers require this attribute to be present before the initial submission http://www.w3.org/TR/WCAG-TECHS/ARIA2.html
$( this.currentForm ).find( "[required], [data-rule-required], .required" ).attr( "aria-required", "true" );
},
// http://jqueryvalidation.org/Validator.form/
form: function() {
this.checkForm();
$.extend( this.submitted, this.errorMap );
this.invalid = $.extend({}, this.errorMap );
if ( !this.valid() ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
}
this.showErrors();
return this.valid();
},
checkForm: function() {
this.prepareForm();
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
this.check( elements[ i ] );
}
return this.valid();
},
// http://jqueryvalidation.org/Validator.element/
element: function( element ) {
var cleanElement = this.clean( element ),
checkElement = this.validationTargetFor( cleanElement ),
result = true;
this.lastElement = checkElement;
if ( checkElement === undefined ) {
delete this.invalid[ cleanElement.name ];
} else {
this.prepareElement( checkElement );
this.currentElements = $( checkElement );
result = this.check( checkElement ) !== false;
if ( result ) {
delete this.invalid[ checkElement.name ];
} else {
this.invalid[ checkElement.name ] = true;
}
}
// Add aria-invalid status for screen readers
$( element ).attr( "aria-invalid", !result );
if ( !this.numberOfInvalids() ) {
// Hide error containers on last error
this.toHide = this.toHide.add( this.containers );
}
this.showErrors();
return result;
},
// http://jqueryvalidation.org/Validator.showErrors/
showErrors: function( errors ) {
if ( errors ) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
for ( var name in errors ) {
this.errorList.push({
message: errors[ name ],
element: this.findByName( name )[ 0 ]
});
}
// remove items from success list
this.successList = $.grep( this.successList, function( element ) {
return !( element.name in errors );
});
}
if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else {
this.defaultShowErrors();
}
},
// http://jqueryvalidation.org/Validator.resetForm/
resetForm: function() {
if ( $.fn.resetForm ) {
$( this.currentForm ).resetForm();
}
this.submitted = {};
this.lastElement = null;
this.prepareForm();
this.hideErrors();
var i, elements = this.elements()
.removeData( "previousValue" )
.removeAttr( "aria-invalid" );
if ( this.settings.unhighlight ) {
for ( i = 0; elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ],
this.settings.errorClass, "" );
}
} else {
elements.removeClass( this.settings.errorClass );
}
},
numberOfInvalids: function() {
return this.objectLength( this.invalid );
},
objectLength: function( obj ) {
/* jshint unused: false */
var count = 0,
i;
for ( i in obj ) {
count++;
}
return count;
},
hideErrors: function() {
this.hideThese( this.toHide );
},
hideThese: function( errors ) {
errors.not( this.containers ).text( "" );
this.addWrapper( errors ).hide();
},
valid: function() {
return this.size() === 0;
},
size: function() {
return this.errorList.length;
},
focusInvalid: function() {
if ( this.settings.focusInvalid ) {
try {
$( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [])
.filter( ":visible" )
.focus()
// manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
.trigger( "focusin" );
} catch ( e ) {
// ignore IE throwing errors when focusing hidden elements
}
}
},
findLastActive: function() {
var lastActive = this.lastActive;
return lastActive && $.grep( this.errorList, function( n ) {
return n.element.name === lastActive.name;
}).length === 1 && lastActive;
},
elements: function() {
var validator = this,
rulesCache = {};
// select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea" )
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this );
}
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
return false;
}
rulesCache[ this.name ] = true;
return true;
});
},
clean: function( selector ) {
return $( selector )[ 0 ];
},
errors: function() {
var errorClass = this.settings.errorClass.split( " " ).join( "." );
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
},
reset: function() {
this.successList = [];
this.errorList = [];
this.errorMap = {};
this.toShow = $( [] );
this.toHide = $( [] );
this.currentElements = $( [] );
},
prepareForm: function() {
this.reset();
this.toHide = this.errors().add( this.containers );
},
prepareElement: function( element ) {
this.reset();
this.toHide = this.errorsFor( element );
},
elementValue: function( element ) {
var val,
$element = $( element ),
type = element.type;
if ( type === "radio" || type === "checkbox" ) {
return this.findByName( element.name ).filter(":checked").val();
} else if ( type === "number" && typeof element.validity !== "undefined" ) {
return element.validity.badInput ? false : $element.val();
}
val = $element.val();
if ( typeof val === "string" ) {
return val.replace(/\r/g, "" );
}
return val;
},
check: function( element ) {
element = this.validationTargetFor( this.clean( element ) );
var rules = $( element ).rules(),
rulesCount = $.map( rules, function( n, i ) {
return i;
}).length,
dependencyMismatch = false,
val = this.elementValue( element ),
result, method, rule;
for ( method in rules ) {
rule = { method: method, parameters: rules[ method ] };
try {
result = $.validator.methods[ method ].call( this, val, element, rule.parameters );
// if a method indicates that the field is optional and therefore valid,
// don't mark it as valid when there are no other rules
if ( result === "dependency-mismatch" && rulesCount === 1 ) {
dependencyMismatch = true;
continue;
}
dependencyMismatch = false;
if ( result === "pending" ) {
this.toHide = this.toHide.not( this.errorsFor( element ) );
return;
}
if ( !result ) {
this.formatAndAdd( element, rule );
return false;
}
} catch ( e ) {
if ( this.settings.debug && window.console ) {
console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
}
if ( e instanceof TypeError ) {
e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.";
}
throw e;
}
}
if ( dependencyMismatch ) {
return;
}
if ( this.objectLength( rules ) ) {
this.successList.push( element );
}
return true;
},
// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
// return the generic message if present and no method specific message is present
customDataMessage: function( element, method ) {
return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" );
},
// return the custom message for the given element name and validation method
customMessage: function( name, method ) {
var m = this.settings.messages[ name ];
return m && ( m.constructor === String ? m : m[ method ]);
},
// return the first defined argument, allowing empty strings
findDefined: function() {
for ( var i = 0; i < arguments.length; i++) {
if ( arguments[ i ] !== undefined ) {
return arguments[ i ];
}
}
return undefined;
},
defaultMessage: function( element, method ) {
return this.findDefined(
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
// title is never undefined, so handle empty string as undefined
!this.settings.ignoreTitle && element.title || undefined,
$.validator.messages[ method ],
"<strong>Warning: No message defined for " + element.name + "</strong>"
);
},
formatAndAdd: function( element, rule ) {
var message = this.defaultMessage( element, rule.method ),
theregex = /\$?\{(\d+)\}/g;
if ( typeof message === "function" ) {
message = message.call( this, rule.parameters, element );
} else if ( theregex.test( message ) ) {
message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters );
}
this.errorList.push({
message: message,
element: element,
method: rule.method
});
this.errorMap[ element.name ] = message;
this.submitted[ element.name ] = message;
},
addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
}
return toToggle;
},
defaultShowErrors: function() {
var i, elements, error;
for ( i = 0; this.errorList[ i ]; i++ ) {
error = this.errorList[ i ];
if ( this.settings.highlight ) {
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
}
this.showLabel( error.element, error.message );
}
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if ( this.settings.success ) {
for ( i = 0; this.successList[ i ]; i++ ) {
this.showLabel( this.successList[ i ] );
}
}
if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass );
}
}
this.toHide = this.toHide.not( this.toShow );
this.hideErrors();
this.addWrapper( this.toShow ).show();
},
validElements: function() {
return this.currentElements.not( this.invalidElements() );
},
invalidElements: function() {
return $( this.errorList ).map(function() {
return this.element;
});
},
showLabel: function( element, message ) {
var place, group, errorID,
error = this.errorsFor( element ),
elementID = this.idOrName( element ),
describedBy = $( element ).attr( "aria-describedby" );
if ( error.length ) {
// refresh error/success class
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
// replace message on existing label
error.html( message );
} else {
// create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
// Maintain reference to the element to be placed into the DOM
place = error;
if ( this.settings.wrapper ) {
// make sure the element is visible, even in IE
// actually showing the wrapped element is handled elsewhere
place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent();
}
if ( this.labelContainer.length ) {
this.labelContainer.append( place );
} else if ( this.settings.errorPlacement ) {
this.settings.errorPlacement( place, $( element ) );
} else {
place.insertAfter( element );
}
// Link error back to the element
if ( error.is( "label" ) ) {
// If the error is a label, then associate using 'for'
error.attr( "for", elementID );
} else if ( error.parents( "label[for='" + elementID + "']" ).length === 0 ) {
// If the element is not a child of an associated label, then it's necessary
// to explicitly apply aria-describedby
errorID = error.attr( "id" ).replace( /(:|\.|\[|\]|\$)/g, "\\$1");
// Respect existing non-error aria-describedby
if ( !describedBy ) {
describedBy = errorID;
} else if ( !describedBy.match( new RegExp( "\\b" + errorID + "\\b" ) ) ) {
// Add to end of list if not already present
describedBy += " " + errorID;
}
$( element ).attr( "aria-describedby", describedBy );
// If this element is grouped, then assign to all elements in the same group
group = this.groups[ element.name ];
if ( group ) {
$.each( this.groups, function( name, testgroup ) {
if ( testgroup === group ) {
$( "[name='" + name + "']", this.currentForm )
.attr( "aria-describedby", error.attr( "id" ) );
}
});
}
}
}
if ( !message && this.settings.success ) {
error.text( "" );
if ( typeof this.settings.success === "string" ) {
error.addClass( this.settings.success );
} else {
this.settings.success( error, element );
}
}
this.toShow = this.toShow.add( error );
},
errorsFor: function( element ) {
var name = this.idOrName( element ),
describer = $( element ).attr( "aria-describedby" ),
selector = "label[for='" + name + "'], label[for='" + name + "'] *";
// aria-describedby should directly reference the error element
if ( describer ) {
selector = selector + ", #" + describer.replace( /\s+/g, ", #" );
}
return this
.errors()
.filter( selector );
},
idOrName: function( element ) {
return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name );
},
validationTargetFor: function( element ) {
// If radio/checkbox, validate first element in group instead
if ( this.checkable( element ) ) {
element = this.findByName( element.name );
}
// Always apply ignore filter
return $( element ).not( this.settings.ignore )[ 0 ];
},
checkable: function( element ) {
return ( /radio|checkbox/i ).test( element.type );
},
findByName: function( name ) {
return $( this.currentForm ).find( "[name='" + name + "']" );
},
getLength: function( value, element ) {
switch ( element.nodeName.toLowerCase() ) {
case "select":
return $( "option:selected", element ).length;
case "input":
if ( this.checkable( element ) ) {
return this.findByName( element.name ).filter( ":checked" ).length;
}
}
return value.length;
},
depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param]( param, element ) : true;
},
dependTypes: {
"boolean": function( param ) {
return param;
},
"string": function( param, element ) {
return !!$( param, element.form ).length;
},
"function": function( param, element ) {
return param( element );
}
},
optional: function( element ) {
var val = this.elementValue( element );
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},
startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
this.pending[ element.name ] = true;
}
},
stopRequest: function( element, valid ) {
this.pendingRequest--;
// sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}
delete this.pending[ element.name ];
if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
$( this.currentForm ).submit();
this.formSubmitted = false;
} else if (!valid && this.pendingRequest === 0 && this.formSubmitted ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
this.formSubmitted = false;
}
},
previousValue: function( element ) {
return $.data( element, "previousValue" ) || $.data( element, "previousValue", {
old: null,
valid: true,
message: this.defaultMessage( element, "remote" )
});
},
// cleans up all forms and elements, removes validator-specific events
destroy: function() {
this.resetForm();
$( this.currentForm )
.off( ".validate" )
.removeData( "validator" );
}
},
classRuleSettings: {
required: { required: true },
email: { email: true },
url: { url: true },
date: { date: true },
dateISO: { dateISO: true },
number: { number: true },
digits: { digits: true },
creditcard: { creditcard: true }
},
addClassRules: function( className, rules ) {
if ( className.constructor === String ) {
this.classRuleSettings[ className ] = rules;
} else {
$.extend( this.classRuleSettings, className );
}
},
classRules: function( element ) {
var rules = {},
classes = $( element ).attr( "class" );
if ( classes ) {
$.each( classes.split( " " ), function() {
if ( this in $.validator.classRuleSettings ) {
$.extend( rules, $.validator.classRuleSettings[ this ]);
}
});
}
return rules;
},
normalizeAttributeRule: function( rules, type, method, value ) {
// convert the value to a number for number inputs, and for text for backwards compability
// allows type="date" and others to be compared as strings
if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
value = Number( value );
// Support Opera Mini, which returns NaN for undefined minlength
if ( isNaN( value ) ) {
value = undefined;
}
}
if ( value || value === 0 ) {
rules[ method ] = value;
} else if ( type === method && type !== "range" ) {
// exception: the jquery validate 'range' method
// does not test for the html5 'range' type
rules[ method ] = true;
}
},
attributeRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
// support for <input required> in both html5 and older browsers
if ( method === "required" ) {
value = element.getAttribute( method );
// Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup
if ( value === "" ) {
value = true;
}
// force non-HTML5 browsers to return bool
value = !!value;
} else {
value = $element.attr( method );
}
this.normalizeAttributeRule( rules, type, method, value );
}
// maxlength may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs
if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) {
delete rules.maxlength;
}
return rules;
},
dataRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() );
this.normalizeAttributeRule( rules, type, method, value );
}
return rules;
},
staticRules: function( element ) {
var rules = {},
validator = $.data( element.form, "validator" );
if ( validator.settings.rules ) {
rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {};
}
return rules;
},
normalizeRules: function( rules, element ) {
// handle dependency check
$.each( rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false
if ( val === false ) {
delete rules[ prop ];
return;
}
if ( val.param || val.depends ) {
var keepRule = true;
switch ( typeof val.depends ) {
case "string":
keepRule = !!$( val.depends, element.form ).length;
break;
case "function":
keepRule = val.depends.call( element, element );
break;
}
if ( keepRule ) {
rules[ prop ] = val.param !== undefined ? val.param : true;
} else {
delete rules[ prop ];
}
}
});
// evaluate parameters
$.each( rules, function( rule, parameter ) {
rules[ rule ] = $.isFunction( parameter ) ? parameter( element ) : parameter;
});
// clean number parameters
$.each([ "minlength", "maxlength" ], function() {
if ( rules[ this ] ) {
rules[ this ] = Number( rules[ this ] );
}
});
$.each([ "rangelength", "range" ], function() {
var parts;
if ( rules[ this ] ) {
if ( $.isArray( rules[ this ] ) ) {
rules[ this ] = [ Number( rules[ this ][ 0 ]), Number( rules[ this ][ 1 ] ) ];
} else if ( typeof rules[ this ] === "string" ) {
parts = rules[ this ].replace(/[\[\]]/g, "" ).split( /[\s,]+/ );
rules[ this ] = [ Number( parts[ 0 ]), Number( parts[ 1 ] ) ];
}
}
});
if ( $.validator.autoCreateRanges ) {
// auto-create ranges
if ( rules.min != null && rules.max != null ) {
rules.range = [ rules.min, rules.max ];
delete rules.min;
delete rules.max;
}
if ( rules.minlength != null && rules.maxlength != null ) {
rules.rangelength = [ rules.minlength, rules.maxlength ];
delete rules.minlength;
delete rules.maxlength;
}
}
return rules;
},
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule: function( data ) {
if ( typeof data === "string" ) {
var transformed = {};
$.each( data.split( /\s/ ), function() {
transformed[ this ] = true;
});
data = transformed;
}
return data;
},
// http://jqueryvalidation.org/jQuery.validator.addMethod/
addMethod: function( name, method, message ) {
$.validator.methods[ name ] = method;
$.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ];
if ( method.length < 3 ) {
$.validator.addClassRules( name, $.validator.normalizeRule( name ) );
}
},
methods: {
// http://jqueryvalidation.org/required-method/
required: function( value, element, param ) {
// check if dependency is met
if ( !this.depend( param, element ) ) {
return "dependency-mismatch";
}
if ( element.nodeName.toLowerCase() === "select" ) {
// could be an array for select-multiple or a string, both are fine this way
var val = $( element ).val();
return val && val.length > 0;
}
if ( this.checkable( element ) ) {
return this.getLength( value, element ) > 0;
}
return value.length > 0;
},
// http://jqueryvalidation.org/email-method/
email: function( value, element ) {
// From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
// Retrieved 2014-01-14
// If you have a problem with this implementation, report a bug against the above spec
// Or use custom methods to implement your own email validation
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
},
// http://jqueryvalidation.org/url-method/
url: function( value, element ) {
// Copyright (c) 2010-2013 Diego Perini, MIT licensed
// https://gist.github.com/dperini/729294
// see also https://mathiasbynens.be/demo/url-regex
// modified to allow protocol-relative URLs
return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
},
// http://jqueryvalidation.org/date-method/
date: function( value, element ) {
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
},
// http://jqueryvalidation.org/dateISO-method/
dateISO: function( value, element ) {
return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
},
// http://jqueryvalidation.org/number-method/
number: function( value, element ) {
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
},
// http://jqueryvalidation.org/digits-method/
digits: function( value, element ) {
return this.optional( element ) || /^\d+$/.test( value );
},
// http://jqueryvalidation.org/creditcard-method/
// based on http://en.wikipedia.org/wiki/Luhn_algorithm
creditcard: function( value, element ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
// accept only spaces, digits and dashes
if ( /[^0-9 \-]+/.test( value ) ) {
return false;
}
var nCheck = 0,
nDigit = 0,
bEven = false,
n, cDigit;
value = value.replace( /\D/g, "" );
// Basing min and max length on
// http://developer.ean.com/general_info/Valid_Credit_Card_Types
if ( value.length < 13 || value.length > 19 ) {
return false;
}
for ( n = value.length - 1; n >= 0; n--) {
cDigit = value.charAt( n );
nDigit = parseInt( cDigit, 10 );
if ( bEven ) {
if ( ( nDigit *= 2 ) > 9 ) {
nDigit -= 9;
}
}
nCheck += nDigit;
bEven = !bEven;
}
return ( nCheck % 10 ) === 0;
},
// http://jqueryvalidation.org/minlength-method/
minlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length >= param;
},
// http://jqueryvalidation.org/maxlength-method/
maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length <= param;
},
// http://jqueryvalidation.org/rangelength-method/
rangelength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
},
// http://jqueryvalidation.org/min-method/
min: function( value, element, param ) {
return this.optional( element ) || value >= param;
},
// http://jqueryvalidation.org/max-method/
max: function( value, element, param ) {
return this.optional( element ) || value <= param;
},
// http://jqueryvalidation.org/range-method/
range: function( value, element, param ) {
return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] );
},
// http://jqueryvalidation.org/equalTo-method/
equalTo: function( value, element, param ) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $( param );
if ( this.settings.onfocusout ) {
target.off( ".validate-equalTo" ).on( "blur.validate-equalTo", function() {
$( element ).valid();
});
}
return value === target.val();
},
// http://jqueryvalidation.org/remote-method/
remote: function( value, element, param ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
var previous = this.previousValue( element ),
validator, data;
if (!this.settings.messages[ element.name ] ) {
this.settings.messages[ element.name ] = {};
}
previous.originalMessage = this.settings.messages[ element.name ].remote;
this.settings.messages[ element.name ].remote = previous.message;
param = typeof param === "string" && { url: param } || param;
if ( previous.old === value ) {
return previous.valid;
}
previous.old = value;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
context: validator.currentForm,
success: function( response ) {
var valid = response === true || response === "true",
errors, message, submitted;
validator.settings.messages[ element.name ].remote = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.prepareElement( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
delete validator.invalid[ element.name ];
validator.showErrors();
} else {
errors = {};
message = response || validator.defaultMessage( element, "remote" );
errors[ element.name ] = previous.message = $.isFunction( message ) ? message( value ) : message;
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
}
previous.valid = valid;
validator.stopRequest( element, valid );
}
}, param ) );
return "pending";
}
}
});
// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
var pendingRequests = {},
ajax;
// Use a prefilter if available (1.5+)
if ( $.ajaxPrefilter ) {
$.ajaxPrefilter(function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = xhr;
}
});
} else {
// Proxy ajax
ajax = $.ajax;
$.ajax = function( settings ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = ajax.apply(this, arguments);
return pendingRequests[port];
}
return ajax.apply(this, arguments);
};
}
}));
\ No newline at end of file
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
{% set title = houseId?"修改新房房源":"添加新房房源" %} {% set title = houseId?"修改新房房源":"添加新房房源" %}
<meta charset="utf-8"> <meta charset="utf-8">
<title>{{title}}</title> <title>{{title}}</title>
</head> </head>
<body> <body>
<h2 class="title">{{title}}</h2> <h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data"> <form action="" method="POST" enctype="multipart/form-data" id="newHouse">
<table class="form-table"> <div class="row">
<tbody> <div class="col-md-11">
<tr> <div class="row">
<th><label for="housename">楼盘名</label></th> <div class="col-md-8">
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td> <table class="form-table">
</tr> <tbody>
<tr> <tr>
<th><label for="mark">标签:</label></th> <th><label for="housename">楼盘名</label></th>
<td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td> <td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr>
<th><label for="community_name">小区名</label></th> <tr>
<td> <input name="community_name" id="community_name" type="text" value="{{result.community_name}}" style="width: 150px;" class="regular-text code" ></td> <th><label for="mark">标签:</label></th>
</tr> <td> <input name="mark" id="mark" type="text" value="{{mark}}" class="form-control"></td>
<tr> </tr>
<th><label for="average_price">均价</label></th> <tr>
<td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="regular-text code" style="width: 90px;"></td> <th><label for="community_name">小区名</label></th>
</tr> <td> <input name="community_name" id="community_name" type="text" value="{{result.community_name}}" style="width: 150px;" class="form-control" ></td>
<tr> </tr>
<th><label for="latest_news">最新动态</label></th> <tr>
<td><textarea name="latest_news" rows="4" cols="40" class="large-text code" style="width: 400px;">{{result.latest_news}}</textarea></td> <th><label for="address">地址</label></th>
</tr> <td> <input name="address" type="text" value="{{result.address}}" class="form-control"></td>
<tr> </tr>
<th><label for="from">所属地区</label></th> <tr>
<td> <th><label for="average_price">均价</label></th>
<select id="baseCity" name="baseCity"> <td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control" style="width: 90px;"></td>
<option value="-1"> 城市</option> </tr>
{% for item in city %} <tr>
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <th><label for="latest_news">最新动态</label></th>
{% endfor %} <td><textarea name="latest_news" rows="4" cols="40" class="form-control" style="width: 400px;">{{result.latest_news}}</textarea></td>
</select> </tr>
<select id="baseAreaId" name="baseAreaId"> </tbody>
<option value = "-1">区域</option> </table>
{% if district %} </div>
{% for item in district %} </div>
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} <h2 class="title">位置及周边</h2>
{% endif %} <div class="row">
</select> <div class="col-md-8">
<select id="basePlateId" name="basePlateId"> <table class="form-table">
<option value = "-1">板块</option> <tbody>
{% if district %} <tr>
{% for item in plate %} <th><label for="from">所属地区</label></th>
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <td>
{% endfor %} <select id="baseCity" name="baseCity">
{% endif %} <option value="-1"> 城市</option>
</select> {% for item in city %}
</td> <option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
<tr> </select>
<th><label for="location">地域坐标</label></th> <select id="baseAreaId" name="baseAreaId">
<td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td> <option value = "-1">区域</option>
</tr> {% if district %}
<tr> {% for item in district %}
<th><label for="mainHouse">主力户型</label></th> <option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<td> {% endfor %}
<div id="preview"> {% endif %}
{% set exists_ids = "" %} </select>
{% for item in mainImage %} <select id="basePlateId" name="basePlateId">
{% if exists_ids != "" %} <option value = "-1">板块</option>
{% set exists_ids = exists_ids~"," %} {% if district %}
{% endif %} {% for item in plate %}
{% set exists_ids = exists_ids~item.id %} <option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<div> {% endfor %}
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"><br /> {% endif %}
<select name="exists[{{item.id}}][buildProperty]"> </select>
{% for i in buildProperty %} </td>
<option {{ i.id == item.buildproperty_id?"selected":"" }} value="{{i.id}}">{{i.value}}</option> </tr>
{% endfor %} <tr>
</select> <th><label for="location">地域坐标</label></th>
<input type="text" placeholder="面积" name="exists[{{item.id}}][housearea]" class="regular-text" value="{{item.area}}"> <td> <input name="location" id="location" type="text" value="{{result.location}}" class="form-control"></td>
<input type="button" value="取消" class="cancel existsCancel"> </tr>
</div> <tr>
{% endfor %} <th><label for="traffic">交通线路</label></th>
<input type="hidden" name="exists_ids" value="{{exists_ids}}" > <td> <input name="traffic" type="text" value="{{result.traffic}}" class="form-control" style="width: 300px;"></td>
<input type="file" name="files[0]" property="0" class = "files"multiple class="browser button button-hero"> </tr>
<P></P> <tr>
</div> <th><label for="periphery">周边配套</label></th>
</td> <td> <input name="periphery" type="text" value="{{result.periphery}}" class="form-control" style="width: 300px;"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h2 class="title">位置及周边</h2> </div>
<table class="form-table"> </div>
<tbody>
<tr> <h2 class="title">基本信息</h2>
<th><label for="address">地址</label></th> <div class="row">
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td> <div class="col-md-8">
</tr> <table class="form-table">
<tr> <tbody>
<th><label for="traffic">交通线路</label></th> <tr>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td> <th><label for="developers">建筑类型</label></th>
</tr> <td>
<tr> <select id="baseRoom" name="baseRoom">
<th><label for="periphery">周边配套</label></th> {% for item in room %}
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" style="width: 300px;"></td> <option {{ item.id == result.room_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
</tbody> </select>
</table> </td>
<h2 class="title">基本信息</h2> </tr>
<table class="form-table"> <tr>
<tbody> <th><label for="developers">开发商</label></th>
<tr> <td> <input name="developers" type="text" value="{{result.developer}}" class="form-control" style="width: 150px;"></td>
<th><label for="developers">建筑类型</label></th> </tr>
<td> <tr>
<select id="baseRoom" name="baseRoom"> <th><label for="check_in_time">入住时间</label></th>
{% for item in room %} <td> <input name="check_in_time" id="checkin" type="text" value="{{result.check_in_time}}" class="form-control" style="width: 150px;"></td>
<option {{ item.id == result.room_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> </tr>
{% endfor %} <tr>
</select> <th><label for="property_age">产权年限</label></th>
</td> <td> <input name="property_age" type="text" value="{{result.property_age}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="developers">开发商</label></th> <th><label for="decoration">装修状况</label></th>
<td> <input name="developers" type="text" value="{{result.developer}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="decoration" type="text" value="{{result.decoration}}" class="form-control"style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="check_in_time">入住时间</label></th> <th><label for="covered_area">建筑面积</label></th>
<td> <input name="check_in_time" id="checkin" type="text" value="{{result.check_in_time}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="property_age">产权年限</label></th> <th><label for="volume_rate">容积率</label></th>
<td> <input name="property_age" type="text" value="{{result.property_age}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="volume_rate" type="text" value="{{result.volume_rate}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="decoration">装修状况</label></th> <th><label for="greening_rate">绿化率</label></th>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code"style="width: 90px;"></td> <td> <input name="greening_rate" type="text" value="{{result.greening_rate}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="covered_area">建筑面积</label></th> <th><label for="households">规划户数</label></th>
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="households" type="text" value="{{result.households}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="volume_rate">容积率</label></th> <th><label for="parking_spaces">车位数</label></th>
<td> <input name="volume_rate" type="text" value="{{result.volume_rate}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="parking_spaces" type="text" value="{{result.parking_spaces}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="greening_rate">绿化率</label></th> <th><label for="property_management">物业公司</label></th>
<td> <input name="greening_rate" type="text" value="{{result.greening_rate}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="property_management" type="text" value="{{result.property_management}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="households">规划户数</label></th> <th><label for="property_money">物业费</label></th>
<td> <input name="households" type="text" value="{{result.households}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="property_money" type="text" value="{{result.property_money}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="parking_spaces">车位数</label></th> <th><label for="overview">楼盘概述</label></th>
<td> <input name="parking_spaces" type="text" value="{{result.parking_spaces}}" class="regular-text code" style="width: 50px;"></td> <td> <textarea name="overview" rows="4" cols="40" class="form-control" style="width: 400px;">{{result.overview}}</textarea></td>
</tr> </tr>
<tr> </tbody>
<th><label for="property_management">物业公司</label></th> </table>
<td> <input name="property_management" type="text" value="{{result.property_management}}" class="regular-text code" style="width: 150px;"></td> </div>
</tr> </div>
<tr>
<th><label for="property_money">物业费</label></th> <h2 class="title">关联信息</h2>
<td> <input name="property_money" type="text" value="{{result.property_money}}" class="regular-text code" style="width: 50px;"></td> <div class="row">
</tr> <div class="col-md-12">
<tr> <table class="form-table">
<th><label for="overview">楼盘概述</label></th> <tbody>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code" style="width: 400px;">{{result.overview}}</textarea></td> <tr>
</tr> <th><label for="mainHouse">主力户型</label></th>
</tbody> <td>
</table> <div id="preview">
<h2 class="title">关联信息</h2> {% set exists_ids = "" %}
<table class="form-table"> {% for item in mainImage %}
<tbody> {% if exists_ids != "" %}
<tr> {% set exists_ids = exists_ids~"," %}
<th><label>房源相册</label></th> {% endif %}
<td> {% set exists_ids = exists_ids~item.id %}
<div id="picList"> <div>
{% set exists_photo_ids = "" %} <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"><br />
{% for item in images %} <select name="exists[{{item.id}}][buildProperty]">
{% if exists_photo_ids != "" %} {% for i in buildProperty %}
{% set exists_photo_ids = exists_photo_ids~"," %} <option {{ i.id == item.buildproperty_id?"selected":"" }} value="{{i.id}}">{{i.value}}</option>
{% endif %} {% endfor %}
{% set exists_photo_ids = exists_photo_ids~item.image_id %} </select>
<p> <input type="text" placeholder="面积" name="exists[{{item.id}}][housearea]" class="form-control" value="{{item.area}}">
<input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} /> <input type="button" value="取消" class="cancel existsCancel">
<select name="exists_photo[{{ item.image_id }}][type]"> </div>
{% for i in photoType %} {% endfor %}
<option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option> <input type="hidden" name="exists_ids" value="{{exists_ids}}" >
{% endfor %} <input type="file" name="files[0]" property="0" class = "files"multiple class="browser button button-hero">
</select> <P></P>
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"> </div>
<input type="button" value="取消" class="cancel existsCancel"> </td>
</p> </tr>
{% endfor %} <tr>
<input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" > <th><label>房源相册</label></th>
</div><br /> <td>
<button type="button" id="housePicture" class="button action" data-toggle="modal"> <div id="picList">
新增 {% set exists_photo_ids = "" %}
</button> {% for item in images %}
</td> {% if exists_photo_ids != "" %}
</tr> {% set exists_photo_ids = exists_photo_ids~"," %}
<tr> {% endif %}
<th><label for="traffic">推荐房源</label></th> {% set exists_photo_ids = exists_photo_ids~item.image_id %}
<td> <p>
<div id="houseImg"> <input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} />
{% for item in recommends %} <select name="exists_photo[{{ item.image_id }}][type]">
<p> {% for i in photoType %}
<img src="{{siteUrl}}{{item.path}}" height="100" width="100"> <option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option>
<input type="button" value="删除" class="imgCancel existsCancel"> {% endfor %}
<input type="hidden" name="data[recommend][]" value="{{item.id}}"> </select>
</p> <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100">
{% endfor %} <input type="button" value="取消" class="cancel existsCancel">
</div><br /> </p>
<button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt"> {% endfor %}
添加房源 <input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" >
</button> </div><br />
</td> <button type="button" id="housePicture" class="button action" data-toggle="modal">
</tr> 新增
<tr> </button>
<th><label for="periphery">置业顾问</label></th> </td>
<td> </tr>
<div id="consultantImg"> <tr>
{% for item in consultant %} <th><label for="traffic">推荐房源</label></th>
<p> <td>
<span>{{item.name}}</span> <div id="houseImg">
<input type="button" value="删除" class="consultantCancel existsCancel"> {% for item in recommends %}
<input type="hidden" name="data[recConsultant][]" value="{{item.id}}"> <p>
</p> <img src="{{siteUrl}}{{item.path}}" height="100" width="100">
{% endfor %} <input type="button" value="删除" class="imgCancel existsCancel">
</div><br /> <input type="hidden" name="data[recommend][]" value="{{item.id}}">
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt"> </p>
选择置业顾问 {% endfor %}
</button> </div><br />
</td> <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt">
</tr> 添加房源
{% if role == 'administrator' %} </button>
<tr> </td>
<th><label for="from">状态</label></th> </tr>
<td> <tr>
<select id="status" name="status"> <th><label for="periphery">置业顾问</label></th>
{% for item in status %} <td>
<option value={{item.id}}>{{item.value}}</option> <div id="consultantImg">
{% endfor %} {% for item in consultant %}
</select> <p>
</td> <span>{{item.name}}</span>
</tr> <input type="button" value="删除" class="consultantCancel existsCancel">
{% endif %} <input type="hidden" name="data[recConsultant][]" value="{{item.id}}">
</tbody> </p>
</table> {% endfor %}
<input type="text" name="type" value="1" hidden="hidden"> </div><br />
{% if houseId %} <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden"> 选择置业顾问
{% endif %} </button>
<input type="submit" id="submit" class="button action"> </td>
</form> </tr>
{% if role == 'administrator' %}
<tr>
<!-- Modal --> <th><label for="from">状态</label></th>
<!-- 新增房源弹出层 --> <td>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <select id="status" name="status">
<div class="modal-dialog" role="document"> {% for item in status %}
<div class="modal-content"> <option value={{item.id}}>{{item.value}}</option>
{% endfor %}
<div class="modal-body" style="height: 300px;overflow: auto;"> </select>
<select id="cityId"> </td>
</select> </tr>
<select id="areaId"> {% endif %}
<option value = "-1">区域</option> </tbody>
</select> </table>
<select id="plateId"> </div>
<option value = "-1">板块</option> </div>
</select>
<select id="price"> <input type="text" name="type" value="1" hidden="hidden">
<option value = "-1">价格</option> {% if houseId %}
</select> <input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
<select id="buildProperty"> {% endif %}
<option value = "-1">房型</option> </div>
{% for item in buildProperty %} <div class = "col-md-1">
<option value="{{ item.id }}">{{ item.value }}</option> <input type="submit" id="submit" class="button action" style="position: fixed;">
{% endfor %} </div>
</select> </div>
<select id="room"> </form>
<option value = "-1">类型</option>
{% for item in room %}
<option value="{{ item.id }}">{{ item.value }}</option> <!-- Modal -->
{% endfor %} <!-- 新增房源弹出层 -->
</select> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<select id="acreage"> <div class="modal-dialog" role="document">
<option value = "-1">面积</option> <div class="modal-content">
</select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <div class="modal-body" style="height: 300px;overflow: auto;">
<button type="button" class="button action" id="search">搜索</button> <select id="cityId">
<ul id="houseList"> </select>
</ul> <select id="areaId">
</div> <option value = "-1">区域</option>
</div> </select>
</div> <select id="plateId">
</div> <option value = "-1">板块</option>
</select>
<!-- 置业顾问弹出层 --> <select id="price">
<div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <option value = "-1">价格</option>
<div class="modal-dialog" role="document"> </select>
<div class="modal-content"> <select id="buildProperty">
<div class="modal-body" style="height: 300px;overflow: auto;"> <option value = "-1">房型</option>
<select id="consultCity"> {% for item in buildProperty %}
</select> <option value="{{ item.id }}">{{ item.value }}</option>
<input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName"> {% endfor %}
<button type="button" class="button action" id="searchConsult">搜索</button> </select>
<ul id="consultantList"> <select id="room">
</ul> <option value = "-1">类型</option>
</div> {% for item in room %}
</div> <option value="{{ item.id }}">{{ item.value }}</option>
</div> {% endfor %}
</div> </select>
<select id="acreage">
<option value = "-1">面积</option>
<script> </select>
(function($){ <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext">
$(document).ready(function(){ <button type="button" class="button action" id="search">搜索</button>
<ul id="houseList">
//主力房源中选择图片file的下标 </ul>
var i = 0; </div>
//入住时间选择 </div>
$("#checkin").datepicker({ </div>
dateFormat: "yy-mm-dd" </div>
});
//主力房源选择文件 <!-- 置业顾问弹出层 -->
$("form").on("change",".files",function(){ <div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
readURL(this,1); <div class="modal-dialog" role="document">
$(this).hide(); <div class="modal-content">
}); <div class="modal-body" style="height: 300px;overflow: auto;">
<select id="consultCity">
//主力房源中图片的删除功能 </select>
$("form").on("click",".cancel",function(){ <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName" class="form-control">
$buttonid = $(this).attr("property"); <button type="button" class="button action" id="searchConsult">搜索</button>
$("[property = "+$buttonid+"]").remove(); <ul id="consultantList">
$("form input[type='file']:last-child").show(); </ul>
</div>
}); </div>
//基本信息的联动AJAX </div>
$("#baseCity").change(function(){ </div>
var cityId = $("#baseCity").val();
var baserArea = $("#baseAreaId");
$('#baseAreaId').find('option:not(:first-child)').remove(); <script>
$('#basePlateId').find('option:not(:first-child)').remove(); (function($){
$(document).ready(function(){
//城市联动区域 var titleFlag = 0;
$.ajax({ //主力房源中选择图片file的下标
type: "GET", var i = 0;
url: "/tospur/wp-admin/admin-ajax.php", //入住时间选择
data: "action=serachCity&cityId="+cityId, $("#checkin").datepicker({
success:function(json){ dateFormat: "yy-mm-dd"
addOption(json,baserArea); });
} //主力房源选择文件
}); $("form").on("change",".files",function(){
}); readURL(this,1);
//区域联动板块 $(this).hide();
$("#baseAreaId").change(function(){ });
var basePlate = $("#basePlateId");
var areaId = $("#baseAreaId").val(); //主力房源中图片的删除功能
var cityId = $("#baseCity").val(); $("form").on("click",".cancel",function(){
$('#basePlateId').find('option:not(:first-child)').remove(); $buttonid = $(this).attr("property");
$.ajax({ $("[property = "+$buttonid+"]").remove();
type: "GET", $("form input[type='file']:last-child").show();
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, });
success:function(json){ //基本信息的联动AJAX
addOption(json,basePlate); $("#baseCity").change(function(){
} var cityId = $("#baseCity").val();
}); var baserArea = $("#baseAreaId");
}); $('#baseAreaId').find('option:not(:first-child)').remove();
$('#basePlateId').find('option:not(:first-child)').remove();
//根据上方选择的城市,选择推荐房源的默认城市
$("#recHouseBt").click(function(){ //城市联动区域
$('#cityId').find('option').remove(); $.ajax({
$('#areaId').find('option:not(:first-child)').remove(); type: "GET",
$('#plateId').find('option:not(:first-child)').remove(); url: "/tospur/wp-admin/admin-ajax.php",
$('#price').find('option:not(:first-child)').remove(); data: "action=serachCity&cityId="+cityId,
$('#acreage').find('option:not(:first-child)').remove(); success:function(json){
$("#houseList").find("li").remove(); addOption(json,baserArea);
var acreage =$("#acreage"); }
var price = $("#price"); });
var cityId = $("#baseCity").val(); });
var cityName = $("#baseCity").find("option:selected").text(); //区域联动板块
var option = $("<option>").attr("value",cityId).append(cityName); $("#baseAreaId").change(function(){
$("#cityId").append(option); var basePlate = $("#basePlateId");
if(cityId != -1){ var areaId = $("#baseAreaId").val();
var area = $("#areaId"); var cityId = $("#baseCity").val();
$.ajax({ $('#basePlateId').find('option:not(:first-child)').remove();
type: "GET", $.ajax({
url: "/tospur/wp-admin/admin-ajax.php", type: "GET",
data: "action=serachCity&cityId="+cityId, url: "/tospur/wp-admin/admin-ajax.php",
success:function(json){ data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
addOption(json,area); success:function(json){
} addOption(json,basePlate);
}); }
});
//城市联动房子面积 });
$.ajax({
type: "GET", //根据上方选择的城市,选择推荐房源的默认城市
url: "/tospur/wp-admin/admin-ajax.php", $("#recHouseBt").click(function(){
data: "action=searchArea&cityId="+cityId, $('#cityId').find('option').remove();
success:function(json){ $('#areaId').find('option:not(:first-child)').remove();
addOption(json,acreage); $('#plateId').find('option:not(:first-child)').remove();
} $('#price').find('option:not(:first-child)').remove();
}); $('#acreage').find('option:not(:first-child)').remove();
//城市联动房子价格 $("#houseList").find("li").remove();
$.ajax({ var acreage =$("#acreage");
type: "GET", var price = $("#price");
url: "/tospur/wp-admin/admin-ajax.php", var cityId = $("#baseCity").val();
data: "action=searchUnitPriceRange&cityId="+cityId, var cityName = $("#baseCity").find("option:selected").text();
success:function(json){ var option = $("<option>").attr("value",cityId).append(cityName);
addOption(json,price); $("#cityId").append(option);
} if(cityId != -1){
}); var area = $("#areaId");
addList(0); $.ajax({
} type: "GET",
}); url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId,
//区域联动板块 success:function(json){
$("#areaId").change(function(){ addOption(json,area);
var areaId = $("#areaId").val(); }
var cityId = $("#cityId").val(); });
var plate = $("#plateId");
$("#houseList").find("li").remove(); //城市联动房子面积
$('#plateId').find('option:not(:first-child)').remove(); $.ajax({
$.ajax({ type: "GET",
type: "GET", url: "/tospur/wp-admin/admin-ajax.php",
url: "/tospur/wp-admin/admin-ajax.php", data: "action=searchArea&cityId="+cityId,
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, success:function(json){
success:function(json){ addOption(json,acreage);
addOption(json,plate); }
} });
}); //城市联动房子价格
}); $.ajax({
type: "GET",
//推荐房源下显示图片信息以及房名 url: "/tospur/wp-admin/admin-ajax.php",
$("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){ data: "action=searchUnitPriceRange&cityId="+cityId,
addList(0); success:function(json){
}); addOption(json,price);
}
//添加房源中搜索框的搜索 });
$("#search").click(function(){ addList(0);
$searchtext = $("#searchtext").val(); }
$("#houseList").find("li").remove(); });
$.ajax({
type: "post", //区域联动板块
url: "/tospur/wp-admin/admin-ajax.php", $("#areaId").change(function(){
data: "action=searchHouse&searchText="+$searchtext, var areaId = $("#areaId").val();
success:function(json){ var cityId = $("#cityId").val();
var result = json.result; var plate = $("#plateId");
for(var i = 0; i < result.length; i++){ $("#houseList").find("li").remove();
var name = result[i]["name"]; $('#plateId').find('option:not(:first-child)').remove();
var id = result[i]['id']; $.ajax({
var imgUrl = json.images[id]; type: "GET",
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); url: "/tospur/wp-admin/admin-ajax.php",
var li = $("<li>").addClass("addImg").append(img).append(name); data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
$("#houseList").append(li); success:function(json){
} addOption(json,plate);
} }
}); });
}) });
//根据上方选择的城市,选择推荐置业顾问的默认城市 //推荐房源下显示图片信息以及房名
$("#recConsultantBt").click(function(){ $("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){
$('#consultCity').find('option').remove(); addList(0);
$("#consultantList").find("li").remove(); });
var consulCityId = $("#baseCity").val();
var consultantName =$("#consultantName").val(); //添加房源中搜索框的搜索
var cityName = $("#baseCity").find("option:selected").text(); $("#search").click(function(){
var option = $("<option>").attr("value",consulCityId).append(cityName); $searchtext = $("#searchtext").val();
$("#consultCity").append(option); $("#houseList").find("li").remove();
$.ajax({ $.ajax({
type: "GET", type: "post",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, data: "action=searchHouse&searchText="+$searchtext,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ var result = json.result;
var name = json[i]["consultantName"]; for(var i = 0; i < result.length; i++){
var imgUrl = json[i]["imageUrl"]; var name = result[i]["name"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var id = result[i]['id'];
var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg"); var imgUrl = json.images[id];
$("#consultantList").append(li); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
} var li = $("<li>").addClass("addImg").append(img).append(name);
} $("#houseList").append(li);
}); }
}); }
});
//添加置业顾问弹出层中搜索框的搜索内容 })
$("#searchConsult").click(function(){
var consulCityId = $("#consultCity").val(); //根据上方选择的城市,选择推荐置业顾问的默认城市
var consultantName =$("#consultantName").val(); $("#recConsultantBt").click(function(){
$("#consultantList").find("li").remove(); $('#consultCity').find('option').remove();
$.ajax({ $("#consultantList").find("li").remove();
type: "GET", var consulCityId = $("#baseCity").val();
url: "/tospur/wp-admin/admin-ajax.php", var consultantName =$("#consultantName").val();
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, var cityName = $("#baseCity").find("option:selected").text();
success:function(json){ var option = $("<option>").attr("value",consulCityId).append(cityName);
for( $("#consultCity").append(option);
var i = 0; i <=json.length-1; i++){ $.ajax({
var name = json[i]["consultantName"]; type: "GET",
var imgUrl = json[i]["imageUrl"]; url: "/tospur/wp-admin/admin-ajax.php",
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var li = $("<li>").append(img).append(name).addClass("consultantImg"); success:function(json){
$("#consultantList").append(li); for(var i = 0; i <=json.length-1; i++){
} var name = json[i]["consultantName"];
} var imgUrl = json[i]["imageUrl"];
}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
}) var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li);
//点击添加房源中显示的列表,在界面中显示 }
$("#houseList").on("click",".addImg",function(){ }
var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")}); });
var url = $(this).find("img").attr("src"); });
var img = $("<img>").attr({"src":url,"height":100,"width":100});
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel"); //添加置业顾问弹出层中搜索框的搜索内容
var p = $("<p>").append(img).append(cancel).append(recommendHouse); $("#searchConsult").click(function(){
$("#houseImg").append(p); var consulCityId = $("#consultCity").val();
controlCommand(); var consultantName =$("#consultantName").val();
}); $("#consultantList").find("li").remove();
//添加置业顾问 $.ajax({
$("#consultantList").on("click",".consultantImg",function(){ type: "GET",
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")}); url: "/tospur/wp-admin/admin-ajax.php",
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel"); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var font = $("<font>").append( $(this).text()); success:function(json){
var p = $("<p>").append(font).append(cancel).append(recommendConsultant); for(var i = 0; i <=json.length-1; i++){
$("#consultantImg").append(p); var name = json[i]["consultantName"];
}); var imgUrl = json[i]["imageUrl"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
//新增房源相册 var li = $("<li>").append(img).append(name).addClass("consultantImg");
$("#housePicture").click(function(){ $("#consultantList").append(li);
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); }
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); }
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles"); });
var select = $("<select>").attr("name","data["+i+"][type]"); })
{% for item in photoType %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); //点击添加房源中显示的列表,在界面中显示
{% endfor%} $("#houseList").on("click",".addImg",function(){
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")});
$("#picList").append(p); var url = $(this).find("img").attr("src");
i++ var img = $("<img>").attr({"src":url,"height":100,"width":100});
}); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action imgCancel");
var p = $("<p>").append(img).append(cancel).append(recommendHouse);
//房源相册 $("#houseImg").append(p);
$("#picList").on("change",".picFiles",function(){ controlCommand();
readURL(this,2); });
$(this).hide(); //添加置业顾问
}); $("#consultantList").on("click",".consultantImg",function(){
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")});
//删除房源相册、推荐房源、推荐置业顾问 var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action consultantCancel");
$("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){ var font = $("<font>").append( $(this).text());
$(this).parent("p").remove(); var p = $("<p>").append(font).append(cancel).append(recommendConsultant);
}); $("#consultantImg").append(p);
$("#preview,#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){ });
$(this).parent().remove();
}); //新增房源相册
$("#housePicture").click(function(){
$("#submit").click(function(){ var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
if($("#housename").val()==""){ var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
alert("请输入楼盘名"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
return false; var select = $("<select>").attr("name","data["+i+"][type]");
} var checkTd = $("<th>").append(checkBox);
}); var picDeletTd = $("<td>").append(picDelet);
var selectTd = $("<th>").append(select);
//file上传之前,显示图片的方法 var fileTd = $("<th>").append(file);
function readURL(input,type) { {% for item in photoType %}
if(type == 1){ select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
if (input.files && input.files[0]){ {% endfor%}
var reader = new FileReader(); var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
reader.onload = function (e) { var fontA = $("<font>").append("设为封面");
var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100}); var fontB = $("<font>").append("类型");
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel"); var fontC = $("<font>").append("相册");
var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":4,"property":+i}); var tdA = $("<th>").append(fontA);
var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files"); var tdB = $("<th>").append(fontB);
var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"}); var tdC = $("<th>").append(fontC);
{% for item in buildProperty %}{{item.id}} var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); $("#picList").append(p);
{% endfor%} if( titleFlag== 0){
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text"); $("#picList").before(titleP);
var div = $("<div>").append(select).append(areatext).append(button).append(type); titleFlag = 1
var span = $("<span>").attr({"property":+i}).append(img).append(div); }
$("form").find("#preview > p").before(file); i++
$("#preview > p").append(span); });
i++;
} //房源相册
} $("#picList").on("change",".picFiles",function(){
}else{ readURL(this,2);
if (input.files && input.files[0]){ $(this).hide();
var reader = new FileReader(); });
reader.onload = function (e){
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100}); //删除房源相册、推荐房源、推荐置业顾问
$(input).before(img); $("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){
} $(this).parents("p").remove();
} });
} $("#preview,#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){
reader.readAsDataURL(input.files[0]); $(this).parent().remove();
} });
function addOption(json,select){
var selectId = select.attr("id"); $('#newHouse').validate({
for(var i = 0; i <=json.length-1; i++){ onkeyup: false,
var id = json[i]["id"]; onfocusout: false,
var value = json[i]["value"]; rules: {
if(selectId == "acreage" || selectId == "price"){ housename:'required',
id = value; mark:'required',
} community_name:'required',
var Option = $("<option>").attr({"value": id}).append(value); address:'required',
select.append(Option); average_price:'required',
} latest_news:'required'
} },
messages: {
function controlCommand(){ housename:'请输入楼盘名称',
var num = $("#houseImg > p").length; mark:'请输入标签',
if(num>3){ community_name:'请输入小区名称',
alert("最多只能推荐3个房源"); address:'请输入地址',
$("#houseImg").find("p:last-child").remove(); average_price:'请输入均价',
} latest_news:'请输入最新动态'
} },
errorLabelContainer: "#notice",
errorElement: 'span',
submitHandler: function (form) {
function getUrlParmas(){ form.submit();
var href = location.search.substr(1,location.search.length-1); }
var params = href.split("&"); });
var map = {};
for(item in params){ //file上传之前,显示图片的方法
var key = params[item].split("=")[0] || ""; function readURL(input,type) {
var value = params[item].split("=")[1] || ""; if(type == 1){
map[key] = value; if (input.files && input.files[0]){
} var reader = new FileReader();
return map; reader.onload = function (e) {
} var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100});
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("button action cancel");
function addList($houseType){ var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":4,"property":+i});
$("#houseList").find("li").remove(); var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
var cityId = $("#baseCity").val(); var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
var buildPropertyId = $("#buildProperty").val(); {% for item in buildProperty %}{{item.id}}
var room = $("#room").val(); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
var areaId = $("#areaId").val(); {% endfor%}
var cityId = $("#cityId").val(); var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("form-control");
var plateId = $("#plateId").val(); var div = $("<div>").append(select).append(areatext).append(button).append(type);
var acreage = $("#acreage").val(); var span = $("<span>").attr({"property":+i}).append(img).append(div);
var price = $("#price").val(); $("form").find("#preview > p").before(file);
$.ajax({ $("#preview > p").append(span);
type: "post", i++;
url: "/tospur/wp-admin/admin-ajax.php", }
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType, }
success:function(json){ }else{
var result = json.result; if (input.files && input.files[0]){
var urlParams = getUrlParmas(); var reader = new FileReader();
for(var i = 0; i <result.length; i++){ reader.onload = function (e){
var name = result[i]["name"]; var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
var id = result[i]['id']; $(input).before(img);
var imgUrl = result[i]['path']; }
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); }
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name); }
if(urlParams["id"]){ reader.readAsDataURL(input.files[0]);
if(urlParams["id"]!=id){ }
$("#houseList").append(li); function addOption(json,select){
} var selectId = select.attr("id");
}else{ for(var i = 0; i <=json.length-1; i++){
$("#houseList").append(li); var id = json[i]["id"];
} var value = json[i]["value"];
} if(selectId == "acreage" || selectId == "price"){
} id = value;
}); }
} var Option = $("<option>").attr({"value": id}).append(value);
}); select.append(Option);
})(jQuery); }
}
</script>
function controlCommand(){
</body> var num = $("#houseImg > p").length;
if(num>3){
alert("最多只能推荐3个房源");
$("#houseImg").find("p:last-child").remove();
}
}
function getUrlParmas(){
var href = location.search.substr(1,location.search.length-1);
var params = href.split("&");
var map = {};
for(item in params){
var key = params[item].split("=")[0] || "";
var value = params[item].split("=")[1] || "";
map[key] = value;
}
return map;
}
function addList($houseType){
$("#houseList").find("li").remove();
var cityId = $("#baseCity").val();
var buildPropertyId = $("#buildProperty").val();
var room = $("#room").val();
var areaId = $("#areaId").val();
var cityId = $("#cityId").val();
var plateId = $("#plateId").val();
var acreage = $("#acreage").val();
var price = $("#price").val();
$.ajax({
type: "post",
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType,
success:function(json){
var result = json.result;
var urlParams = getUrlParmas();
for(var i = 0; i <result.length; i++){
var name = result[i]["name"];
var id = result[i]['id'];
var imgUrl = result[i]['path'];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name);
if(urlParams["id"]){
if(urlParams["id"]!=id){
$("#houseList").append(li);
}
}else{
$("#houseList").append(li);
}
}
}
});
}
});
})(jQuery);
</script>
</body>
</html> </html>
\ No newline at end of file
...@@ -285,7 +285,7 @@ ...@@ -285,7 +285,7 @@
<script> <script>
(function($){ (function($){
$(document).ready(function(){ $(document).ready(function(){
var titleFlag = 0;
//主力房源中选择图片file的下标 //主力房源中选择图片file的下标
var i = 0; var i = 0;
//基本信息的联动AJAX //基本信息的联动AJAX
...@@ -482,14 +482,29 @@ ...@@ -482,14 +482,29 @@
//新增房源相册 //新增房源相册
$("#housePicture").click(function(){ $("#housePicture").click(function(){
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
var select = $("<select>").attr("name","data["+i+"][type]"); var select = $("<select>").attr("name","data["+i+"][type]");
var checkTd = $("<th>").append(checkBox);
var picDeletTd = $("<td>").append(picDelet);
var selectTd = $("<th>").append(select);
var fileTd = $("<th>").append(file);
{% for item in photoType %} {% for item in photoType %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%} {% endfor%}
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
var fontA = $("<font>").append("设为封面");
var fontB = $("<font>").append("类型");
var fontC = $("<font>").append("相册");
var tdA = $("<th>").append(fontA);
var tdB = $("<th>").append(fontB);
var tdC = $("<th>").append(fontC);
var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
$("#picList").append(p); $("#picList").append(p);
if( titleFlag== 0){
$("#picList").before(titleP);
titleFlag = 1
}
i++ i++
}); });
......
...@@ -9,239 +9,263 @@ ...@@ -9,239 +9,263 @@
<body> <body>
<h2 class="title">{{title}}</h2> <h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data"> <form action="" method="POST" enctype="multipart/form-data">
<table class="form-table"> <div class="row">
<tbody> <div class="col-md-11">
<tr> <div class="row">
<th><label for="housename">房源名:</label></th> <div class="col-md-8">
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td> <table class="form-table">
</tr> <tbody>
<tr> <tr>
<th><label for="address">小区名称</label></th> <th><label for="housename">房源名:</label></th>
<td> <input name="community_name" type="text" value="{{result.community_name}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="mark">标签:</label></th> <th><label for="address">小区名称</label></th>
<td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td> <td> <input name="community_name" type="text" value="{{result.community_name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
{% if not houseId %} <tr>
<tr> <th><label for="mark">标签:</label></th>
<th><label for="owner_name">业主姓名</label></th> <td> <input name="mark" id="mark" type="text" value="{{mark}}" class="form-control"></td>
<td> <input name="owner_name" id="owner_name" type="text" value="" class="regular-text code" style="width: 150px;"></td> </tr>
</tr> {% if not houseId %}
<tr> <tr>
<th><label for="owner_phone">业主电话</label></th> <th><label for="owner_name">业主姓名</label></th>
<td> <input name="owner_phone" id="owner_phone" type="text" value="" class="regular-text code" style="width: 150px;"></td> <td> <input name="owner_name" id="owner_name" type="text" value="" class="form-control" style="width: 150px;"></td>
</tr> </tr>
{% endif %} <tr>
<tr> <th><label for="owner_phone">业主电话</label></th>
<th><label for="total_price">售价</label></th> <td> <input name="owner_phone" id="owner_phone" type="text" value="" class="form-control" style="width: 150px;"></td>
<td> <input name="total_price" id="total_price" type="text" value="{{result.total_price}}" class="regular-text code" style="width: 90px;"></td> </tr>
</tr> {% endif %}
<tr> <tr>
<th><label for="average_price">单价</label></th> <th><label for="total_price">售价</label></th>
<td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="total_price" id="total_price" type="text" value="{{result.total_price}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
</tbody> <tr>
</table> <th><label for="average_price">单价</label></th>
<h2 class="title">基本信息</h2> <td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control" style="width: 90px;"></td>
<table class="form-table"> </tr>
<tbody> </tbody>
<tr> </table>
<th><label for="from">户型</label></th> </div>
<td> </div>
<select id="buildproperty_id" name="buildproperty_id"> <h2 class="title">基本信息</h2>
{% for item in buildProperty %} <div class="row">
<option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <div class="col-md-8">
{% endfor %} <table class="form-table">
</select> <tbody>
</td> <tr>
</tr> <th><label for="from">户型</label></th>
<tr> <td>
<th><label for="covered_area">面积</label></th> <select id="buildproperty_id" name="buildproperty_id">
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td> {% for item in buildProperty %}
</tr> <option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<tr> {% endfor %}
<th><label for="floor">楼层:</label></th> </select>
<td> <input name="floor" type="text" value="{{result.floor}}" class="regular-text code" style=" width: 70px;"></td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="faceto">朝向:</label></th> <th><label for="covered_area">面积</label></th>
<td> <input name="faceto" type="text" value="{{result.faceto}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="decoration">装修状况</label></th> <th><label for="floor">楼层:</label></th>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="floor" type="text" value="{{result.floor}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="age">建筑年代</label></th> <th><label for="faceto">朝向:</label></th>
<td> <input name="age" type="text" value="{{result.age}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="faceto" type="text" value="{{result.faceto}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="flat">楼号</label></th> <th><label for="decoration">装修状况</label></th>
<td> <input name="flat" type="text" value="{{result.flat}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="decoration" type="text" value="{{result.decoration}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="suite"></label></th> <th><label for="age">建筑年代</label></th>
<td> <input name="suite" type="text" value="{{result.suite}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="age" type="text" value="{{result.age}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="overview">房源点评</label></th> <th><label for="flat">楼号</label></th>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code" style=" width: 400px;">{{result.overview}} <td> <input name="flat" type="text" value="{{result.flat}}" class="form-control" style=" width: 50px;"></td>
</textarea></td> </tr>
</tr> <tr>
<tr> <th><label for="suite"></label></th>
<th><label for="from">所属地区</label></th> <td> <input name="suite" type="text" value="{{result.suite}}" class="form-control" style=" width: 50px;"></td>
<td> </tr>
<select id="baseCity" name="baseCity"> <tr>
<option value="-1"> 城市</option> <th><label for="overview">房源点评</label></th>
{% for item in city %} <td> <textarea name="overview" rows="4" cols="40" class="form-control" style=" width: 400px;">{{result.overview}}</textarea></td>
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> </tr>
{% endfor %}
</select> </tbody>
<select id="baseAreaId" name="baseAreaId"> </table>
<option value = "-1">区域</option> </div>
{% if district %} </div>
{% for item in district %}
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <h2 class="title">位置及周边</h2>
{% endfor %} <div class="row">
{% endif %} <div class="col-md-8">
</select> <table class="form-table">
<select id="basePlateId" name="basePlateId"> <tbody>
<option value = "-1">板块</option> <tr>
{% if district %} <th><label for="from">所属地区</label></th>
{% for item in plate %} <td>
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <select id="baseCity" name="baseCity">
{% endfor %} <option value="-1"> 城市</option>
{% endif %} {% for item in city %}
</select> <option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</td> {% endfor %}
</tr> </select>
<select id="baseAreaId" name="baseAreaId">
<tr> <option value = "-1">区域</option>
<th><label for="location">地域坐标</label></th> {% if district %}
<td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td> {% for item in district %}
</tr> <option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tbody> {% endfor %}
</table> {% endif %}
<h2 class="title">位置及周边</h2> </select>
<table class="form-table"> <select id="basePlateId" name="basePlateId">
<tbody> <option value = "-1">板块</option>
<tr> {% if district %}
<th><label for="address">地址</label></th> {% for item in plate %}
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td> <option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
<tr> {% endif %}
<th><label for="traffic">交通线路</label></th> </select>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td> </td>
</tr> </tr>
<tr>
<th><label for="periphery">周边配套</label></th> <tr>
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" style="width: 300px;"></td> <th><label for="location">地域坐标</label></th>
</tr> <td> <input name="location" id="location" type="text" value="{{result.location}}" class="form-control"></td>
</tbody> </tr>
</table> <tr>
<th><label for="address">地址</label></th>
<h2 class="title">关联信息</h2> <td> <input name="address" type="text" value="{{result.address}}" class="form-control"></td>
<table class="form-table"> </tr>
<tbody> <tr>
<tr> <th><label for="traffic">交通线路</label></th>
<th><label>房源相册</label></th> <td> <input name="traffic" type="text" value="{{result.traffic}}" class="form-control" style="width: 300px;"></td>
<td> </tr>
<div id="picList"> <tr>
{% set exists_photo_ids = "" %} <th><label for="periphery">周边配套</label></th>
{% for item in images %} <td> <input name="periphery" type="text" value="{{result.periphery}}" class="form-control" style="width: 300px;"></td>
{% if exists_photo_ids != "" %} </tr>
{% set exists_photo_ids = exists_photo_ids~"," %} </tbody>
{% endif %} </table>
{% set exists_photo_ids = exists_photo_ids~item.image_id %} </div>
<p> </div>
<input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} /> <h2 class="title">关联信息</h2>
<select name="exists_photo[{{ item.image_id }}][type]"> <div class="row">
{% for i in photoType %} <div class="col-md-12">
<option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option> <table class="form-table">
{% endfor %} <tbody>
</select> <tr>
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"> <th><label>房源相册</label></th>
<input type="button" value="取消" class="cancel existsCancel"> <td>
</p> <div id="picList">
{% endfor %} {% set exists_photo_ids = "" %}
<input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" > {% for item in images %}
</div><br /> {% if exists_photo_ids != "" %}
<button type="button" id="housePicture" class="button action" data-toggle="modal"> {% set exists_photo_ids = exists_photo_ids~"," %}
新增 {% endif %}
</button> {% set exists_photo_ids = exists_photo_ids~item.image_id %}
</td> <p>
</tr> <input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} />
<tr> <select name="exists_photo[{{ item.image_id }}][type]">
<th><label for="traffic">推荐房源</label></th> {% for i in photoType %}
<td> <option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option>
<div id="houseImg"> {% endfor %}
{% for item in recommends %} </select>
<p> <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100">
<img src="{{siteUrl}}{{item.path}}" height="100" width="100"> <input type="button" value="取消" class="cancel existsCancel">
<input type="button" value="删除" class="imgCancel existsCancel"> </p>
<input type="hidden" name="data[recommend][]" value="{{item.id}}"> {% endfor %}
</p> <input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" >
{% endfor %} </div><br />
</div><br /> <button type="button" id="housePicture" class="button action" data-toggle="modal">
<button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt"> 新增
添加房源 </button>
</button> </td>
</td> </tr>
</tr> <tr>
<tr> <th><label for="traffic">推荐房源</label></th>
<th><label for="feature">房源特色</label></th> <td>
<td> <div id="houseImg">
<div id="feature"> {% for item in recommends %}
{% for item in featureOld %} <p>
<p> <img src="{{siteUrl}}{{item.path}}" height="100" width="100">
<span>{{ item.name }}</span> <input type="button" value="删除" class="imgCancel existsCancel">
<input type="button" value="删除" class="featureCancel existsCancel"> <input type="hidden" name="data[recommend][]" value="{{item.id}}">
<input type="hidden" name="data[houseFeature][]" value="{{item.tag_id}}"> </p>
</p> {% endfor %}
{% endfor %} </div><br />
</div><br/> <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt">
<button type="button" class="button action" data-toggle="modal" data-target="#houseFeature" id="featureBt"> 添加房源
添加特色 </button>
</button> </td>
</td> </tr>
</tr> <tr>
<tr> <th><label for="feature">房源特色</label></th>
<th><label for="consultant">置业顾问</label></th> <td>
<td> <div id="feature">
<div id="consultantImg"> {% for item in featureOld %}
{% for item in consultant %} <p>
<p> <span>{{ item.name }}</span>
<span>{{item.name}}</span> <input type="button" value="删除" class="featureCancel existsCancel">
<input type="button" value="删除" class="consultantCancel existsCancel"> <input type="hidden" name="data[houseFeature][]" value="{{item.tag_id}}">
<input type="hidden" name="data[recConsultant][]" value="{{item.id}}"> </p>
</p> {% endfor %}
{% endfor %} </div><br/>
</div><br /> <button type="button" class="button action" data-toggle="modal" data-target="#houseFeature" id="featureBt">
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt"> 添加特色
选择置业顾问 </button>
</button> </td>
</td> </tr>
</tr> <tr>
{% if role == 'administrator' %} <th><label for="consultant">置业顾问</label></th>
<tr> <td>
<th><label for="from">状态</label></th> <div id="consultantImg">
<td> {% for item in consultant %}
<select id="status" name="status"> <p>
{% for item in status %} <span>{{item.name}}</span>
<option value={{item.id}}>{{item.value}}</option> <input type="button" value="删除" class="consultantCancel existsCancel">
{% endfor %} <input type="hidden" name="data[recConsultant][]" value="{{item.id}}">
</select> </p>
</td> {% endfor %}
</tr> </div><br />
{% endif %} <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
</tbody> 选择置业顾问
</table> </button>
<input type="text" name="type" value="2" hidden="hidden"> </td>
{% if houseId %} </tr>
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden"> {% if role == 'administrator' %}
{% endif %} <tr>
<input type="submit" id="submit" class="button action"> <th><label for="from">状态</label></th>
<td>
<select id="status" name="status">
{% for item in status %}
<option value={{item.id}}>{{item.value}}</option>
{% endfor %}
</select>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
<input type="text" name="type" value="2" hidden="hidden">
{% if houseId %}
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
{% endif %}
</div>
<div class="col-md-1">
<input type="submit" id="submit" class="button action">
</div>
</div>
</form> </form>
<!-- Modal --> <!-- Modal -->
...@@ -281,7 +305,7 @@ ...@@ -281,7 +305,7 @@
<select id="acreage"> <select id="acreage">
<option value = "-1">面积</option> <option value = "-1">面积</option>
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext" class="form-control">
<button type="button" class="button action" id="search">搜索</button> <button type="button" class="button action" id="search">搜索</button>
<ul id="houseList"> <ul id="houseList">
</ul> </ul>
...@@ -301,7 +325,7 @@ ...@@ -301,7 +325,7 @@
<option value="{{ item.id }}">{{ item.value }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName"> <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName" class="form-control">
<button type="button" class="button action" id="searchConsult">搜索</button> <button type="button" class="button action" id="searchConsult">搜索</button>
<ul id="consultantList"> <ul id="consultantList">
</ul> </ul>
...@@ -332,6 +356,7 @@ ...@@ -332,6 +356,7 @@
<script> <script>
(function($){ (function($){
$(document).ready(function(){ $(document).ready(function(){
var titleFlag = 0;
//主力房源中选择图片file的下标 //主力房源中选择图片file的下标
var i = 0; var i = 0;
//基本信息的联动AJAX //基本信息的联动AJAX
...@@ -526,14 +551,29 @@ ...@@ -526,14 +551,29 @@
//新增房源相册 //新增房源相册
$("#housePicture").click(function(){ $("#housePicture").click(function(){
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
var select = $("<select>").attr("name","data["+i+"][type]"); var select = $("<select>").attr("name","data["+i+"][type]");
var checkTd = $("<th>").append(checkBox);
var picDeletTd = $("<td>").append(picDelet);
var selectTd = $("<th>").append(select);
var fileTd = $("<th>").append(file);
{% for item in photoType %} {% for item in photoType %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%} {% endfor%}
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
var fontA = $("<font>").append("设为封面");
var fontB = $("<font>").append("类型");
var fontC = $("<font>").append("相册");
var tdA = $("<th>").append(fontA);
var tdB = $("<th>").append(fontB);
var tdC = $("<th>").append(fontC);
var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
$("#picList").append(p); $("#picList").append(p);
if( titleFlag== 0){
$("#picList").before(titleP);
titleFlag = 1
}
i++ i++
}); });
//显示选中的特色 //显示选中的特色
...@@ -582,7 +622,7 @@ ...@@ -582,7 +622,7 @@
{% for item in buildProperty %}{{item.id}} {% for item in buildProperty %}{{item.id}}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%} {% endfor%}
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text"); var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("form-control");
var div = $("<div>").append(select).append(areatext).append(button).append(type); var div = $("<div>").append(select).append(areatext).append(button).append(type);
var span = $("<span>").attr({"property":+i}).append(img).append(div); var span = $("<span>").attr({"property":+i}).append(img).append(div);
$("form").find("#preview > p").before(file); $("form").find("#preview > p").before(file);
......
...@@ -13,7 +13,7 @@ add_action('init', 'tospur_init'); ...@@ -13,7 +13,7 @@ add_action('init', 'tospur_init');
function tospur_init() function tospur_init()
{ {
require_once(PLUGIN_DIR . 'Config.php'); require_once(PLUGIN_DIR . 'Config.php');
require_once(PLUGIN_DIR . 'Tools/TCSync.php'); require_once(PLUGIN_DIR . 'Tools/TCSync.php');
require_once(PLUGIN_DIR . 'Tools/Image.php'); require_once(PLUGIN_DIR . 'Tools/Image.php');
require_once(PLUGIN_DIR . 'Dao/SearchDao.php'); require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Admin/House.php'); require_once(PLUGIN_DIR . 'Admin/House.php');
......
...@@ -15,5 +15,4 @@ if ($user_id != 0) { ...@@ -15,5 +15,4 @@ if ($user_id != 0) {
exit; exit;
} }
?> ?>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=360, user-scalable=0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<title>评分</title>
<link rel="stylesheet" href="{{ theme }}/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ theme }}/css/star-rating.min.css">
<script src="{{ theme }}/js/jquery.min.js"></script>
<script src="{{ theme }}/js/star-rating.min.js"></script>
<script>
$(document).ready(function () {
var score = 0;
$('#score').rating({
min: 0,
max: 5,
step: 0.5,
size: 'xs',
showClear: false,
showCaption: false,
hoverEnabled: false,
starCaptions: function (data) {
score = data;
$(this).val(score);
}
});
var scoreForm = $('#scoreForm');
scoreForm.submit(function () {
if (score > 0) {
$.ajax({
type: 'POST',
url: '{{ url }}/wp-admin/admin-ajax.php/',
data: 'action=add_score&' + scoreForm.serialize(),
success: function (data) {
if (data.code == 2000) {
alert('评分成功');
}else{
alert('不能重复评分');
}
}
});
} else {
alert('请选择评分');
}
return false;
});
});
</script>
</head>
<body>
<form id="scoreForm" method="post">
<br>
<label for="score">评分</label>
<input type="hidden" id="score" name="score" value="0">
<input type="hidden" name="user_id" value="{{ user_id }}">
<input type="hidden" name="consultant_id" value="{{ consultant_id }}">
<br>
<p class="submit">
<input type="submit" id="score_submit" value="提交">
</p>
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment