<div class="clearfix">
<label for="username">${i18n('username')}</label>
<div class="input" id="username-div">
- {{if $data.username}}
+ {{if $data.username.length>0}}
<span class="uneditable-input">${$data.username}</span>
{{else}}
<input type="text" id="username" name="username" size="30" class="required" data-bind="value: username"/>
</div>
</fieldset>
<button data-bind="click: save" class="btn" id="user-create-form-register-button">${i18n('save')}</button>
- <button onclick="$('#user-create').hide()" class="btn" id="user-create-form-cancel-button">${i18n('cancel')}</button>
+ <button class="btn" id="user-create-form-cancel-button">${i18n('cancel')}</button>
</form>
</script>
}
};
this.createUser = function() {
+ $.log("user#createUser");
+ var valid = $("#user-create").valid();
+ if (!valid) {
+ return;
+ }
var currentUser = this;
$.ajax("restServices/redbackServices/userService/createUser", {
data: "{\"user\": " + ko.toJSON(this)+"}",
this.save=function(){
$.log("user.save create:"+window.redbackModel.createUser);
if (window.redbackModel.createUser==true){
- return this.create();
+ var valid = $("#main-content #createUserForm #user-create").valid();
+
+ if (valid==false) {
+ $.log("user#save valid:false");
+ return;
+ } else {
+ $.log("user#save valid:true");
+ return this.create();
+ }
} else {
return this.update();
}
});
this.addUser=function() {
- screenChange();
+ clearUserMessages();
window.redbackModel.createUser=true;
$("#main-content #user-edit").remove();
$('#main-content #user-create').show();
ko.renderTemplate("redback/user-edit-tmpl", new user(), null, $("#createUserForm").get(0),"replaceChildren");
- $("#user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) {
+ $("#main-content #createUserForm #user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) {
e.preventDefault();
$('#user-create').hide();
});
customShowError(validator,errorMap,errorMap);
}
});
- $("#createUserForm #user-create").delegate("#user-create-form-save-button", "click keydown", function(e) {
+ $("#main-content #createUserForm #user-create").delegate("#user-create-form-register-button", "click keydown", function(e) {
e.preventDefault();
- var valid = $("#user-create").valid();
- if (!valid) {
- return;
- }
- user.createUser();
});
};
this.editUserBox=function(user) {
window.redbackModel.createUser=false;
- screenChange();
+ clearUserMessages();
$("#main-content #user-edit").remove();
$("#main-content").append("<div id='user-edit'></div>");
$("#main-content #user-edit").attr("data-bind",'template: {name:"redback/user-edit-tmpl",data: user}');
var viewModel = new userViewModel(user);
ko.applyBindings(viewModel,$("#main-content #user-edit").get(0));
- jQuery("#main-content #user-create").validate({
- rules: {
- confirmPassword: {
- equalTo: "#password"
- }
- },
- showErrors: function(validator, errorMap, errorList) {
- customShowError(validator,errorMap,errorMap);
- }
- });
+
+
$("#main-content #user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) {
e.preventDefault();
$('#main-content #user-create').remove();
});
+
$("#main-content #user-create").validate({
rules: {
confirmPassword: {
}
user.update();
});
+
}
}