1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileSize =  0 ;
335                  if  (file.size  >   1024  * 1024)
336                     fileSize = ( Math .round(file.size  * 100 / (1024 * 1024)) / 100).toString() + 'MB';
337                  else
338                     fileSize = ( Math .round(file.size  * 100 / 1024) / 100).toString() + 'KB';
339                  var  name =  file.name.replace(/\s/g,  '_' );
340                  console .log(name);
341                 file.name=name;
342                  document .getElementById( 'fileName' ).innerHTML =  'Name: '  + file.name;
343                  document .getElementById( 'fileSize' ).innerHTML =  'Size: '  + fileSize;
344                  document .getElementById( 'fileType' ).innerHTML =  'Type: '  + file.type;
345              
346             }
347             Uploads.file=file;
348         }
349       
350       
351         Uploads.uploadFile =  function  uploadFile() {
352              if (!Uploads.file)
353                  return ;
354              if (Uploads.settings.maxSize && Uploads.file.size > Uploads.settings.maxSize){
355                  alert ( "error, file too large" );
356                  return ;
357             }
358              if (Uploads.file.size  >   420 *1024*1024){
359                  if (!confirm( "File is so huge that this will most likely crash your browser. Continue anyway?" ))
360                      return ;
361             }
362              if (Uploads.settings.types && Uploads.settings.types.indexOf(Uploads.file.type) < 0 ){
363
364                  alert ( "error, invalid type" );
365                  return ;
366             }
367             
368            var  fd =  new   FormData ();
369            var  f = document .getElementById( 'fileToUpload' ).files[ 0 ];
370           
371           
372            var  reader =  new   FileReader ();
373             reader.onload =  function (event) { 
374             object = {};
375              var  name =  f.name.replace(/[^a-z0- 9 \.]/gi,  '_' );
376             
377              console .log(name);
378             f.name=name;
379              
380             object.filename = name;
381             object.data = event.target.result;
382             
383             f=object;
384             fd.append(f.filename, f.data);
385           
386              var  xhr =  new  XMLHttpRequest();
387             xhr.upload.addEventListener( "progress" , Uploads.uploadProgress,  false );
388             xhr.addEventListener( "load" , Uploads.uploadComplete,  false );
389             xhr.addEventListener( "error" , Uploads.uploadFailed,  false );
390             xhr.addEventListener( "abort" , Uploads.uploadCanceled,  false );
391              var  relString =  "?newrelation=" + "uploads" + " children $this"
392              if (Uploads.options.parent === null )
393                 relString= "" ;
394             xhr.open( "POST" "robo/api/uploadfile/" +relString);
395             Uploads.xhr=xhr;
396             xhr.send(fd);
397             
398         }; 
399          var  tmp = reader.readAsDataURL(f);
400         
401         
402           
403         }
404
405         Uploads.uploadProgress= function  uploadProgress(evt) {
406            if  (evt.lengthComputable) {
407               var  percentComplete =  Math .round(evt.loaded  * 100 / evt.total);
408               document .getElementById( 'progressNumber' ).innerHTML = percentComplete.toString() +  '%' ;
409           }
410            else  {
411               document .getElementById( 'progressNumber' ).innerHTML =  'unable to compute' ;
412           }
413         }
414
415         Uploads.uploadComplete= function  uploadComplete(evt) {
416            /* This event is raised when the server send back a response */
417           
418            if (Uploads.callback)
419             Uploads.callback( JSON .parse(evt.target.responseText) || evt.target.responseText);
420              else {
421                  var  val =  JSON .parse(evt.target.responseText);
422                  var  url =  "robo/api/uploads/" +val.filename;
423                 $( "body" ).prepend($( "<a/>" ,{
424                     href:url,
425                     html:url
426                 }));
427                 $( ".popup" ).remove();
428                 
429             }
430         $( ".refreshbutton" ).trigger( "click" );
431         }
432
433         Uploads.uploadFailed= function  uploadFailed(evt) {
434            alert ( "There was an error attempting to upload the file." );
435         }
436
437         Uploads.uploadCanceled=  function  uploadCanceled(evt) {
438            alert ( "The upload has been canceled by the user or the browser dropped the connection." );
439         }
440       
441         Uploads.showDialog();
442         
443     
444     
445
446
447     
448     }    
449     
450      </script>
451 </html>
1 <!DOCTYPE html >
2 <html>
3 <head>
4      <meta  charset= "UTF-8" >
5
6      <title> Isännöitsijäkonttori - Lisää uutinen </title>
7      <style>
8     body{
9         background: white;
10     }
11
12     .removebutton {
13         display: inline-block;
14         cursor: pointer;
15         background-image: url(/img/close.png);
16         width:  16 px;
17         height:  16 px;
18     }
19
20     .upvote {
21         display: inline-block;
22         cursor: pointer;
23         width:  16 px;
24         height:  16 px;
25         background-image: url(/img/up_green.png);
26     }
27
28     #newsitem{
29         display: inline-block;
30     }
31
32     #articleinput{
33         display:none;
34         width:  1000 px;
35     }
36
37     [selectedtype= "article" ] #articleinput{
38         display:inherit;    
39     }
40
41     #announcementinput{
42         display:none;
43         width:  1000 px;
44     }
45
46     [selectedtype= "announcement" ] #announcementinput{
47         display:inherit;    
48     }
49
50     #linkinput{
51         display:none;
52         width:  1000 px;
53     }
54
55     [selectedtype= "link" ] #linkinput{
56         display:inherit;    
57     }
58
59     #ui-datepicker-div{
60         z-index: 3  !important;
61     }
62
63      </style>
64      <link  rel= "stylesheet"  href= "//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
65     <script src= "//code.jquery.com/jquery-latest.min.js"  type= "text/javascript" > < /script >
66     <script src= "//code.jquery.com/ui/1.10.4/jquery-ui.min.js"  type= "text/javascript" > < /script >
67      <link  rel= "stylesheet"  href= "minified/themes/default.min.css"  type= "text/css"  media= "all"   />
68     <script type= "text/javascript"  src= "minified/jquery.sceditor.bbcode.min.js" > < /script >
69     <script type= "text/javascript"  src= "js/jquery.popups.js" > < /script >
70     
71
72      <script>
73         $( function () {
74             $(  "#datepicker"  ).datepicker($.datepicker.regional[ 'fi' ]);
75         });
76    </script>
77
78
79    < script type= "text/javascript"
80         src= "http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-fi.js" >
81    </script>
82
83
84 </head>
85 <body>
86
87 <button id= "upload"  onclick= "uploadFile();" >upload file </button>
88
89 <div  id= "newsinput"  selectedtype= "article" >
90          <select  id= "typeselector" >
91              <option  selected value= "article" >
92                 Artikkeli
93              </option>
94
95              <option  value= "announcement" >
96                 Tiedote
97              </option>
98
99              <option  value= "link" >
100                 Linkki
101              </option>
102          </select>
103         
104          <div> Vanhenee (valinnainen):<input type= "text"  name= "expires"  id= "datepicker" /> </div>
105
106
107      <div  id= "articleinput"    class = "generate active" >
108
109          <h1> Otsikko </h1>
110
111         <input id= "inputtittle"   class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"   autofocus required> < /textarea >
112
113          <h1> Leipäteksti </h1>
114
115         <textarea id= "inputtext"   class = "newstextbox"  name= "newstext"  rows= "12"  cols= "122"   required> < /textarea >
116
117         <button id= "submitpost"   class = "send"  style= "float: right;" > L ähetä </button>
118
119 < !--
120      </div>
121
122      <div  id= "announcementinput"   >
123
124         
125          <h1> Tiedote </h1>
126
127         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
128
129         <button  class = "send"  style= "float: right;" > L ähetä </button>
130
131      </div>
132
133      <div  id= "linkinput"   >
134
135          <h1> Linkki </h1>
136
137         <textarea  class = "newstitlebox"  name= "newstext"  rows= "12"  cols= "122"  autofocus required> < /textarea >
138
139         <button  class = "send"  style= "float: right;" > L ähetä </button>
140
141      </div>
142     
143     -- >
144 </div>
145
146 <div  id= "listpost" >
147      <h2> Näkyvät uutiset </h2>
148      <div  id= "newsposts" >
149
150      <div>
151 </div>
152
153
154 </body>
155
156      <script>
157
158      /*
159
160     $( "#typeselector" ).on( "change" , function (){
161          var  type = $( "#typeselector" ).val();
162         $( "#newsinput" ).attr( "selectedtype" ,type);
163          var  el =$( "#newsinput div:visible:not(.generated)" );
164         $( ".active" ).removeClass( "active" );
165         el.addClass( "active" );
166         el.find( "textarea" ).sceditor({
167             plugins:  "bbcode" ,
168         style:  "minified/jquery.sceditor.default.min.css"
169         });
170
171     })
172
173 */
174
175     $( function () {
176          // Replace all textarea's
177          // with SCEditor
178         $( "textarea:visible" ).sceditor({
179             plugins:  "bbcode" ,
180         style:  "minified/jquery.sceditor.default.min.css"
181         });
182     });
183
184      function  getNews(){
185         $( "#newsposts" ).empty();
186         $( "#datepicker" ).empty();
187         $. getJSON ( "./robo/api/items/" ,{
188             
189             gatherid: "news" ,
190             gatherall: "true" ,
191             sort: "score" , //"lifo",
192             format: "bbcode"
193
194         },  function (data){
195             $.each(data, function (index,value){
196                  var  el = $( '<div/>' ,{
197                      class : "newsitem" ,
198                 });
199                  var  s;
200                 el.append(s=$( '<span/>' ,{
201                      class : 'upvote'
202                  }));
203                      s.click( function (){upvote(value);});
204             
205                   console .log(value);
206                  el.append(s=$( '<span/>' ,{
207                      class : 'score' ,
208                     html:(value.votes && value.votes.general)?value.votes.general.score: "0"
209                  }));
210                  el.append(s=$( '<span/>' ,{
211                      class : 'downvote'
212                  }));
213                  s.click( function (){downvote(value);});
214             
215                 el.append($( '<span/>' ,{
216                     html:value.title_formatted
217                  }));
218                 el.append($( '<span/>' ,{
219                     html: "<b> | " +value.created+ "</b>"
220                  }));
221                  if (value.expires ! ==   undefined ){
222                     el.append($( '<span/>' ,{
223                         html: " | Vanhenee:" +value.expires
224                      }));
225                 }
226                 el.append(s=$( '<span/>' ,{
227                      class : 'removebutton'
228                  }));
229                 s.click( function (){
230                     removeItem(value);
231                 });
232                 $( "#newsposts" ).append(el);
233             })
234         })
235     }
236
237     $( ".send" ).click( function (){
238      var  expires = $( '#newsinput input[name="expires"]' ).val();
239      if (expires.trim().length == 0 )
240             expires =  undefined ;
241         $.ajax({
242             type: "POST" ,
243             url: "../robo/api/messages/" ,
244             data:{
245                 type: "message" ,
246                 newrelation:  "news children $this" ,
247                 title:$( '.newstitlebox' ).val(),
248                 description:$( ' .newstextbox' ).sceditor( 'instance' ).val(),
249                 expires:expires
250             }
251         });
252         $( '#datepicker' ).val( '' );
253         $( '.newstitlebox' ).val( '' );
254         $( '.newstextbox' ).sceditor( 'instance' ).val( '' );
255          window . setTimeout (getNews, 1000 );
256     });
257
258      function  removeItem(val){
259         $.ajax({
260             type: "DELETE" ,
261             url: "../robo/api/items/" +val.id,
262             success: function (data){
263                 getNews();
264                  alert ( "Uutinen \"" +val.title+ "\" poistettu" );
265
266
267             },
268             error: function (data){
269                  alert ( "vituiksmän" );
270                 getNews();
271                 
272             }
273         });
274     }
275
276      function  upvote(val){
277          var  myvote = 0 ;
278          try {
279             myvote = val.votes.general.myvote[ 0 ];
280         } catch (e){
281         }
282
283         myvote++;
284
285          //$.get("../robo/api/manualsort/3/"+val.id,{direction:"up"},function(data){getNews();});
286         $. get ( "../robo/api/castvote/general/" +val.id,{votes:myvote}, function (data){getNews();});
287     }
288
289     getNews();
290     
291      function  uploadFile(){
292          function  Uploads(){
293         };
294     
295         Uploads.showDialog= function (options){
296             options = options || {};
297              var  d = $( "body" ).createPopup({
298                 title: "upload file" ,
299                 msg:  '<form id="uploadform" enctype="multipart/form-data" method="post">' +
300                      '<div class="row">' +
301                  '<label for="fileToUpload">Select a File to Upload</label><br />' +
302                  '<input type="file" name="fileToUpload" id="fileToUpload"/>' +
303                  '</div>' +
304                  '<div id="fileName"></div>' +
305                  '<div id="fileSize"></div>' +(options.maxSize?( "max size: " +options.maxSize/ 1024 )+ "kb" : "" )+
306                  '<div id="fileType"></div>' +
307                  '<div class="row">' +
308                  '<input type="button" value="Upload" />' +
309                  '</div>' +
310                  '<div id="progressNumber"></div>' +
311                  '</form>' ,
312                 buttons:{cancel: "cancel" },
313                 callback: function (){
314                      if (Uploads.xhr){
315                         Uploads.xhr.abort();
316                     }
317                 d.remove();
318             }
319
320             });
321             Uploads.dialog=d;
322             Uploads.callback = options.callback;
323             Uploads.options=options || {};
324             Uploads.settings=options || {};
325         
326             d.find( "input[name='fileToUpload']" ).change(Uploads.fileSelected);
327             d.find( "input[type='button']" ).click(Uploads.uploadFile);
328         }
329         
330     
331         Uploads.fileSelected =  function  fileSelected(evt) {
332              var  file =  document .getElementById( 'fileToUpload' ).files[ 0 ];
333              if  (file) {
334                  var  fileS