Typeadmin.js 3.86 KB
/**
 * @package	anc_text
 * @since	20140416 
 * @copyright (c) netz.coop eG
 * @author	netz.coop eG
 */
//$.noConflict();

	var Anc_Text_Typeadmin  = {
		"pastDraggable" : "",
		/**
		 * 
		 * @param element param_dropzone_element - welches die dropzone darstellen soll
		 * @param element param_input_element - optional - set input.value - bekommt die rückgabe id vom hochgeladenen bild
		 * @param string param_url_upload - url die das bild entgegen nimmt
		 * @param element param_note_element - rückgabe notiz (fehler, erfolgreich)
		 * @returns {undefined}
		 */
		"droppableFile" : 	function(param_dropzone_element, param_input_element, param_url_upload, param_note_element, param_url_simpleowngallery,param_secure) {
			/**
			 * fnc teil der die dateien aus dem dateiexplorer entgegen nimmt
			 */
			param_dropzone_element.dropzone({ 
				url: param_url_upload,
				paramName: "file", // The name that will be used to transfer the file
				maxFilesize: 50, // MB
				maxFiles: 10, 
				params: { form_key : param_secure },
	//			maxfilesexceeded: function(file) { },
				processing: function(file) { 
					jQuery(" button.button ").attr("disabled", "disabled");
					param_note_element.append('<div>Bild wird hochgeladen. Bitte warten!</div>');
					jQuery(" > .preview-database-text ", param_dropzone_element).remove();
					jQuery(" > img ", param_dropzone_element).remove();				
					this.removeAllFiles();
				},
				init: function() {
					this.on("complete", function (file) {
						if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
//							alert('file.width: '+file.width+' file.height: '+file.height);
						}
					 });					
					this.on("success", function(file,rep) {
						var reponse = jQuery.parseJSON( rep );
						if(param_input_element) {
							param_input_element.attr('value', reponse.id);
						}
						
						
						if(reponse.status === 'OK') {
							var noteclass = 'anc-success';
							jQuery(".anc-text-owngallery-content .anc-text-owngallery-content-view").load(param_url_simpleowngallery, function() {});
						} else {
							var noteclass = 'anc-error';
						}
						jQuery(" button.button ").attr("disabled", false);
						jQuery(" div ", param_note_element).remove();
						param_note_element.append('<div class="'+noteclass+'">'+reponse.message+'</div>');
						
					});
				}
			});		

			var droppable_opt = {
				accept:".anc-text-draggable",
				tolerance: 'touch',

				drop: function(typ, ui) {
					var currentDraggable = jQuery(ui.draggable).attr('id');
					jQuery(this).append(jQuery(ui.draggable).clone());
					if(param_input_element) {
						param_input_element.attr('value', ui.draggable.attr('id'));
					}
					jQuery(" > div ", param_dropzone_element).remove();
					
					//If there is an object prior to the current one
					if (this.pastDraggable != "") {
						jQuery("#" + this.pastDraggable).remove();	//Place past object into its original coordinate
					}
					this.pastDraggable = currentDraggable;
				},
				activate: function(typ, ui) {},
				deactivate: function(typ, ui) {},						
				over: function(typ, ui) {},					
				out: function(typ, ui) {
					jQuery(ui.draggable).remove();		//	jQuery(this).droppable('option', 'accept', '.anc-text-draggable');
				},											
			}
			param_dropzone_element.droppable(droppable_opt);		
		},
		
		"draggableFile" : function() {
			var draggable_opt = {
				revert: "invalid",							// im zweifel gehts wieder zurück zum ursprung
				cursor: "move",								// mauszeiger .... 
				containment: "#ancsubbundleproduct",		// element darf nur innerhalb von containment bewegt werden
				opacity: .5,
				snap:true,									// einrasten
				snapMode:"inner",
				grid: [10,10],
				stack: '.anc-text-draggable',	//	letzter drop  liegt vorne
				helper: 'clone',							// nicht moven sondern kopieren
				//	snapTolerance:50,
			}
			jQuery(' .anc-text-draggable').draggable(draggable_opt);		
		}		
		
	}