⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registercomponent.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
字号:
// This component creates a registration form and goes to a web service to// do the actual registration// requires RegistrationServicefunction RegisterComponent(oStringBundle, oRegService) {	// call super()	BiComponent.call(this);	this.stringBundle = oStringBundle;	this.regService = oRegService;	// Create the components/objects	this.messageLabel = new BiLabel;	this.fullNameLabel = new BiLabel;	this.fullNameField = new BiTextField;	this.emailLabel = new BiLabel;	this.emailField = new BiTextField;	this.passwordLabel = new BiLabel;	this.passwordField = new BiPasswordField;	this.password2Label = new BiLabel;	this.password2Field = new BiPasswordField;	this.companyLabel = new BiLabel;	this.companyField = new BiTextField;	this.homePageLabel = new BiLabel;	this.homePageField = new BiTextField;	this.emailUpdatesCheckBox = new BiCheckBox( "", true );	this.requiredGroup = new BiGroupBox;	this.optionalGroup = new BiGroupBox;	this.licenseLabel = new BiLabel;	this.errorLabel = new BiLabel;	this.registerButton = new BiButton;	this.cancelButton = new BiButton;	this.registerProgress = new BiUndeterminedProgressBar;	this.updateStrings();	// set some of the properties for these components	this.messageLabel.setWrap(true);	// this assosciates the label with the field	this.fullNameLabel.setLabelFor(this.fullNameField);	this.emailLabel.setLabelFor(this.emailField);	this.passwordLabel.setLabelFor(this.passwordField);	this.password2Label.setLabelFor(this.password2Field);	this.companyLabel.setLabelFor(this.companyField);	this.homePageLabel.setLabelFor(this.homePageField);	this.errorLabel.setWrap(true);	this.errorLabel.setBorder( new BiBorder(1, "solid", "ThreeDDarkShadow") );	this.errorLabel.setBackColor("Window");	this.errorLabel.setForeColor("WindowText");	this.errorLabel.setPadding(5);	this.errorLabel.setIcon( new BiImage( application.getPath() + "images/exclamation.16.png", 16, 16 ) );	// set the fixed size and position values	// the dynamic position is done in layoutAllChildre*	this.requiredGroup.setLeft(5);	this.requiredGroup.setRight(5);	this.optionalGroup.setLeft(5);	this.optionalGroup.setRight(5);	this.licenseLabel.setLeft(5);	this.licenseLabel.setRight(5);	this.messageLabel.setLeft(10);	this.messageLabel.setRight(10);	this.fullNameLabel.setLeft(10);	this.fullNameLabel.setWidth(105);	this.emailLabel.setLeft(10);	this.emailLabel.setWidth(105);	this.passwordLabel.setLeft(10);	this.passwordLabel.setWidth(105);	this.password2Label.setLeft(10);	this.password2Label.setWidth(105);	this.companyLabel.setLeft(10);	this.companyLabel.setWidth(105);	this.homePageLabel.setLeft(10);	this.homePageLabel.setWidth(105);	this.emailUpdatesCheckBox.setLeft( 10 );	this.emailUpdatesCheckBox.setRight( 10 );	this.fullNameField.setLeft(115);	this.emailField.setLeft(115);	this.passwordField.setLeft(115);	this.password2Field.setLeft(115);	this.companyField.setLeft(115);	this.homePageField.setLeft(115);	this.fullNameField.setRight(10);	this.emailField.setRight(10);	this.passwordField.setRight(10);	this.password2Field.setRight(10);	this.companyField.setRight(10);	this.homePageField.setRight(10);	this.registerProgress.setLeft(10);	this.registerProgress.setRight(10);	this.registerProgress.setVisible(false);	this.errorLabel.setLeft(10);	this.errorLabel.setRight(10);	this.errorLabel.setVisible(false);	this.registerButton.setBottom(10);	this.registerButton.setWidth(80);	this.registerButton.setRight(100);	this.cancelButton.setBottom(10);	this.cancelButton.setWidth(80);	this.cancelButton.setRight(10);	// add all the components	this.add(this.requiredGroup);	this.add(this.optionalGroup);	this.add(this.messageLabel);	this.requiredGroup.add(this.fullNameLabel);	this.requiredGroup.add(this.fullNameField);	this.requiredGroup.add(this.emailLabel);	this.requiredGroup.add(this.emailField);	this.requiredGroup.add(this.passwordLabel);	this.requiredGroup.add(this.passwordField);	this.requiredGroup.add(this.password2Label);	this.requiredGroup.add(this.password2Field);	this.optionalGroup.add(this.companyLabel);	this.optionalGroup.add(this.companyField);	this.optionalGroup.add(this.homePageLabel);	this.optionalGroup.add(this.homePageField);	this.optionalGroup.add(this.emailUpdatesCheckBox);	this.add(this.licenseLabel);	this.add(this.registerButton);	this.add(this.cancelButton);	this.add(this.registerProgress);	this.add(this.errorLabel);	// add event listeners	this.regService.addEventListener("register", this.onWsResult, this);	this.regService.addEventListener("registererror", this.onWsResult, this);	this.registerButton.addEventListener("action", this.register, this);	this.cancelButton.addEventListener("action", this.close, this);	this.stringBundle.addEventListener("change", this.updateStrings, this);}// make RegisterComponent extend BiComponentvar _p = RegisterComponent.prototype = new BiComponent;_p._className = "RegisterComponent";RegisterComponent.LICENSE_URI = "../../../download/license.html";//RegisterComponent.LICENSE_URI = "http://www.bindows.net/download/license.html";// override layoutAllChildrenY to calculate the position_p.layoutAllChildrenY = function () {	var y = 10;	this.messageLabel.setTop(y);	y += this.messageLabel.getHeight() + 10;;	this.requiredGroup.setTop(y);	var y2 = 20;	this.fullNameLabel.setTop(y2);	this.fullNameField.setTop( y2 - 2);	y2 += this.fullNameLabel.getHeight() + 15;	this.emailLabel.setTop(y2);	this.emailField.setTop( y2 - 2 );	y2 += this.emailLabel.getHeight() + 15;	this.passwordLabel.setTop(y2);	this.passwordField.setTop( y2 - 2 );	y2 += this.passwordLabel.getHeight() + 15;	this.password2Label.setTop(y2);	this.password2Field.setTop( y2 - 2 );	y2 += this.password2Label.getHeight() + 15;	this.requiredGroup.setHeight(y2);	//----------------------	y += y2 + 10;	y2 = 20;	this.optionalGroup.setTop(y);	this.companyLabel.setTop(y2);	this.companyField.setTop( y2 - 2 );	y2 += this.companyLabel.getHeight() + 15;	this.homePageLabel.setTop(y2);	this.homePageField.setTop( y2 - 2 );	y2 += this.homePageLabel.getHeight() + 15;	this.emailUpdatesCheckBox.setTop( y2 - 2 );	y2 += this.emailUpdatesCheckBox.getHeight() + 15;	this.optionalGroup.setHeight(y2);	//----------------------	y += y2 + 10;	this.licenseLabel.setTop(y);	y += this.licenseLabel.getHeight() + 10;	this.registerProgress.setTop(y);	this.errorLabel.setTop(y);	// call super.layoutAllChildrenY()	BiComponent.prototype.layoutAllChildrenY.call(this);};// if you override layoutAllChildrenY or layoutAllChildrenX you also need to// override layoutAllChildren. Otherwise your y (or x) changes will not be called// when both width and height are changed_p.layoutAllChildren = function () {	this.layoutAllChildrenY();	this.layoutAllChildrenX();};// this updates the UI and calls the registrationService register_p.register = function () {	var error = this.validate();	if (error != "") {		// since we got an error we show the error label and update its text		this.errorLabel.setVisible(true);		this.errorLabel.setText(error);	}	else {		this.registerButton.setFocused(true);		var fullName = this.fullNameField.getText();		var password = this.passwordField.getText();		var password2 = this.password2Field.getText();		var email = this.emailField.getText();		var company = this.companyField.getText();		var homePage = this.homePageField.getText();		var allowEmail = this.emailUpdatesCheckBox.getChecked();		// call the service (asynchronously)		this.regService.register(fullName, password, email, company, homePage, allowEmail);		// disable fields while we wait for the response from the server		this.setFieldsEnabled(false);		this.registerProgress.setVisible(true);		this.errorLabel.setVisible(false);		// start the progress bar		this.registerProgress.start();	}};_p.close = function () {	application.getWindow().close();};// enables the text fields_p.setFieldsEnabled = function (b) {	this.fullNameField.setEnabled(b);	this.passwordField.setEnabled(b);	this.password2Field.setEnabled(b);	this.companyField.setEnabled(b);	this.homePageField.setEnabled(b);	this.registerButton.setEnabled(b);};// validates the text in the required fields_p.validate = function () {	var fullName = this.fullNameField.getText();	var password = this.passwordField.getText();	var password2 = this.password2Field.getText();	var email = this.emailField.getText();	var error = "";	if (/^\s*$/.test(fullName)) {		error = this.stringBundle.getString("invalidFullName");	}	else if (/^\s*$/.test(password)) {		error = this.stringBundle.getString("invalidPassword");	}	else if (password != password2) {		error = this.stringBundle.getString("passwordsDoNotMatch");	}	else if ( !(/^\S+(\.S+)*@\S+(\.\S+)*$/.test(email)) ) {		error = this.stringBundle.getString("invalidEmail");	}	return error;}// called when the register event is fired from the// registrationService_p.onWsResult = function (e) {	this.registerProgress.stop();	this.setFieldsEnabled(true);	this.registerProgress.setVisible(false);	this.registerProgress.setValue(10);	if (e.result.error) {		this.errorLabel.setText(e.result.errorDetail.string);		this.errorLabel.setVisible(true);	}	else if (e.result.value.ErrorCode != 0) {		this.errorLabel.setText(e.result.value.Message);		this.errorLabel.setVisible(true);	}	else {		this.dispatchEvent(new BiEvent("register"));	}	try {		this.fullNameField.setFocused(true);		this.fullNameField.selectAll();	}	catch (ex) {}};_p.getEmail = function () {	return this.emailField.getText();};_p.updateStrings = function () {	this.messageLabel.setText( this.stringBundle.getString("loginInfoMessage") );	this.fullNameLabel.setText( this.stringBundle.getString("fullNameLabel") );	this.passwordLabel.setText( this.stringBundle.getString("passwordLabel") );	this.password2Label.setText( this.stringBundle.getString("retypePasswordLabel") );	this.emailLabel.setText( this.stringBundle.getString("emailLabel") );	this.companyLabel.setText( this.stringBundle.getString("companyLabel") );	this.homePageLabel.setText( this.stringBundle.getString("homePageLabel") );	this.emailUpdatesCheckBox.setText( this.stringBundle.getString("emailUpdatesLabel") );	this.requiredGroup.setText( this.stringBundle.getString("requiredGroupTitle") );	this.optionalGroup.setText( this.stringBundle.getString("optionalGroupTitle") );	this.registerButton.setText( this.stringBundle.getString("registerButton") );	this.cancelButton.setText( this.stringBundle.getString("cancelButton") );	this.licenseLabel.setHtml("<a href='" + RegisterComponent.LICENSE_URI + "' target='_blank'>" +		this.stringBundle.getString("licenseLinkLabel") + "</a>");};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -