web/static/ldt/js/projectscontents.js
branchmodal_update
changeset 31 0d829ac13c4b
parent 24 57a2650a7f87
child 32 7bb37c869d0d
--- a/web/static/ldt/js/projectscontents.js	Thu Feb 17 18:50:34 2011 +0100
+++ b/web/static/ldt/js/projectscontents.js	Mon Feb 28 12:43:13 2011 +0100
@@ -16,25 +16,6 @@
 
 function init_events_base(base_node, embed_url) {
 	
-	$('.ldt_link',base_node).each(function(i){
-		$(this).attr("target","_iri");
-	});
-	$('.ldt_link',base_node).nyroModal({
-		filters: ['iriIFrame'],
-		sizes: {
-			minW: '1022',
-			minH: '662'
-		},
-		showCloseButton: true,
-		callbacks: {
-			afterShowCont: function(nm) {
-				nm.store.iframe.height(662);
-				nm.store.iframe.width(1022);
-			}
-		}
-      });
-    	
-
 	$('.ldt_link_embed',base_node).click(function(e) {
 		e.preventDefault();
 		var link = $(e.target);
@@ -89,6 +70,29 @@
 
 };
 
+function testAndClose() {
+	// Here we ask LDT if the current work is modified and if the user want to save it.
+	var ldtSwf =  $('#ldtInitSwf',$.nmTop().store.iframe.contents()).get(0);
+	// In the ldt_link_create case, the modal page can be the form, or the ldt swf. So we have to test.
+	if (ldtSwf) {
+		if (ldtSwf.name=="ldtInitSwf") {
+            if(ldtSwf.isModified()=="true") {
+                //ldtSwf.forceSave();
+                ldtSwf.askSave();
+            }
+			else{
+				forceModalClose();
+			}
+		}
+		else{
+			forceModalClose();
+		}
+	}
+	else{
+		forceModalClose();
+	}
+}
+
 
 function searchCallback(target, container_selector, url, timeout) {
 
@@ -191,6 +195,38 @@
 
 function init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) {
 
+	// These are the functions called when we display a project in an LDT modal window
+	$('.ldt_link',base_node).each(function(i){
+		$(this).attr("target","_iri");
+	});
+	$('.ldt_link',base_node).nyroModal({
+		filters: ['iriIframe'],
+		sizes: {
+			minW: '1022',
+			minH: '662'
+		},
+		showCloseButton: true,
+		closeOnEscape:false,
+		closeOnClick:false,
+		callbacks: {
+			afterShowCont: function(nm) {
+				nm.store.iframe.height(662);
+				nm.store.iframe.width(1022);
+			},
+			close: function(nm) {
+				// We don't do anything here, we hack the callback directly from the close function.
+			},
+			afterClose: function(nm) {
+				// Can't do that because searchprojectfilterurl is not defined in init_events_base params
+				searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
+			}
+		},
+		close:function(nm){
+			testAndClose();
+		}
+    });
+
+
 	$('.ldt_link_create',base_node).each(function(i){
 		$(this).attr("target","_iri");
 	});
@@ -201,6 +237,9 @@
 			minW: '600',
 			minH: '500'
 		},
+		showCloseButton:true,
+		closeOnEscape:false,
+		closeOnClick:false,
 		callbacks: {
 			afterShowCont: function(nm) {
 				nm.store.iframe.width(600);
@@ -224,7 +263,10 @@
 			afterClose: function(nm) {
 				searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
 			}	
-	    }
+	    },
+		close:function(){
+			testAndClose();
+		}
 		
     });