summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/vendor/view
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/www/js/vendor/view')
-rw-r--r--StoneIsland/www/js/vendor/view/formview.js146
-rw-r--r--StoneIsland/www/js/vendor/view/serializable.js6
2 files changed, 5 insertions, 147 deletions
diff --git a/StoneIsland/www/js/vendor/view/formview.js b/StoneIsland/www/js/vendor/view/formview.js
deleted file mode 100644
index 8cd222e3..00000000
--- a/StoneIsland/www/js/vendor/view/formview.js
+++ /dev/null
@@ -1,146 +0,0 @@
-var FormView = View.extend({
-
- method: "post",
- useMinotaur: false,
-
- events: {
- "submit form": "save"
- },
-
- initialize: function(opt){
- if (opt && opt.parent) {
- this.parent = opt.parent
- }
- this.$form = this.$("form")
- this.$errors = this.$(".errors")
- this.$errorList = this.$(".errorList")
- },
-
- reset: function(){
- this.$("input,textarea").not("[type='submit']").not("[type='hidden']").val("")
- },
-
- showErrors: function(errors){
- if (errors && errors.length) {
- this.$errorList.empty();
- for (var i in errors) {
- this.$errorList.append('<div>' + errors[i] + '</div>');
- }
- this.$errors.css("opacity", 1.0);
- setTimeout(function(){
- this.$errors.show().css("opacity", 1.0);
- }.bind(this), 200)
- }
- },
-
- serialize: function(){
- var fd = new FormData(), hasCSRF = false
-
- this.$("input[name], select[name], textarea[name]").each( function(){
- if (this.type == "file") {
- if (this.files.length > 0) {
- fd.append(this.name, this.files[0]);
- }
- }
-// else if (this.type == "password") {
-// if (this.value.length > 0) {
-// fd.append(this.name, SHA1.hex('bucky$' + this.value + '$bucky'))
-// }
-// }
- else {
- fd.append(this.name, this.value);
- hasCSRF = hasCSRF || this.name == "_csrf"
- }
- });
-
-// if (! hasCSRF) {
-// fd.append("_csrf", $("[name=_csrf]").attr("value"))
-// }
-//
- return fd
- },
-
- save: function(e, successCallback, errorCallback){
- e && e.preventDefault()
-
- this.$errors.hide().css("opacity", 0.0);
-
- if (this.validate) {
- var errors = this.validate()
- if (errors && errors.length) {
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- }
-
- var action = typeof this.action == "function" ? this.action() : this.action
- if (! action) return
-
- var request = $.ajax({
- url: action,
- type: this.method,
- data: this.serialize(),
-// headers: { "csrf-token": $("[name=_csrf]").attr("value") },
- dataType: "json",
- processData: false,
- contentType: false,
- success: function(response){
-
- if (response.error) {
- var errors = []
- for (var key in response.error.errors) {
- errors.push(response.error.errors[key].message);
- }
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- else {
- if (successCallback) {
- successCallback(response)
- }
- if (this.success) {
- this.success(response)
- }
- }
-
-
- }.bind(this),
- error: function(response){
- }.bind(this),
- complete: function(response){
- if (this.useMinotaur) {
- Minotaur.hide()
- }
- }.bind(this),
- })
-
- if (this.useMinotaur) {
- Minotaur.show()
- }
-
- },
-
-})
-
-/*
-
-var ModalFormView = ModalView.extend(FormView.prototype).extend({
-
- load: function(){
- this.reset()
- this.show()
- }
-
-})
-
-*/ \ No newline at end of file
diff --git a/StoneIsland/www/js/vendor/view/serializable.js b/StoneIsland/www/js/vendor/view/serializable.js
index ae742d75..5dfca06e 100644
--- a/StoneIsland/www/js/vendor/view/serializable.js
+++ b/StoneIsland/www/js/vendor/view/serializable.js
@@ -35,9 +35,11 @@ var SerializableView = View.extend({
msgs.push(e[1])
}.bind(this))
this.$msg.html(msgs.join("<br>"))
+ this.$msg.addClass('alert-notice')
},
hide_errors: function(){
+ this.$msg.removeClass('alert-notice')
this.$msg.html("")
},
@@ -76,4 +78,6 @@ var SerializableView = View.extend({
console.log("FAIL", data)
},
-}) \ No newline at end of file
+})
+
+var FormView = View.extend(SerializableView).extend(ScrollableView)