File upload implementation part1
This commit is contained in:
@@ -360,6 +360,35 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
||||
@state['text'] = state.text
|
||||
@$el.val(state.text)
|
||||
|
||||
class WSF_FILE_CONTROL extends WSF_CONTROL
|
||||
attach_events: ()->
|
||||
super
|
||||
self = @
|
||||
@$el.change ()->
|
||||
self.change()
|
||||
|
||||
change: ()->
|
||||
#update local state
|
||||
@state['file'] = null
|
||||
@state['type'] = null
|
||||
@state['size'] = null
|
||||
if @$el[0].files.length>0
|
||||
file = @$el[0].files[0]
|
||||
@state['file'] = file.name
|
||||
@state['type'] = file.type
|
||||
@state['size'] = file.size
|
||||
if @state['callback_change']
|
||||
@trigger_callback(@control_name, 'change')
|
||||
@trigger('change')
|
||||
|
||||
value:()->
|
||||
return @$el.val()
|
||||
|
||||
update: (state) ->
|
||||
if state.text?
|
||||
@state['text'] = state.text
|
||||
@$el.val(state.text)
|
||||
|
||||
class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL
|
||||
|
||||
class WSF_NAVLIST_ITEM_CONTROL extends WSF_BUTTON_CONTROL
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DROPDOWN_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_NAVLIST_ITEM_CONTROL, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PASSWORD_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, parseSuggestions, redirect, show_alert, start_modal, start_modal_big, template, tmpl,
|
||||
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DROPDOWN_CONTROL, WSF_FILE_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_NAVLIST_ITEM_CONTROL, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PASSWORD_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, parseSuggestions, redirect, show_alert, start_modal, start_modal_big, template, tmpl,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
@@ -596,6 +596,55 @@ WSF_INPUT_CONTROL = (function(_super) {
|
||||
|
||||
})(WSF_CONTROL);
|
||||
|
||||
WSF_FILE_CONTROL = (function(_super) {
|
||||
|
||||
__extends(WSF_FILE_CONTROL, _super);
|
||||
|
||||
function WSF_FILE_CONTROL() {
|
||||
return WSF_FILE_CONTROL.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
WSF_FILE_CONTROL.prototype.attach_events = function() {
|
||||
var self;
|
||||
WSF_FILE_CONTROL.__super__.attach_events.apply(this, arguments);
|
||||
self = this;
|
||||
return this.$el.change(function() {
|
||||
return self.change();
|
||||
});
|
||||
};
|
||||
|
||||
WSF_FILE_CONTROL.prototype.change = function() {
|
||||
var file;
|
||||
this.state['file'] = null;
|
||||
this.state['type'] = null;
|
||||
this.state['size'] = null;
|
||||
if (this.$el[0].files.length > 0) {
|
||||
file = this.$el[0].files[0];
|
||||
this.state['file'] = file.name;
|
||||
this.state['type'] = file.type;
|
||||
this.state['size'] = file.size;
|
||||
}
|
||||
if (this.state['callback_change']) {
|
||||
this.trigger_callback(this.control_name, 'change');
|
||||
}
|
||||
return this.trigger('change');
|
||||
};
|
||||
|
||||
WSF_FILE_CONTROL.prototype.value = function() {
|
||||
return this.$el.val();
|
||||
};
|
||||
|
||||
WSF_FILE_CONTROL.prototype.update = function(state) {
|
||||
if (state.text != null) {
|
||||
this.state['text'] = state.text;
|
||||
return this.$el.val(state.text);
|
||||
}
|
||||
};
|
||||
|
||||
return WSF_FILE_CONTROL;
|
||||
|
||||
})(WSF_CONTROL);
|
||||
|
||||
WSF_PASSWORD_CONTROL = (function(_super) {
|
||||
|
||||
__extends(WSF_PASSWORD_CONTROL, _super);
|
||||
|
||||
@@ -21,6 +21,7 @@ feature
|
||||
|
||||
initialize_controls
|
||||
local
|
||||
n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE]
|
||||
n1_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||
n2_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||
n3_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||
@@ -32,6 +33,11 @@ feature
|
||||
Precursor
|
||||
create form.make
|
||||
form.add_class ("form-horizontal")
|
||||
--File
|
||||
create filebox.make
|
||||
create n0_container.make ("File Upload", filebox)
|
||||
n0_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (100000,"File must be smaller than 100KB"))
|
||||
form.add_control (n0_container)
|
||||
--Number 1
|
||||
create textbox1.make ("1")
|
||||
create n1_container.make ("Number1", textbox1)
|
||||
@@ -122,6 +128,8 @@ feature
|
||||
|
||||
button2: WSF_BUTTON_CONTROL
|
||||
|
||||
filebox: WSF_FILE_CONTROL
|
||||
|
||||
textbox1: WSF_INPUT_CONTROL
|
||||
|
||||
textbox2: WSF_INPUT_CONTROL
|
||||
|
||||
Reference in New Issue
Block a user