X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fstatic%2Fjs%2Frecord_generator.js;fp=manifold%2Fstatic%2Fjs%2Frecord_generator.js;h=f53c7ee9e77484fea12d7c6c2d494885ba4a514f;hb=7e483a038eb61377f8f738ad7cb3b35d8dce5f37;hp=0000000000000000000000000000000000000000;hpb=5de3330b8219f03bc53d9bbace764ee3912e6017;p=myslice.git diff --git a/manifold/static/js/record_generator.js b/manifold/static/js/record_generator.js new file mode 100644 index 00000000..f53c7ee9 --- /dev/null +++ b/manifold/static/js/record_generator.js @@ -0,0 +1,71 @@ +/* Buffered DOM updates */ +var RecordGenerator = Class.extend({ + + init: function(query, generators, number) + { + this._query = query; + this._generators = generators; + this._number = number; + }, + + random_int: function(options) + { + var default_options = { + max: 1000 + } + + if (typeof options == 'object') + options = $.extend(default_options, options); + else + options = default_options; + + return Math.floor(Math.random()*(options.max+1)); + }, + + random_string: function() + { + var default_options = { + possible: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + len: this.random_int({max: 15}) + } + + if (typeof options == 'object') + options = $.extend(default_options, options); + else + options = default_options; + + var text = ""; + + for( var i=0; i < options.len; i++ ) + text += options.possible.charAt(Math.floor(Math.random() * options.possible.length)); + + return text; + + }, + + generate_record: function() + { + var self = this; + var record = {}; + + $.each(this._query.fields, function(i, field) { + record[field] = self[self._generators[field]](); + }); + + // Publish records + manifold.raise_record_event(self._query.query_uuid, NEW_RECORD, record); + + }, + + run: function() + { + var record; + manifold.raise_record_event(this._query.query_uuid, CLEAR_RECORDS); + for (var i = 0; i < this._number; i++) { + record = this.generate_record(); + /* XXX publish record */ + } + manifold.raise_record_event(this._query.query_uuid, DONE); + + } +});