FORGE.features.assets.dialog = { config: { $editDialog: $('
').css('display', 'none') }, init: function () { var self = FORGE.features.assets.dialog; // Set up new assets $(document).on('click', '#new-asset-link', function (e) { self.showNew('#new-asset-dialog');; e.preventDefault(); }); // Set up editing and saving $(document).on('click', '.basic-asset-edit', self.showEdit); $(document).on('submit', '.asset-update', self.updateAsset); // Set up the auto-resize fields $(document).on('keyup', '#options_width', function() { self.changeImageHeight($(this).val()); }); $(document).on('keyup', '#options_height', function() { self.changeImageWidth($(this).val()); }); }, showNew: function (id, url) { // figure out the correct params to send var self = FORGE.features.assets.dialog, default_url = '/forge/assets/new', url = (typeof(url) != 'undefined') ? url : default_url; if (typeof($asset_id_container) != 'undefined' && url == default_url) { url += '?single=true' } self.config.$newDialog = $(id); self.config.$newDialog.dialog({title: 'Upload Assets', width: 550, modal: true, close: self.config.$newDialog.html('') }); self.config.$newDialog.html("' alt='Loading...' />"); self.config.$newDialog.load(url); }, showEdit: function (event) { event.preventDefault(); var self = FORGE.features.assets.dialog, url = this.href; $.ajax({ url: url, dataType: 'HTML', success: function(data) { self.config.$editDialog.html(data); self.config.$editDialog.dialog({title: "Edit Asset", width: 500, modal: true, close: function() { dialog.html(''); } }); } }); }, updateAsset: function (event) { event.preventDefault(); var self = FORGE.features.assets.dialog, $this = $(this), data = $this.serialize, url = $this.attr('action'); $.ajax({ url: url, dataType: 'json', success: function() { var item = $(''); self.config.$editDialog.dialog('close'); } }); }, changeImageHeight: function (current_width) { var self = FORGE.features.assets.dialog, divisor = self.config.$base_width / self.config.$base_height; $('#options_height').val(Math.floor(current_width / divisor)); }, changeImageWidth: function (current_height) { var self = FORGE.features.assets.dialog, divisor = self.config.$base_width / self.config.$base_height; $('#options_width').val(Math.floor(current_height / divisor)); } }