Add disable option
This commit is contained in:
@@ -340,6 +340,9 @@ class WSF_BUTTON_CONTROL extends WSF_CONTROL
|
||||
@trigger_callback(@control_name, 'click')
|
||||
|
||||
update: (state) ->
|
||||
if state.disabled != undefined
|
||||
@state['disabled'] = state.disabled
|
||||
@$el.prop('disabled', state.disabled)
|
||||
if state.text?
|
||||
@state['text'] = state.text
|
||||
@$el.text(state.text)
|
||||
@@ -362,6 +365,9 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
||||
return @$el.val()
|
||||
|
||||
update: (state) ->
|
||||
if state.disabled != undefined
|
||||
@state['disabled'] = state.disabled
|
||||
@$el.prop('disabled', state.disabled)
|
||||
if state.text?
|
||||
@state['text'] = state.text
|
||||
@$el.val(state.text)
|
||||
@@ -434,8 +440,10 @@ class WSF_FILE_CONTROL extends WSF_CONTROL
|
||||
return @$el.val()
|
||||
|
||||
update: (state) ->
|
||||
if state.removable != undefined
|
||||
@state['removable'] = state.removable
|
||||
if state.disabled != undefined
|
||||
@state['disabled'] = state.disabled
|
||||
@$el.prop('disabled', state.disabled)
|
||||
@refresh()
|
||||
if state.file_name != undefined
|
||||
@state['file_name'] = state.file_name
|
||||
if state.file_type != undefined
|
||||
@@ -443,29 +451,37 @@ class WSF_FILE_CONTROL extends WSF_CONTROL
|
||||
if state.file_size != undefined
|
||||
@state['file_size'] = state.file_size
|
||||
if state.file_id != undefined
|
||||
@uploading = false
|
||||
@progressbar.remove()
|
||||
@state['file_id'] = state.file_id
|
||||
@$el.parent().find("p").remove()
|
||||
if state.file_id!=null
|
||||
@$el.hide()
|
||||
fname = $("""<p></p>""").addClass("form-control-static").text(@state['file_name'])
|
||||
@$el.parent().append(fname)
|
||||
if @state['removable']
|
||||
fname.append(" ");
|
||||
btn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger")
|
||||
self = @
|
||||
btn.click ()->
|
||||
self.progressbar.remove()
|
||||
self.$el.parent().find("p").remove()
|
||||
self.$el.show()
|
||||
self.$el.val('')
|
||||
self.change()
|
||||
fname.append(btn)
|
||||
else
|
||||
@$el.show()
|
||||
@$el.val('')
|
||||
@change()
|
||||
if @state['file_id'] != state.file_id
|
||||
@state['file_id'] = state.file_id
|
||||
if @state['callback_uploaddone']
|
||||
@trigger_callback(@control_name, 'uploaddone')
|
||||
@uploading = false
|
||||
@refresh()
|
||||
|
||||
refresh: ()->
|
||||
if @uploading
|
||||
return
|
||||
@progressbar.remove()
|
||||
@$el.parent().find("p").remove()
|
||||
if @state['file_id'] != null
|
||||
@$el.hide()
|
||||
fname = $("""<p></p>""").addClass("form-control-static").text(@state['file_name'])
|
||||
@$el.parent().append(fname)
|
||||
if not @state['disabled']
|
||||
fname.append(" ");
|
||||
removebtn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger")
|
||||
self = @
|
||||
removebtn.click ()->
|
||||
self.progressbar.remove()
|
||||
self.$el.parent().find("p").remove()
|
||||
self.$el.show()
|
||||
self.$el.val('')
|
||||
self.change()
|
||||
fname.append(removebtn)
|
||||
else
|
||||
@$el.show()
|
||||
@$el.val('')
|
||||
@change()
|
||||
|
||||
|
||||
class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL
|
||||
|
||||
@@ -550,6 +550,10 @@ WSF_BUTTON_CONTROL = (function(_super) {
|
||||
};
|
||||
|
||||
WSF_BUTTON_CONTROL.prototype.update = function(state) {
|
||||
if (state.disabled !== void 0) {
|
||||
this.state['disabled'] = state.disabled;
|
||||
this.$el.prop('disabled', state.disabled);
|
||||
}
|
||||
if (state.text != null) {
|
||||
this.state['text'] = state.text;
|
||||
return this.$el.text(state.text);
|
||||
@@ -590,6 +594,10 @@ WSF_INPUT_CONTROL = (function(_super) {
|
||||
};
|
||||
|
||||
WSF_INPUT_CONTROL.prototype.update = function(state) {
|
||||
if (state.disabled !== void 0) {
|
||||
this.state['disabled'] = state.disabled;
|
||||
this.$el.prop('disabled', state.disabled);
|
||||
}
|
||||
if (state.text != null) {
|
||||
this.state['text'] = state.text;
|
||||
return this.$el.val(state.text);
|
||||
@@ -687,9 +695,10 @@ WSF_FILE_CONTROL = (function(_super) {
|
||||
};
|
||||
|
||||
WSF_FILE_CONTROL.prototype.update = function(state) {
|
||||
var btn, fname, self;
|
||||
if (state.removable !== void 0) {
|
||||
this.state['removable'] = state.removable;
|
||||
if (state.disabled !== void 0) {
|
||||
this.state['disabled'] = state.disabled;
|
||||
this.$el.prop('disabled', state.disabled);
|
||||
this.refresh();
|
||||
}
|
||||
if (state.file_name !== void 0) {
|
||||
this.state['file_name'] = state.file_name;
|
||||
@@ -701,32 +710,45 @@ WSF_FILE_CONTROL = (function(_super) {
|
||||
this.state['file_size'] = state.file_size;
|
||||
}
|
||||
if (state.file_id !== void 0) {
|
||||
this.uploading = false;
|
||||
this.progressbar.remove();
|
||||
this.state['file_id'] = state.file_id;
|
||||
this.$el.parent().find("p").remove();
|
||||
if (state.file_id !== null) {
|
||||
this.$el.hide();
|
||||
fname = $("<p></p>").addClass("form-control-static").text(this.state['file_name']);
|
||||
this.$el.parent().append(fname);
|
||||
if (this.state['removable']) {
|
||||
fname.append(" ");
|
||||
btn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger");
|
||||
self = this;
|
||||
btn.click(function() {
|
||||
self.progressbar.remove();
|
||||
self.$el.parent().find("p").remove();
|
||||
self.$el.show();
|
||||
self.$el.val('');
|
||||
return self.change();
|
||||
});
|
||||
return fname.append(btn);
|
||||
if (this.state['file_id'] !== state.file_id) {
|
||||
this.state['file_id'] = state.file_id;
|
||||
if (this.state['callback_uploaddone']) {
|
||||
this.trigger_callback(this.control_name, 'uploaddone');
|
||||
}
|
||||
} else {
|
||||
this.$el.show();
|
||||
this.$el.val('');
|
||||
return this.change();
|
||||
this.uploading = false;
|
||||
}
|
||||
return this.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
WSF_FILE_CONTROL.prototype.refresh = function() {
|
||||
var fname, removebtn, self;
|
||||
if (this.uploading) {
|
||||
return;
|
||||
}
|
||||
this.progressbar.remove();
|
||||
this.$el.parent().find("p").remove();
|
||||
if (this.state['file_id'] !== null) {
|
||||
this.$el.hide();
|
||||
fname = $("<p></p>").addClass("form-control-static").text(this.state['file_name']);
|
||||
this.$el.parent().append(fname);
|
||||
if (!this.state['disabled']) {
|
||||
fname.append(" ");
|
||||
removebtn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger");
|
||||
self = this;
|
||||
removebtn.click(function() {
|
||||
self.progressbar.remove();
|
||||
self.$el.parent().find("p").remove();
|
||||
self.$el.show();
|
||||
self.$el.val('');
|
||||
return self.change();
|
||||
});
|
||||
return fname.append(removebtn);
|
||||
}
|
||||
} else {
|
||||
this.$el.show();
|
||||
this.$el.val('');
|
||||
return this.change();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,13 +26,15 @@ feature -- Implementation
|
||||
control.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h1", "", "File Upload Demo"))
|
||||
create form.make
|
||||
--File
|
||||
create filebox.make (true)
|
||||
create filebox.make
|
||||
filebox.set_upload_function (agent upload_file)
|
||||
filebox.set_upload_done_event (agent submit_form)
|
||||
create n0_container.make ("File Upload", filebox)
|
||||
n0_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (10000000, "File must be smaller than 10MB"))
|
||||
form.add_control (n0_container)
|
||||
--File
|
||||
create filebox2.make (true)
|
||||
create filebox2.make
|
||||
filebox2.set_upload_function (agent upload_file)
|
||||
create n1_container.make ("Auto start Upload", filebox2)
|
||||
filebox2.set_change_event (agent
|
||||
do
|
||||
@@ -49,18 +51,29 @@ feature -- Implementation
|
||||
button1.set_click_event (agent submit_form)
|
||||
button1.add_class ("col-lg-offset-2")
|
||||
form.add_control (button1)
|
||||
|
||||
control.add_control (form)
|
||||
navbar.set_active (5)
|
||||
end
|
||||
|
||||
submit_form
|
||||
do
|
||||
form.validate
|
||||
if form.is_valid then
|
||||
filebox.start_upload
|
||||
do
|
||||
form.validate
|
||||
if form.is_valid then
|
||||
if attached filebox.file as f then
|
||||
if not f.is_uploaded then
|
||||
filebox.set_disabled (true)
|
||||
filebox.start_upload
|
||||
filebox2.set_disabled (true)
|
||||
button1.set_disabled (true)
|
||||
button1.set_text ("Uploading ...")
|
||||
else
|
||||
button1.set_text ("Done")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
upload_file (f: ITERABLE [WSF_UPLOADED_FILE]): detachable String
|
||||
do
|
||||
@@ -90,5 +103,4 @@ feature -- Properties
|
||||
|
||||
n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE]
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user