mirror of
https://github.com/fergalmoran/dss.git
synced 2025-12-22 09:38:18 +00:00
200 lines
6.4 KiB
JavaScript
Executable File
200 lines
6.4 KiB
JavaScript
Executable File
// Generated by CoffeeScript 1.4.0
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__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; };
|
|
|
|
define(['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl/MixEditView', 'jquery.fileupload', 'jquery.fileupload-process', 'jquery.fileupload-audio', 'jquery.fileupload-ui', 'jquery.iframe-transport', 'jquery.ui.widget', 'lib/bootstrap-fileupload', 'lib/select2', 'lib/ajaxfileupload', 'ace', 'lib/bootstrap-tag.min'], function(EditableView, moment, utils, Syphon, Template) {
|
|
var MixEditView;
|
|
return MixEditView = (function(_super) {
|
|
|
|
__extends(MixEditView, _super);
|
|
|
|
function MixEditView() {
|
|
this.saveChanges = __bind(this.saveChanges, this);
|
|
return MixEditView.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
MixEditView.prototype.template = _.template(Template);
|
|
|
|
MixEditView.prototype.events = {
|
|
"click #save-changes": "saveChanges",
|
|
"change #mix_image": "imageChanged"
|
|
};
|
|
|
|
MixEditView.prototype.ui = {
|
|
image: "#mix-image"
|
|
};
|
|
|
|
MixEditView.working = false;
|
|
|
|
MixEditView.patch = false;
|
|
|
|
MixEditView.prototype.checkRedirect = function() {
|
|
if (this.state === 2) {
|
|
return Backbone.history.navigate("/mix/" + this.model.get("slug"), {
|
|
trigger: true
|
|
});
|
|
}
|
|
};
|
|
|
|
MixEditView.prototype.initialize = function() {
|
|
this.guid = utils.generateGuid();
|
|
return this.state = 0;
|
|
};
|
|
|
|
MixEditView.prototype.onDomRefresh = function() {
|
|
var _this = this;
|
|
$("#fileupload", this.el).fileupload({
|
|
downloadTemplateId: void 0,
|
|
url: "/_upload/",
|
|
start: function() {
|
|
return $("#mix-details", this.el).show();
|
|
},
|
|
done: function() {
|
|
_this.state++;
|
|
$("#div-upload-mix", _this.el).hide();
|
|
return _this.checkRedirect();
|
|
}
|
|
});
|
|
this.setupImageEditable({
|
|
el: this.ui.image,
|
|
showbuttons: false,
|
|
chooseMessage: "Choose mix image"
|
|
});
|
|
$("#mix-imageupload", this.el).jas_fileupload({
|
|
uploadtype: "image"
|
|
});
|
|
return true;
|
|
};
|
|
|
|
MixEditView.prototype.onRender = function() {
|
|
var parent;
|
|
console.log("MixEditView: onRender");
|
|
this.sendImage = false;
|
|
parent = this;
|
|
if (!this.model.id) {
|
|
$("#upload-hash", this.el).val(this.guid);
|
|
} else {
|
|
$("#div-upload-mix", this.el).hide();
|
|
this.patch = true;
|
|
this.state = 1;
|
|
}
|
|
$("#genres", this.el).select2({
|
|
placeholder: "Start typing and choose or press enter",
|
|
minimumInputLength: 1,
|
|
multiple: true,
|
|
ajax: {
|
|
url: "/ajax/lookup/genre/",
|
|
dataType: "json",
|
|
data: function(term, page) {
|
|
return {
|
|
q: term
|
|
};
|
|
},
|
|
results: function(data, page) {
|
|
return {
|
|
results: data
|
|
};
|
|
}
|
|
},
|
|
initSelection: function(element, callback) {
|
|
var genres, result;
|
|
console.log("MixEditView: genres:initSelection");
|
|
result = [];
|
|
genres = parent.model.get("genres");
|
|
if (genres !== undefined) {
|
|
$.each(genres, function(data) {
|
|
return result.push({
|
|
id: this.id,
|
|
text: this.description
|
|
});
|
|
});
|
|
}
|
|
return callback(result);
|
|
},
|
|
createSearchChoice: function(term, data) {
|
|
if ($(data).filter(function() {
|
|
return this.text.localeCompare(term) === 0;
|
|
}).length === 0) {
|
|
return {
|
|
id: term,
|
|
text: term
|
|
};
|
|
}
|
|
}
|
|
});
|
|
return this;
|
|
};
|
|
|
|
MixEditView.prototype.saveChanges = function() {
|
|
var data,
|
|
_this = this;
|
|
console.log("MixEditView: saveChanges");
|
|
data = Syphon.serialize($("#mix-details-form", this.el)[0]);
|
|
this.model.set(data);
|
|
this.model.set("upload-hash", this.guid);
|
|
this.model.set("upload-extension", $("#upload-extension", this.el).val());
|
|
$.each($("#genres", this.el).select2("data"), function(i, item) {
|
|
return _this.model.get("genres").add({
|
|
description: item.text
|
|
});
|
|
});
|
|
if (!this.sendImage) {
|
|
this.model.unset("mix_image");
|
|
}
|
|
this.model.unset("comments");
|
|
this._saveChanges({
|
|
patch: this.patch,
|
|
success: function() {
|
|
if (_this.sendImage) {
|
|
$.ajaxFileUpload({
|
|
url: "/ajax/upload_mix_image/" + _this.model.get("id") + "/",
|
|
secureuri: false,
|
|
fileElementId: "mix_image",
|
|
success: function(data, status) {
|
|
if (typeof data.error !== "undefined") {
|
|
if (data.error !== "") {
|
|
return alert(data.error);
|
|
} else {
|
|
return alert(data.msg);
|
|
}
|
|
} else {
|
|
$("#mix-details", _this.el).hide();
|
|
_this.state++;
|
|
return _this.checkRedirect();
|
|
}
|
|
},
|
|
error: function(data, status, e) {
|
|
return utils.showError(e);
|
|
}
|
|
});
|
|
} else {
|
|
$("#mix-details", _this.el).hide();
|
|
_this.state++;
|
|
_this.checkRedirect();
|
|
}
|
|
return true;
|
|
},
|
|
error: function(model, response) {
|
|
return utils.showError("Error", "Something went wrong<br />Nerd stuff is: " + response);
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
MixEditView.prototype.imageChanged = function(evt) {
|
|
this.sendImage = true;
|
|
return true;
|
|
};
|
|
|
|
MixEditView;
|
|
|
|
|
|
return MixEditView;
|
|
|
|
})(EditableView);
|
|
});
|
|
|
|
}).call(this);
|