Skip to content

Commit e66b914

Browse files
committed
Code refactored
1 parent ef96178 commit e66b914

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2878
-2645
lines changed

admin-js/admin-router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
Exyht.Router.map(function() {
77
this.route('index', {path: Exyht.BaseUrl});
8-
this.route('comments', {path: Exyht.BaseUrl+'/comments/:post_id'});
8+
this.route('comment', {path: Exyht.BaseUrl+'/comment/:post_id'});
99
this.route('typeblogpost', {path: Exyht.BaseUrl+'/typeblogpost'});
1010
this.route('profilesetting', {path: Exyht.BaseUrl+'/profilesetting'});
1111
this.route('uisettings', {path: Exyht.BaseUrl+'/uisettings'});
@@ -29,11 +29,11 @@ model: function()
2929
}
3030
});
3131

32-
Exyht.CommentsRoute = Ember.Route.extend({
32+
Exyht.CommentRoute = Ember.Route.extend({
3333
model: function(params)
3434
{
3535
return Ember.$.getJSON(Exyht.currentBaseUri+'/getComments/'+params.post_id).then(function(data) {
36-
return data;
36+
return {"comments":data};
3737
});
3838
}
3939
});

admin-js/component/count-posts.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
|-------------------------
3+
| Count posts Component
4+
|-------------------------
5+
*/
6+
Exyht.CountPostsComponent = Ember.Component.extend({
7+
numberOfPost: function() {
8+
var response,
9+
NoOfPost = this.get("posts").get('length');
10+
11+
if(NoOfPost === 1){
12+
response = "1 Post";
13+
}else if(NoOfPost > 1){
14+
response = NoOfPost+" Posts";
15+
}else{
16+
response = "No Post";
17+
}
18+
return response;
19+
}.property("posts")
20+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
|---------------------------
3+
| Editor action Component
4+
|---------------------------
5+
*/
6+
Exyht.EditorActionComponent = Ember.Component.extend({
7+
isSavingAsDraft: false,
8+
isPublishing: false,
9+
status: [
10+
{postStatus: "Publish", id: 1},
11+
{postStatus: "Draft", id: 0}
12+
],
13+
currentStatus: {
14+
id: 1
15+
},
16+
actions: {
17+
createPost: function(value1, value2){
18+
var blogTitle = this.get('ntitle').trim();
19+
var blogBody = this.get('nbody').trim();
20+
21+
var self = this;
22+
23+
if ((!blogTitle || blogTitle.length < 5) || (!blogBody || blogBody.length < 20)) {
24+
return false;
25+
}
26+
this.set(value1, true);
27+
console.log('Request: Sending request');
28+
29+
return $.ajax({
30+
type: "POST",
31+
url: Exyht.BaseUrl+"/"+value2,
32+
data: {title: blogTitle, body: blogBody},
33+
success: function(msg){
34+
console.log('Response: '+msg);
35+
self.set(value1, false);
36+
self.setProperties({
37+
'ntitle': '',
38+
'nbody': ''
39+
});
40+
alert(msg);
41+
}
42+
});
43+
},
44+
createNew: function(){
45+
this.send('createPost', 'isPublishing', 'createNewPost');
46+
},
47+
createDraft: function(){
48+
this.send('createPost', 'isSavingAsDraft', 'createNewDraft');
49+
},
50+
saveProfileEdit: function(){
51+
var aboutAuthor = this.get('nbody').trim();
52+
console.log('Request: Sending request');
53+
$.ajax({
54+
type: "POST",
55+
url: Exyht.BaseUrl+"/saveProfileEdit",
56+
data: {about: aboutAuthor},
57+
success: function(msg){
58+
console.log('Response: '+msg);
59+
alert(msg);
60+
}
61+
});
62+
},
63+
cancelProfileEditing: function(){
64+
this.setProperties({
65+
'isProfileEditingOn': false,
66+
'isEditingOn': false,
67+
'ntitle': '',
68+
'nbody': '',
69+
'postId': '',
70+
'editOnForProfSetContr': false
71+
});
72+
},
73+
saveEdit: function(postId){
74+
var blogTitle = this.get('ntitle').trim();
75+
var blogBody = this.get('nbody').trim();
76+
var status = this.get('currentStatus.id');
77+
if ((!blogTitle || this.get('ntitle').length < 5) || (!blogBody || this.get('nbody').length < 20)/* || !csrfToken*/) {
78+
return false;
79+
}
80+
$.ajax({
81+
type: "POST",
82+
url: Exyht.BaseUrl+"/saveEdit",
83+
data: {postId: postId, title: blogTitle, body: blogBody, status: status},
84+
success: function(msg){
85+
console.log('Response: '+msg);
86+
alert(msg);
87+
}
88+
});
89+
},
90+
cancelEditing: function(){
91+
this.setProperties({
92+
'isEditingOn': false,
93+
'ntitle': '',
94+
'nbody': '',
95+
'postId': ''
96+
});
97+
}
98+
}
99+
});

admin-js/component/editor-tools.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
|---------------------------
3+
| Editor tools Component
4+
|---------------------------
5+
*/
6+
Exyht.EditorToolsComponent = Ember.Component.extend({
7+
postKey: function(){
8+
9+
var nbodyLength = this.get('nbody').length;
10+
var leastNewBodyLength = Math.abs(20 - nbodyLength);
11+
12+
if(nbodyLength === 0 || nbodyLength < 20){
13+
14+
this.set('showNbodyLength', true);
15+
16+
}else{
17+
18+
this.set('showNbodyLength', false);
19+
}
20+
21+
this.set('newBodyLength', leastNewBodyLength);
22+
23+
}.observes('nbody'),
24+
actions: {
25+
// Editor tools
26+
ctv: function(input){
27+
var textarea = $('textarea');
28+
textarea.val(textarea.val() + input);
29+
},
30+
citv: function(input1, input2){
31+
var textarea = $('textarea');
32+
if (textarea.val() === ''){
33+
textarea.val(textarea.val() + input1);
34+
}else{
35+
textarea.val(textarea.val() + input2);
36+
}
37+
},
38+
insertBold: function(){
39+
this.send('ctv', " **bold** ");
40+
},
41+
insertItalic: function(){
42+
this.send('ctv', " *italic* ");
43+
},
44+
insertLink: function(){
45+
this.send('citv', "[Link description](http://example.com)", "\n [Link description](http://example.com)");
46+
},
47+
insertQuote: function(){
48+
this.send('ctv', "\n > your quote here");
49+
},
50+
insertCode: function(){
51+
this.send('citv', "`For inline code` \n\n\tFor pre code", "\n\n`For inline code` \n\n\tFor pre code");
52+
},
53+
imgTabStatus: function(){
54+
this.set('isImageTab', true);
55+
},
56+
vidTabStatus: function(){
57+
this.set('isImageTab', false);
58+
},
59+
ivtask: function(value){
60+
var textarea = $('textarea');
61+
var ivUrl = $('#'+value+'UrlTextField');
62+
if (ivUrl.val() === ''){
63+
var iveVal = (value == 'image')?"![alt text](http://example.com/image.jpg)":"![isyoutube](Link to youtube)";
64+
textarea.val(textarea.val() + iveVal);
65+
}else{
66+
var ivVal = (value == 'image')?'alt text':'isyoutube';
67+
textarea.val(textarea.val() + "!["+ivVal+"]("+ivUrl.val()+")");
68+
}
69+
ivUrl.val('');
70+
},
71+
insertImage: function(){
72+
if(this.get('isImageTab') === true){
73+
this.send('ivtask', 'image');
74+
}else{
75+
this.send('ivtask', 'video');
76+
}
77+
},
78+
cancelUploadImage: function(){
79+
$("#loadingDiv").hide();
80+
},
81+
insertOrderedlist: function(){
82+
this.send('ctv', "Indent one space after the dot \'.\'\n\n1. Ordered list1\n2. Ordered list2");
83+
},
84+
insertUnorderedlist: function(){
85+
this.send('ctv', "Indent one space after the + or -.\n\n- Unordered list1\n\t+ Nested list");
86+
},
87+
insertHorizontalrule: function(){
88+
this.send('citv', "-----\nNew line", "\n\n-----\nNew line");
89+
},
90+
insertStrikethrough: function(){
91+
this.send('ctv', "<del>Strike through</del>");
92+
},
93+
insertSubscript: function(){
94+
this.send('ctv', "Sub<sub>script</sub>");
95+
},
96+
insertSuperscript: function(){
97+
this.send('ctv', "Sub<sup>script</sup>");
98+
},
99+
insertHeading1: function(){
100+
this.send('citv', "# Heading1\n", "\n# Heading1\n");
101+
},
102+
insertHeading2: function(){
103+
this.send('citv', "# Heading2\n", "\n# Heading2\n");
104+
},
105+
insertHeading3: function(){
106+
this.send('citv', "# Heading3\n", "\n# Heading3\n");
107+
},
108+
resetTextarea: function(){
109+
var textarea = $('textarea');
110+
textarea.val("");
111+
}
112+
}
113+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
|---------------------------
3+
| Image gallery Component
4+
|---------------------------
5+
*/
6+
Exyht.ImageGalleryComponent = Ember.Component.extend({
7+
img_from: 15, // load more pics offset
8+
img_to: 30, // load more pics limit
9+
totalImgs: function(){
10+
var galryLen = this.get('images').filterBy('img_visible', true).get('length');
11+
return (galryLen > 0)?galryLen : 0;
12+
}.property('images.@each.img_visible'),
13+
14+
inInsert: function(){
15+
this.scheduleMasonry();
16+
$(window).on('scroll', $.proxy(this.didScroll, this));
17+
}.on('didInsertElement'),
18+
19+
onLeaving: function(){
20+
this.destroyMasonry();
21+
this.setProperties({
22+
'img_from': 15,
23+
'img_to': 30
24+
});
25+
$(window).off('scroll', $.proxy(this.didScroll, this));
26+
}.on('willDestroyElement'),
27+
28+
scheduleMasonry: function(){
29+
Ember.run.scheduleOnce('afterRender', this, this.applyMasonry);
30+
}.observes('images.@each'),
31+
32+
applyMasonry: function(){
33+
var $galleryContainer = $('#galleryContainer');
34+
// initialize
35+
$galleryContainer.imagesLoaded(function() {
36+
// check if masonry is initialized
37+
var msnry = $galleryContainer.data('masonry');
38+
if ( msnry ) {
39+
msnry.reloadItems();
40+
// disable transition
41+
var transitionDuration = msnry.options.transitionDuration;
42+
msnry.options.transitionDuration = 0;
43+
msnry.layout();
44+
// reset transition
45+
msnry.options.transitionDuration = transitionDuration;
46+
} else {
47+
// init masonry
48+
$galleryContainer.masonry({
49+
itemSelector: '.item',
50+
columnWidth: 150
51+
});
52+
}
53+
});
54+
},
55+
56+
destroyMasonry: function(){
57+
$('#galleryContainer').masonry('destroy');
58+
},
59+
60+
didScroll: function(){
61+
if($(window).scrollTop() + $(window).height() == $(document).height()){
62+
// Debounce for 1 second
63+
Ember.run.debounce(this, this.loadPics, 1000);
64+
}
65+
},
66+
67+
loadPics: function(){
68+
// Request for more 15 imgs
69+
// Request for large number of imgs will make the App slow
70+
var g_imgs = this.get('images'),
71+
self = this,
72+
g_img_from = this.get('img_from'),
73+
g_img_to = this.get('img_to');
74+
75+
if(g_img_from <= (this.get('totalImgs') + 15)){
76+
// Make the request to the server for more imgs
77+
$.getJSON(Exyht.currentBaseUri+'/getGalleryImg/'+g_img_from+'/'+g_img_to).then(function(data) {
78+
// Set new offset & limit, to load next imgs
79+
self.set('img_from', self.get('img_to'));
80+
var moreImgTo = parseInt(self.get('img_from')) + 15;
81+
self.set('img_to', moreImgTo);
82+
// Iterate responsed data
83+
$.each(data, function(index){
84+
// Don't push if responsed img id matches with the already pushed last img's id
85+
if(data[index].id != (g_img_to + 1)){
86+
g_imgs.pushObject({
87+
id: data[index].id,
88+
src_path: data[index].src_path,
89+
img_visible: data[index].img_visible
90+
});
91+
}
92+
});
93+
});
94+
}
95+
}
96+
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
|----------------
3-
| App Controller
4-
|----------------
2+
|---------------------------
3+
| Log out Component
4+
|---------------------------
55
*/
6-
Exyht.ApplicationController = Ember.ObjectController.extend({
6+
Exyht.LogOutComponent = Ember.Component.extend({
77
actions: {
88
logOut: function(){
99
$.post( Exyht.BaseUrl+"/logout", function( data ) {
@@ -12,5 +12,5 @@ Exyht.ApplicationController = Ember.ObjectController.extend({
1212
}
1313
});
1414
}
15-
},
15+
}
1616
});

0 commit comments

Comments
 (0)