diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index 748517e962..c68e7370ea 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -77,11 +77,17 @@ var et2_date = et2_inputWidget.extend({ node.addClass("et2_date"); var _this = this; + var dateformat = egw.preference("dateformat"); + if (!dateformat) dateformat = "Y-m-d"; + dateformat = dateformat.replace("Y","%Y").replace("d","%d").replace("m","%m").replace("M", "%b"); + var setup = { inputField: this.options.id, button: this.button.attr("id"), showsTime: false, - onUpdate: function(_value) {_this.set_value(_value)} + onUpdate: function(_value) {_this.set_value(_value)}, + daFormat: dateformat, + firstDay: egw.preference("weekdaystarts","calendar") }; window.setTimeout(function() { Calendar.setup(setup); diff --git a/etemplate/js/et2_widget_file.js b/etemplate/js/et2_widget_file.js new file mode 100644 index 0000000000..b1bf6ea17f --- /dev/null +++ b/etemplate/js/et2_widget_file.js @@ -0,0 +1,130 @@ +/** + * eGroupWare eTemplate2 - JS Number object + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Nathan Gray + * @copyright Nathan Gray 2011 + * @version $Id$ + */ + +"use strict"; + +/*egw:uses + et2_core_inputWidget; +*/ + +/** + * Class which implements file upload + */ +var et2_file = et2_inputWidget.extend({ + + attributes: { + "multiple": { + "name": "Multiple files", + "type": "boolean", + "default": false, + "description": "Allow the user to select more than one file to upload at a time. Subject to browser support." + }, + "max_file_size": { + "name": "Maximum file size", + "type": "integer", + "default":"8388608", + "description": "Largest file accepted, in bytes. Subject to server limitations. 8Mb = 8388608" + }, + "blur": { + "name": "Placeholder", + "type": "string", + "default": "", + "description": "This text get displayed if an input-field is empty and does not have the input-focus (blur). It can be used to show a default value or a kind of help-text." + }, + "progress": { + "name": "Progress node", + "type": "string", + "default": et2_no_init, + "description": "The ID of an alternate node (div) to display progress and results." + } + }, + + init: function() { + this._super.apply(this, arguments) + + this.node = null; + + this.createInputWidget(); + }, + + createInputWidget: function() { + this.node = $j(document.createElement("div")).addClass("et2_file"); + this.input = $j(document.createElement("input")) + .attr("type", "file").attr("placeholder", this.options.blur) + .appendTo(this.node) + .change(this, this.change); + this.progress = this.options.progress ? + $j(document.getElementById(this.options.progress)) : + $j(document.createElement("div")).appendTo(this.node); + this.progress.addClass("progress"); + + if(this.options.multiple) { + this.input.attr("multiple","multiple"); + } + this.setDOMNode(this.node[0]); + }, + + getInputNode: function() { + return this.input[0]; + }, + + /** + * User has selected some files file, send them off + */ + change: function(e) { +console.log(e); + if(!e.target.files || e.target.files.length == 0) return; + + for(var i = 0; i < e.target.files.length; i++) { + var file = e.target.files[i]; + + // Add to list + var status = this.createStatus(file); + this.progress.append(status); + + // Check if OK + if(file.size > this.options.max_file_size) { + // TODO: Try to slice into acceptable pieces + status.addClass("ui-state-error"); + this.showMessage(egw.lang("File is too large."), "validation_error"); + var self = this; + window.setTimeout(function() {self.hideMessage(true); status.remove();}, 5000); + } + } + + // Reset field + e.data.input.attr("type", "input").attr("type","file"); + }, + + /** + * Upload a single file asyncronously + */ + _upload_file: function(file) { + // Start upload + console.log(this, file); + + }, + + /** + * Creates the elements used for displaying the file, and it's upload status + * + * @param file A JS File object + * @return a jQuery object with the elements + */ + createStatus: function(file) { + return $j("
  • "+file.name+"

  • "); + } + +}); + +et2_register_widget(et2_file, ["file"]); + diff --git a/etemplate/js/et2_widget_number.js b/etemplate/js/et2_widget_number.js index ce6d452d1f..a1c1529e4f 100644 --- a/etemplate/js/et2_widget_number.js +++ b/etemplate/js/et2_widget_number.js @@ -37,6 +37,14 @@ var et2_number = et2_textbox.extend({ "type": "integer", "default": et2_no_init, "description": "Maximum allowed value" + }, + "precision": { + // TODO: Implement this in some nice way other than HTML5's step attribute + "name": "Precision", + "type": "integer", + "default": et2_no_init, + "description": "Allowed precision - # of decimal places", + "ignore": true } }, @@ -59,6 +67,14 @@ var et2_number = et2_textbox.extend({ } else { this.input.attr("min",this.min); } + }, + set_max: function(_value) { + this.max = _value; + if(this.max == null) { + this.input.removeAttr("max"); + } else { + this.input.attr("max",this.max); + } } }); diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index a35fccc465..cf6f6c90ac 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -30,6 +30,8 @@ et2_widget_tabs; et2_widget_hrule; et2_widget_image; + et2_widget_upload; + et2_widget_file; et2_extension_nextmatch; diff --git a/etemplate/js/test/et2_test_file_upload.xet b/etemplate/js/test/et2_test_file_upload.xet new file mode 100644 index 0000000000..cbc6f124a3 --- /dev/null +++ b/etemplate/js/test/et2_test_file_upload.xet @@ -0,0 +1,10 @@ + + + + + diff --git a/etemplate/js/test/test.php b/etemplate/js/test/test.php index 0a41f972bd..df4e9a3371 100644 --- a/etemplate/js/test/test.php +++ b/etemplate/js/test/test.php @@ -35,6 +35,7 @@ Testing from inside framework, so JS includes work Basic widgits Date/time widgits Validation + Upload
    ETemplate2 container: