Forums de discussion

<aui:script use="aui-io" /> prevents look&feel pop-up f

thumbnail
Jim Klo, modifié il y a 13 années.

<aui:script use="aui-io" /> prevents look&feel pop-up f

Junior Member Publications: 75 Date d'inscription: 07/11/08 Publications récentes
I've built a new portlet plugin, and trying to utilize some of the AUI & YUI 3 features in 6.0.5.

Here's my problem:

if I create a aui:script block like so:


<aui:script use="aui-io" position="auto">
function setupUploader() {
	A.on('io:start', function(id, args) {
	    jQuery('.expandable').css("cursor", "default");
	    jQuery('.submission form').hide();
	    document.getElementById('loading').style.display='block';
  	});
  	
  	A.on('io:complete', function (id, o, args) {
  
  	  if (o &amp;&amp; o.responseText) {  
  	  	response = A.JSON.parse(o.responseText);
  	  }
  	  
  	  if (response &amp;&amp; response.success == true) {
  	  	appSubmitSuccess();
  	  } else if (response &amp;&amp; response.success == false) {
  	  	appSubmitError(response);
  	  }
    });
}

function uploadFile() {

	var cfg = {
		method: "POST",
		form: {
			id: "<portlet:namespace />upload_form",
			upload: true
		}
	};
  	A.io('&lt;%= ajaxFileSubmit %&gt;', cfg);

  	return false;
}
</aui:script>


After I deploy my portlet, place it on a page, I cannot open the look and feel dialog, it just sits there and spins.

Anyone out there have any ideas why or how to fix?
thumbnail
Jim Klo, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Junior Member Publications: 75 Date d'inscription: 07/11/08 Publications récentes
Anyone?
thumbnail
Nate Cavanaugh, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Junior Member Publications: 94 Date d'inscription: 27/11/06 Publications récentes
Hi Jim,
Are there any errors being thrown?

Also, are you including jQuery onto your page? Your code is relying on it, and we don't include it by default anymore in 6.0.5 (you would use the Node package for that), but that might be one possibility.

One other possibility is that you're defining functions inside of the same block as you're doing a "use" statement.

Everything inside of an aui:script block that contains a "use" attribute is called asynchronously, so it could fire right away (if the resources are on the page) or if the network resolution is taking a long time, it could execute later on.

So if you're defining a function inside of there, but then in another piece of code, you're calling one of you're functions before that code has returned, you have a race condition where the function you're trying to execute is defined after the point you call it.

Does that make sense?

I can show you the difference quickly:

<aui:script>alert('not "using" any modules, Im fired right away');</aui:script>

<aui:script use="aui-io">alert('"using" aui-io, Im fired when its ready');</aui:script>


So we make sure never to define a function inside of an aui-script block that has a "use" attribute, unless we're creating another module to be used.

But then how do you define a function that uses a module?

Luckily, we've already solved this problem, and created Liferay.provide.

Here's how your code would look:
<aui:script>
	Liferay.provide(window, 'setupUploader',
		function() {
			var A = AUI();

			A.on('io:start', function(id, args) {
		        jQuery('.expandable').css("cursor", "default");
		        jQuery('.submission form').hide();
		        document.getElementById('loading').style.display='block';
		      });

		      A.on('io:complete', function (id, o, args) {
		        if (o &amp;&amp; o.responseText) {
		            response = A.JSON.parse(o.responseText);
		        }

		        if (response &amp;&amp; response.success == true) {
		            appSubmitSuccess();
		        } else if (response &amp;&amp; response.success == false) {
		            appSubmitError(response);
		        }
		    });
		},
		['aui-io']
	);

	Liferay.provide(window, 'uploadFile',
		function() {
			var A = AUI();

			 var cfg = {
			        method: "POST",
			        form: {
			            id: "<portlet:namespace />upload_form",
			            upload: true
			        }
			    };
			  A.io('&lt;%= ajaxFileSubmit %&gt;', cfg);
		},
		['aui-io']
	);
</aui:script>


You would still call the code blocks the same way:
setupUploader() and uploadFile(), but this method definition basically guarantees that your function is always available and will fire only when the modules have been loaded.

I hope that's enough info (but not too much that it's overwhelming emoticon, but please let me know if that helps.

Thanks Jim,
thumbnail
Jim Klo, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Junior Member Publications: 75 Date d'inscription: 07/11/08 Publications récentes
Thanks Nate! I will try. Hopefully this solves our woes. Yes, we are including jQuery ourselves - I did know of the early and late binding with aui:script via the use auto/inline, but the Liferay.provide(...) That's a great tidbit of not very well advertised info.
thumbnail
Jim Klo, modifié il y a 13 années.

aui:script with use="aui-io" inhibits look&feel dialog

Junior Member Publications: 75 Date d'inscription: 07/11/08 Publications récentes
Nate, unfortunately this doesn't seem to solve the problem.

Let me clarify a little bit more:

My script code, seems to work fine when using the <aui:script> with 'use' attribute or define the functions using the Liferay.provide(...). However when I do, Liferay's out of the box "Look & Feel" dialog no longer function. All I get is a dialog with spinning loading wheel. If I remove the use or Liferay.provide(...), the "Look & Feel" dialog begins to work again, however my methods which depend on the aui-io no longer work (which would be expected).

Unfortunately I need both working. emoticon
thumbnail
Jakub Liska, modifié il y a 13 années.

RE: aui:script with use="aui-io" inhibits look&feel dialog

Regular Member Publications: 187 Date d'inscription: 25/03/10 Publications récentes
Hi Jim,

would you mind sending JSP (if it is JSP) containing the javascript ? I'm doing a similar thing (form with file upload) but I got stuck cause I'm quite new to javascript. It'd really help.
thumbnail
DO Hung Thuan, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Junior Member Publications: 55 Date d'inscription: 16/09/09 Publications récentes
Nate Cavanaugh:
Hi Jim,
Are there any errors being thrown?

Also, are you including jQuery onto your page? Your code is relying on it, and we don't include it by default anymore in 6.0.5 (you would use the Node package for that), but that might be one possibility.

One other possibility is that you're defining functions inside of the same block as you're doing a "use" statement.

Everything inside of an aui:script block that contains a "use" attribute is called asynchronously, so it could fire right away (if the resources are on the page) or if the network resolution is taking a long time, it could execute later on.

So if you're defining a function inside of there, but then in another piece of code, you're calling one of you're functions before that code has returned, you have a race condition where the function you're trying to execute is defined after the point you call it.

Does that make sense?

I can show you the difference quickly:

<aui:script>alert('not "using" any modules, Im fired right away');</aui:script>

<aui:script use="aui-io">alert('"using" aui-io, Im fired when its ready');</aui:script>


So we make sure never to define a function inside of an aui-script block that has a "use" attribute, unless we're creating another module to be used.

But then how do you define a function that uses a module?

Luckily, we've already solved this problem, and created Liferay.provide.

Here's how your code would look:
<aui:script>
	Liferay.provide(window, 'setupUploader',
		function() {
			var A = AUI();

			A.on('io:start', function(id, args) {
		        jQuery('.expandable').css("cursor", "default");
		        jQuery('.submission form').hide();
		        document.getElementById('loading').style.display='block';
		      });

		      A.on('io:complete', function (id, o, args) {
		        if (o &amp;&amp; o.responseText) {
		            response = A.JSON.parse(o.responseText);
		        }

		        if (response &amp;&amp; response.success == true) {
		            appSubmitSuccess();
		        } else if (response &amp;&amp; response.success == false) {
		            appSubmitError(response);
		        }
		    });
		},
		['aui-io']
	);

	Liferay.provide(window, 'uploadFile',
		function() {
			var A = AUI();

			 var cfg = {
			        method: "POST",
			        form: {
			            id: "<portlet:namespace />upload_form",
			            upload: true
			        }
			    };
			  A.io('&lt;%= ajaxFileSubmit %&gt;', cfg);
		},
		['aui-io']
	);
</aui:script>


You would still call the code blocks the same way:
setupUploader() and uploadFile(), but this method definition basically guarantees that your function is always available and will fire only when the modules have been loaded.

I hope that's enough info (but not too much that it's overwhelming emoticon, but please let me know if that helps.

Thanks Jim,


Hi Nate Cavanaugh
can u tell me more use attribute "USE" in tag "<AUI:SCRIPT>" or link or document? i down't know more it, i don't know how use it.
thumbnail
Jakub Liska, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Regular Member Publications: 187 Date d'inscription: 25/03/10 Publications récentes
Hi Nate,

If I run this exactly as you say,

<liferay-portlet:actionurl var="example">
	<portlet:param name="action" value="example" />
</liferay-portlet:actionurl>

<aui:script>
   Liferay.provide(window, 'uploadFile',
        function() {
            var A = AUI();

             var cfg = {
                    method: "POST",
                    form: {
                        id: "<portlet:namespace />fm2",
                        upload: true
                    }
                };
              alert('works');
              A.io('&lt;%= example %&gt;', cfg);
        },
        ['aui-io']
    );
</aui:script>


I get "J is null" perhaps from YUI.add("io-base", ........... somewhere

I'm quite new to Javascript, debugging these filtered *.min.js files is impossible. I can't find this one that is not filtered anywhere. It should get success response... Do you have any idea what could be wrong ?
thumbnail
Jakub Liska, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Regular Member Publications: 187 Date d'inscription: 25/03/10 Publications récentes
I really don't understand what's wrong,

if I go like this :

	 Liferay.provide(window, 'post',
	        function() {
	
			var A = AUI();
	
			A.io("<liferay-portlet:resourceurl id="example3" />", {
			   method: 'POST',
			   data: {
			     <portlet:namespace />description: 'value'
			   }
			});
	    },
	     ['aui-io']
	  );


everything's fine, but If I do it like this :

    Liferay.provide(window, 'uploadFile1',
        function() {
            var A = AUI();

            A.io("<liferay-portlet:resourceurl id="example3" />", {
                  method: "POST",
                  form: {
                      id: "<portlet:namespace />fm2",
                      upload: false
              		}
        	});
        }
        ['aui-io']
    );


I'm getting these "R is null" "J is null" errors... and the ajax request doesn't start. The "J" errors goes from here

YUI.add("
io - form ", function (emoticon {
....

Uncaught exception: TypeError: Cannot convert 'J' to object
Error thrown at line 197, column 4234 in <anonymous function: _serialize>(M, R):
H=0,O=J.elements.length
called from line 120, column 5085 in a(h, w, p):
q=D.io._serialize(w.form,w.data);
called from line 1, column 5477 in <anonymous function>() in http://localhost:8080/web/guest/home:
a.io("http://localhost:8080/web/guest/home?p_p_id=1_WAR_brokerageportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=example3&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=2",{method:"POST",form:{id:"fm",upload:false}})
called from line 3, column 140481 in <anonymous function: _proxy>(j, n, g, m, f, e):
g.apply(j,l)
called via Function.prototype.apply() from line 3, column 102934 in <anonymous function: h.bind>():
return m.apply(k||m,l)
called via Function.prototype.apply() from line 1, column 9214 in <anonymous function: _notify>(z, w, x):
z(this,w)
called from line 1, column 9075 in <anonymous function: use>(C, emoticon:
C._notify(z,B,w)
called from line 1, column 9214 in <anonymous function: _notify>(z, w, x):
z(this,w)
called from line 1, column 10585 in <anonymous function: _use>(W):
x._notify(B,U,y)
called from line 3, column 64635 in <anonymous function: _finish>(y, x):
w.call(this.context,{msg:y,data:this.data,success:x})
thumbnail
Jakub Liska, modifié il y a 13 années.

RE: <aui:script use="aui-io" /> prevents look&feel pop-

Regular Member Publications: 187 Date d'inscription: 25/03/10 Publications récentes
Omg I knew it. It only works in firefox...

<form id="myform">
	<fieldset id="simpleForm">
		<legend>Example </legend>

			<p>
				<label class="aui-field-label" for="description">Description:</label>
				<input label="Description" name="description">
			</p>

			<p>
				<input class="aui-button-input" type="submit" value="Submit" onClick="uploadFile1()">
				<input class="aui-button-input" type="reset" value="Reset">
			</p>
	</fieldset>
</form>

<aui:script>
    Liferay.provide(window, 'uploadFile1',
        function() {
            var A = AUI();

            A.io("<liferay-portlet:resourceurl id="example3" />", {
                  method: "POST",
                  form: {
                      id: 'myform',
                      upload: false
              		}
        	});
        },
        ['aui-io']
    );
</aui:script>


ISSUE TICKET