Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
Expand All @@ -24,6 +25,7 @@
import android.support.v4.app.NotificationCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
Expand Down Expand Up @@ -574,7 +576,7 @@ private void trackSavePostAnalytics() {

// Menu actions
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(final MenuItem item) {
int itemId = item.getItemId();

if (itemId == android.R.id.home) {
Expand Down Expand Up @@ -604,34 +606,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}

// Disable ActionBar buttons while there are failed media uploads in the post/page
if (mEditorFragment.hasFailedMediaUploads()) {
ToastUtils.showToast(this, R.string.editor_toast_failed_uploads, Duration.SHORT);
return false;
}

if (itemId == R.id.menu_save_post) {
// If the post is new and there are no changes, don't publish
updatePostObject(false);
if (!mPost.isPublishable()) {
ToastUtils.showToast(this, R.string.error_publish_empty_post, Duration.SHORT);
return false;
}

savePostToDb();
trackSavePostAnalytics();

if (!NetworkUtils.isNetworkAvailable(this)) {
ToastUtils.showToast(this, R.string.error_publish_no_network, Duration.SHORT);
return false;
}

PostUploadService.addPostToUpload(mPost);
PostUploadService.setLegacyMode(!mShowNewEditor);
startService(new Intent(this, PostUploadService.class));
setResult(RESULT_OK);
finish();
return true;
return savePost();
} else if (itemId == R.id.menu_preview_post) {
mViewPager.setCurrentItem(PAGE_PREVIEW);
} else if (itemId == R.id.menu_post_settings) {
Expand All @@ -645,6 +621,44 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}

private boolean savePost() {
// Show an Alert Dialog asking the user if he wants to remove all failed media before upload
if (mEditorFragment.hasFailedMediaUploads()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.editor_toast_failed_uploads)
.setPositiveButton(R.string.editor_remove_failed_uploads, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Clear failed uploads
mEditorFragment.removeAllFailedMediaUploads();
}
}).setNegativeButton(android.R.string.cancel, null);
builder.create().show();
return true;
}

// If the post is new and there are no changes, don't publish
updatePostObject(false);
if (!mPost.isPublishable()) {
ToastUtils.showToast(this, R.string.error_publish_empty_post, Duration.SHORT);
return false;
}

savePostToDb();
trackSavePostAnalytics();

if (!NetworkUtils.isNetworkAvailable(this)) {
ToastUtils.showToast(this, R.string.error_publish_no_network, Duration.SHORT);
return false;
}

PostUploadService.addPostToUpload(mPost);
PostUploadService.setLegacyMode(!mShowNewEditor);
startService(new Intent(this, PostUploadService.class));
setResult(RESULT_OK);
finish();
return true;
}

@Override
public void openContextMenu(View view) {
if (PermissionUtils.checkAndRequestCameraAndStoragePermissions(this, MEDIA_PERMISSION_REQUEST_CODE)) {
Expand Down
4 changes: 3 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,9 @@
<string name="editor_toast_invalid_path">Invalid file path</string>
<string name="editor_toast_changes_saved">Changes saved</string>
<string name="editor_toast_uploading_please_wait">You are currently uploading media. Please wait until this completes.</string>
<string name="editor_toast_failed_uploads">Some media uploads have failed. Please retry them or delete them.</string>
<string name="editor_toast_failed_uploads">Some media uploads have failed. You can\'t save or publish
your post in this state. Would you like to remove all failed media?</string>
<string name="editor_remove_failed_uploads">Remove failed uploads</string>

<!-- failure messages when retrieving a single reader post -->
<string name="reader_err_get_post_generic">Unable to retrieve this post</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ public boolean hasFailedMediaUploads() {
return (mFailedMediaIds.size() > 0);
}

@Override
public void removeAllFailedMediaUploads() {
mWebView.execJavaScriptFromString("ZSSEditor.removeAllFailedMediaUploads();");
}

@Override
public Spanned getSpannedContent() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
public abstract void setUrlForVideoPressId(String videoPressId, String url, String posterUrl);
public abstract boolean isUploadingMedia();
public abstract boolean hasFailedMediaUploads();
public abstract void removeAllFailedMediaUploads();
public abstract void setTitlePlaceholder(CharSequence text);
public abstract void setContentPlaceholder(CharSequence text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,9 @@ public boolean hasFailedMediaUploads() {
return false;
}

@Override
public void removeAllFailedMediaUploads() {}

@Override
public void setTitlePlaceholder(CharSequence text) {

Expand Down
46 changes: 33 additions & 13 deletions libs/editor/libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ ZSSEditor.onMutationObserved = function(mutations) {
var mediaIdentifier = removedNode.attributes.getNamedItem("data-wpid").value;
var parentRange = ZSSEditor.getParentRangeOfFocusedNode();
ZSSEditor.removeImage(mediaIdentifier);
ZSSEditor.setRange(parentRange);
if (parentRange != null) {
ZSSEditor.setRange(parentRange);
}
ZSSEditor.sendMediaRemovedCallback(mediaIdentifier);
} else if (removedNode.attributes.getNamedItem("data-video_wpid")) {
// An uploading or failed video was deleted manually - remove its container and send the callback
var mediaIdentifier = removedNode.attributes.getNamedItem("data-video_wpid").value;
var parentRange = ZSSEditor.getParentRangeOfFocusedNode();
ZSSEditor.removeVideo(mediaIdentifier);
ZSSEditor.setRange(parentRange);
if (parentRange != null) {
ZSSEditor.setRange(parentRange);
}
ZSSEditor.sendMediaRemovedCallback(mediaIdentifier);
}
}
Expand Down Expand Up @@ -945,34 +949,39 @@ ZSSEditor.markAllUploadingMediaAsFailed = function(message) {
}
};

/**
* @brief Sends a callback with a list of failed images
*/
ZSSEditor.getFailedMedia = function() {
ZSSEditor.getFailedMediaIdArray = function() {
var html = ZSSEditor.getField("zss_field_content").getHTML();
var tmp = document.createElement( "div" );
var tmpDom = $( tmp ).html( html );
var matches = tmpDom.find("img.failed");

var functionArgument = "function=getFailedMedia";
var mediaIdArray = [];

for (var i = 0; i < matches.size(); i++) {
var mediaId;
var mediaId = null;
if (matches[i].hasAttribute("data-wpid")) {
mediaId = matches[i].getAttribute("data-wpid");
} else if (matches[i].hasAttribute("data-video_wpid")) {
mediaId = matches[i].getAttribute("data-video_wpid");
}

// Track pre-existing failed media nodes for manual deletion events
ZSSEditor.trackNodeForMutation(this.getMediaContainerNodeWithIdentifier(mediaId));

if (mediaId.length > 0) {
if (mediaId !== null) {
mediaIdArray.push(mediaId);
}
}
return mediaIdArray;
};

/**
* @brief Sends a callback with a list of failed images
*/
ZSSEditor.getFailedMedia = function() {
var mediaIdArray = ZSSEditor.getFailedMediaIdArray();
for (var i = 0; i < mediaIdArray.length; i++) {
// Track pre-existing failed media nodes for manual deletion events
ZSSEditor.trackNodeForMutation(this.getMediaContainerNodeWithIdentifier(mediaIdArray[i]));
}

var functionArgument = "function=getFailedMedia";
var joinedArguments = functionArgument + defaultCallbackSeparator + "ids=" + mediaIdArray.toString();
ZSSEditor.callback('callback-response-string', joinedArguments);
};
Expand Down Expand Up @@ -1261,6 +1270,14 @@ ZSSEditor.removeImage = function(imageNodeIdentifier) {
}
};

ZSSEditor.removeAllFailedMediaUploads = function() {
console.log("Remove all failed media");
var failedMediaArray = ZSSEditor.getFailedMediaIdArray();
for (var i = 0; i < failedMediaArray.length; i++) {
ZSSEditor.removeImage(failedMediaArray[i]);
}
}

/**
* @brief Inserts a video tag using the videoURL as source and posterURL as the
* image to show while video is loading.
Expand Down Expand Up @@ -2765,6 +2782,9 @@ ZSSEditor.parentTags = function() {

ZSSEditor.getParentRangeOfFocusedNode = function() {
var selection = window.getSelection();
if (selection.focusNode == null) {
return null;
}
return selection.getRangeAt(selection.focusNode.parentNode);
};

Expand Down